fix
This commit is contained in:
@@ -243,10 +243,7 @@ type chatResponse struct {
|
||||
CompletionTokens int `json:"completion_tokens"`
|
||||
TotalTokens int `json:"total_tokens"`
|
||||
} `json:"usage"`
|
||||
Error *struct {
|
||||
Message string `json:"message"`
|
||||
Type string `json:"type"`
|
||||
} `json:"error"`
|
||||
Error *openAIErrorBody `json:"error"`
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -466,8 +463,13 @@ func (c *OpenAIClient) doEmbed(ctx context.Context, texts []string) ([][]float32
|
||||
}
|
||||
|
||||
func (c *OpenAIClient) doComplete(ctx context.Context, system, user string, temperature float64, maxTokens int, reasoningEffort string) (Completion, bool, error) {
|
||||
sysRole := "system"
|
||||
if openAIReasoningChatModel(c.Model) {
|
||||
// GPT-5 family prefers developer over system on Chat Completions.
|
||||
sysRole = "developer"
|
||||
}
|
||||
reqBody := buildChatCompletionBody(c.Model, []chatMessage{
|
||||
{Role: "system", Content: system},
|
||||
{Role: sysRole, Content: system},
|
||||
{Role: "user", Content: user},
|
||||
}, temperature, maxTokens, reasoningEffort)
|
||||
body, err := json.Marshal(reqBody)
|
||||
@@ -502,19 +504,13 @@ func (c *OpenAIClient) doComplete(ctx context.Context, system, user string, temp
|
||||
return Completion{}, false, decErr
|
||||
}
|
||||
if res.StatusCode == http.StatusTooManyRequests || res.StatusCode >= 500 {
|
||||
msg := "rate limited or server error"
|
||||
if parsed.Error != nil && parsed.Error.Message != "" {
|
||||
msg = TruncateError(errors.New(parsed.Error.Message))
|
||||
}
|
||||
msg := formatOpenAIHTTPError(res.StatusCode, parsed.Error)
|
||||
httpErr := errors.New(msg)
|
||||
stopWait(httpErr)
|
||||
return Completion{}, true, httpErr
|
||||
}
|
||||
if res.StatusCode >= 400 {
|
||||
msg := fmt.Sprintf("openai http %d", res.StatusCode)
|
||||
if parsed.Error != nil && parsed.Error.Message != "" {
|
||||
msg = TruncateError(errors.New(parsed.Error.Message))
|
||||
}
|
||||
msg := formatOpenAIHTTPError(res.StatusCode, parsed.Error)
|
||||
httpErr := errors.New(msg)
|
||||
stopWait(httpErr)
|
||||
return Completion{}, false, httpErr
|
||||
|
||||
Reference in New Issue
Block a user