Hello,
I have started a server using lmstudio and llama3 model (same problem with any other model I've tested).
I'm chatting with the said model using autogen without problem.
Though, I followed the autogen Tool Use tutorial* and instead of using the registered function, the model ignores it and answers the question by itself.
I suppose I do something wrong but I don't find what.
Here is the code. Any help to understand why this is not working would be greatly appreciated 🙂
import tempfile
from typing import Annotated, Literal
from autogen import ConversableAgent
assistant_system_message = """
You are a helpful AI assistant.
You can help with simple calculations.
Return 'TERMINATE' when the task is done.
"""
assistant = ConversableAgent(
"Assistant",
llm_config={
"config_list": [
{
"model": "lmstudio-community/Meta-Llama-3-8B-Instruct-Q8_0",
"base_url": "http://localhost:1234/v1",
"api_key": "lm-studio"
},
],
},
system_message=assistant_system_message,
)
user_proxy = ConversableAgent(
name="User",
llm_config=False,
is_termination_msg=lambda x: x.get("content", "") and x.get("content", "").rstrip().endswith("TERMINATE"),
human_input_mode="NEVER",
)
Operator = Literal["+", "-", "*", "/"]
@user_proxy.register_for_execution()
@assistant.register_for_llm(name="calculator", description="A simple calculator.")
def calculator(a: int, b: int, operator: Annotated[Operator, "operator"]) -> int:
if operator == "+":
return a + b
elif operator == "-":
return a - b
elif operator == "*":
return a * b
elif operator == "/":
return int(a / b)
else:
raise ValueError("Invalid operator")
chat_result = user_proxy.initiate_chat(assistant,message="What is (44232 + 13312 / (232 - 32)) * 5?")
Open In Colab