Google Gemini Function Calling ๐Ÿš€ EASILY Integrate your OWN Function!

Mervin Praison ยท Beginner ยท๐Ÿง  Large Language Models ยท2y ago

Key Takeaways

This video demonstrates how to integrate custom functions with the Gemini large language model using Python, specifically by creating a function to retrieve real-time stock prices using Yahoo Finance.

Full Transcript

this is amazing what if you can do function calling in Gemini large language model what if you can integrate that in your python application that's exactly what we're going to see today let's get [Music] started hi everyone I'm really excited to show you about function calling in Gemini large language model I'm going to take you through step by step on how to do this but before that I regularly create videos in regards to Artificial Intelligence on my YouTube channel so do subscribe and click the Bell icon to stay tuned coming to using Gemini API using vertex AI we've already covered this in a previous video which I will link that in the description below as a quick summary we import the generative model we Define the model name we initiated the chat and send the question to the chat model now I'm going to run this code the question is what is the stock price of Apple so in your terminal python function calling. and click enter and here is the response as AA language model I don't have real time access to the stock market and cannot provide the stock price of Apple this is when the function calling come in you can integrate your own application you can integrate your own function in Gemini how can we do that in this image we can see already we have initiated our model and we are sending prompt to gerini model but now we are going to add extra one more step which is function calling we're going to install why Finance this is required to get the realtime stock price so in this we are going to create application to get the realtime stock price and integrate that in gerini using function calling so as a first step you are importing y Finance as YF next we are going to add function declaration part and Tool these are required to perform function calling and next we're going to write the get stock price function this function get the ticker symbol and then use that to get the latest stock price next we need to write function definition so I'm going to add a tools variable the function is tool which we have already declared at the top and this is the way you define the function function declarations and sending the list of functions so here we are passing only one function which is get stock price and we are defining the properties ticker is the only parameter for example by providing AAPL it will automatically give us the stock price of Apple now we're going to add this Tools in the generative model function now we have completed model initialization and sending a prompt the third step is to check the function calling in this we are getting the function calling from the response we received now we're going to print function call and also let's see the response I'm going to delete this in your terminal python function calling. pi and click enter and here is the response so we receive the function call with the Apple symbol AAPL and the full response now we need to pause this run the function and send the value back to Gemini in this step we are checking if there is a function calling happening or not if it is happening then we are processing that and sending back the response to Gemini let's try to write that in coding so here we are going to add the list of functions which is get stock price and check it against the received response if the received function name contains get stock price then get the arguments that is a symbol and then run the function using this this will automatically run the get stock price function retrieve the stock price of Apple and now we need to send that back to Gemini so to do that response is equals chat. send message we are using the partt from function response and sending the function name that is get stock price and the and also the value which we received by running the get stock function finally chat response we getting the value and then printing the response else we are printing the chat response without function calling so here we check if a function calling is initiated if it is initiated then it will automatically run the function send the result back to gerini IF function calling is not initiated then it will automatically print the default response which we received from step two as we have seen here initially we are sending the prompt if a function calling is initiated then it will come to function calling and then print the results IF function calling is not initiated it will directly print the results as a quick summary we created get stock price function this will automatically get the stock price using Yahoo finance then we are defining the tools and passing this tools to the generative model tools next we are checking if function calling is initiated by Gemini if it is initiated then run the function and send the response back to gerini if no function calling is initiated just print the original response that's it now we going to run this code in your terminal python function calling. pi and click enter so we can see function calling got initiated and we got the answer the current stock price of Apple is $11 19757 as simple as that now you are able to integrate your own function own program into Gemini I'm going to create more videos in regards to Gemini so stay tuned I hope you like this video do like share and subscribe and thanks for watching

Original Description

๐ŸŒŸ Welcome to an Exciting Journey with Gemini Large Language Model & Python! In today's video, we delve into the fascinating world of function calling in the Gemini large language model. ๐Ÿง  I'll guide you step-by-step on integrating this cutting-edge technology into your Python applications. ๐Ÿ ๐Ÿ” What We Cover: Introduction to Function Calling in Gemini Setting up the Gemini API with Vertex AI Writing a get_stock_price Function with Yahoo Finance Implementing Function Calls in Gemini Running the Code & Seeing Real-Time Results ๐Ÿ”” Stay Updated! Don't miss out on our future content about Artificial Intelligence. Subscribe and hit the bell icon for regular updates! ๐Ÿ“บ ๐Ÿ’ก Takeaways: Learn how to seamlessly integrate real-time functions, like fetching stock prices, into your Gemini AI applications, enhancing their capabilities and making them more interactive and responsive. What if you could use function calling in Gemini, the large language model? In this video, we'll show you how to integrate function calling into your Python application. By following these step-by-step instructions, you'll be able to create your own application that retrieves real-time stock prices using the Y Finance library. Watch the video to learn how to integrate your own functions into Gemini and get the stock price of Apple in real-time! ๐Ÿ‘ Like, Share, and Subscribe! If you find this video helpful, please like, share, and subscribe for more content on Artificial Intelligence and Python programming. Timestamps: 0:00 Introduction to Function Calling in Gemini 0:20 Step-by-Step Integration Guide 0:39 Using Gemini API with Vertex AI 0:51 Running the Python Code 1:09 Integrating Real-Time Stock Price Function 2:00 Defining and Using the get_stock_price Function 3:08 Processing Function Calls in Gemini 4:17 Handling Non-Function Calls 5:00 Final Code Run and Results 5:30 Closing Thoughts and Future Content Preview code: https://mer.vin/2023/12/gemini-function-calling/ #GeminiFunctionCallin
Watch on YouTube โ†— (saves to browser)
Sign in to unlock AI tutor explanation ยท โšก30

Playlist

Uploads from Mervin Praison ยท Mervin Praison ยท 0 of 60

โ† Previous Next โ†’
1 Build GCP Infra using Pulumi in YAML format
Build GCP Infra using Pulumi in YAML format
Mervin Praison
2 How to Convert a Pulumi YAML File to Python Format
How to Convert a Pulumi YAML File to Python Format
Mervin Praison
3 Speed Up AWS EKS: A Complete Guide to Performance Tuning & Debugging!
Speed Up AWS EKS: A Complete Guide to Performance Tuning & Debugging!
Mervin Praison
4 Learn GCP GKE to AWS EKS Migration in Just 5 Minutes: Quick Guide
Learn GCP GKE to AWS EKS Migration in Just 5 Minutes: Quick Guide
Mervin Praison
5 AWS & Kubernetes: The Definitive Guide to Data Persistence with PV and PVC
AWS & Kubernetes: The Definitive Guide to Data Persistence with PV and PVC
Mervin Praison
6 ChatGPT Voice Conversation RELEASED! It's AMAZING!! (Demo)
ChatGPT Voice Conversation RELEASED! It's AMAZING!! (Demo)
Mervin Praison
7 How to Install Mistral 7B in Minutes: Quick & Easy Guide! โœ…
How to Install Mistral 7B in Minutes: Quick & Easy Guide! โœ…
Mervin Praison
8 Code Llama Install Locally: ๐Ÿ๐Ÿ’ป Elevate Your Python Skills!
Code Llama Install Locally: ๐Ÿ๐Ÿ’ป Elevate Your Python Skills!
Mervin Praison
9 Orca Mini: Your Ultimate Guide to Install and Test on Mac & Linux ๐Ÿ’ป
Orca Mini: Your Ultimate Guide to Install and Test on Mac & Linux ๐Ÿ’ป
Mervin Praison
10 Quick & Easy Vicuna Setup on Mac and Linux ๐Ÿ’ป
Quick & Easy Vicuna Setup on Mac and Linux ๐Ÿ’ป
Mervin Praison
11 Quick Guide: Llama2 Local Installation and ChatGPT with pip! Python๐Ÿ› ๏ธ
Quick Guide: Llama2 Local Installation and ChatGPT with pip! Python๐Ÿ› ๏ธ
Mervin Praison
12 Query PDFs Like a Pro with Local GPT: Full Setup Guide! ๐Ÿ“œ
Query PDFs Like a Pro with Local GPT: Full Setup Guide! ๐Ÿ“œ
Mervin Praison
13 LM Studio: EASIEST way to Run Large Language Models Locally!
LM Studio: EASIEST way to Run Large Language Models Locally!
Mervin Praison
14 AMAZING ChatGPT Vision is OUT! ๐Ÿคฏ 14+ Examples (Step-by-Step) FULL Tutorial
AMAZING ChatGPT Vision is OUT! ๐Ÿคฏ 14+ Examples (Step-by-Step) FULL Tutorial
Mervin Praison
15 Unbelievable! Build ANY App Instantly with Smol AI! ๐Ÿ˜ฒ๐Ÿ”ฅ
Unbelievable! Build ANY App Instantly with Smol AI! ๐Ÿ˜ฒ๐Ÿ”ฅ
Mervin Praison
16 Amazing! AutoGen Made Easy: A Step-by-Step Beginners Guide ๐Ÿ“š
Amazing! AutoGen Made Easy: A Step-by-Step Beginners Guide ๐Ÿ“š
Mervin Praison
17 How to Set Up LoLLMS and Run LLMs Locally! ๐Ÿš€ Step-by-Step Tutorial
How to Set Up LoLLMS and Run LLMs Locally! ๐Ÿš€ Step-by-Step Tutorial
Mervin Praison
18 GPT4All: INSANE Way to Run Large Language Models Locally! ๐Ÿ˜ฒ Step-By-Step Tutorial
GPT4All: INSANE Way to Run Large Language Models Locally! ๐Ÿ˜ฒ Step-By-Step Tutorial
Mervin Praison
19 Incredible AI-Powered NPCs in Unity Game Engine: Step by Step Tutorial!๐Ÿคฏ
Incredible AI-Powered NPCs in Unity Game Engine: Step by Step Tutorial!๐Ÿคฏ
Mervin Praison
20 MemGPT ๐Ÿง  LLM as Operating System. It's INSANE! Step-by-Step Tutorial ๐Ÿคฏ
MemGPT ๐Ÿง  LLM as Operating System. It's INSANE! Step-by-Step Tutorial ๐Ÿคฏ
Mervin Praison
21 Text Generation Web UI: MIND-BLOWING Way to Run LLM Locally! ๐Ÿคฏ
Text Generation Web UI: MIND-BLOWING Way to Run LLM Locally! ๐Ÿคฏ
Mervin Praison
22 Unlock the INSANE Power of OpenAI GPT-4 with C#/.NET! ๐Ÿ˜ฒ
Unlock the INSANE Power of OpenAI GPT-4 with C#/.NET! ๐Ÿ˜ฒ
Mervin Praison
23 Integrate Langchain and Ollama for Local AI Power ๐Ÿคฏ Indeed POWERFUL!
Integrate Langchain and Ollama for Local AI Power ๐Ÿคฏ Indeed POWERFUL!
Mervin Praison
24 ChatDev: INSANE Virtual AI Agents! Future of Software Development ๐Ÿ˜ฒ
ChatDev: INSANE Virtual AI Agents! Future of Software Development ๐Ÿ˜ฒ
Mervin Praison
25 Query PDFs Using Mistral: Unlock INSANE Power! ๐Ÿคฏ
Query PDFs Using Mistral: Unlock INSANE Power! ๐Ÿคฏ
Mervin Praison
26 AutoGen + Open-Source LLMs: UNBELIEVABLE! Step-by-Step Tutorial You Can't Miss! ๐Ÿคฏ
AutoGen + Open-Source LLMs: UNBELIEVABLE! Step-by-Step Tutorial You Can't Miss! ๐Ÿคฏ
Mervin Praison
27 AutoGen + Text Generation WebUI: Unbelievable 100% Local Private Setup ๐Ÿคฏ
AutoGen + Text Generation WebUI: Unbelievable 100% Local Private Setup ๐Ÿคฏ
Mervin Praison
28 MemGPT: Amazing! External Context for LLM #ai #llm #memgpt  #generativeai #mem #gpt #openai #chatgpt
MemGPT: Amazing! External Context for LLM #ai #llm #memgpt #generativeai #mem #gpt #openai #chatgpt
Mervin Praison
29 GeniA: Kubernetes + AI for MIND-BLOWING Operational Efficiency! ๐Ÿคฏ FULL Tutorial
GeniA: Kubernetes + AI for MIND-BLOWING Operational Efficiency! ๐Ÿคฏ FULL Tutorial
Mervin Praison
30 VertexAI Meets LangChain for Mind-Blowing AI Conversations! ๐Ÿ˜ฒ Step by Step Tutorial
VertexAI Meets LangChain for Mind-Blowing AI Conversations! ๐Ÿ˜ฒ Step by Step Tutorial
Mervin Praison
31 Simplified ChatGPT API Setup on Node.js for Newbies! ๐Ÿ˜ Step by Step Tutorial
Simplified ChatGPT API Setup on Node.js for Newbies! ๐Ÿ˜ Step by Step Tutorial
Mervin Praison
32 Autogen: Ollama integration ๐Ÿคฏ Step by Step Tutorial. Mind-blowing!
Autogen: Ollama integration ๐Ÿคฏ Step by Step Tutorial. Mind-blowing!
Mervin Praison
33 LiteLLM: One-Function Call to ANY Large Language Model! ๐Ÿคฏ UNBELIEVABLE!
LiteLLM: One-Function Call to ANY Large Language Model! ๐Ÿคฏ UNBELIEVABLE!
Mervin Praison
34 ChatGPT Chatbot in Less Time Than You Think! ๐Ÿš€๐Ÿ˜Ž Step-by-Step Tutorial
ChatGPT Chatbot in Less Time Than You Think! ๐Ÿš€๐Ÿ˜Ž Step-by-Step Tutorial
Mervin Praison
35 LiteLLM Chatbot: Build Your Own in MINUTES! INSANE! ๐Ÿค–๐Ÿ”ฅ
LiteLLM Chatbot: Build Your Own in MINUTES! INSANE! ๐Ÿค–๐Ÿ”ฅ
Mervin Praison
36 Create Chatbot: Turn ANY Open-Source LLM into a Conversation Pro! ๐Ÿค–
Create Chatbot: Turn ANY Open-Source LLM into a Conversation Pro! ๐Ÿค–
Mervin Praison
37 Create Chatbot: Ollama Integration Made UNBELIEVABLY Easy! ๐ŸŽ‰
Create Chatbot: Ollama Integration Made UNBELIEVABLY Easy! ๐ŸŽ‰
Mervin Praison
38 LlamaIndex + ChatGPT: Ingest Data and Experience UNBELIEVABLE Query Results! ๐ŸŒŸ
LlamaIndex + ChatGPT: Ingest Data and Experience UNBELIEVABLE Query Results! ๐ŸŒŸ
Mervin Praison
39 INSANE! OpenAgents: Automated Data Analysis with Kaggle ๐Ÿคฏ
INSANE! OpenAgents: Automated Data Analysis with Kaggle ๐Ÿคฏ
Mervin Praison
40 React.js LLM Agent for Next-Gen Coding using ChatGPT ๐Ÿš€ Mind-Blowing ๐Ÿคฏ
React.js LLM Agent for Next-Gen Coding using ChatGPT ๐Ÿš€ Mind-Blowing ๐Ÿคฏ
Mervin Praison
41 MemGPT + Any LLM ๐Ÿš€ 100% Local & Private Integration Unveiled! Unlimited Memory
MemGPT + Any LLM ๐Ÿš€ 100% Local & Private Integration Unveiled! Unlimited Memory
Mervin Praison
42 MemGPT  + AutoGen ๐Ÿง ๐Ÿค– Unlimited Memory & Autonomous AI Agents! INSANE๐Ÿคฏ
MemGPT + AutoGen ๐Ÿง ๐Ÿค– Unlimited Memory & Autonomous AI Agents! INSANE๐Ÿคฏ
Mervin Praison
43 AutoGen + Google's Palm LLM & More! Revolutionary AI Integration ๐Ÿš€
AutoGen + Google's Palm LLM & More! Revolutionary AI Integration ๐Ÿš€
Mervin Praison
44 MemGPT & LM Studio Integration Revealed! ๐Ÿ”ฅ Next-Level AI
MemGPT & LM Studio Integration Revealed! ๐Ÿ”ฅ Next-Level AI
Mervin Praison
45 ๐Ÿš€ AutoLLM: Unlock the Power of 100+ Language Models! Step-by-Step Tutorial
๐Ÿš€ AutoLLM: Unlock the Power of 100+ Language Models! Step-by-Step Tutorial
Mervin Praison
46 AutoLLM & Gradio Integration You Won't Believe! ๐Ÿคฏ Mind-Blowing
AutoLLM & Gradio Integration You Won't Believe! ๐Ÿคฏ Mind-Blowing
Mervin Praison
47 AutoLLM & FastAPI Tutorial: Query 100+ Language Models! ๐Ÿ˜ฑ
AutoLLM & FastAPI Tutorial: Query 100+ Language Models! ๐Ÿ˜ฑ
Mervin Praison
48 Quivr: LLM's Second Brain - Transforming Data Management & Advanced Query with AI! ๐Ÿคฏ
Quivr: LLM's Second Brain - Transforming Data Management & Advanced Query with AI! ๐Ÿคฏ
Mervin Praison
49 AutoGen & MemGPT with Local LLM: A Complete Setup Tutorial! ๐Ÿง  AMAZING ๐Ÿคฏ
AutoGen & MemGPT with Local LLM: A Complete Setup Tutorial! ๐Ÿง  AMAZING ๐Ÿคฏ
Mervin Praison
50 LocalAI: Free, Open Source OpenAI Alternative ๐Ÿš€ INSANE ๐Ÿคฏ Step-by-Step Tutorial
LocalAI: Free, Open Source OpenAI Alternative ๐Ÿš€ INSANE ๐Ÿคฏ Step-by-Step Tutorial
Mervin Praison
51 Yarn Mistral 7B 128k LARGE context window, Small size ๐Ÿคฏ INSANE ๐Ÿš€ Setup Tutorial!
Yarn Mistral 7B 128k LARGE context window, Small size ๐Ÿคฏ INSANE ๐Ÿš€ Setup Tutorial!
Mervin Praison
52 Zephyr-7B: The Small and Mighty LLM ๐Ÿคฏ Step by Step Tutorial! ๐Ÿ“˜
Zephyr-7B: The Small and Mighty LLM ๐Ÿคฏ Step by Step Tutorial! ๐Ÿ“˜
Mervin Praison
53 Promptfoo: How to Test Your LLM ? ๐Ÿš€  VERY EASY!
Promptfoo: How to Test Your LLM ? ๐Ÿš€ VERY EASY!
Mervin Praison
54 Pydantic: How to Validate LLM Responses? ๐Ÿš€ Quality Response. VERY EASY!!!!
Pydantic: How to Validate LLM Responses? ๐Ÿš€ Quality Response. VERY EASY!!!!
Mervin Praison
55 Pydantic: FORCE Your AI to Respond Back in UPPERCASE! ๐Ÿคฏ Step-by-Step Tutorial ๐Ÿ”ฅ
Pydantic: FORCE Your AI to Respond Back in UPPERCASE! ๐Ÿคฏ Step-by-Step Tutorial ๐Ÿ”ฅ
Mervin Praison
56 Pydantic: How to use LLM to convert unstructured data to structured data?
Pydantic: How to use LLM to convert unstructured data to structured data?
Mervin Praison
57 AutoGen Function Calling: INSANE ๐Ÿš€ Custom Integrations! Step-by-Step Tutorial ๐Ÿคฏ
AutoGen Function Calling: INSANE ๐Ÿš€ Custom Integrations! Step-by-Step Tutorial ๐Ÿคฏ
Mervin Praison
58 OpenAI Assistants API + Python ๐Ÿค– How to get started? (FULL Tutorial) ๐Ÿคฏ INSANE
OpenAI Assistants API + Python ๐Ÿค– How to get started? (FULL Tutorial) ๐Ÿคฏ INSANE
Mervin Praison
59 GPT-4 Vision API ๐Ÿคฏ INSANE Video Recognition Powers! Step-by-Step Tutorial ๐Ÿš€
GPT-4 Vision API ๐Ÿคฏ INSANE Video Recognition Powers! Step-by-Step Tutorial ๐Ÿš€
Mervin Praison
60 GPT-4 Vision API ๐Ÿš€ The Future of Image Recognition! ๐Ÿคฏ Step-by-Step Tutorial
GPT-4 Vision API ๐Ÿš€ The Future of Image Recognition! ๐Ÿคฏ Step-by-Step Tutorial
Mervin Praison

This video teaches viewers how to integrate custom functions with the Gemini large language model using Python, enabling them to create more sophisticated applications that leverage the model's capabilities. By following along, viewers can learn how to use the yfinance library to retrieve real-time stock prices and return the results to the Gemini model.

Key Takeaways
  1. Import necessary libraries, including yfinance
  2. Define a custom function to retrieve real-time stock prices
  3. Initialize the Gemini model and define the tools variable
  4. Pass the custom function to the Gemini model using the tools variable
  5. Check for function calling in the response from the Gemini model
  6. Run the custom function and send the results back to the Gemini model if function calling is initiated
๐Ÿ’ก The Gemini large language model can be extended with custom functions using the tools variable, allowing developers to create more complex and sophisticated applications.
๐Ÿ”’ Pro feature: Ask AI to explain this lesson โ†’

Related Reads

Chapters (10)

Introduction to Function Calling in Gemini
0:20 Step-by-Step Integration Guide
0:39 Using Gemini API with Vertex AI
0:51 Running the Python Code
1:09 Integrating Real-Time Stock Price Function
2:00 Defining and Using the get_stock_price Function
3:08 Processing Function Calls in Gemini
4:17 Handling Non-Function Calls
5:00 Final Code Run and Results
5:30 Closing Thoughts and Future Content Preview
Up next
5 Levels of AI Agents - From Simple LLM Calls to Multi-Agent Systems
Dave Ebbelaar (LLM Eng)
Watch โ†’