mirror of
https://github.com/blakeblackshear/frigate.git
synced 2025-07-30 13:48:07 +02:00
Adapt openai.py to work with xAI (#16903)
* Adapt openai.py to work with xAI It appears xAI is a bit more strict in regards to how the prompt is sent. This changes the prompt to be a dictionary with `"type": "text"` which works with OpenAI and xAI. * Adapt openai.py to work with xAI add "detail": "low" * Adapt openai.py to work with xAI Apply Ruff formatting and linting fixes
This commit is contained in:
parent
f3765bc391
commit
180b0af3c9
@ -26,23 +26,30 @@ class OpenAIClient(GenAIClient):
|
|||||||
def _send(self, prompt: str, images: list[bytes]) -> Optional[str]:
|
def _send(self, prompt: str, images: list[bytes]) -> Optional[str]:
|
||||||
"""Submit a request to OpenAI."""
|
"""Submit a request to OpenAI."""
|
||||||
encoded_images = [base64.b64encode(image).decode("utf-8") for image in images]
|
encoded_images = [base64.b64encode(image).decode("utf-8") for image in images]
|
||||||
|
messages_content = []
|
||||||
|
for image in encoded_images:
|
||||||
|
messages_content.append(
|
||||||
|
{
|
||||||
|
"type": "image_url",
|
||||||
|
"image_url": {
|
||||||
|
"url": f"data:image/jpeg;base64,{image}",
|
||||||
|
"detail": "low",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
messages_content.append(
|
||||||
|
{
|
||||||
|
"type": "text",
|
||||||
|
"text": prompt,
|
||||||
|
}
|
||||||
|
)
|
||||||
try:
|
try:
|
||||||
result = self.provider.chat.completions.create(
|
result = self.provider.chat.completions.create(
|
||||||
model=self.genai_config.model,
|
model=self.genai_config.model,
|
||||||
messages=[
|
messages=[
|
||||||
{
|
{
|
||||||
"role": "user",
|
"role": "user",
|
||||||
"content": [
|
"content": messages_content,
|
||||||
{
|
|
||||||
"type": "image_url",
|
|
||||||
"image_url": {
|
|
||||||
"url": f"data:image/jpeg;base64,{image}",
|
|
||||||
"detail": "low",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
for image in encoded_images
|
|
||||||
]
|
|
||||||
+ [prompt],
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
timeout=self.timeout,
|
timeout=self.timeout,
|
||||||
|
Loading…
Reference in New Issue
Block a user