Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### New features

* `ChatAuto()`'s new `provider_model` takes both provider and model in a single string in the format `"{provider}/{model}"`, e.g. `"openai/gpt-5"`. If not provided, `ChatAuto()` looks for the `CHATLAS_CHAT_PROVIDER_MODEL` environment variable, defaulting to `"openai"` if neither are provided. Unlike previous versions of `ChatAuto()`, the environment variables are now used *only if function arguments are not provided*. In other words, if `provider_model` is given, the `CHATLAS_CHAT_PROVIDER_MODEL` environment variable is ignored. Similarly, `CHATLAS_CHAT_ARGS` are only used if no `kwargs` are provided. This improves interactive use cases, makes it easier to introduce application-specific environment variables, and puts more control in the hands of the developer. (#159)
* The `.register_tool()` method now accepts a `Tool` instance as input. This is primarily useful for binding things like `annotations` to the `Tool` in one place, and registering it in another. (#172)
* The `.register_tool()` method now:
* Accepts a `Tool` instance as input. This is primarily useful for binding things like `annotations` to the `Tool` in one place, and registering it in another. (#172)
* Supports function parameter names that start with an underscore. (#174)
* The `ToolAnnotations` type gains an `extra` key field -- providing a place for providing additional information that other consumers of tool annotations (e.g., [shinychat](https://posit-dev.github.io/shinychat/)) may make use of.

### Bug fixes
Expand Down
14 changes: 11 additions & 3 deletions chatlas/_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,13 +326,21 @@ def func_to_basemodel(func: Callable) -> type[BaseModel]:
)
annotation = Any

# create_model() will error if the field name starts with `_` (since Pydantic
# uses this to indicate private fields). We can work around this by using an alias.
alias = None
if name.startswith("_"):
field_name, alias = (name.lstrip("_"), name)
else:
field_name, alias = (name, None)

if param.default != inspect.Parameter.empty:
field = Field(default=param.default)
field = Field(default=param.default, alias=alias)
else:
field = Field()
field = Field(alias=alias)

# Add the field to our fields dict
fields[name] = (annotation, field)
fields[field_name] = (annotation, field)

return create_model(func.__name__, **fields)

Expand Down
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,9 @@ def assert_tools_parallel(
):
chat = chat_fun(system_prompt="Be very terse, not even punctuation.")

def favorite_color(person: str):
def favorite_color(_person: str):
"""Returns a person's favourite colour"""
return "sage green" if person == "Joe" else "red"
return "sage green" if _person == "Joe" else "red"

chat.register_tool(favorite_color)

Expand Down
Loading