Skip to content

.register_tool(model=MyParams) errors unexpectedly when MyParams contains Field(alias=...) #160

@cpsievert

Description

@cpsievert

For example

import chatlas as ctl
from pydantic import BaseModel, Field

chat = ctl.ChatAuto(provider="openai")

class MyParams(BaseModel):
    n: int = Field(..., description="Number of items to list", alias="_n")

def list_items(_n: int):
    return [f"Item {i + 1}" for i in range(_n)]

chat.register_tool(list_items, model=MyParams)
ValueError: `model` fields must match tool function parameters exactly. Fields found in one but not the other: {'n', '_n'}

Note that Field(alias=...) is the only way to create a BaseModel where the field starts with _*. This is, in turn, a problem for shinychat's tool calling UI where _intent is a special parameter.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions