forked from phoenix/litellm-mirror
Merge pull request #4373 from CorrM/main
[Fix-Improve] Improve Ollama prompt input and fix Ollama function calling key error
This commit is contained in:
commit
75c8f77d9a
3 changed files with 35 additions and 13 deletions
|
@ -451,7 +451,7 @@ async def ollama_acompletion(url, data, model_response, encoding, logging_obj):
|
||||||
{
|
{
|
||||||
"id": f"call_{str(uuid.uuid4())}",
|
"id": f"call_{str(uuid.uuid4())}",
|
||||||
"function": {
|
"function": {
|
||||||
"name": function_call["name"],
|
"name": function_call.get("name", function_call.get("function", None)),
|
||||||
"arguments": json.dumps(function_call["arguments"]),
|
"arguments": json.dumps(function_call["arguments"]),
|
||||||
},
|
},
|
||||||
"type": "function",
|
"type": "function",
|
||||||
|
|
|
@ -434,7 +434,7 @@ async def ollama_async_streaming(
|
||||||
{
|
{
|
||||||
"id": f"call_{str(uuid.uuid4())}",
|
"id": f"call_{str(uuid.uuid4())}",
|
||||||
"function": {
|
"function": {
|
||||||
"name": function_call["name"],
|
"name": function_call.get("name", function_call.get("function", None)),
|
||||||
"arguments": json.dumps(function_call["arguments"]),
|
"arguments": json.dumps(function_call["arguments"]),
|
||||||
},
|
},
|
||||||
"type": "function",
|
"type": "function",
|
||||||
|
|
|
@ -172,14 +172,36 @@ def ollama_pt(
|
||||||
images.append(base64_image)
|
images.append(base64_image)
|
||||||
return {"prompt": prompt, "images": images}
|
return {"prompt": prompt, "images": images}
|
||||||
else:
|
else:
|
||||||
prompt = "".join(
|
prompt = ""
|
||||||
(
|
for message in messages:
|
||||||
m["content"]
|
role = message["role"]
|
||||||
if isinstance(m["content"], str) is str
|
content = message.get("content", "")
|
||||||
else "".join(m["content"])
|
|
||||||
)
|
if "tool_calls" in message:
|
||||||
for m in messages
|
tool_calls = []
|
||||||
)
|
|
||||||
|
for call in message["tool_calls"]:
|
||||||
|
call_id: str = call["id"]
|
||||||
|
function_name: str = call["function"]["name"]
|
||||||
|
arguments = json.loads(call["function"]["arguments"])
|
||||||
|
|
||||||
|
tool_calls.append({
|
||||||
|
"id": call_id,
|
||||||
|
"type": "function",
|
||||||
|
"function": {
|
||||||
|
"name": function_name,
|
||||||
|
"arguments": arguments
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
prompt += f"### Assistant:\nTool Calls: {json.dumps(tool_calls, indent=2)}\n\n"
|
||||||
|
|
||||||
|
elif "tool_call_id" in message:
|
||||||
|
prompt += f"### User:\n{message["content"]}\n\n"
|
||||||
|
|
||||||
|
elif content:
|
||||||
|
prompt += f"### {role.capitalize()}:\n{content}\n\n"
|
||||||
|
|
||||||
return prompt
|
return prompt
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue