other-emerald
other-emerald3mo ago

[Solved ✅] How to run actions with a LiteLLM client

I want to use composio actions to run with a LiteLLM client where I am passing the model (eg: claude-3.5) and the base url for that model. Is it possible to achieve ?
8 Replies
Soham
Soham3mo ago
yes should be. Can you share your code so far? @frenzyScholar
other-emerald
other-emeraldOP3mo ago
here is the code @Soham :
from composio_openai import ComposioToolSet, Action
from litellm.router import Router
import instructor
from pydantic import BaseModel

composio_tools = ComposioToolSet(entity_id = "<your_entity_id>", api_key = "<your_api_key>")

tools = composio_tools.get_tools(actions=[Action.TWITTER_CREATION_OF_A_POST])

router = Router(
model_list=[
{
"model_name": "anthropic/claude-3.5",
"litellm_params": {
"model": "anthropic/claude-3.5",
"api_key": "<your-api-key>",
"api_base": "<your-api-base-url>",
},
}
]
)
client = instructor.patch(router.completion) # Pass the completion method instead


user = client(
model="anthropic/claude-3.5",
messages=[
{"role": "user", "content": "Generate a tweet about the recent political events in the world"},
],
tools=tools,
tool_choice="auto",
)


print(f"user: {user}")
from composio_openai import ComposioToolSet, Action
from litellm.router import Router
import instructor
from pydantic import BaseModel

composio_tools = ComposioToolSet(entity_id = "<your_entity_id>", api_key = "<your_api_key>")

tools = composio_tools.get_tools(actions=[Action.TWITTER_CREATION_OF_A_POST])

router = Router(
model_list=[
{
"model_name": "anthropic/claude-3.5",
"litellm_params": {
"model": "anthropic/claude-3.5",
"api_key": "<your-api-key>",
"api_base": "<your-api-base-url>",
},
}
]
)
client = instructor.patch(router.completion) # Pass the completion method instead


user = client(
model="anthropic/claude-3.5",
messages=[
{"role": "user", "content": "Generate a tweet about the recent political events in the world"},
],
tools=tools,
tool_choice="auto",
)


print(f"user: {user}")
everytime the code throws a new error
Soham
Soham3mo ago
checking right now. Give me 5 mins.
other-emerald
other-emeraldOP3mo ago
sure
Soham
Soham3mo ago
Thanks for sharing the code!
other-emerald
other-emeraldOP3mo ago
@Soham any updates man ?
Soham
Soham3mo ago
from composio_openai import ComposioToolSet, App
from litellm.router import Router
import dotenv
import anthropic
import instructor
# Load environment variables from .env
dotenv.load_dotenv()

# Initialize tools
composio_toolset = ComposioToolSet()

# Get GitHub tools that are pre-configured
actions = composio_toolset.get_tools(apps=[App.GITHUB])

router = Router(
model_list=[
{
"model_name": "anthropic/claude-3-5",
"litellm_params": {
"model": "claude-3-opus-20240229",
"api_key": "",
},
}
]
)

# Get response from the LLM
response = router.completion(
model="anthropic/claude-3-5",
messages=[
{"role": "user", "content": "Star me composiohq/composio repo in github."},
],
tools=actions,
tool_choice="auto",
)
print(response)
# Execute the function calls
result = composio_toolset.handle_tool_calls(response=response)
print(result)
from composio_openai import ComposioToolSet, App
from litellm.router import Router
import dotenv
import anthropic
import instructor
# Load environment variables from .env
dotenv.load_dotenv()

# Initialize tools
composio_toolset = ComposioToolSet()

# Get GitHub tools that are pre-configured
actions = composio_toolset.get_tools(apps=[App.GITHUB])

router = Router(
model_list=[
{
"model_name": "anthropic/claude-3-5",
"litellm_params": {
"model": "claude-3-opus-20240229",
"api_key": "",
},
}
]
)

# Get response from the LLM
response = router.completion(
model="anthropic/claude-3-5",
messages=[
{"role": "user", "content": "Star me composiohq/composio repo in github."},
],
tools=actions,
tool_choice="auto",
)
print(response)
# Execute the function calls
result = composio_toolset.handle_tool_calls(response=response)
print(result)
@frenzyScholar sorry it took some time.
other-emerald
other-emeraldOP3mo ago
Will try executing this and will let you know. This worked. Thanks alot @Soham for helping out.

Did you find this page helpful?