Skip to content

Commit

Permalink
fix(llm): transform message content for Groq provider
Browse files Browse the repository at this point in the history
Ensure message content is a string for Groq API compatibility.
Groq doesn't support the array format used by other providers.

Co-authored-by: Bob <[email protected]>
  • Loading branch information
ErikBjare and TimeToBuildBob committed Dec 11, 2024
1 parent d2109fe commit 84c8316
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions gptme/llm/llm_openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ def chat(messages: list[Message], model: str, tools: list[ToolSpec] | None) -> s
messages = list(_prep_o1(messages))

messages_dicts = handle_files(msgs2dicts(messages))
_transform_msgs_for_special_provider(messages_dicts)

from openai import NOT_GIVEN # fmt: skip

Expand Down Expand Up @@ -148,6 +149,7 @@ def stream(
messages = list(_prep_o1(messages))

messages_dicts = handle_files(msgs2dicts(messages))
_transform_msgs_for_special_provider(messages_dicts)

from openai import NOT_GIVEN # fmt: skip

Expand Down Expand Up @@ -278,6 +280,14 @@ def _process_file(msg: dict) -> dict:
return msg


def _transform_msgs_for_special_provider(messages_dicts: list[dict]):
if get_provider() == "groq":
# groq needs message.content to be a string
messages_dicts = [
{**msg, "content": msg["content"][0]["text"]} for msg in messages_dicts
]


def parameters2dict(parameters: list[Parameter]) -> dict[str, object]:
required = []
properties = {}
Expand Down

0 comments on commit 84c8316

Please sign in to comment.