-
Notifications
You must be signed in to change notification settings - Fork 1.5k
feat: apply reasoning effort and surface thinking blocks for Google chat models #28273
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
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
c8687dd
fix(coderd/x/chatd/chatprovider): map reasoning effort to Google thin…
ibetitsmike 925b20e
feat: add thinking_level to Google chat model thinking config
ibetitsmike 64c2cd5
fix(coderd/x/chatd/chatprovider): gate thinking_level to Gemini 3+ mo…
ibetitsmike 123dbdc
fix(coderd/x/chatd/chatprovider): drop pinned thinking_level for pre-…
ibetitsmike d0ef34f
fix(coderd/x/chatd/chatprovider): clamp thinking_level to each Gemini…
ibetitsmike f896d35
fix(coderd/x/chatd/chatprovider): clamp Gemini reasoning_effort on th…
ibetitsmike 0620042
Merge remote-tracking branch 'origin/main' into mike/chatd-google-rea…
ibetitsmike 3b6a945
feat: surface Gemini thinking blocks on the OpenAI-compat chat path
ibetitsmike ba90c73
docs(coderd/x/chatd/chatprovider): note response rewriting in the com…
ibetitsmike 79751f0
fix(coderd/x/chatd/chatprovider): gate the Gemini thinking_config rew…
ibetitsmike 0862514
fix(coderd/x/chatd/chatprovider): restrict thinking_budget support to…
ibetitsmike 48ded66
fix(coderd/x/chatd/chatprovider): forward pinned Google thinking conf…
ibetitsmike 1b1833f
fix(coderd/x/chatd/chatprovider): request thought summaries on the na…
ibetitsmike b98252d
fix(coderd/x/chatd/chatprovider): clamp effort none to a low thinking…
ibetitsmike cea28de
fix(internal/googleopenai): gate the non-streaming thought rewrite on…
ibetitsmike 831676f
fix(aibridge/intercept/chatcompletions): serialize Google blocking re…
ibetitsmike 24a6c42
fix(coderd/x/chatd/chatprovider): drop the MINIMAL thinking level for…
ibetitsmike 2b5e582
fix(coderd/x/chatd/chatprovider): fail closed for specialized Gemini …
ibetitsmike daa2a3a
refactor(coderd/x/googleopenai): move googleopenai out of the top-lev…
ibetitsmike b67cc8e
test(site/src/pages/AISettingsPage/ModelsPage): cover thinking level …
ibetitsmike File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
aibridge/intercept/chatcompletions/blocking_internal_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| package chatcompletions | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "testing" | ||
|
|
||
| "github.com/openai/openai-go/v3" | ||
| "github.com/stretchr/testify/require" | ||
| "github.com/tidwall/gjson" | ||
|
|
||
| "github.com/coder/coder/v2/aibridge/intercept" | ||
| ) | ||
|
|
||
| // The typed openai.ChatCompletion round trip drops provider-specific fields, | ||
| // so Google blocking responses must be serialized from the raw upstream body | ||
| // or Gemini's thought metadata never reaches the client. | ||
| func TestBlockingMarshalCompletionPreservesGoogleExtraContent(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| raw := `{"id":"upstream-id","object":"chat.completion","choices":[{"index":0,"finish_reason":"stop","message":{"role":"assistant","content":"<thought>hidden</thought>answer","extra_content":{"google":{"thought":true,"thought_signature":"sig"}}}}],"usage":{"prompt_tokens":1,"completion_tokens":2,"total_tokens":3}}` | ||
| var completion openai.ChatCompletion | ||
| require.NoError(t, json.Unmarshal([]byte(raw), &completion)) | ||
| completion.ID = "bridge-id" | ||
| completion.Usage.CompletionTokens = 7 | ||
|
|
||
| t.Run("GoogleUpstreamKeepsRawFields", func(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| out, err := (&BlockingInterception{interceptionBase: interceptionBase{ | ||
| cfg: intercept.Config{BaseURL: "https://generativelanguage.googleapis.com/v1beta/openai/"}, | ||
| }}).marshalCompletion(&completion) | ||
| require.NoError(t, err) | ||
|
|
||
| require.True(t, gjson.GetBytes(out, "choices.0.message.extra_content.google.thought").Bool()) | ||
| require.Equal(t, "sig", gjson.GetBytes(out, "choices.0.message.extra_content.google.thought_signature").String()) | ||
| require.Equal(t, "bridge-id", gjson.GetBytes(out, "id").String()) | ||
| require.Equal(t, int64(7), gjson.GetBytes(out, "usage.completion_tokens").Int()) | ||
| }) | ||
|
|
||
| t.Run("OtherUpstreamsUseTypedMarshal", func(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| out, err := (&BlockingInterception{interceptionBase: interceptionBase{ | ||
| cfg: intercept.Config{BaseURL: "https://api.openai.com/v1"}, | ||
| }}).marshalCompletion(&completion) | ||
| require.NoError(t, err) | ||
|
|
||
| require.False(t, gjson.GetBytes(out, "choices.0.message.extra_content").Exists()) | ||
| require.Equal(t, "bridge-id", gjson.GetBytes(out, "id").String()) | ||
| require.Equal(t, int64(7), gjson.GetBytes(out, "usage.completion_tokens").Int()) | ||
| }) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.