Skip to content

Conversation

@cpsievert
Copy link
Collaborator

@cpsievert cpsievert commented Nov 6, 2025

Pairs with tidyverse/ellmer#795

As mentioned there, streaming support for generated images isn't (yet) supported (since we likely want to think through this problem more generally than just images)

import chatlas as ctl

openai_image_gen = ctl.ToolBuiltIn(
    name="image_gen",
    definition=dict(type="image_generation", quality="low", size="1024x1024"),
)

chat = ctl.ChatOpenAI(model="gpt-5")
chat.register_tool(openai_image_gen)
chat.chat("Generate an image as quickly as possible.")

chatg = ctl.ChatGoogle(model="nano-banana-pro-preview")
chatg.chat("Draw a cat.")

Note that the image can be printed in a notebook context with

turn = chat.get_last_turn()
turn.contents[0]

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for image generation and introduces a new ToolBuiltIn class to handle provider-specific built-in tools. The key changes enable the framework to differentiate between custom tools (regular Tool instances) and provider-native tools (like image generation) that pass raw provider-specific JSON directly through to the API.

Key changes:

  • Introduced ToolBuiltIn class for provider-specific tools that pass raw definitions to APIs
  • Updated all provider implementations to accept Tool | ToolBuiltIn in tool-related signatures
  • Added image generation support for OpenAI provider with proper MIME type detection
  • Enhanced Google provider to handle inline image data responses

Reviewed Changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
chatlas/_tools.py Adds new ToolBuiltIn class definition and exports it
chatlas/_provider_snowflake.py Updates type signatures to accept ToolBuiltIn and raises NotImplementedError for built-in tools
chatlas/_provider_openai_generic.py Updates token counting signatures to support ToolBuiltIn
chatlas/_provider_openai_completions.py Handles both Tool and ToolBuiltIn in schema generation
chatlas/_provider_openai.py Implements image generation result handling and supports ToolBuiltIn in tool parameters
chatlas/_provider_google.py Adds inline image data handling and filters out ToolBuiltIn from tool conversion
chatlas/_provider_anthropic.py Updates tool schema generation to handle ToolBuiltIn instances
chatlas/_provider.py Updates abstract provider interface signatures for ToolBuiltIn support
chatlas/_mcp_manager.py Updates tool storage type to support ToolBuiltIn
chatlas/_content.py Adds from_tool support for ToolBuiltIn and Jupyter display methods for images
chatlas/_chat.py Updates tool registration, invocation logic, and type checking for ToolBuiltIn
chatlas/init.py Exports ToolBuiltIn class

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@cpsievert cpsievert marked this pull request as ready for review December 29, 2025 18:01
@cpsievert cpsievert requested a review from Copilot December 29, 2025 18:01

This comment was marked as resolved.

@cpsievert
Copy link
Collaborator Author

Seems the Anthropic batch test failures are probably intermittent

@cpsievert cpsievert merged commit ccf0157 into main Dec 29, 2025
2 of 7 checks passed
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.

2 participants