Welcome to the world of AI-powered GraphQL! This guide will show you how to bind the GraphQL Agent Tool with your LLM models. It's like giving your GraphQL tools a brain! 🧠
The GraphQL Agent Tool can be bound with any LLM that supports tool calling. This enables your LLM to:
Here's how to bind the GraphQL Agent Tool with your LLM:
import { GraphqlAgentTool } from "graphql-agent-tool";
import { YourLLM } from "your-llm-package";
// Create a GraphQL tool for country information
const countryInfoTool = new GraphqlAgentTool({
name: "getCountryInfo",
purpose: "Retrieves information about countries including capital, population, and languages...",
url: "https://countries.trevorblades.com",
query: `
query GetCountryInfo($countryCode: ID!) {
country(code: $countryCode) {
capital
population
languages {
name
}
}
}
`,
}).getTool();
// Create a GraphQL tool for space information
const spaceInfoTool = new GraphqlAgentTool({
name: "getSpaceInfo",
purpose: "Retrieves information about space missions and launches...",
url: "https://api.spacex.land/graphql",
query: `
query GetLaunches($limit: Int!) {
launches(limit: $limit) {
mission_name
launch_date_local
launch_site {
site_name_long
}
}
}
`,
}).getTool();
// Create a GraphQL tool for movie information
const movieInfoTool = new GraphqlAgentTool({
name: "getMovieInfo",
purpose: "Retrieves information about movies including title, release date, and cast...",
url: "https://tmdb.sandbox.zoosh.ie/graphql",
query: `
query GetMovie($id: ID!) {
movie(id: $id) {
title
releaseDate
cast {
name
character
}
}
}
`,
}).getTool();
// Bind the tools with your LLM
const llm = new YourLLM({
tools: [countryInfoTool, spaceInfoTool, movieInfoTool],
});
// The LLM can now use these tools autonomously
const response = await llm.chat("What's the capital of India and when was the last SpaceX launch?");
Here are some free, open GraphQL APIs you can use with the tool:
Countries API
https://countries.trevorblades.com
SpaceX API
https://api.spacex.land/graphql
TMDB GraphQL
https://tmdb.sandbox.zoosh.ie/graphql
Rick and Morty API
https://rickandmortyapi.com/graphql
AniList API
https://graphql.anilist.co
Ready to explore more? Check out:
Happy AI-powered querying! 🎉