mirror of
https://github.com/googleapis/genai-toolbox.git
synced 2026-01-09 15:38:08 -05:00
docs: add llamaindex sdk info to toolbox docs (#330)
This commit is contained in:
@@ -75,8 +75,8 @@ You can load toolsets by name:
|
||||
|
||||
```python
|
||||
# This will load all tools
|
||||
all_tools = await client.aload_toolset()
|
||||
all_tools = client.load_toolset()
|
||||
|
||||
# This will only load the tools listed in 'my_second_toolset'
|
||||
my_second_toolset = await client.aload_toolset("my_second_toolset")
|
||||
my_second_toolset = client.load_toolset("my_second_toolset")
|
||||
```
|
||||
@@ -100,7 +100,7 @@ out the resources in the [How-to section](../../how-to/_index.md)
|
||||
Once your server is up and running, you can load the tools into your
|
||||
application. See below the list of Client SDKs for using various frameworks:
|
||||
|
||||
{{< tabpane text=true >}}
|
||||
{{< tabpane text=true persist=header >}}
|
||||
{{% tab header="LangChain" lang="en" %}}
|
||||
|
||||
Once you've installed the [Toolbox LangChain
|
||||
@@ -114,11 +114,31 @@ from toolbox_langchain import ToolboxClient
|
||||
client = ToolboxClient("http://127.0.0.1:5000")
|
||||
|
||||
# these tools can be passed to your application!
|
||||
tools = await client.aload_toolset()
|
||||
tools = client.load_toolset()
|
||||
{{< /highlight >}}
|
||||
|
||||
For more detailed instructions on using the Toolbox LangChain SDK, see the
|
||||
[project's README](https://github.com/googleapis/genai-toolbox-langchain-python/blob/main/README.md).
|
||||
|
||||
{{% /tab %}}
|
||||
{{% tab header="Llamaindex" lang="en" %}}
|
||||
|
||||
Once you've installed the [Toolbox Llamaindex
|
||||
SDK](https://github.com/googleapis/genai-toolbox-llamaindex-python), you can load
|
||||
tools:
|
||||
|
||||
{{< highlight python >}}
|
||||
from toolbox_llamaindex import ToolboxClient
|
||||
|
||||
# update the url to point to your server
|
||||
client = ToolboxClient("http://127.0.0.1:5000")
|
||||
|
||||
# these tools can be passed to your application!
|
||||
tools = client.load_toolset()
|
||||
{{< /highlight >}}
|
||||
|
||||
For more detailed instructions on using the Toolbox Llamaindex SDK, see the
|
||||
[project's README](https://github.com/googleapis/genai-toolbox-llamaindex-python/blob/main/README.md).
|
||||
|
||||
{{% /tab %}}
|
||||
{{< /tabpane >}}
|
||||
|
||||
@@ -84,7 +84,7 @@ You can use this setup quickly set up Toolbox + Postgres to follow along in our
|
||||
|
||||
|
||||
|
||||
## Connecting with Toolbox Client SDL
|
||||
## Connecting with Toolbox Client SDK
|
||||
|
||||
Next, we will use Toolbox with the Client SDKs:
|
||||
|
||||
@@ -96,11 +96,19 @@ Next, we will use Toolbox with the Client SDKs:
|
||||
|
||||
1. Import and initialize the client with the URL:
|
||||
|
||||
```bash
|
||||
from toolbox_langchain_sdk import ToolboxClient
|
||||
{{< tabpane persist=header >}}
|
||||
{{< tab header="LangChain" lang="Python" >}}
|
||||
from toolbox_langchain import ToolboxClient
|
||||
|
||||
# Replace with the cloud run service URL generated above
|
||||
toolbox = ToolboxClient("$YOUR_URL")
|
||||
```
|
||||
# Replace with the cloud run service URL generated above
|
||||
toolbox = ToolboxClient("http://$YOUR_URL")
|
||||
{{< /tab >}}
|
||||
{{< tab header="Llamaindex" lang="Python" >}}
|
||||
from toolbox_llamaindex import ToolboxClient
|
||||
|
||||
# Replace with the cloud run service URL generated above
|
||||
toolbox = ToolboxClient("http://$YOUR_URL")
|
||||
{{< /tab >}}
|
||||
{{< /tabpane >}}
|
||||
|
||||
|
||||
|
||||
@@ -168,9 +168,18 @@ Next, we will use Toolbox with client SDK:
|
||||
|
||||
1. Import and initialize the toolbox client with the URL retrieved above:
|
||||
|
||||
```bash
|
||||
from toolbox_langchain_sdk import ToolboxClient
|
||||
{{< tabpane persist=header >}}
|
||||
{{< tab header="LangChain" lang="Python" >}}
|
||||
from toolbox_langchain import ToolboxClient
|
||||
|
||||
# Replace with the cloud run service URL generated above
|
||||
toolbox = ToolboxClient("http://$YOUR_URL")
|
||||
{{< /tab >}}
|
||||
{{< tab header="Llamaindex" lang="Python" >}}
|
||||
from toolbox_llamaindex import ToolboxClient
|
||||
|
||||
# Replace with the cloud run service URL generated above
|
||||
toolbox = ToolboxClient("http://$YOUR_URL")
|
||||
{{< /tab >}}
|
||||
{{< /tabpane >}}
|
||||
|
||||
# Replace with the cloud run service URL generated above
|
||||
toolbox = ToolboxClient("http://$YOUR_URL")
|
||||
```
|
||||
|
||||
@@ -58,7 +58,7 @@ when the tool is invoked. This allows you to cache and refresh the ID token as
|
||||
needed.
|
||||
|
||||
### Specifying tokens during load
|
||||
{{< tabpane >}}
|
||||
{{< tabpane persist=header >}}
|
||||
{{< tab header="LangChain" lang="Python" >}}
|
||||
async def get_auth_token():
|
||||
# ... Logic to retrieve ID token (e.g., from local storage, OAuth flow)
|
||||
@@ -66,19 +66,41 @@ async def get_auth_token():
|
||||
return "YOUR_ID_TOKEN" # Placeholder
|
||||
|
||||
# for a single tool use:
|
||||
authorized_tool = await toolbox.aload_tool("my-tool-name", auth_tokens={"my_auth": get_auth_token})
|
||||
authorized_tool = toolbox.load_tool("my-tool-name", auth_tokens={"my_auth": get_auth_token})
|
||||
|
||||
# for a toolset use:
|
||||
authorized_tools = await toolbox.aload_toolset("my-toolset-name", auth_tokens={"my_auth": get_auth_token})
|
||||
authorized_tools = toolbox.load_toolset("my-toolset-name", auth_tokens={"my_auth": get_auth_token})
|
||||
{{< /tab >}}
|
||||
{{< tab header="Llamaindex" lang="Python" >}}
|
||||
async def get_auth_token():
|
||||
# ... Logic to retrieve ID token (e.g., from local storage, OAuth flow)
|
||||
# This example just returns a placeholder. Replace with your actual token retrieval.
|
||||
return "YOUR_ID_TOKEN" # Placeholder
|
||||
|
||||
# for a single tool use:
|
||||
authorized_tool = toolbox.load_tool("my-tool-name", auth_tokens={"my_auth": get_auth_token})
|
||||
|
||||
# for a toolset use:
|
||||
authorized_tools = toolbox.load_toolset("my-toolset-name", auth_tokens={"my_auth": get_auth_token})
|
||||
{{< /tab >}}
|
||||
{{< /tabpane >}}
|
||||
|
||||
|
||||
### Specifying tokens for existing tools
|
||||
|
||||
{{< tabpane >}}
|
||||
{{< tabpane persist=header >}}
|
||||
{{< tab header="LangChain" lang="Python" >}}
|
||||
tools = await toolbox.aload_toolset()
|
||||
tools = toolbox.load_toolset()
|
||||
# for a single token
|
||||
auth_tools = [tool.add_auth_token("my_auth", get_auth_token) for tool in tools]
|
||||
# OR, if multiple tokens are needed
|
||||
authorized_tool = tools[0].add_auth_tokens({
|
||||
"my_auth1": get_auth1_token,
|
||||
"my_auth2": get_auth2_token,
|
||||
})
|
||||
{{< /tab >}}
|
||||
{{< tab header="Llamaindex" lang="Python" >}}
|
||||
tools = toolbox.load_toolset()
|
||||
# for a single token
|
||||
auth_tools = [tool.add_auth_token("my_auth", get_auth_token) for tool in tools]
|
||||
# OR, if multiple tokens are needed
|
||||
|
||||
Reference in New Issue
Block a user