-
-
Notifications
You must be signed in to change notification settings - Fork 304
Expand file tree
/
Copy pathRequest.php
More file actions
171 lines (146 loc) · 3.91 KB
/
Copy pathRequest.php
File metadata and controls
171 lines (146 loc) · 3.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<?php
declare(strict_types=1);
namespace Prism\Prism\Structured;
use Closure;
use Prism\Prism\Concerns\ChecksSelf;
use Prism\Prism\Concerns\HasProviderOptions;
use Prism\Prism\Concerns\HasReasoning;
use Prism\Prism\Contracts\Message;
use Prism\Prism\Contracts\PrismRequest;
use Prism\Prism\Contracts\Schema;
use Prism\Prism\Enums\StructuredMode;
use Prism\Prism\Enums\ToolChoice;
use Prism\Prism\Tool;
use Prism\Prism\ValueObjects\Messages\SystemMessage;
use Prism\Prism\ValueObjects\ProviderTool;
class Request implements PrismRequest
{
use ChecksSelf, HasProviderOptions, HasReasoning;
/**
* @param SystemMessage[] $systemPrompts
* @param array<int, Message> $messages
* @param array<int, Tool> $tools
* @param array<string, mixed> $clientOptions
* @param array{0: array<int, int>|int, 1?: Closure|int, 2?: ?callable, 3?: bool} $clientRetry
* @param array<string, mixed> $providerOptions
* @param array<int, ProviderTool> $providerTools
*/
public function __construct(
protected array $systemPrompts,
protected string $model,
protected string $providerKey,
protected ?string $prompt,
protected array $messages,
protected ?int $maxTokens,
protected int|float|null $temperature,
protected int|float|null $topP,
protected array $clientOptions,
protected array $clientRetry,
protected Schema $schema,
protected StructuredMode $mode,
protected array $tools,
protected string|ToolChoice|null $toolChoice,
protected int $maxSteps,
array $providerOptions = [],
protected array $providerTools = [],
?bool $reasoningEnabled = null,
) {
$this->providerOptions = $providerOptions;
$this->reasoningEnabled = $reasoningEnabled;
}
/**
* @return SystemMessage[]
*/
public function systemPrompts(): array
{
return $this->systemPrompts;
}
#[\Override]
public function model(): string
{
return $this->model;
}
public function provider(): string
{
return $this->providerKey;
}
public function prompt(): ?string
{
return $this->prompt;
}
/**
* @return array<int, Message>
*/
public function messages(): array
{
return $this->messages;
}
public function maxTokens(): ?int
{
return $this->maxTokens;
}
public function temperature(): int|float|null
{
return $this->temperature;
}
public function topP(): int|float|null
{
return $this->topP;
}
/**
* @return array<string, mixed>
*/
public function clientOptions(): array
{
return $this->clientOptions;
}
/**
* @return array{0: array<int, int>|int, 1?: Closure|int, 2?: ?callable, 3?: bool}
*/
public function clientRetry(): array
{
return $this->clientRetry;
}
public function schema(): Schema
{
return $this->schema;
}
public function mode(): StructuredMode
{
return $this->mode;
}
public function addMessage(Message $message): self
{
$this->messages = array_merge($this->messages, [$message]);
return $this;
}
/**
* @return array<int, Tool>
*/
public function tools(): array
{
return $this->tools;
}
public function toolChoice(): string|ToolChoice|null
{
return $this->toolChoice;
}
public function maxSteps(): int
{
return $this->maxSteps;
}
/**
* @return array<int, ProviderTool>
*/
public function providerTools(): array
{
return $this->providerTools;
}
public function resetToolChoice(): self
{
if (is_string($this->toolChoice) || $this->toolChoice === ToolChoice::Any) {
$this->toolChoice = ToolChoice::Auto;
}
return $this;
}
}