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

MotleyTool LlamaIndex compatibility fix #74

Merged
merged 1 commit into from
Sep 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions motleycrew/tools/tool.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import functools
import inspect
from typing import Callable, Union, Optional, Dict, Any

from langchain.tools import BaseTool
Expand Down Expand Up @@ -157,11 +158,22 @@ def to_llama_index_tool(self) -> LlamaIndex__BaseTool:
LlamaIndex tool.
"""
ensure_module_is_installed("llama_index")

if inspect.signature(self.tool._run).parameters.get("config", None) is not None:
fn = functools.partial(self.tool._run, config=RunnableConfig())
else:
fn = self.tool._run

fn_schema = self.tool.args_schema
fn_schema.model_json_schema = (
fn_schema.schema
) # attempt to make it compatible with Langchain's old Pydantic v1

llama_index_tool = LlamaIndex__FunctionTool.from_defaults(
fn=functools.partial(self.tool._run, config=RunnableConfig()),
fn=fn,
name=self.tool.name,
description=self.tool.description,
fn_schema=self.tool.args_schema,
fn_schema=fn_schema,
)
return llama_index_tool

Expand Down
Loading