Skip to content

Conversation

@jamesrochabrun
Copy link
Owner

@jamesrochabrun jamesrochabrun commented Sep 30, 2025

Summary

Adds support for custom tools that return plain text instead of JSON in the Response API.

Changes

  • Tool.swift: Add CustomTool struct and .custom case to Tool enum
  • OutputItem.swift: Add CustomToolCall struct and .customToolCall case for response handling
  • ToolChoiceMode.swift: Add CustomToolChoice struct and .customTool case for forced tool selection

Benefits

Custom tools enable models to return plain text responses without JSON wrapping, which is useful for:

  • Code execution tools (e.g., print("hello world") instead of {"code": "print(\"hello world\")"))
  • Mathematical expressions
  • Structured text outputs
  • Avoiding unnecessary JSON overhead

Example Usage

// Define a custom tool
let customTool = Tool.custom(.init(
    name: "code_exec",
    description: "Executes arbitrary Python code."
))

// Use in Response API
let parameters = ModelResponseParameter(
    input: .string("Use the code_exec tool to print hello world."),
    model: .custom("gpt-5"),
    tools: [customTool]
)

// Response will include CustomToolCall with plain text input
// e.g., input: "print(\"hello world\")"

Implementation Notes

  • Only implements explicitly documented OpenAI API features
  • Custom tool outputs for multi-turn conversations are not included as they are not documented
  • All changes follow existing patterns for FunctionTool and FunctionToolCall
  • Build completed successfully with no errors

Files Changed

  • Sources/OpenAI/Public/Shared/Tool.swift (+33 lines)
  • Sources/OpenAI/Public/ResponseModels/Response/OutputItem.swift (+30 lines)
  • Sources/OpenAI/Public/Shared/ToolChoiceMode.swift (+27 lines)

Total: 3 files changed, 90 insertions

🤖 Generated with Claude Code

jamesrochabrun and others added 2 commits September 29, 2025 23:58
Add support for custom tools that return plain text instead of JSON in the Response API.

Changes:
- Add CustomTool struct and .custom case to Tool enum
- Add CustomToolCall struct and .customToolCall case to OutputItem enum
- Add CustomToolChoice struct and .customTool case to ToolChoiceMode enum

Custom tools enable models to return plain text responses without JSON wrapping,
useful for scenarios like code execution, mathematical expressions, or structured
text outputs.

Note: CustomToolCallOutput was intentionally not included as it is not documented
in the OpenAI API documentation for multi-turn conversations with custom tools.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@jamesrochabrun jamesrochabrun force-pushed the jroch-some-more-additioons branch from bf884bd to e3d3d35 Compare September 30, 2025 07:24
jamesrochabrun and others added 4 commits September 30, 2025 00:26
Add support for GPT-5 Codex model.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Apply swiftformat fixes to ChatStructuredOutputToolProvider:
- Organize declarations (move init before properties)
- Wrap multiline conditional assignments
- Remove redundant optional binding
- Fix indentation and trailing spaces

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Upgrade swiftformat from 0.56.1 to 0.58.2 to match CI version and fix all linting issues.

Changes applied:
- Convert property declarations to inferred types (propertyTypes)
- Add MARK comments before top-level types (markTypes)
- Wrap long lines (wrap)
- Organize declarations (organizeDeclarations)
- Remove trailing spaces (trailingSpace)
- Fix indentation (indent)

27 files formatted across Examples, Sources, and Tests directories.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@jamesrochabrun jamesrochabrun merged commit 5240490 into main Sep 30, 2025
3 checks passed
@jamesrochabrun jamesrochabrun deleted the jroch-some-more-additioons branch September 30, 2025 07:46
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.

1 participant