Skip to content

Commit 89301a1

Browse files
committed
chore: make timeouts configurable for all the adapters
1 parent c395eaf commit 89301a1

4 files changed

Lines changed: 30 additions & 8 deletions

File tree

src/Agents/Adapters/Deepseek.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,25 +40,33 @@ class Deepseek extends Adapter
4040
*/
4141
protected float $temperature;
4242

43+
/**
44+
* @var int
45+
*/
46+
protected int $timeout;
47+
4348
/**
4449
* Create a new Deepseek adapter
4550
*
4651
* @param string $apiKey
4752
* @param string $model
4853
* @param int $maxTokens
4954
* @param float $temperature
55+
* @param int $timeout
5056
*
5157
* @throws \Exception
5258
*/
5359
public function __construct(
5460
string $apiKey,
5561
string $model = self::MODEL_DEEPSEEK_CHAT,
5662
int $maxTokens = 1024,
57-
float $temperature = 1.0
63+
float $temperature = 1.0,
64+
int $timeout = 90
5865
) {
5966
$this->apiKey = $apiKey;
6067
$this->maxTokens = $maxTokens;
6168
$this->temperature = $temperature;
69+
$this->timeout = $timeout;
6270
$this->setModel($model);
6371
}
6472

@@ -79,7 +87,7 @@ public function send(array $messages, ?callable $listener = null): Message
7987

8088
$client = new Client();
8189
$client
82-
->setTimeout(90)
90+
->setTimeout($this->timeout)
8391
->addHeader('authorization', 'Bearer '.$this->apiKey)
8492
->addHeader('content-type', Client::CONTENT_TYPE_APPLICATION_JSON);
8593

src/Agents/Adapters/OpenAI.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ class OpenAI extends Adapter
5555
*/
5656
protected string $endpoint;
5757

58+
/**
59+
* @var int
60+
*/
61+
protected int $timeout;
62+
5863
/**
5964
* Create a new OpenAI adapter
6065
*
@@ -63,6 +68,7 @@ class OpenAI extends Adapter
6368
* @param int $maxTokens
6469
* @param float $temperature
6570
* @param string|null $endpoint
71+
* @param int $timeout
6672
*
6773
* @throws \Exception
6874
*/
@@ -71,12 +77,14 @@ public function __construct(
7177
string $model = self::MODEL_GPT_3_5_TURBO,
7278
int $maxTokens = 1024,
7379
float $temperature = 1.0,
74-
?string $endpoint = null
80+
?string $endpoint = null,
81+
int $timeout = 90
7582
) {
7683
$this->apiKey = $apiKey;
7784
$this->maxTokens = $maxTokens;
7885
$this->temperature = $temperature;
7986
$this->endpoint = $endpoint ?? self::ENDPOINT;
87+
$this->timeout = $timeout;
8088
$this->setModel($model);
8189
}
8290

@@ -97,7 +105,7 @@ public function send(array $messages, ?callable $listener = null): Message
97105

98106
$client = new Client();
99107
$client
100-
->setTimeout(90)
108+
->setTimeout($this->timeout)
101109
->addHeader('authorization', 'Bearer '.$this->apiKey)
102110
->addHeader('content-type', Client::CONTENT_TYPE_APPLICATION_JSON);
103111

src/Agents/Adapters/Perplexity.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class Perplexity extends OpenAI
4242
* @param int $maxTokens
4343
* @param float $temperature
4444
* @param string|null $endpoint
45+
* @param int $timeout
4546
*
4647
* @throws \Exception
4748
*/
@@ -50,14 +51,16 @@ public function __construct(
5051
string $model = self::MODEL_SONAR,
5152
int $maxTokens = 1024,
5253
float $temperature = 1.0,
53-
?string $endpoint = null
54+
?string $endpoint = null,
55+
int $timeout = 90
5456
) {
5557
parent::__construct(
5658
$apiKey,
5759
$model,
5860
$maxTokens,
5961
$temperature,
60-
$endpoint ?? self::ENDPOINT
62+
$endpoint ?? self::ENDPOINT,
63+
$timeout
6164
);
6265
}
6366

src/Agents/Adapters/XAI.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class XAI extends OpenAI
2727
* @param int $maxTokens
2828
* @param float $temperature
2929
* @param string|null $endpoint
30+
* @param int $timeout
3031
*
3132
* @throws \Exception
3233
*/
@@ -35,14 +36,16 @@ public function __construct(
3536
string $model = self::MODEL_GROK_2_LATEST,
3637
int $maxTokens = 1024,
3738
float $temperature = 1.0,
38-
?string $endpoint = null
39+
?string $endpoint = null,
40+
int $timeout = 90
3941
) {
4042
parent::__construct(
4143
$apiKey,
4244
$model,
4345
$maxTokens,
4446
$temperature,
45-
$endpoint ?? self::ENDPOINT
47+
$endpoint ?? self::ENDPOINT,
48+
$timeout
4649
);
4750
}
4851

0 commit comments

Comments
 (0)