From 78d9b52dde26ce413e174768717befafbf108d22 Mon Sep 17 00:00:00 2001 From: Tobiloba Adedeji Date: Wed, 16 Apr 2025 11:00:57 +0100 Subject: [PATCH 1/4] docs: add langchain integration --- docs/agent-integrations/langchain.md | 75 ++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 docs/agent-integrations/langchain.md diff --git a/docs/agent-integrations/langchain.md b/docs/agent-integrations/langchain.md new file mode 100644 index 00000000..7685371c --- /dev/null +++ b/docs/agent-integrations/langchain.md @@ -0,0 +1,75 @@ +--- +sidebar_position: 9 +--- + +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; + +# Langchain integration + +:::note +Integrations with Langchain can be done with Python or Javascript. +::: + +LangChain is a framework for developing large language model (LLM) powered applications. + +You can configure Langchain to use any Gaia node as the LLM backend, that way you can build any AI agent or AI-powered application that uses Gaia for inferencing. + +## Prerequisites + +You will need a Gaia node ready to provide LLM services through a public URL. You can: + +- [Run your own node](../../getting-started/quick-start) +- [Use a public node](../nodes) + +If you are using a public node, you will need an [API key](https://www.gaianet.ai/setting/gaia-api-keys). Gaia overs free 50,000 API credits to use with the available services such as public nodes. + +In this tutorial, we will be running our not need an API key, you can use a string like: "Gaia". + + To get started with running your node, you can follow the guide on the [Setting up your own node](/getting-started/quick-start) page first and then come back here for integrations. + +## Integration with Gaia + +Integrations with Langchain and Gaia can be done with any JavaScript or Python. There are code snippets below that show how integration looks like in both languages: + + + + ```js + import { ChatOpenAI, OpenAI } from "@langchain/openai"; + import dotenv from "dotenv"; + + dotenv.config(); + + + const model = new ChatOpenAI({ + configuration: { + apiKey: process.env.GAIANET_API_KEY, + model: "Llama-3-Groq-8B-Tool", + baseURL: + "gaia-node-url/v1", + }, + }); + + const response = await model.invoke("Hello, world!"); + + console.log(response) + ``` + + + ```python + from langchain_openai import ChatOpenAI, OpenAI + + model = ChatOpenAI( + api_key=os.environ.get("GAIANET_API_KEY"), + model="Llama-3-Groq-8B-Tool", + base_url="gaia-node-url/v1" + ) + + reponse = model.invoke("Hello, world!") + + print(response) + ``` + + + +From the above, you can then start making invocations to the model and you're good to go! \ No newline at end of file From 377f7459a5ca89e93528395f9c15ed3958ab15fe Mon Sep 17 00:00:00 2001 From: Tobiloba Adedeji Date: Wed, 16 Apr 2025 11:03:23 +0100 Subject: [PATCH 2/4] docs: add langchain integration --- docs/agent-integrations/langchain.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/agent-integrations/langchain.md b/docs/agent-integrations/langchain.md index 7685371c..819bfe6d 100644 --- a/docs/agent-integrations/langchain.md +++ b/docs/agent-integrations/langchain.md @@ -72,4 +72,4 @@ Integrations with Langchain and Gaia can be done with any JavaScript or Python. -From the above, you can then start making invocations to the model and you're good to go! \ No newline at end of file +From the above, you can then start making invocations to the model. The LangChain also opens up integrations with [LangGraph](https://www.langchain.com/langgraph) and [LangSmith](https://www.langchain.com/langsmith). \ No newline at end of file From bb318f264de94196c48a4a51c769f8321337ab7d Mon Sep 17 00:00:00 2001 From: Tobiloba Adedeji Date: Wed, 16 Apr 2025 11:05:35 +0100 Subject: [PATCH 3/4] docs: add further updates --- docs/agent-integrations/langchain.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/agent-integrations/langchain.md b/docs/agent-integrations/langchain.md index 819bfe6d..78203fa2 100644 --- a/docs/agent-integrations/langchain.md +++ b/docs/agent-integrations/langchain.md @@ -58,6 +58,7 @@ Integrations with Langchain and Gaia can be done with any JavaScript or Python. ```python from langchain_openai import ChatOpenAI, OpenAI + import os model = ChatOpenAI( api_key=os.environ.get("GAIANET_API_KEY"), From a34d7009b00348b93a10231cc192d1feb1baaf8d Mon Sep 17 00:00:00 2001 From: Tobiloba Adedeji Date: Thu, 17 Apr 2025 12:19:41 +0100 Subject: [PATCH 4/4] docs: add updates based on feedback --- docs/agent-integrations/langchain.md | 64 +++++++++++++++++++++++++--- 1 file changed, 58 insertions(+), 6 deletions(-) diff --git a/docs/agent-integrations/langchain.md b/docs/agent-integrations/langchain.md index 78203fa2..3a1680ea 100644 --- a/docs/agent-integrations/langchain.md +++ b/docs/agent-integrations/langchain.md @@ -22,14 +22,39 @@ You will need a Gaia node ready to provide LLM services through a public URL. Yo - [Run your own node](../../getting-started/quick-start) - [Use a public node](../nodes) -If you are using a public node, you will need an [API key](https://www.gaianet.ai/setting/gaia-api-keys). Gaia overs free 50,000 API credits to use with the available services such as public nodes. +If you are using a public node, you will need an [API key](https://www.gaianet.ai/setting/gaia-api-keys). **Gaia overs free 50,000 API credits to use with available services such as public nodes when you apply for a developer account**. -In this tutorial, we will be running our not need an API key, you can use a string like: "Gaia". +### Setup - To get started with running your node, you can follow the guide on the [Setting up your own node](/getting-started/quick-start) page first and then come back here for integrations. +- Project setup on machine (JavaScript or Python) + +- Langchain Installation: + + + + ```bash + npm install @langchain/openai @langchain/core dotenv + ``` + + + + ```bash + pip install langchain langchain-openai python-dotenv + ``` + + + ## Integration with Gaia +To get started with running your Gaia node, you can follow the guide on the [Setting up your own node](/getting-started/quick-start) page for a quickstart. + +In this guide, we will be running our Gaia node locally so we do not need an API key, you can use a string like: "Gaia" as a placeholder. Create a `.env` file and store your API key: + +```bash +GAIANET_API_KEY="Gaia" +``` + Integrations with Langchain and Gaia can be done with any JavaScript or Python. There are code snippets below that show how integration looks like in both languages: @@ -40,7 +65,6 @@ Integrations with Langchain and Gaia can be done with any JavaScript or Python. dotenv.config(); - const model = new ChatOpenAI({ configuration: { apiKey: process.env.GAIANET_API_KEY, @@ -52,8 +76,9 @@ Integrations with Langchain and Gaia can be done with any JavaScript or Python. const response = await model.invoke("Hello, world!"); - console.log(response) + console.log(response) ``` + ```python @@ -70,7 +95,34 @@ Integrations with Langchain and Gaia can be done with any JavaScript or Python. print(response) ``` + + + + +## Invoking Gaia models + +Once you have the basic connection established, you can start using Langchain's powerful features. Start by making invocations to the model. + + + + ```js + + // ... + const response = await model.invoke("Hello, world!"); + + console.log(response) + ``` + + + + ```python + # ... + response = model.invoke("Hello, world!") + + print(response) + ``` + -From the above, you can then start making invocations to the model. The LangChain also opens up integrations with [LangGraph](https://www.langchain.com/langgraph) and [LangSmith](https://www.langchain.com/langsmith). \ No newline at end of file +The LangChain support also opens up integrations with [LangGraph](https://www.langchain.com/langgraph) and [LangSmith](https://www.langchain.com/langsmith).