-
Notifications
You must be signed in to change notification settings - Fork 0
videos #18
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
base: main
Are you sure you want to change the base?
videos #18
Changes from all commits
bbdd7fd
c18dbd2
b35399b
b910577
ac9c888
9289ffe
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 |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| package openai | ||
|
|
||
| import "strconv" | ||
|
|
||
| type ResponseRequest struct { | ||
| Background *bool `json:"background,omitzero"` | ||
| Conversation *any `json:"conversation,omitzero"` | ||
|
|
@@ -89,3 +91,58 @@ type ImageResponseMetadata struct { | |
| Size string `json:"size,omitempty"` | ||
| Usage ImageResponseUsage `json:"usage,omitempty"` | ||
| } | ||
|
|
||
| type VideoResponseMetadata struct { | ||
| Model string `json:"model,omitempty"` | ||
| Size string `json:"size,omitempty"` | ||
| Seconds string `json:"seconds,omitempty"` | ||
| } | ||
|
|
||
| func (v *VideoResponseMetadata) GetSecondsAsFloat() float64 { | ||
| if secondsFloat, err := strconv.ParseFloat(v.Seconds, 64); err == nil { | ||
| return secondsFloat | ||
| } | ||
| return 0 | ||
| } | ||
|
Comment on lines
+101
to
+106
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. Don't silently coerce invalid video duration to If 💡 Suggested direction-func (v *VideoResponseMetadata) GetSecondsAsFloat() float64 {
- if secondsFloat, err := strconv.ParseFloat(v.Seconds, 64); err == nil {
- return secondsFloat
- }
- return 0
+func (v *VideoResponseMetadata) GetSecondsAsFloat() (float64, error) {
+ return strconv.ParseFloat(v.Seconds, 64)
}🤖 Prompt for AI Agents |
||
|
|
||
| type TranscriptionResponseUsageInputTokenDetails struct { | ||
| TextTokens int `json:"text_tokens,omitempty"` | ||
| AudioTokens int `json:"audio_tokens,omitempty"` | ||
| } | ||
| type TranscriptionResponseUsage struct { | ||
| Type string `json:"type"` | ||
| TotalTokens int `json:"total_tokens,omitempty"` | ||
| InputTokens int `json:"input_tokens,omitempty"` | ||
| InputTokenDetails TranscriptionResponseUsageInputTokenDetails `json:"input_token_details,omitempty"` | ||
| OutputTokens int `json:"output_tokens,omitempty"` | ||
| } | ||
| type TranscriptionResponse struct { | ||
| Text string `json:"text,omitempty"` | ||
| Usage TranscriptionResponseUsage `json:"usage,omitempty"` | ||
| } | ||
|
|
||
| type TranscriptionStreamChunk struct { | ||
| Type string `json:"type"` | ||
| Delta string `json:"delta,omitempty"` | ||
| Text string `json:"text,omitempty"` | ||
| Usage TranscriptionResponseUsage `json:"usage,omitempty"` | ||
| } | ||
|
|
||
| func (c *TranscriptionStreamChunk) IsDone() bool { | ||
| return c.Type == "transcript.text.done" | ||
| } | ||
|
|
||
| func (c *TranscriptionStreamChunk) IsDelta() bool { | ||
| return c.Type == "transcript.text.delta" | ||
| } | ||
|
|
||
| func (c *TranscriptionStreamChunk) IsSegment() bool { | ||
| return c.Type == "transcript.text.segment" | ||
| } | ||
|
|
||
| func (c *TranscriptionStreamChunk) GetText() string { | ||
| if c.IsDelta() { | ||
| return c.Delta | ||
| } | ||
| return c.Text | ||
| } | ||
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.
Support size-less video pricing before forcing
model-sizelookup.The new cost map contains plain keys like
sora-2andsora-2-pro, but this implementation always requiresmetadata.Sizeand always looks upmodel-size. Any response without a size will now error and record$0, even though you already have a fallback price configured.💡 Suggested fix
func (ce *CostEstimator) EstimateVideoCost(metadata *VideoResponseMetadata) (float64, error) { if metadata == nil { return 0, errors.New("metadata is nil") } costMap, ok := ce.tokenCostMap["video"] if !ok { return 0, errors.New("video cost map is not provided") } model := metadata.Model - size, err := normalizedVideoSize(metadata.Size) - if err != nil { - return 0, err - } - costKey := fmt.Sprintf("%s-%s", model, size) - cost, ok := costMap[costKey] + costKey := model + if metadata.Size != "" { + size, err := normalizedVideoSize(metadata.Size) + if err != nil { + return 0, err + } + costKey = fmt.Sprintf("%s-%s", model, size) + } + cost, ok := costMap[costKey] if !ok { return 0, errors.New("model with provided size is not present in the video cost map") } return cost * metadata.GetSecondsAsFloat(), nil }Also applies to: 841-852
🤖 Prompt for AI Agents