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
30 changes: 15 additions & 15 deletions llm_grok.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,18 +143,18 @@ def build_messages(self, prompt, conversation):
messages.append(
{"role": "system", "content": prev_response.prompt.system}
)
messages.append(
{"role": "user", "content": prev_response.prompt.prompt}
)
# Add tool_results after user message if present
# Add tool_results before user message (they belong to the previous turn)
if prev_response.prompt.tool_results:
for tool_result in prev_response.prompt.tool_results:
messages.append({
"role": "tool",
"tool_call_id": tool_result.tool_call_id,
"content": tool_result.content,
"content": tool_result.output,
})

messages.append(
{"role": "user", "content": prev_response.prompt.prompt}
)

# Add assistant response with tool_calls if present
tool_calls = prev_response.tool_calls()
content = prev_response.text()
Expand All @@ -164,24 +164,24 @@ def build_messages(self, prompt, conversation):
if tool_calls:
assistant_message["tool_calls"] = [
{
"id": tc.id,
"id": tc.tool_call_id,
"type": "function",
"function": {
"name": tc.name,
"arguments": tc.arguments,
"arguments": json.dumps(tc.arguments),
},
}
for tc in tool_calls
]
messages.append(assistant_message)

# Add tool_results before final user message if present
# Add tool_results before final user message (they belong to the previous turn)
if prompt.tool_results:
for tool_result in prompt.tool_results:
messages.append({
"role": "tool",
"tool_call_id": tool_result.tool_call_id,
"content": tool_result.content,
"content": tool_result.output,
})

messages.append({"role": "user", "content": prompt.prompt})
Expand Down Expand Up @@ -346,7 +346,7 @@ def execute(self, prompt, stream, response, conversation, key=None):
"function": {
"name": tool.name,
"description": tool.description,
"parameters": tool.parameters,
"parameters": tool.input_schema,
},
}
for tool in prompt.tools
Expand Down Expand Up @@ -420,9 +420,9 @@ def execute(self, prompt, stream, response, conversation, key=None):
if tc["id"] and tc["function"]["name"]:
response.add_tool_call(
llm.ToolCall(
id=tc["id"],
tool_call_id=tc["id"],
name=tc["function"]["name"],
arguments=tc["function"]["arguments"],
arguments=json.loads(tc["function"]["arguments"]),
)
)
else:
Expand All @@ -444,9 +444,9 @@ def execute(self, prompt, stream, response, conversation, key=None):
for tool_call_data in message["tool_calls"]:
response.add_tool_call(
llm.ToolCall(
id=tool_call_data["id"],
tool_call_id=tool_call_data["id"],
name=tool_call_data["function"]["name"],
arguments=tool_call_data["function"]["arguments"],
arguments=json.loads(tool_call_data["function"]["arguments"]),
)
)
if "content" in message:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "llm-grok"
version = "1.4.1"
version = "1.4.2"
description = "LLM plugin providing access to Grok models using the xAI API"
readme = "README.md"
authors = [{name = "Benedikt Hiepler"}]
Expand Down
Loading