Using Composio With LiteLLM

Star A Repository on Github

In this example, we will use LiteLLM to star a repository on Github using Composio Tools

1

Install Packages

Python
$ pip install composio_openai litellm
2

Import Libraries, Initialize ComposioToolSet & Create Router

Python
$from composio_openai import ComposioToolSet, App
>from litellm.router import Router
>
>toolset = ComposioToolSet()
>
>router = Router(
> model_list=[
> {
> "model_name": "anthropic/claude-3-5",
> "litellm_params": {
> "model": "claude-3-opus-20240229",
> "api_key": "<your-anthropic-api-key>",
> },
> }
> ]
>)
3

Connect Your GitHub Account

You need to have an active GitHub Integration. Learn how to do this here
$composio login
>composio add github

Don’t forget to set your COMPOSIO_API_KEY and OPENAI_API_KEY in your environment variables.

4

Get All Github Tools

You can get all the tools for a given app as shown below, but you can get specific actions and filter actions using usecase & tags. Learn more here

Python
1tools = toolset.get_tools(apps=[App.GITHUB])
5

Configure Router

Python
1response = router.completion(
2 model="anthropic/claude-3-5",
3 messages=[
4 {"role": "user", "content": "Star the repository composiohq/composio on github"},
5 ],
6 tools=tools,
7 tool_choice="auto",
8)
6

Execute Tool Calls

Python
1result = toolset.handle_tool_calls(response=response)
2print(result)
Built with