Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
d9fb001
feat(dashscope): implement DashScope integration with auto/manual cac…
lihq1403 Aug 20, 2025
08c02a3
feat(client): Add DashScope client integration and intelligent routin…
lihq1403 Aug 20, 2025
c7869a1
fix(client): Update request options to use RequestOptions constants a…
lihq1403 Aug 20, 2025
cc34276
feat(usage): Enhance DashScope usage handling with conversion and cac…
lihq1403 Aug 21, 2025
7b27fdb
fix(response): Correct cached_tokens assignment to use cacheReadInput…
lihq1403 Aug 21, 2025
8605749
feat(usage): Enhance usage tracking and conversion for improved cache…
lihq1403 Aug 21, 2025
192d8fa
feat(errors): Add status code handling to custom exception classes fo…
lihq1403 Aug 22, 2025
2265a1d
feat(tokens): Update token calculations to include cache write tokens…
lihq1403 Aug 25, 2025
fd3e83f
feat(toolCalls): Normalize tool call IDs for cross-platform compatibi…
lihq1403 Sep 5, 2025
befa674
feat(errors): Enrich context with Guzzle RequestException response in…
lihq1403 Sep 5, 2025
c08ca2f
feat(toolCalls): Add handling for empty tool call IDs in normalizatio…
lihq1403 Sep 7, 2025
a9da3f1
feat(logging): Enhance logging with checkpoint intervals and duration…
lihq1403 Sep 11, 2025
9a00b8a
feat(timeout): Introduce stream_total timeout configuration for impro…
lihq1403 Sep 11, 2025
e0f3040
feat(timeout): Add stream_total configuration for total stream timeou…
lihq1403 Sep 11, 2025
ce337b2
feat(errors): Enhance LLMInvalidRequestException with detailed provid…
lihq1403 Sep 16, 2025
e653fb8
feat(validation): Add image format validation for user messages in Ch…
lihq1403 Sep 16, 2025
4aa8f48
feat(validation): Simplify error message for unsupported image format…
lihq1403 Sep 16, 2025
0f7bcc9
feat(imageDownloader): Add ImageDownloader utility for downloading an…
lihq1403 Sep 16, 2025
36e0e07
feat(message): Trim whitespace from content and text properties in me…
lihq1403 Sep 16, 2025
bd17d44
feat(sse): Implement early closure for SSE client on [DONE] event
lihq1403 Sep 16, 2025
7ddb173
feat(sse): Enhance exception detection with detailed chunk informatio…
lihq1403 Sep 16, 2025
3cdcddf
feat(message): Trim whitespace from content in AbstractMessage constr…
lihq1403 Sep 19, 2025
b6894a1
feat(config): Use environment variables for Azure OpenAI configuration
lihq1403 Oct 1, 2025
eafb482
feat(error): Ensure stream is seekable before rewinding response body…
lihq1403 Oct 19, 2025
2fe83d2
feat(tests): Mock closeEarly method in ChatCompletionStreamResponseTe…
lihq1403 Oct 20, 2025
78acb8c
refactor: Update nullable type declarations for improved readability
lihq1403 Oct 20, 2025
3f7c06a
feat(error): Enhance error handling to extract messages from response…
lihq1403 Oct 20, 2025
2d430ac
feat(i18n): Update error messages and suggestions to English for impr…
lihq1403 Oct 20, 2025
76c2a00
feat(logging): Add logging for last chunk data in stream processing m…
lihq1403 Oct 23, 2025
cd40189
feat(sse): Improve SSEClient for non-blocking stream reading and buff…
lihq1403 Oct 23, 2025
e2687c9
feat(sse): Increase buffer size for non-blocking data reads in SSEClient
lihq1403 Oct 23, 2025
31e76d0
feat(sse): Increase buffer size for non-blocking data reads in SSEClient
lihq1403 Oct 23, 2025
fb8e5cd
feat(logging): Log first and last 5 chunks in response stream processing
lihq1403 Oct 24, 2025
d51680c
feat(aws-bedrock): Add custom client and event stream parser without …
lihq1403 Oct 24, 2025
db20c18
feat(aws-bedrock): Enhance AwsEventStreamParser for non-blocking stre…
lihq1403 Oct 24, 2025
61c23de
refactor(CustomConverseStreamConverter): remove unused chunk return s…
lihq1403 Oct 27, 2025
911227a
feat(model-options): add default and max tokens configuration options
lihq1403 Oct 27, 2025
94a5b9b
feat(ConverseCustomClient): URL-encode model ID to support special ch…
lihq1403 Oct 28, 2025
b690b11
feat(aws-bedrock): Implement first chunk timeout for streaming reques…
lihq1403 Oct 29, 2025
4ad8019
feat(aws-bedrock): Enhance AwsEventStreamParser with improved timeout…
lihq1403 Oct 30, 2025
544958b
refactor(SSEClient): Simplify stream reading logic and improve event …
lihq1403 Oct 30, 2025
2f54591
refactor(AwsEventStreamParser): Simplify message reading and remove m…
lihq1403 Oct 30, 2025
e59e22a
feat(transport): Implement OdinSimpleCurl for enhanced streaming requ…
lihq1403 Oct 31, 2025
1c504eb
refactor(SimpleCURLClient): Increase header channel capacity and impr…
lihq1403 Oct 31, 2025
89620e3
refactor(SimpleCURLClient): Increase write channel capacity for impro…
lihq1403 Oct 31, 2025
752dcf2
feat(ConverseCustomClient): Implement support for OdinSimpleCurl in c…
lihq1403 Nov 1, 2025
8bd1d2f
feat(SimpleCURLClient): Enhance timeout handling and improve error re…
lihq1403 Nov 1, 2025
d0c0d6b
feat(SimpleCURLClient): Add configurable header timeout for improved …
lihq1403 Nov 1, 2025
516f4c3
refactor(OdinSimpleCurl, SimpleCURLClient): Replace RuntimeException …
lihq1403 Nov 1, 2025
9d8118d
feat(AwsEventStreamParser, SimpleCURLClient): Improve stream reading …
lihq1403 Nov 1, 2025
038b324
feat(AwsEventStreamParser, SimpleCURLClient, SSEClient): Add detailed…
lihq1403 Nov 1, 2025
78d0651
refactor(SSEClient): Move stream validity check after yielding chunk …
lihq1403 Nov 3, 2025
0e8c90d
refactor(ChatCompletionStreamResponse): Use TimeUtil for duration cal…
lihq1403 Nov 3, 2025
d96b54b
feat(SimpleCURLClient): Add lastRead property for tracking last read …
lihq1403 Nov 3, 2025
9a271f4
feat(SimpleCURLClient): Enhance last read tracking with array storage…
lihq1403 Nov 3, 2025
5264232
feat(SSEClient): Add logging for last read chunks from SimpleCURLClie…
lihq1403 Nov 4, 2025
1b72b9e
refactor(SimpleCURLClient): Simplify destructor and update last read …
lihq1403 Nov 4, 2025
69fec50
refactor(SimpleCURLClient): Remove unnecessary EOF flag manipulation …
lihq1403 Nov 4, 2025
15afb61
feat(AwsEventStreamParser): Add logging for last read chunks from Sim…
lihq1403 Nov 4, 2025
db21d92
feat(SimpleCURLClient): Add connection and stream chunk timeout options
lihq1403 Nov 4, 2025
b5cb567
feat(Logging): Add max text length configuration for log data formatting
lihq1403 Nov 18, 2025
b9bd535
feat(ChatCompletionStreamResponse): Add logging for chat completion r…
lihq1403 Nov 18, 2025
5bef9e5
feat(Gemini): Add Gemini client and configuration support
lihq1403 Nov 19, 2025
03ff6f8
feat(Gemini): Implement chat completions and streaming support with r…
lihq1403 Nov 19, 2025
04b1fce
feat(ImageProcessing): Add remote image downloading and base64 conver…
lihq1403 Nov 19, 2025
4c5da57
feat(Gemini): Implement caching strategies and event handling for cha…
lihq1403 Nov 19, 2025
98ba58a
feat(Gemini): Enhance caching strategy with improved message handling…
lihq1403 Nov 20, 2025
7f9412f
feat(Gemini): Enhance caching configuration and logging for chat resp…
lihq1403 Nov 20, 2025
035b13c
feat(Gemini): Add tool call tracking and improve cache handling in ch…
lihq1403 Nov 20, 2025
c187fcc
feat(Gemini): Implement thought signature caching and enhance cache m…
lihq1403 Nov 20, 2025
0f12baf
feat(Gemini): Refactor caching logic and enhance cache management for…
lihq1403 Nov 21, 2025
2e5cf24
feat(Gemini): Add methods to set stream chunk and first chunk timeout…
lihq1403 Nov 21, 2025
250d6e5
feat(Gemini): Add null check for API options and adjust timeout setti…
lihq1403 Nov 21, 2025
ea1e10d
feat(Gemini): Increase stream chunk timeout to improve response handling
lihq1403 Nov 21, 2025
85d89dd
feat(Gemini): Update SWOW_VERSION to v1.6.2 in test configuration
lihq1403 Nov 21, 2025
dcb4b4b
feat(Gemini): Enhance coroutine handling in SimpleCURLClient for impr…
lihq1403 Nov 21, 2025
7bf9585
feat(tests): Update stream chunk timeout and enhance AwsBedrock confi…
lihq1403 Nov 21, 2025
bdc7f6b
feat(dependencies): Add hyperf/engine as a development dependency
lihq1403 Nov 21, 2025
090218c
feat(Gemini): Update coroutine handling in SimpleCURLClient to use Co…
lihq1403 Nov 21, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on: [ push, pull_request ]

env:
SWOOLE_VERSION: '5.1.5'
SWOW_VERSION: 'v1.2.0'
SWOW_VERSION: 'v1.6.2'

jobs:
ci:
Expand Down
6 changes: 6 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
],
"exclude-from-classmap": [
"vendor/aws/aws-sdk-php/src/Api/Validator.php"
],
"files": [
"src/Api/Transport/SimpleCURLClient.php"
]
},
"autoload-dev": {
Expand All @@ -28,19 +31,22 @@
"ext-bcmath": "*",
"ext-mbstring": "*",
"aws/aws-sdk-php": "^3.0",
"ext-curl": "*",
"dtyq/php-mcp": "0.1.*",
"guzzlehttp/guzzle": "^7.0|^6.0",
"hyperf/cache": "~2.2.0 || 3.0.* || 3.1.*",
"hyperf/config": "~2.2.0 || 3.0.* || 3.1.*",
"hyperf/di": "~2.2.0 || 3.0.* || 3.1.*",
"hyperf/logger": "~2.2.0 || 3.0.* || 3.1.*",
"hyperf/retry": "~2.2.0 || 3.0.* || 3.1.*",
"hyperf/event": "~2.2.0 || 3.0.* || 3.1.*",
"hyperf/qdrant-client": "*",
"justinrainbow/json-schema": "^6.3",
"yethee/tiktoken": "^0.1.2"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.0",
"hyperf/engine": "^2.0",
"mockery/mockery": "^1.0",
"phpstan/phpstan": "^1.0",
"phpunit/phpunit": ">=7.0",
Expand Down
9 changes: 9 additions & 0 deletions examples/aws/aws_chat.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,12 @@

echo PHP_EOL;
echo '耗时' . (microtime(true) - $start) . '秒' . PHP_EOL;

// Display usage information
$usage = $response->getUsage();
if ($usage) {
echo PHP_EOL . '=== Token 使用情况 ===' . PHP_EOL;
echo '输入 Tokens: ' . $usage->getPromptTokens() . PHP_EOL;
echo '输出 Tokens: ' . $usage->getCompletionTokens() . PHP_EOL;
echo '总计 Tokens: ' . $usage->getTotalTokens() . PHP_EOL;
}
89 changes: 89 additions & 0 deletions examples/aws/aws_chat_custom.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php

declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
! defined('BASE_PATH') && define('BASE_PATH', dirname(__DIR__, 2));

require_once dirname(__FILE__, 3) . '/vendor/autoload.php';

use Hyperf\Context\ApplicationContext;
use Hyperf\Di\ClassLoader;
use Hyperf\Di\Container;
use Hyperf\Di\Definition\DefinitionSourceFactory;
use Hyperf\Odin\Api\Providers\AwsBedrock\AwsType;
use Hyperf\Odin\Api\Request\ChatCompletionRequest;
use Hyperf\Odin\Api\RequestOptions\ApiOptions;
use Hyperf\Odin\Logger;
use Hyperf\Odin\Message\AssistantMessage;
use Hyperf\Odin\Message\SystemMessage;
use Hyperf\Odin\Message\UserMessage;
use Hyperf\Odin\Model\AwsBedrockModel;

use function Hyperf\Support\env;

ClassLoader::init();

$container = ApplicationContext::setContainer(new Container((new DefinitionSourceFactory())()));

echo '=== AWS Bedrock Custom Client Test (Without AWS SDK) ===' . PHP_EOL . PHP_EOL;

// Create AWS Bedrock model instance with CONVERSE_CUSTOM type
// This uses custom Guzzle + SigV4 implementation instead of AWS SDK
$model = new AwsBedrockModel(
'us.anthropic.claude-3-7-sonnet-20250219-v1:0',
[
'access_key' => env('AWS_ACCESS_KEY'),
'secret_key' => env('AWS_SECRET_KEY'),
'region' => env('AWS_REGION', 'us-east-1'),
'type' => AwsType::CONVERSE_CUSTOM, // Use custom client without AWS SDK
],
new Logger(),
);
$model->setApiRequestOptions(new ApiOptions([
'proxy' => env('HTTP_CLIENT_PROXY'),
'http_handler' => env('ODIN_HTTP_HANDLER', 'auto'),
]));

$messages = [
new SystemMessage('You are a helpful AI assistant. Always include emoji in your responses.'),
new UserMessage('Explain quantum entanglement in simple terms.'),
];

$start = microtime(true);

// Use non-streaming API
$request = new ChatCompletionRequest($messages);
$request->setThinking([
'type' => 'enabled',
'budget_tokens' => 4000,
]);
$response = $model->chatWithRequest($request);

// Output full response
$message = $response->getFirstChoice()->getMessage();
if ($message instanceof AssistantMessage) {
echo 'Response: ' . ($message->getReasoningContent() ?? $message->getContent()) . PHP_EOL;
}

echo PHP_EOL . 'Duration: ' . round(microtime(true) - $start, 2) . ' seconds' . PHP_EOL;

// Output usage information
$usage = $response->getUsage();
echo PHP_EOL . '=== Token Usage ===' . PHP_EOL;
echo 'Input Tokens: ' . $usage->getPromptTokens() . PHP_EOL;
echo 'Output Tokens: ' . $usage->getCompletionTokens() . PHP_EOL;
echo 'Total Tokens: ' . $usage->getTotalTokens() . PHP_EOL;

if ($usage->getCachedTokens() > 0) {
echo PHP_EOL . 'Cache Hit: ' . $usage->getCachedTokens() . ' tokens' . PHP_EOL;
echo 'Cache Hit Rate: ' . $usage->getCacheHitRatePercentage() . '%' . PHP_EOL;
}

echo PHP_EOL . '✅ Custom client (without AWS SDK) works perfectly!' . PHP_EOL;
9 changes: 9 additions & 0 deletions examples/aws/aws_chat_stream.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,12 @@
}

echo PHP_EOL . '耗时: ' . round(microtime(true) - $start, 2) . ' 秒' . PHP_EOL;

// Display usage information
$usage = $streamResponse->getUsage();
if ($usage) {
echo PHP_EOL . '=== Token 使用情况 ===' . PHP_EOL;
echo '输入 Tokens: ' . $usage->getPromptTokens() . PHP_EOL;
echo '输出 Tokens: ' . $usage->getCompletionTokens() . PHP_EOL;
echo '总计 Tokens: ' . $usage->getTotalTokens() . PHP_EOL;
}
Loading