mirror of
https://github.com/tiennm99/litellm.git
synced 2026-08-05 22:25:05 +00:00
Improve ollama prompt: this formula give good result with AutoGen
This commit is contained in:
@@ -135,7 +135,7 @@ def convert_to_ollama_image(openai_image_url: str):
|
||||
|
||||
|
||||
def ollama_pt(
|
||||
model, messages
|
||||
model, messages
|
||||
): # https://github.com/ollama/ollama/blob/af4cf55884ac54b9e637cd71dadfe9b7a5685877/docs/modelfile.md#template
|
||||
if "instruct" in model:
|
||||
prompt = custom_prompt(
|
||||
@@ -178,12 +178,27 @@ def ollama_pt(
|
||||
content = message.get("content", "")
|
||||
|
||||
if "tool_calls" in message:
|
||||
tool_calls = []
|
||||
|
||||
for call in message["tool_calls"]:
|
||||
function_name = call["function"]["name"]
|
||||
call_id: str = call["id"]
|
||||
function_name: str = call["function"]["name"]
|
||||
arguments = json.loads(call["function"]["arguments"])
|
||||
prompt += f"### FunctionCall ({call["id"]}):\nFunctionName: {function_name}\nArguments: {json.dumps(arguments)}\n\n"
|
||||
|
||||
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"### FunctionCall Result ({message["tool_call_id"]}):\n{message["content"]}\n\n"
|
||||
prompt += f"### User:\n{message["content"]}\n\n"
|
||||
|
||||
elif content:
|
||||
prompt += f"### {role.capitalize()}:\n{content}\n\n"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user