-
Notifications
You must be signed in to change notification settings - Fork 199
fix: add reasoning content in request and response for gcp anthropic #1607
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
30c3e4d
e09547c
250d487
1cc37e1
d11ea91
f301ee9
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 |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ package openai | |
|
|
||
| import ( | ||
| "bytes" | ||
| "encoding/base64" | ||
| "encoding/json" | ||
| "errors" | ||
| "fmt" | ||
|
|
@@ -515,8 +516,8 @@ type ChatCompletionAssistantMessageParamContent struct { | |
| Text *string `json:"text,omitempty"` | ||
|
|
||
| // The signature for a thinking block. | ||
| Signature *string `json:"signature,omitempty"` | ||
| RedactedContent []byte `json:"redactedContent,omitempty"` | ||
| Signature *string `json:"signature,omitempty"` | ||
| RedactedContent *RedactedContentUnion `json:"redactedContent,omitempty"` | ||
| *AnthropicContentFields `json:",inline,omitempty"` | ||
| } | ||
|
|
||
|
|
@@ -1588,6 +1589,43 @@ func (e EmbeddingUnion) MarshalJSON() ([]byte, error) { | |
| return json.Marshal(e.Value) | ||
| } | ||
|
|
||
| // RedactedContentUnion is a union type that can handle both []byte and string formats. | ||
| // AWS Bedrock uses []byte while GCP Anthropic uses string. | ||
| type RedactedContentUnion struct { | ||
| Value any | ||
| } | ||
|
|
||
| // UnmarshalJSON implements json.Unmarshaler to handle both []byte and string formats. | ||
| func (r *RedactedContentUnion) UnmarshalJSON(data []byte) error { | ||
| // Try to unmarshal as []byte first (base64 encoded). | ||
| var str string | ||
| if err := json.Unmarshal(data, &str); err == nil { | ||
| // Try to decode as base64 first (this would be []byte encoded as base64) | ||
| if decoded, err := base64.StdEncoding.DecodeString(str); err == nil { | ||
|
Contributor
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. Why do we need to decode in gateway ?
Contributor
Author
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. This is to check whether it's |
||
| r.Value = decoded | ||
| return nil | ||
| } | ||
| // If not base64, treat as plain string | ||
| r.Value = str | ||
| return nil | ||
| } | ||
|
|
||
| return errors.New("redactedContent must be either []byte (base64 encoded) or string") | ||
| } | ||
|
|
||
| // MarshalJSON implements json.Marshaler. | ||
| func (r RedactedContentUnion) MarshalJSON() ([]byte, error) { | ||
| switch v := r.Value.(type) { | ||
| case []byte: | ||
| // Encode []byte as base64 string | ||
| return json.Marshal(base64.StdEncoding.EncodeToString(v)) | ||
| case string: | ||
| return json.Marshal(v) | ||
| default: | ||
| return json.Marshal(r.Value) | ||
| } | ||
| } | ||
|
|
||
| // EmbeddingUsage represents the usage information for an embeddings request. | ||
| // https://platform.openai.com/docs/api-reference/embeddings/object#embeddings/object-usage | ||
| type EmbeddingUsage struct { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.