Skip to content
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
15 changes: 13 additions & 2 deletions lib/Service/OpenAiFileService.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ private function buildVideoContent(File $file, string $fileType, ServiceConfig $
}

/**
* @return list<array{type: string, text: string}|array{type: string, file: array{filename: string, file_data: string}}>
* @return list<array<string, mixed>>
*/
private function buildDocumentContent(File $file, string $fileType, ServiceConfig $service): array {
if (!$service->getMultimodalDocumentEnabled()) {
Expand All @@ -248,11 +248,22 @@ private function buildDocumentContent(File $file, string $fileType, ServiceConfi
'text' => 'Filename:' . $file->getName() . "\nContent:\n" . $text,
]];
}
$dataUri = 'data:' . $fileType . ';base64,' . base64_encode(stream_get_contents($file->fopen('rb')));

if ($service->isUsingMistral()) {
// Mistral does not accept the default openai shape so we use a fallback for them
return [[
'type' => 'document_url',
'document_url' => $dataUri,
'document_name' => $file->getName(),
]];
}

return [[
'type' => 'file',
'file' => [
'filename' => $file->getName(),
'file_data' => 'data:' . $fileType . ';base64,' . base64_encode(stream_get_contents($file->fopen('rb'))),
'file_data' => $dataUri,
],
]];
}
Expand Down
4 changes: 4 additions & 0 deletions lib/Service/ServiceConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,10 @@ public function isUsingOpenRouter(): bool {
return str_starts_with(strtolower($this->url), 'https://openrouter.ai');
}

public function isUsingMistral(): bool {
return str_starts_with(strtolower($this->url), 'https://api.mistral.ai');
}

public function getApiKey(): string {
return $this->apiKey;
}
Expand Down
Loading