From c0d27f605cf0f747cdced9cb6806f2227994d726 Mon Sep 17 00:00:00 2001 From: omaralalwi Date: Wed, 16 Jul 2025 23:56:11 +0300 Subject: [PATCH 1/3] feat / support pass max tokens option --- README-AR.md | 1 + README-CN.md | 1 + README.md | 1 + src/DeepSeekClient.php | 11 +++++++++++ src/Enums/Configs/TemperatureValues.php | 1 + src/Enums/Requests/QueryFlags.php | 1 + 6 files changed, 16 insertions(+) diff --git a/README-AR.md b/README-AR.md index 10905a9..8e9ad5a 100644 --- a/README-AR.md +++ b/README-AR.md @@ -100,6 +100,7 @@ $response = $client ->withModel(Models::CODER->value) ->withStream() ->withTemperature(1.2) + ->setMaxTokens(8192) ->query('Explain quantum computing in simple terms') ->run(); diff --git a/README-CN.md b/README-CN.md index ebd7e19..b93bb99 100644 --- a/README-CN.md +++ b/README-CN.md @@ -99,6 +99,7 @@ $response = $client ->withModel(Models::CODER->value) ->withStream() ->withTemperature(1.2) + ->setMaxTokens(8192) ->query('Explain quantum computing in simple terms') ->run(); diff --git a/README.md b/README.md index c70c40f..6ec9b7e 100644 --- a/README.md +++ b/README.md @@ -99,6 +99,7 @@ $response = $client ->withModel(Models::CODER->value) ->withStream() ->setTemperature(1.2) + ->setMaxTokens(8192) ->query('Explain quantum computing in simple terms') ->run(); diff --git a/src/DeepSeekClient.php b/src/DeepSeekClient.php index 93c989d..63592a1 100644 --- a/src/DeepSeekClient.php +++ b/src/DeepSeekClient.php @@ -49,6 +49,7 @@ class DeepSeekClient implements ClientContract protected bool $stream; protected float $temperature; + protected int $maxTokens; /** * response result contract @@ -79,6 +80,7 @@ public function __construct(ClientInterface $httpClient) $this->requestMethod = 'POST'; $this->endpointSuffixes = EndpointSuffixes::CHAT->value; $this->temperature = (float) TemperatureValues::GENERAL_CONVERSATION->value; + $this->maxTokens = (int) TemperatureValues::MAX_TOKENS->value; $this->tools = null; } @@ -89,9 +91,12 @@ public function run(): string QueryFlags::MODEL->value => $this->model, QueryFlags::STREAM->value => $this->stream, QueryFlags::TEMPERATURE->value => $this->temperature, + QueryFlags::MAX_TOKENS->value => $this->maxTokens, QueryFlags::TOOLS->value => $this->tools, ]; + \Log::info(['debug info: this is $requestData :' => $requestData ]); + $this->setResult((new Resource($this->httpClient, $this->endpointSuffixes))->sendRequest($requestData, $this->requestMethod)); return $this->getResult()->getContent(); } @@ -183,6 +188,12 @@ public function setTemperature(float $temperature): self return $this; } + public function setMaxTokens(int $maxTokens): self + { + $this->maxTokens = $maxTokens; + return $this; + } + public function buildQuery(string $content, ?string $role = null): array { return [ diff --git a/src/Enums/Configs/TemperatureValues.php b/src/Enums/Configs/TemperatureValues.php index 12c21b1..b9b9a93 100644 --- a/src/Enums/Configs/TemperatureValues.php +++ b/src/Enums/Configs/TemperatureValues.php @@ -12,4 +12,5 @@ enum TemperatureValues: string case TRANSLATION = "1.4"; case CREATIVE_WRITING = "1.5"; case POETRY = "1.6"; + case MAX_TOKENS = "4096"; } diff --git a/src/Enums/Requests/QueryFlags.php b/src/Enums/Requests/QueryFlags.php index 0e2b49a..2b4b557 100644 --- a/src/Enums/Requests/QueryFlags.php +++ b/src/Enums/Requests/QueryFlags.php @@ -8,5 +8,6 @@ enum QueryFlags: string case MODEL = 'model'; case STREAM = 'stream'; case TEMPERATURE = 'temperature'; + case MAX_TOKENS = 'max_tokens'; case TOOLS = 'tools'; } From ab01fa544cbbd0225fa46c5500b4dcc4125679b8 Mon Sep 17 00:00:00 2001 From: omaralalwi Date: Thu, 17 Jul 2025 00:03:22 +0300 Subject: [PATCH 2/3] clean u p --- composer.json | 4 ++-- src/DeepSeekClient.php | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index 5f03fd6..20f2766 100644 --- a/composer.json +++ b/composer.json @@ -47,9 +47,9 @@ "name": "Omar Alalwi", "email": "omaralwi2010@gmail.com", "role": "creator" - } + }g ], - "version": "2.0.4", + "version": "2.0.5", "require": { "php": "^8.1.0", "nyholm/psr7": "^1.8", diff --git a/src/DeepSeekClient.php b/src/DeepSeekClient.php index 63592a1..c44d0cd 100644 --- a/src/DeepSeekClient.php +++ b/src/DeepSeekClient.php @@ -95,8 +95,6 @@ public function run(): string QueryFlags::TOOLS->value => $this->tools, ]; - \Log::info(['debug info: this is $requestData :' => $requestData ]); - $this->setResult((new Resource($this->httpClient, $this->endpointSuffixes))->sendRequest($requestData, $this->requestMethod)); return $this->getResult()->getContent(); } From dde2965ef938b365e6b24e41c29d88e29b29c521 Mon Sep 17 00:00:00 2001 From: omaralalwi Date: Thu, 17 Jul 2025 00:03:37 +0300 Subject: [PATCH 3/3] clean up --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 20f2766..e4a48f2 100644 --- a/composer.json +++ b/composer.json @@ -47,7 +47,7 @@ "name": "Omar Alalwi", "email": "omaralwi2010@gmail.com", "role": "creator" - }g + } ], "version": "2.0.5", "require": {