Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@ccurme
Copy link
Collaborator

@ccurme ccurme commented Jul 15, 2024

Note: this allows the schema to be passed in positionally.

from langchain_core.pydantic_v1 import BaseModel, Field
from langchain_core.runnables import RunnableLambda


class Add(BaseModel):
    """Add two integers together."""

    a: int = Field(..., description="First integer")
    b: int = Field(..., description="Second integer")


def add(input: dict) -> int:
    return input["a"] + input["b"]


runnable = RunnableLambda(add)
as_tool = runnable.as_tool(Add)
as_tool.args_schema.schema()
{'title': 'Add',
 'description': 'Add two integers together.',
 'type': 'object',
 'properties': {'a': {'title': 'A',
   'description': 'First integer',
   'type': 'integer'},
  'b': {'title': 'B', 'description': 'Second integer', 'type': 'integer'}},
 'required': ['a', 'b']}

@ccurme ccurme requested a review from baskaryan July 15, 2024 14:08
@vercel
Copy link

vercel bot commented Jul 15, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
langchain ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 15, 2024 2:22pm

@dosubot dosubot bot added the lgtm label Jul 15, 2024
@baskaryan baskaryan merged commit 888fbc0 into master Jul 15, 2024
@baskaryan baskaryan deleted the cc/runnable_tool_schema branch July 15, 2024 14:51
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.

3 participants