Skip to content

feat / support pass max tokens option #51

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions README-AR.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ $response = $client
->withModel(Models::CODER->value)
->withStream()
->withTemperature(1.2)
->setMaxTokens(8192)
->query('Explain quantum computing in simple terms')
->run();

Expand Down
1 change: 1 addition & 0 deletions README-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ $response = $client
->withModel(Models::CODER->value)
->withStream()
->withTemperature(1.2)
->setMaxTokens(8192)
->query('Explain quantum computing in simple terms')
->run();

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ $response = $client
->withModel(Models::CODER->value)
->withStream()
->setTemperature(1.2)
->setMaxTokens(8192)
->query('Explain quantum computing in simple terms')
->run();

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"role": "creator"
}
],
"version": "2.0.4",
"version": "2.0.5",
"require": {
"php": "^8.1.0",
"nyholm/psr7": "^1.8",
Expand Down
9 changes: 9 additions & 0 deletions src/DeepSeekClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class DeepSeekClient implements ClientContract
protected bool $stream;

protected float $temperature;
protected int $maxTokens;

/**
* response result contract
Expand Down Expand Up @@ -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;
}

Expand All @@ -89,6 +91,7 @@ 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,
];

Expand Down Expand Up @@ -183,6 +186,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 [
Expand Down
1 change: 1 addition & 0 deletions src/Enums/Configs/TemperatureValues.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ enum TemperatureValues: string
case TRANSLATION = "1.4";
case CREATIVE_WRITING = "1.5";
case POETRY = "1.6";
case MAX_TOKENS = "4096";
}
1 change: 1 addition & 0 deletions src/Enums/Requests/QueryFlags.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ enum QueryFlags: string
case MODEL = 'model';
case STREAM = 'stream';
case TEMPERATURE = 'temperature';
case MAX_TOKENS = 'max_tokens';
case TOOLS = 'tools';
}