Skip to content

Commit

Permalink
Added system instructions and tools to stream
Browse files Browse the repository at this point in the history
  • Loading branch information
Plytas committed Jan 10, 2025
1 parent 9c39211 commit 2fea930
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/Requests/GenerativeModel/StreamGenerateContentRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
use Gemini\Data\Content;
use Gemini\Data\GenerationConfig;
use Gemini\Data\SafetySetting;
use Gemini\Data\Tool;
use Gemini\Data\ToolConfig;
use Gemini\Enums\Method;
use Gemini\Foundation\Request;
use Gemini\Requests\Concerns\HasJsonBody;
Expand All @@ -26,12 +28,16 @@ class StreamGenerateContentRequest extends Request
/**
* @param array<string|Blob|array<string|Blob>|Content> $parts
* @param array<SafetySetting> $safetySettings
* @param array<Tool> $tools
*/
public function __construct(
protected readonly string $model,
protected readonly array $parts,
protected readonly array $safetySettings = [],
protected readonly ?GenerationConfig $generationConfig = null
protected readonly ?GenerationConfig $generationConfig = null,
protected readonly ?Content $systemInstruction = null,
protected readonly array $tools = [],
protected readonly ?ToolConfig $toolConfig = null,
) {}

public function resolveEndpoint(): string
Expand All @@ -56,6 +62,12 @@ protected function defaultBody(): array
$this->safetySettings ?? []
),
'generationConfig' => $this->generationConfig?->toArray(),
'systemInstruction' => $this->systemInstruction?->toArray(),
'tools' => array_map(
static fn (Tool $tool): array => $tool->toArray(),
$this->tools ?? []
),
'toolConfig' => $this->toolConfig?->toArray(),
];
}
}
3 changes: 3 additions & 0 deletions src/Resources/GenerativeModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ public function streamGenerateContent(string|Blob|array|Content ...$parts): Stre
parts: $parts,
safetySettings: $this->safetySettings,
generationConfig: $this->generationConfig,
systemInstruction: $this->systemInstruction,
tools: $this->tools,
toolConfig: $this->toolConfig,
)
);

Expand Down

0 comments on commit 2fea930

Please sign in to comment.