-
Notifications
You must be signed in to change notification settings - Fork 200
Support connector-scoped OpenAI-compatible request behavior #9826
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
Open
dfliess
wants to merge
3
commits into
rilldata:main
Choose a base branch
from
dfliess:fix/openai-compatible-request-behavior
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| package runtime | ||
|
|
||
| import ( | ||
| "math" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestGenerateConnectionKeyPreservesNestedJSONTypes(t *testing.T) { | ||
| base := cachedConnectionConfig{instanceID: "instance", name: "connector", driver: "openai"} | ||
|
|
||
| stringConfig := base | ||
| stringConfig.config = map[string]any{"extra_body": map[string]any{"extension": "[END]"}} | ||
| sliceConfig := base | ||
| sliceConfig.config = map[string]any{"extra_body": map[string]any{"extension": []any{"END"}}} | ||
| require.NotEqual(t, mustGenerateKey(t, stringConfig), mustGenerateKey(t, sliceConfig), | ||
| "a string and a JSON array must never reuse one connector handle") | ||
|
|
||
| mapLikeString := base | ||
| mapLikeString.config = map[string]any{"extra_body": "map[a:b]"} | ||
| nestedMap := base | ||
| nestedMap.config = map[string]any{"extra_body": map[string]any{"a": "b"}} | ||
| require.NotEqual(t, mustGenerateKey(t, mapLikeString), mustGenerateKey(t, nestedMap), | ||
| "a string and a JSON object must never reuse one connector handle") | ||
| } | ||
|
|
||
| func TestGenerateConnectionKeyIsCanonicalAndDoesNotExposeSecrets(t *testing.T) { | ||
| left := cachedConnectionConfig{ | ||
| instanceID: "instance", name: "connector", driver: "openai", | ||
| config: map[string]any{ | ||
| "api_key": "super-secret", | ||
| "extra_body": map[string]any{"thinking": map[string]any{"type": "disabled"}, "seed": float64(1)}, | ||
| }, | ||
| } | ||
| right := cachedConnectionConfig{ | ||
| instanceID: "instance", name: "connector", driver: "openai", | ||
| config: map[string]any{ | ||
| "extra_body": map[string]any{"seed": float64(1), "thinking": map[string]any{"type": "disabled"}}, | ||
| "api_key": "super-secret", | ||
| }, | ||
| } | ||
|
|
||
| leftKey := mustGenerateKey(t, left) | ||
| require.Equal(t, leftKey, mustGenerateKey(t, right), "map insertion order must not change connector identity") | ||
| require.NotContains(t, leftKey, "super-secret", "cache keys must not embed credentials") | ||
| } | ||
|
|
||
| func TestGetConnectionRejectsConfigThatCannotBeKeyed(t *testing.T) { | ||
| cfg := cachedConnectionConfig{ | ||
| instanceID: "instance", name: "connector", driver: "openai", | ||
| config: map[string]any{"temperature": math.NaN()}, | ||
| } | ||
|
|
||
| // The error must surface before the connection cache is used (it is nil here). | ||
| _, _, err := (&Runtime{}).getConnection(t.Context(), cfg) | ||
| require.ErrorContains(t, err, `connector "connector"`) | ||
| } | ||
|
|
||
| func mustGenerateKey(t *testing.T, cfg cachedConnectionConfig) string { | ||
| t.Helper() | ||
| key, err := generateKey(cfg) | ||
| require.NoError(t, err) | ||
| return key | ||
| } |
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.
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.
structured_output_modeandextra_bodyare not declared in the OpenAI block ofruntime/parser/schema/project.schema.yaml, which this PR does not touch. That block generatesdocs/docs/reference/project-files/connectors.mdthroughcli/cmd/docs/generate_project.go:29,488(make docs.generate), so the OpenAI connector reference this page links to for "additional configuration options" will not list either property, andruntime/ai/instructions/instructions.go:198feeds the same schema to the AI assistant, which will keep reporting that these keys do not exist on anopenaiconnector. Nothing fails at runtime:runtime/parser/parse_connector.go:16captures connector properties withmapstructure:",remain"and never validates them against the schema.mainhas since reworked that block, so the two properties (and ideally theextra_bodyexample) need to go on top of its current version.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.
Added
structured_output_modeandextra_bodyto the OpenAI block, with an example for a compatible provider, and regeneratedconnectors.md. I compared the OpenAI block onmainand on this branch and it is the same, so this goes on top of the current version.