GPTAssistantAgent + Function Calling

parmarjatin4911@gmail.com - Jan 28 - - Dev Community

GPTAssistantAgent + Function Calling

import autogen
from autogen.agentchat.contrib.gpt_assistant_agent import GPTAssistantAgent
import openai
import yfinance as yf

client = openai.OpenAI()

def get_stock_price(symbol: str) -> float:
stock = yf.Ticker(symbol)
price = stock.history(period="1d")['Close'].iloc[-1]
return price

tools_list = [{
"type": "function",
"function": {
"name": "get_stock_price",
"description": "Retrieve the latest closing price of a stock using its ticker symbol",
"parameters": {
"type": "object",
"properties": {
"symbol": {
"type": "string",
"description": "The ticker symbol of the stock"
}
},
"required": ["symbol"]
}
}
}]

llm_config = {
"tools": tools_list,
}
gpt_assistant = GPTAssistantAgent(
name="Stock Assistant",
instructions="""
You are a Stock Expert.
Reply TERMINATE when the task is solved and there is no problem
""",
llm_config=llm_config
)
gpt_assistant.register_function(
function_map={
"get_stock_price": get_stock_price,
}
)

user_proxy = autogen.UserProxyAgent(
name="MervinPraison",
code_execution_config={
"work_dir" : "coding",
}
)

user_proxy.initiate_chat(
gpt_assistant,
message="""
What is the stock price of Apple?
"""
)

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player