Open Haripritamreddy opened 5 months ago
We are migrating code from function calls to tool calls. Do you have an option to use tool calls with Gemini?
No It is not working.Unlike function calling which is partially working It is giving altleast json output.But when i use tool calls with litellm its throwing erros.
import autogen from typing import Literal from typing_extensions import Annotated
config_list = [ { 'model': 'gpt-3.5-turbo', 'api_key': 'anything', 'base_url': 'http://abce-35-231-22-211.ngrok-free.app', } ]
llm_config = { "config_list": config_list, "timeout": 120, }
currency_bot = autogen.AssistantAgent( name="currency_bot", system_message="For currency exchange tasks, only use the functions you have been provided with. Reply TERMINATE " "when the task is done.", llm_config=llm_config, )
user_proxy = autogen.UserProxyAgent( name="user_proxy", is_termination_msg=lambda x: x.get("content", "") and x.get("content", "").rstrip().endswith("TERMINATE"), human_input_mode="NEVER", max_consecutive_auto_reply=10, )
CurrencySymbol = Literal["USD", "EUR"]
def exchange_rate(base_currency: CurrencySymbol, quote_currency: CurrencySymbol) -> float: if base_currency == quote_currency: return 1.0 elif base_currency == "USD" and quote_currency == "EUR": return 1 / 1.09 elif base_currency == "EUR" and quote_currency == "USD": return 1.1 else: raise ValueError(f"Unknown currencies {base_currency}, {quote_currency}")
@user_proxy.register_for_execution() @currency_bot.register_for_llm(description="Currency exchange calculator.") def currency_calculator( base_amount: Annotated[float, "Amount of currency in base_currency"], base_currency: Annotated[CurrencySymbol, "Base currency"] = "USD", quote_currency: Annotated[CurrencySymbol, "Quote currency"] = "EUR", ) -> str: quote_amount = exchange_rate(base_currency, quote_currency) * base_amount return f"{quote_amount} {quote_currency}"
user_proxy.initiate_chat( currency_bot, message="How much is 123.45 USD in EUR?", )
Error:
How much is 123.45 USD in EUR?
Traceback (most recent call last):
File "c:\Users\Asus\Documents\autogen\function_test.py", line 60, in
It looks like we broke it with all of the latest changes :/ I opened an issue for it and will fix it soon https://github.com/microsoft/autogen/issues/1206
Is function calling working now? It seems to fail with gemini-1.5-flash-latest for me. Here are Gemini's docs: https://ai.google.dev/gemini-api/docs/function-calling
@nileshtrivedi function calling is working, but it might be broken in your use case. Can you please create a detailed issue with a code example and mention me it? I'll take it over from there
Describe the issue
I have used litellm to get open ai compatable api for google's gemini pro model and used it in base_url.So when i tried function calling it is returning a json object but it is not the used format.I have tried different prompts but it still's not working.
Steps to reproduce
1.Step 1: import yfinance as yf import autogen
Configuration for OpenAI API
config_list = [ { 'model': 'gpt-3.5-turbo', 'api_key': 'anything', 'base_url': 'https://6ad3-35-245-36-6.ngrok-free.app', } ]
Autogen configuration
llm_config = { "functions": [ { "name": "get_stock_price", "description": "Get the current stock price for a given stock symbol.", "parameters": { "type": "object", "properties": { "symbol": { "type": "string", "description": "Stock symbol to get the price for.", } }, "required": ["symbol"], }, }, ], "config_list": config_list, "timeout": 120, }
Autogen agent initialization
chatbot = autogen.AssistantAgent( name="chatbot", system_message="For coding tasks, only use the functions you have been provided with. Reply TERMINATE when the task is done.", llm_config=llm_config, )
Function to get stock price
def get_stock_price(symbol): try:
Use yfinance to get stock price
Autogen user proxy initialization
user_proxy = autogen.UserProxyAgent( name="user_proxy", is_termination_msg=lambda x: x.get("content", "") and x.get("content", "").rstrip().endswith("TERMINATE"), human_input_mode="NEVER", max_consecutive_auto_reply=10, code_execution_config={"work_dir": "coding"}, )
Register the get_stock_price function
user_proxy.register_function( function_map={ "get_stock_price": get_stock_price, } )
Start the conversation
user_proxy.initiate_chat( chatbot, message="Get the current stock price for symbol apple.", )
Screenshots and logs
Additional Information
No response