Skip to content

Commit

Permalink
Add compatibility checks for config parameter in MotleyTool's Llama…
Browse files Browse the repository at this point in the history
…Index integration & workaround for Pydantic v1 compatibility (#74)
  • Loading branch information
whimo committed Sep 2, 2024
1 parent f7dd1a9 commit 6c1b56d
Showing 1 changed file with 14 additions and 2 deletions.
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

0 comments on commit 6c1b56d

Please sign in to comment.