Build Autonomous AI Agents with Function Calling | by Julian Yip | Apr, 2024

From Towards Data Science: 2024-04-07 10:53:52

2. User-generated messageuser_prompt = “Can you recommend some good local coffee shops?”# 3. Tool list as per OpenAI’s formattools = toolschat_generator.run(messages=[ChatMessage.from_user(user_prompt)],tools=tools,context=context)The output should include a response from the model using the function provided in the tools list, for example: {“replies”:[“The coffee shop opens at 9 am.”]}Step 4: Extend model to support APIsNext, we extended the model to interact with external APIs. When tools are invoked, they will be provided with suggested actions, which are then used as inputs to the integrated API functions. This process is essential for autonomous decision making and allows for reliable parsing of JSON responses. With this functionality, the model can act as an autonomous AI assistant, handle personal research tasks, and even control IoT devices through voice commands. Functions like get_items and purchase_item allow the model to access external databases and place orders, while rag_pipeline_func leverages RAG to retrieve information from unstructured texts. To implement these features, we constructed the necessary functions, designated the tools using the proper format required by OpenAI, and interlinked them with the chat model. By following these steps, developers can enhance their chatbots with external API functionality, making them more efficient and versatile assistants.



Read more at Towards Data Science: Build Autonomous AI Agents with Function Calling | by Julian Yip | Apr, 2024