Connecting LLMs to tools

Google for Developers · Beginner ·🧠 Large Language Models ·2y ago

Key Takeaways

Connecting Large Language Models to external tools and APIs to leverage real-time information and take actions

Full Transcript

if you've been following the AI space you probably know that large language models are helping developers build all sorts of neat and novel applications that's because LMS are excellent at processing and producing nuanced fluid language but llms have some limitations for one out of the box they're not connected to the external world when responding to user queries they don't have access to knowledge outside of their training data this means they can't return real-time information about things like weather or traffic or the news and they also can't take actions like booking flights sending messages or writing information to a database in other words if we want llms to be really useful they need to be able to interact with the outside world when we ask an llm what the weather is at Austin tomorrow we wanted to pull this information from a weather API and if we wanted to do something more complicated like using LM as a helpful assistant that can help us book a trip at some point we're going to have to call some apis to put flights and make hotel reservations so how exactly do we teach llms to use external tools like apis let's take a look let's say we want to build a chatbot that has access to a weather API so that we can ask about the weather and it can give us updates in real time for example what's the weather in Austin how would we architect an app like this well the first step is to write a prompt to get the llm to specify when a call to the weather API is needed and second we need to write the application code to actually go out and execute that API call finally we need to feed the API output back into the llm so that it can produce a response for the user let's break down each of these three steps as usual with LMS the first thing that we want to do is to design a prompt and as a reminder a prompt is the text that we feed into an llm to get it to take on a particular Behavior in this case we want to write a prompt that allows the model to indicate what an API call is necessary here's one way we can structure that prompt we might start with an instruction that tells the llm what our objective is like your objective is to complete the user's tasks then we describe the tools the llm can use to complete the user request in this case the weather API for example you have access to the following tool followed by an example of what using the tool command looks like what we're doing here is simply telling the llm what tools it has access to in plain old English since llms are capable of processing nuanced natural language this is actually often enough to get the llm to take on the behavior that we want however sometimes it's also helpful to add some illustrative examples to our prompt showing the llm that we want Its Behavior to be one example input could be what is the weather in New York tomorrow and the example response we'd want is the command weather and the City New York we passed this prompt into an llm with a new user request like what's the weather in Austin tomorrow the llm should output something like this which is what we want what we've done here is design a prompt that can get an llm to Output tool commands when they're required to complete the user's request however just to be clear the LM isn't actually calling any of these apis it's just producing text that indicates that we the programmer should go out and actually make that API call and that's something we have to design at our application code so let's see what that might look like first we need to detect when the model outputs a tool command in our case we prompting the model to Output the tool command in these curly brackets so we just need to do a string search to identify when a command has been issued then we have to actually go out and execute this command to do that we'll take this string weather Austin and we'll extract the parameters we need to make the API call how we do this depends on the API and how complex it is here we just have to identify the target City Austin we write code to call the API and then we get back some response which is typically in the Json format okay let's recap we got the nlm to Output when an API command is needed to complete the user's query then our application executed the API command let's suppose the response into this Json object which contains the weather in Austin now we could just return the space on blob back to the user technically it answers the question but most people don't want to read Json so instead let's use the llm to take this info and produce a more conversational response we can accomplish this by writing a brand new prompt that shows the llm how to issue commands and how to rephrase the API output into something more conversational we'll rewrite our original prompt do just that here's the prompt we started with remember it included an example of the user asking for the weather in New York let's extend that example by showing the model how to reframe the API output first we add a new field to The Prompt where we append the Json response note that we're not gonna ever actually show the end user this Json but it will be part of the model prompt finally we add an example of how the model should rephrase the Json into something that sounds conversational like setup Now using this prompt when we ask what's the weather in Austin the bot responds starts with a command then we go out and we execute the API commanded code and append the response to the prompt then we call the Alum a second time and this time it takes an API response and voila our end user gets their question answered with real-time accurate weather this is one basic way to design an llm application that can interact with just one tool but how would you extend this to multiple Tools in addition to listing out all the tool commands that we want our analog to have access to we might need a more sophisticated prompt maybe one that even includes logic about when to use each tool one reason prompting technique known as react is a way of writing columns that combines Keen of thought prompting with taking actions as a reminder in a cloud prompting is a technique where we nudge the llm to explain steps of reasoning to arrive and answered the react technique can be especially useful if a single user query requires multiple steps and maybe even multiple tools to complete designing prompts to teach llms how to use tools is an active and developing area of research if you're curious to learn more about different prompting methods we've put some links in the description below that's the basics of connecting large language models to external tools let us know in the comments what tools you're using with llms thank you

Original Description

Large Language Models (LLMs) are helpful in many use cases for devs. However, their lack of access to knowledge outside of their training data limits their usefulness. If you’ve ever wanted an LLM to return real-time information or take an action, this video is for you. Prompt LLMs how to leverage external sources of information! Chapters: 0:00 - Intro 1:01 - Overview 1:31 - Prompt the LLM to call an API 3:08 - Write application code to call the API 3:43 - Feed API response to the LLM Resources: ReAct Prompting → https://goo.gle/43Jc3FW Subscribe to Google for Developers → https://goo.gle/developers #MachineLearning #MLmodels #LLMs #GenerativeAI
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from Google for Developers · Google for Developers · 0 of 60

← Previous Next →
1 Developer Journey - Sunnyvale DSC Summit ‘19
Developer Journey - Sunnyvale DSC Summit ‘19
Google for Developers
2 How Google is working with students - Sunnyvale DSC Summit ‘19
How Google is working with students - Sunnyvale DSC Summit ‘19
Google for Developers
3 Starting your career in the Cloud - Sunnyvale DSC Summit ‘19
Starting your career in the Cloud - Sunnyvale DSC Summit ‘19
Google for Developers
4 The Solution Challenge  - Sunnyvale DSC Summit ‘19
The Solution Challenge - Sunnyvale DSC Summit ‘19
Google for Developers
5 Firebase - Sunnyvale DSC Summit ‘19
Firebase - Sunnyvale DSC Summit ‘19
Google for Developers
6 Cloud Hero - Sunnyvale DSC Summit ‘19
Cloud Hero - Sunnyvale DSC Summit ‘19
Google for Developers
7 Panel discussion  - Sunnyvale DSC Summit ‘19
Panel discussion - Sunnyvale DSC Summit ‘19
Google for Developers
8 The art of negotiation - Sunnyvale DSC Summit ‘19
The art of negotiation - Sunnyvale DSC Summit ‘19
Google for Developers
9 Courage to care, solve and share - Sunnyvale DSC Summit ‘19
Courage to care, solve and share - Sunnyvale DSC Summit ‘19
Google for Developers
10 Version 9 of Angular, Glass Enterprise Edition 2, path to DX deprecation, & more!
Version 9 of Angular, Glass Enterprise Edition 2, path to DX deprecation, & more!
Google for Developers
11 [DEPRECATING] Introducing a new series (Assistant for Developers Pro Tips)
[DEPRECATING] Introducing a new series (Assistant for Developers Pro Tips)
Google for Developers
12 Detecting memory bugs with HWASan, Bazel 2.1, Next ‘20 session guide, & more!
Detecting memory bugs with HWASan, Bazel 2.1, Next ‘20 session guide, & more!
Google for Developers
13 Why Podcast.app chose a .app domain name
Why Podcast.app chose a .app domain name
Google for Developers
14 Machine Learning Bootcamp Jakarta 2019
Machine Learning Bootcamp Jakarta 2019
Google for Developers
15 Android Studio 3.6, Android 11 Developer Preview, Kubeflow 1.0, & more!
Android Studio 3.6, Android 11 Developer Preview, Kubeflow 1.0, & more!
Google for Developers
16 [DEPRECATING]  Importance of community (Assistant on Air)
[DEPRECATING] Importance of community (Assistant on Air)
Google for Developers
17 Why the Flutter team switched from .io to a .dev domain name
Why the Flutter team switched from .io to a .dev domain name
Google for Developers
18 3 website-building tips from .dev creators
3 website-building tips from .dev creators
Google for Developers
19 Why NimbleDroid chose a .app domain name
Why NimbleDroid chose a .app domain name
Google for Developers
20 Android Platform Codelab, Bazel 2.2, Maps Android Utility Library v1.0, & more!
Android Platform Codelab, Bazel 2.2, Maps Android Utility Library v1.0, & more!
Google for Developers
21 Google for Games Developer Summit: A free, digital experience for game developers
Google for Games Developer Summit: A free, digital experience for game developers
Google for Developers
22 Inspecting Home Graph (Assistant for Developers Pro Tips)
Inspecting Home Graph (Assistant for Developers Pro Tips)
Google for Developers
23 Google for Games Developer Summit Keynote
Google for Games Developer Summit Keynote
Google for Developers
24 Stadia Games & Entertainment presents: Keys to a great game pitch (Google Games Dev Summit)
Stadia Games & Entertainment presents: Keys to a great game pitch (Google Games Dev Summit)
Google for Developers
25 Empowering game developers with Stadia R&D (Google Games Dev Summit)
Empowering game developers with Stadia R&D (Google Games Dev Summit)
Google for Developers
26 Supercharging discoverability with Stadia (Google Games Dev Summit)
Supercharging discoverability with Stadia (Google Games Dev Summit)
Google for Developers
27 Stadia Games & Entertainment presents: Creating for content creators (Google Games Dev Summit)
Stadia Games & Entertainment presents: Creating for content creators (Google Games Dev Summit)
Google for Developers
28 Bringing Destiny to Stadia: A postmortem (Google Games Dev Summit)
Bringing Destiny to Stadia: A postmortem (Google Games Dev Summit)
Google for Developers
29 Live Captioning in Google Slides
Live Captioning in Google Slides
Google for Developers
30 [DEPRECATING]  User engagement for the Google Assistant
[DEPRECATING] User engagement for the Google Assistant
Google for Developers
31 TensorFlow Dev Summit ‘20, Google for Games Dev Summit, Cloud AI Platform Pipelines, & much more!
TensorFlow Dev Summit ‘20, Google for Games Dev Summit, Cloud AI Platform Pipelines, & much more!
Google for Developers
32 Top 5 from the TensorFlow Dev Summit 2020
Top 5 from the TensorFlow Dev Summit 2020
Google for Developers
33 Developer Student Clubs 2019 Turkey Leads Summit
Developer Student Clubs 2019 Turkey Leads Summit
Google for Developers
34 Building simpler payment experiences | Google Pay Plugin for Magento 2
Building simpler payment experiences | Google Pay Plugin for Magento 2
Google for Developers
35 Become A Developer Student Club Lead
Become A Developer Student Club Lead
Google for Developers
36 Firebase Kotlin Extensions, ARM apps on the Android Emulator, Angular v9.1, & more!
Firebase Kotlin Extensions, ARM apps on the Android Emulator, Angular v9.1, & more!
Google for Developers
37 Test suite for Smart Home (Assistant for Developers Pro Tips)
Test suite for Smart Home (Assistant for Developers Pro Tips)
Google for Developers
38 Google Play updates, Bazel 3.0, Business Console for Google Pay, & more!
Google Play updates, Bazel 3.0, Business Console for Google Pay, & more!
Google for Developers
39 How to use error logs (Assistant for Developers Pro Tips)
How to use error logs (Assistant for Developers Pro Tips)
Google for Developers
40 Contact Center AI, Android Studio 4.1 Canary 5, TensorFlow QAT API, & more!
Contact Center AI, Android Studio 4.1 Canary 5, TensorFlow QAT API, & more!
Google for Developers
41 WebView DevTools, Kotlin meets gRPC, Flutter CodePen support, & more! (Episode 200)
WebView DevTools, Kotlin meets gRPC, Flutter CodePen support, & more! (Episode 200)
Google for Developers
42 Offline handling for Smart Home (Assistant for Developers Pro Tips)
Offline handling for Smart Home (Assistant for Developers Pro Tips)
Google for Developers
43 Android 11 Dev Preview 3, Google Fonts for Flutter, Shielded VM, & more!
Android 11 Dev Preview 3, Google Fonts for Flutter, Shielded VM, & more!
Google for Developers
44 Machine Learning Foundations: Ep #1 - What is ML?
Machine Learning Foundations: Ep #1 - What is ML?
Google for Developers
45 Flutter web support updates, BigQuery materialized views, Cloud Spanner emulator, & more!
Flutter web support updates, BigQuery materialized views, Cloud Spanner emulator, & more!
Google for Developers
46 Computer vision by building a neural network with TensorFlow | Machine Learning Foundations
Computer vision by building a neural network with TensorFlow | Machine Learning Foundations
Google for Developers
47 Machine Learning Foundations: Ep #3 - Convolutions and pooling
Machine Learning Foundations: Ep #3 - Convolutions and pooling
Google for Developers
48 Android 11 Beta plans, Flutter 1.17, Dart 2.8, & much more!
Android 11 Beta plans, Flutter 1.17, Dart 2.8, & much more!
Google for Developers
49 Machine Learning Foundations: Ep #4 - Coding with Convolutional Neural Networks
Machine Learning Foundations: Ep #4 - Coding with Convolutional Neural Networks
Google for Developers
50 Google Developers ML Summit
Google Developers ML Summit
Google for Developers
51 Real-world image classification using convolutional neural networks | Machine Learning Foundations
Real-world image classification using convolutional neural networks | Machine Learning Foundations
Google for Developers
52 Adobe XD support for Flutter, Architecture Framework, temporary closures with Places API, & more!
Adobe XD support for Flutter, Architecture Framework, temporary closures with Places API, & more!
Google for Developers
53 Machine Learning Foundations: Ep #6 - Convolutional cats and dogs
Machine Learning Foundations: Ep #6 - Convolutional cats and dogs
Google for Developers
54 Machine Learning Foundations: Ep #7 - Image augmentation and overfitting
Machine Learning Foundations: Ep #7 - Image augmentation and overfitting
Google for Developers
55 Announcing Firebase Live, Flutter Day, Java 11 on Google Cloud Functions, & more!
Announcing Firebase Live, Flutter Day, Java 11 on Google Cloud Functions, & more!
Google for Developers
56 Machine Learning Foundations: Ep #8 - Tokenization for Natural Language Processing
Machine Learning Foundations: Ep #8 - Tokenization for Natural Language Processing
Google for Developers
57 Android 11 Beta, Google Play Asset Delivery, Firebase Crashlytics SDK, & much more!
Android 11 Beta, Google Play Asset Delivery, Firebase Crashlytics SDK, & much more!
Google for Developers
58 Natural Language Processing: Using sequencing APIs in TensorFlow | Machine Learning Foundations
Natural Language Processing: Using sequencing APIs in TensorFlow | Machine Learning Foundations
Google for Developers
59 Build a sarcasm classifier using NLP and TensorFlow | Machine Learning Foundations
Build a sarcasm classifier using NLP and TensorFlow | Machine Learning Foundations
Google for Developers
60 AR Realism with the ARCore Depth API
AR Realism with the ARCore Depth API
Google for Developers

Related Reads

📰
TAI #214: Kimi K3 Brings Open Weight Closer to the Frontier
Kimi K3 brings open weight closer to the frontier, and Fable disproves an 87-year-old math conjecture, showcasing AI's capabilities in math and science
Medium · LLM
📰
MCP Explained: How AI Learns to Use the Real World
Learn how AI uses the Model Context Protocol to interact with the real world and leverage external resources
Medium · LLM
📰
What is the Model Context Protocol (MCP)?
Learn about the Model Context Protocol (MCP), an open standard for connecting language models to tools and data through a consistent interface
Dev.to AI
📰
Green Is Not Correct — field notes from an AI orchestrator, end of a long shift
Learn from an AI orchestrator's field notes at the end of a long shift, exploring the complexities of AI operations
Medium · LLM

Chapters (4)

Intro
1:01 Overview 1:31 - Prompt the LLM to call an API
3:08 Write application code to call the API
3:43 Feed API response to the LLM
Up next
5 Levels of AI Agents - From Simple LLM Calls to Multi-Agent Systems
Dave Ebbelaar (LLM Eng)
Watch →