Skip to content

feat(compose): add ResponseFormat type and WithResponseFormat model o… - #1146

Open
N3kox wants to merge 1 commit into
mainfrom
feat/response_format
Open

feat(compose): add ResponseFormat type and WithResponseFormat model o…#1146
N3kox wants to merge 1 commit into
mainfrom
feat/response_format

Conversation

@N3kox

@N3kox N3kox commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

…ption

What type of PR is this?

Check the PR title.

  • This PR title match the format: <type>(optional scope): <description>
  • The description of this PR title is user-oriented and clear enough for others to understand.
  • Attach the PR updating the user documentation if the current PR requires user awareness at the usage level. User docs repo

(Optional) Translate the PR title into Chinese.

(Optional) More detailed description for this PR(en: English/zh: Chinese).

en:
zh(optional):

(Optional) Which issue(s) this PR fixes:

(optional) The PR that updates user documentation:

@codecov

codecov Bot commented Jul 17, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.35%. Comparing base (922b6a8) to head (8e3da40).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
components/model/option.go 0.00% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1146      +/-   ##
==========================================
+ Coverage   83.29%   83.35%   +0.05%     
==========================================
  Files         162      162              
  Lines       23398    23498     +100     
==========================================
+ Hits        19490    19587      +97     
- Misses       2639     2640       +1     
- Partials     1269     1271       +2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread schema/response_format.go Outdated
@@ -0,0 +1,49 @@
/*
* Copyright 2024 CloudWeGo Authors

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ok

Comment thread schema/response_format.go
import "github.com/eino-contrib/jsonschema"

// ResponseFormatType specifies the format the model must output.
type ResponseFormatType string

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

需要有个 text 类型吗,印象中似乎有的模型有这个枚举值?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

有这个 enum,但传与不传的效果我没测试出来差异,所以暂时没加。

Comment thread schema/response_format.go Outdated
// Schema is the JSON Schema definition.
Schema *jsonschema.Schema
// Strict requires the model to strictly adhere to the schema.
Strict bool

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

大部分支持 JSONSchema 的都有这个 strict 参数是吗

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

不是,支持的大概一半吧。

Comment thread schema/response_format.go Outdated
// ResponseFormatJSONSchema defines the JSON Schema for structured output.
type ResponseFormatJSONSchema struct {
// Name is a required identifier for the schema.
Name string

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

这个 Name 和 Description 在这里是怎么给到模型的?没想出来有啥用

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

openai name 没有明确说,description 是会提供给模型的, 但 name 是 required,description 是 optional

  • The name of the response format. Must be a-z, A-Z, 0-9, or contain underscores and dashes, with a maximum length of 64.
  • A description of what the response format is for, used by the model to determine how to respond in the format.

以 deepseek 为例,response format 就是一段 prompt

response_format_template: str = "## Response Format:\n\nYou MUST strictly adhere to the following schema to reply:\n{schema}"

Comment thread components/model/option.go Outdated
}

// WithResponseFormat sets the response format for the model.
// Only available for ChatModel.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

为啥会有这句,这不就是 ModelOption 吗?是说不支持 AgenticModel?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

写的不对,改了。

@N3kox
N3kox force-pushed the feat/response_format branch from 854be50 to 66f33c6 Compare July 21, 2026 03:15
@N3kox
N3kox force-pushed the feat/response_format branch from 66f33c6 to 8e3da40 Compare July 21, 2026 07:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants