Skip to content

Commit 4aedcae

Browse files
authored
Merge pull request #51 from deepseek-php/feat-support-pass-max-tokens-option
feat / support pass max tokens option
2 parents 1f078c7 + dde2965 commit 4aedcae

File tree

7 files changed

+15
-1
lines changed

7 files changed

+15
-1
lines changed

README-AR.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ $response = $client
100100
->withModel(Models::CODER->value)
101101
->withStream()
102102
->withTemperature(1.2)
103+
->setMaxTokens(8192)
103104
->query('Explain quantum computing in simple terms')
104105
->run();
105106

README-CN.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ $response = $client
9999
->withModel(Models::CODER->value)
100100
->withStream()
101101
->withTemperature(1.2)
102+
->setMaxTokens(8192)
102103
->query('Explain quantum computing in simple terms')
103104
->run();
104105

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ $response = $client
9999
->withModel(Models::CODER->value)
100100
->withStream()
101101
->setTemperature(1.2)
102+
->setMaxTokens(8192)
102103
->query('Explain quantum computing in simple terms')
103104
->run();
104105

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"role": "creator"
5050
}
5151
],
52-
"version": "2.0.4",
52+
"version": "2.0.5",
5353
"require": {
5454
"php": "^8.1.0",
5555
"nyholm/psr7": "^1.8",

src/DeepSeekClient.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class DeepSeekClient implements ClientContract
4949
protected bool $stream;
5050

5151
protected float $temperature;
52+
protected int $maxTokens;
5253

5354
/**
5455
* response result contract
@@ -79,6 +80,7 @@ public function __construct(ClientInterface $httpClient)
7980
$this->requestMethod = 'POST';
8081
$this->endpointSuffixes = EndpointSuffixes::CHAT->value;
8182
$this->temperature = (float) TemperatureValues::GENERAL_CONVERSATION->value;
83+
$this->maxTokens = (int) TemperatureValues::MAX_TOKENS->value;
8284
$this->tools = null;
8385
}
8486

@@ -89,6 +91,7 @@ public function run(): string
8991
QueryFlags::MODEL->value => $this->model,
9092
QueryFlags::STREAM->value => $this->stream,
9193
QueryFlags::TEMPERATURE->value => $this->temperature,
94+
QueryFlags::MAX_TOKENS->value => $this->maxTokens,
9295
QueryFlags::TOOLS->value => $this->tools,
9396
];
9497

@@ -183,6 +186,12 @@ public function setTemperature(float $temperature): self
183186
return $this;
184187
}
185188

189+
public function setMaxTokens(int $maxTokens): self
190+
{
191+
$this->maxTokens = $maxTokens;
192+
return $this;
193+
}
194+
186195
public function buildQuery(string $content, ?string $role = null): array
187196
{
188197
return [

src/Enums/Configs/TemperatureValues.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ enum TemperatureValues: string
1212
case TRANSLATION = "1.4";
1313
case CREATIVE_WRITING = "1.5";
1414
case POETRY = "1.6";
15+
case MAX_TOKENS = "4096";
1516
}

src/Enums/Requests/QueryFlags.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ enum QueryFlags: string
88
case MODEL = 'model';
99
case STREAM = 'stream';
1010
case TEMPERATURE = 'temperature';
11+
case MAX_TOKENS = 'max_tokens';
1112
case TOOLS = 'tools';
1213
}

0 commit comments

Comments
 (0)