optimistic-gold
optimistic-goldβ€’3mo ago

[Solved βœ…] Litellm support for composio actions/apps

I am using llama models and claude 3.5 which are hosted on openrouter via the litellm python library. Is there any way to run composio actions and apps on these ?
12 Replies
flat-fuchsia
flat-fuchsiaβ€’3mo ago
Hey are you using litellm just for chat interface??
optimistic-gold
optimistic-goldOPβ€’3mo ago
Currently yes but I need to execute composio actions using litellm
flat-fuchsia
flat-fuchsiaβ€’3mo ago
flat-fuchsia
flat-fuchsiaβ€’3mo ago
You can pass tools to langchain as usual you do (can send you resources for using composio tools in langchain)
optimistic-gold
optimistic-goldOPβ€’3mo ago
I have tried this approach doesn't seems to work
flat-fuchsia
flat-fuchsiaβ€’3mo ago
What was the issue??
optimistic-gold
optimistic-goldOPβ€’3mo ago
Was encountering various issues
flat-fuchsia
flat-fuchsiaβ€’3mo ago
Could you send me a screenshot of it?? @frenzyScholar
optimistic-gold
optimistic-goldOPβ€’3mo ago
from composio_openai import ComposioToolSet, Action
import litellm
from litellm.router import Router
import instructor
from pydantic import BaseModel

composio_tools = ComposioToolSet(entity_id = "", api_key = "")

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



# litellm.error_logger_verbose = True # πŸ‘ˆ print DEBUG LOGS

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
import litellm
from litellm.router import Router
import instructor
from pydantic import BaseModel

composio_tools = ComposioToolSet(entity_id = "", api_key = "")

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



# litellm.error_logger_verbose = True # πŸ‘ˆ print DEBUG LOGS

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}")
this the code I am trying getting the following error, as of now:
[2024-12-06 11:41:48,577][INFO] Logging is set to INFO, use `logging_level` argument or `COMPOSIO_LOGGING_LEVEL` change this
Traceback (most recent call last):
File "/Users/yashvardhan/Documents/Desktop_Folders/ProjectsAndTutorials/composio_test/litellm_function_calling.py", line 34, in <module>
client = instructor.patch(router.completion) # Pass the completion method instead
File "/Users/yashvardhan/Documents/Desktop_Folders/ProjectsAndTutorials/composio_test/venv/lib/python3.10/site-packages/instructor/patch.py", line 137, in patch
func = client.chat.completions.create
AttributeError: 'function' object has no attribute 'chat'
[2024-12-06 11:41:48,577][INFO] Logging is set to INFO, use `logging_level` argument or `COMPOSIO_LOGGING_LEVEL` change this
Traceback (most recent call last):
File "/Users/yashvardhan/Documents/Desktop_Folders/ProjectsAndTutorials/composio_test/litellm_function_calling.py", line 34, in <module>
client = instructor.patch(router.completion) # Pass the completion method instead
File "/Users/yashvardhan/Documents/Desktop_Folders/ProjectsAndTutorials/composio_test/venv/lib/python3.10/site-packages/instructor/patch.py", line 137, in patch
func = client.chat.completions.create
AttributeError: 'function' object has no attribute 'chat'
@thatsmeadarsh @thatsmeadarsh can you please help with this this is just one of the errors that I got.
Soham
Sohamβ€’3mo ago
Checking.
flat-fuchsia
flat-fuchsiaβ€’3mo ago
Hey @frenzyScholar, is it working fine for you now??
optimistic-gold
optimistic-goldOPβ€’3mo ago
yes, thanks

Did you find this page helpful?