#[Solved ✅] How to run actions with a LiteLLM client
1 messages · Page 1 of 1 (latest)
here is the code @narrow granite :
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
checking right now. Give me 5 mins.
sure
Thanks for sharing the code!
@narrow granite any updates man ?
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)
@clear swan sorry it took some time.
Will try executing this and will let you know.
This worked. Thanks alot @narrow granite for helping out.