-
Notifications
You must be signed in to change notification settings - Fork 401
feat(kosong): support structured response formats #1397
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f2b73f1
4bc40df
1fa7b33
a4b56ef
d35dcaa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@moonshot-ai/kosong": patch | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The gen-changesets rules require internal Useful? React with 👍 / 👎. |
||
| --- | ||
|
|
||
| Add provider-level structured response format support. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ import type { | |
| FinishReason, | ||
| GenerateOptions, | ||
| ProviderRequestAuth, | ||
| ResponseFormat, | ||
| StreamedMessage, | ||
| ThinkingEffort, | ||
| } from '#/provider'; | ||
|
|
@@ -127,6 +128,19 @@ function toolToGoogleGenAI(tool: Tool): GoogleTool { | |
| ], | ||
| }; | ||
| } | ||
|
|
||
| function applyResponseFormat( | ||
| config: Record<string, unknown>, | ||
| format: ResponseFormat | undefined, | ||
| ): void { | ||
| if (format === undefined) return; | ||
| config['responseMimeType'] = 'application/json'; | ||
| delete config['responseSchema']; | ||
| delete config['responseJsonSchema']; | ||
| if (format.type === 'json_schema') { | ||
| config['responseJsonSchema'] = format.jsonSchema.schema; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If a Google provider was configured with the native Useful? React with 👍 / 👎. |
||
| } | ||
| } | ||
| interface GoogleContent { | ||
| role: string; | ||
| parts: GooglePart[]; | ||
|
|
@@ -819,6 +833,7 @@ export class GoogleGenAIChatProvider implements ChatProvider { | |
| systemInstruction: systemPrompt, | ||
| ...(tools.length > 0 ? { tools: tools.map((t) => toolToGoogleGenAI(t)) } : {}), | ||
| }; | ||
| applyResponseFormat(config, options?.responseFormat); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When the caller asks for a Gemini structured response while any tools are supplied, the config already contains Useful? React with 👍 / 👎. |
||
|
|
||
| try { | ||
| const client = this._createClient(options?.auth); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This changeset lists only the internal
@moonshot-ai/kosongpackage, but the repository's changeset rules require internal package source changes that enter the CLI bundle to manually list@moonshot-ai/kimi-code. As written, the private/internal package can be versioned without bumping the published CLI artifact, so this provider-layer behavior may not ship in the next CLI release/changelog.Useful? React with 👍 / 👎.