Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sawra/llamaindex extension #121

Merged
merged 23 commits into from
Jun 13, 2024
Merged

Sawra/llamaindex extension #121

merged 23 commits into from
Jun 13, 2024

Conversation

sawradip
Copy link
Contributor

@sawradip sawradip commented Jun 8, 2024

Added composio-llamaindex plugin

Copy link
Contributor

ellipsis-dev bot commented Jun 8, 2024

Your free trial has expired. To keep using Ellipsis, sign up at https://app.ellipsis.dev for $20/seat/month or reach us at help@ellipsis.dev

@@ -53,6 +53,14 @@ def __init__(
)
self.runtime = runtime
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How was this working earlier?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not see it to be used anywhere...it was just being set, so I just added proper setter, cause when we inherit from a child class, like from langchain for llamaindex, it was not possible to set that externally.

Comment on lines +72 to +95
def _wrap_tool(
self,
schema: t.Dict[str, t.Any],
entity_id: t.Optional[str] = None,
) -> FunctionTool:
"""Wraps composio tool as LlamaIndex FunctionTool object."""
app = schema["appName"]
action = schema["name"]
description = schema["description"]
schema_params = schema["parameters"]

action_func = self.prepare_python_function(
app=app,
action=action,
description=description,
schema_params=schema_params,
entity_id=entity_id,
)
return FunctionTool.from_defaults(
action_func,
name=action,
description=description,
)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to pass the function params as pydantic fields in the llamaindex.
Otherwise, the param descriptions won't go the LLM.
https://docs.llamaindex.ai/en/latest/module_guides/deploying/agents/tools/#functiontool

from pydantic import Field


def get_weather(
    location: str = Field(
        description="A city name and state, formatted like '<name>, <state>'"
    ),
) -> str:
    """Usfeful for getting the weather for a given location."""
    ...


tool = FunctionTool.from_defaults(get_weather)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Comment on lines 105 to 111
Example Output:
{
'owner': (<class 'str'>, FieldInfo(default=Ellipsis, description='The account owner of the repository.', extra={'examples': ([],)})),
'repo': (<class 'str'>, FieldInfo(default=Ellipsis, description='The name of the repository without the `.git` extension.', extra={'examples': ([],)}))}
}

"""
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Example Output:
{
'owner': (<class 'str'>, FieldInfo(default=Ellipsis, description='The account owner of the repository.', extra={'examples': ([],)})),
'repo': (<class 'str'>, FieldInfo(default=Ellipsis, description='The name of the repository without the `.git` extension.', extra={'examples': ([],)}))}
}
"""
Example:
```python
>>> json_schema_to_fields_dict()
{
'owner': (<class 'str'>, FieldInfo(default=Ellipsis, description='The account owner of the repository.', extra={'examples': ([],)})),
'repo': (<class 'str'>, FieldInfo(default=Ellipsis, description='The name of the repository without the `.git` extension.', extra={'examples': ([],)}))}
}
```
"""

(This is just a suggested format for writing docstring, you can ignore if you want to)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

taken into consideration and modified.

@@ -9,7 +9,7 @@

setup(
name="composio_autogen",
version="0.3.9-rc.3",
version="0.3.9rc4",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert the version bump, we don't want perform a release with every single change

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure, how to proceed with this, should I match all the versions with master? master contains 0.3.9 everywhere I guess.

Copy link
Contributor

@kaavee315 kaavee315 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you print and test the Llamaindex tools? Let's double check and post here the output to know all the descriptions are going.

),
)


def json_schema_to_fields_dict(json_schema: t.Dict[str, t.Any]) -> t.Type[BaseModel]:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add UT for this function?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added UT.

@@ -258,3 +288,45 @@ def get_signature_format_from_schema_params(schema_params: t.Dict) -> t.List[Par
else:
optional_parameters.append(param)
return required_parameters + optional_parameters


def get_pydantic_signature_format_from_schema_params(schema_params: t.Dict) -> t.List[Parameter]:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added UT.

@sawradip
Copy link
Contributor Author

Did you print and test the Llamaindex tools? Let's double check and post here the output to know all the descriptions are going.

Waiting for railway fix.

@sawradip
Copy link
Contributor Author

Did you print and test the Llamaindex tools? Let's double check and post here the output to know all the descriptions are going.

Waiting for railway fix.

Checked.

@@ -78,16 +78,14 @@ def __init__(
output_in_file=output_in_file,
)

def _wrap_tool(
def prepare_python_function(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def prepare_python_function(
def _prepare_python_function(

If a user is not supposed to use a method directly define them as private methods

)
self.runtime = "llamaindex"

def prepare_python_function(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

@sawradip
Copy link
Contributor Author

@angrybayblade Fixed.

@angrybayblade angrybayblade merged commit 4e2bfb7 into master Jun 13, 2024
5 checks passed
@angrybayblade angrybayblade deleted the sawra/llamaindex_extension branch June 13, 2024 04:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants