Skip to content

Commit 1dc933d

Browse files
committed
don't send modalities or message timestamp in groq provider
1 parent 4eb6fe6 commit 1dc933d

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

llms/extensions/app/db.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import json
22
import os
3+
import time
34
from datetime import datetime, timedelta
45
from typing import Any, Dict
56

@@ -344,9 +345,12 @@ def prepare_thread(self, thread, id=None, user=None):
344345
else:
345346
thread["createdAt"] = now
346347
thread["updatedAt"] = now
348+
initial_timestamp = int(time.time() * 1000) + 1
347349
if "messages" in thread:
348-
for m in thread["messages"]:
350+
for idx, m in enumerate(thread["messages"]):
349351
self.ctx.cache_message_inline_data(m)
352+
if "timestamp" not in m:
353+
m["timestamp"] = initial_timestamp + idx
350354
return with_user(thread, user=user)
351355

352356
def create_thread(self, thread: Dict[str, Any], user=None):

llms/main.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,8 +1216,8 @@ def to_response(self, response, chat, started_at, context=None):
12161216
def chat_summary(self, chat):
12171217
return chat_summary(chat)
12181218

1219-
def process_chat(self, chat, provider_id=None):
1220-
return process_chat(chat, provider_id)
1219+
async def process_chat(self, chat, provider_id=None):
1220+
return await process_chat(chat, provider_id)
12211221

12221222
async def chat(self, chat, context=None):
12231223
chat["model"] = self.provider_model(chat["model"]) or chat["model"]
@@ -1272,7 +1272,7 @@ async def chat(self, chat, context=None):
12721272
if self.enable_thinking is not None:
12731273
chat["enable_thinking"] = self.enable_thinking
12741274

1275-
chat = await process_chat(chat, provider_id=self.id)
1275+
chat = await self.process_chat(chat, provider_id=self.id)
12761276
_log(f"POST {self.chat_url}")
12771277
_log(chat_summary(chat))
12781278
# remove metadata if any (conflicts with some providers, e.g. Z.ai)
@@ -1304,6 +1304,15 @@ def __init__(self, **kwargs):
13041304
kwargs["api"] = "https://api.groq.com/openai/v1"
13051305
super().__init__(**kwargs)
13061306

1307+
async def process_chat(self, chat, provider_id=None):
1308+
ret = await process_chat(chat, provider_id)
1309+
chat.pop("modalities", None) # groq doesn't support modalities
1310+
messages = chat.get("messages", []).copy()
1311+
for message in messages:
1312+
message.pop("timestamp", None) # groq doesn't support timestamp
1313+
ret["messages"] = messages
1314+
return ret
1315+
13071316

13081317
class XaiProvider(OpenAiCompatible):
13091318
sdk = "@ai-sdk/xai"

0 commit comments

Comments
 (0)