Skip to main content
You can also check this cookbook in Colab here. This notebook demonstrates how to set up and leverage OpenAI Function Calling combined with Dappier for detailed stock market analysis. By integrating real-time trading data and automated function execution, this notebook walks you through a practical approach to generating intelligent, up-to-date investment strategies. In this notebook, you’ll explore:
  • OpenAI Function Calling: A powerful feature that enables large language models to automatically detect and invoke external tools to accomplish tasks in a structured and contextual manner.
  • Dappier: A platform connecting LLMs to real-time, rights-cleared data from trusted sources, specializing in domains like finance, web search, and news. It delivers enriched, prompt-ready data, empowering AI with verified and up-to-date information for diverse applications.
  • Stock Market Analysis: A real-world use case where the assistant reasons over live stock price changes, breaking news, and trade volume in the last 24 hours to deliver a comprehensive financial analysis and investment strategy for a selected company.
This setup not only demonstrates a flexible architecture for building intelligent financial assistants but also serves as a foundation for developing other real-world applications requiring real-time information retrieval, structured tool use, and contextual decision-making. Here’s the Video Walkthrough section, following the same format and tone as the original:

πŸ“Ί Video Walkthrough

Prefer watching? Here’s a video version of this notebook:

πŸ“¦ Installation

Install the required packages:

πŸ”‘ Setting Up API Keys

You’ll need to set up your API keys for OpenAI, Dappier.
This ensures that the tools can interact with external services securely.
You can go to here to get API Key from Dappier with free credits.
Python
You can go to here to get API Key from Open AI.
Python

βš™οΈ Initialize Clients

Set up the OpenAI and Dappier Python SDK clients.
Python

πŸ›°οΈ Define the Dappier Tool Function

This function will be called by the LLM to fetch real-time stock market data, including the latest news and trades.
Python

πŸ“‹ Define the User Prompt

This prompt instructs the assistant to gather recent news, trades, and performance metrics, and generate an investment strategy based on those findings.
Python

🧠 Define the Tool Schema for OpenAI

We’ll register dappier_real_time_stock_analysis as a callable tool for OpenAI’s function calling.
Python

πŸ€– Run the Assistant Workflow

This function runs the full interaction: the model decides which tools to use, retrieves the data, and then generates a final response.
Python

πŸš€ Generate the Stock Analysis & Strategy

Run the full conversation and stream the final response as the investment report and strategy.
Python

🌟 Highlights

This notebook has guided you through setting up and running a real-time stock analysis workflow using OpenAI Function Calling and Dappier. You can adapt and expand this example for various other scenarios requiring live financial insights, contextual understanding, and intelligent decision-making. Key tools utilized in this notebook include:
  • OpenAI Function Calling: Allows the model to automatically determine when to invoke external tools, enabling dynamic decision-making during a conversation.
  • Dappier: A platform connecting LLMs to real-time, rights-cleared data from trusted sources, specializing in domains like finance, news, and trading. It delivers enriched, prompt-ready data, empowering AI with verified and up-to-date information for diverse applications.
  • Streamed Response Generation: Leverages OpenAI’s streaming capability to output responses incrementally, improving performance and responsiveness when generating long-form content.
This comprehensive setup allows you to adapt and expand the example for various financial use cases requiring real-time information retrieval, AI-powered orchestration, and live strategy generation.