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

1 messages · Page 1 of 1 (latest)

clear swan
#

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 ?

narrow granite
#

yes should be. Can you share your code so far?

#

@clear swan

clear swan
#

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

narrow granite
#

checking right now. Give me 5 mins.

clear swan
#

sure

narrow granite
#

Thanks for sharing the code!

clear swan
#

@narrow granite any updates man ?

narrow granite
#
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.

clear swan
#

Will try executing this and will let you know.

clear swan
#

This worked. Thanks alot @narrow granite for helping out.