feat: ✨ switch openai to responses api
This commit is contained in:
1 parent
bbf6893ca7
commit
8bac66dd5a
5 files changed
+351
-20
No files matched your search
@@ -1343,13 +1343,14 @@ func TestCreateProviderFromConfig_MinimaxPreservesUserExtraBody(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCreateProviderFromConfig_CustomHeaders(t *testing.T) {
|
||||
var gotSource, gotAuth string
|
||||
var gotSource, gotAuth, gotPath string
|
||||
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
gotSource = r.Header.Get("X-Source")
|
||||
gotAuth = r.Header.Get("Authorization")
|
||||
gotPath = r.URL.Path
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
_, _ = w.Write([]byte(`{"choices":[{"message":{"content":"ok"},"finish_reason":"stop"}]}`))
|
||||
_, _ = w.Write([]byte(openaiResponsesResponse))
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
@@ -1383,11 +1384,17 @@ func TestCreateProviderFromConfig_CustomHeaders(t *testing.T) {
|
||||
if gotAuth != "Token config-auth" {
|
||||
t.Fatalf("Authorization = %q, want %q", gotAuth, "Token config-auth")
|
||||
}
|
||||
if gotPath != "/responses" {
|
||||
t.Fatalf("request path = %q, want /responses", gotPath)
|
||||
}
|
||||
}
|
||||
|
||||
// openaiCompatResponse is the JSON response used by OpenAI-compatible providers.
|
||||
const openaiCompatResponse = `{"choices":[{"message":{"content":"ok"},"finish_reason":"stop"}]}`
|
||||
|
||||
// openaiResponsesResponse is the JSON response used by native Responses API providers.
|
||||
const openaiResponsesResponse = `{"status":"completed","output":[{"type":"message","content":[{"type":"output_text","text":"ok"}]}]}`
|
||||
|
||||
// anthropicResponse is the JSON response used by Anthropic providers.
|
||||
const anthropicResponse = `{"content":[{"type":"text","text":"ok"}],"stop_reason":"end_turn","model":"claude-sonnet-4-20250514","usage":{"input_tokens":10,"output_tokens":5}}`
|
||||
|
||||
@@ -1407,7 +1414,7 @@ func TestCreateProviderFromConfig_UserAgent(t *testing.T) {
|
||||
name: "openai default user agent",
|
||||
model: "openai/gpt-4o",
|
||||
apiKey: "test-key",
|
||||
response: openaiCompatResponse,
|
||||
response: openaiResponsesResponse,
|
||||
wantUA: defaultUA,
|
||||
},
|
||||
{
|
||||
@@ -1415,7 +1422,7 @@ func TestCreateProviderFromConfig_UserAgent(t *testing.T) {
|
||||
model: "openai/gpt-4o",
|
||||
apiKey: "test-key",
|
||||
userAgent: "MyAgent/1.2.3",
|
||||
response: openaiCompatResponse,
|
||||
response: openaiResponsesResponse,
|
||||
wantUA: "MyAgent/1.2.3",
|
||||
},
|
||||
{
|
||||
@@ -1437,7 +1444,7 @@ func TestCreateProviderFromConfig_UserAgent(t *testing.T) {
|
||||
name: "azure default user agent",
|
||||
model: "azure/my-deployment",
|
||||
apiKey: "test-azure-key",
|
||||
response: openaiCompatResponse,
|
||||
response: openaiResponsesResponse,
|
||||
wantUA: defaultUA,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"maps"
|
||||
@@ -16,6 +17,7 @@ import (
|
||||
"github.com/sipeed/picoclaw/pkg/logger"
|
||||
"github.com/sipeed/picoclaw/pkg/providers/common"
|
||||
"github.com/sipeed/picoclaw/pkg/providers/messageutil"
|
||||
orc "github.com/sipeed/picoclaw/pkg/providers/openai_responses_common"
|
||||
"github.com/sipeed/picoclaw/pkg/providers/protocoltypes"
|
||||
)
|
||||
|
||||
@@ -457,6 +459,60 @@ func assistantMessageEmpty(msg Message) bool {
|
||||
strings.TrimSpace(msg.ToolCallID) == ""
|
||||
}
|
||||
|
||||
// shouldUseResponsesAPI keeps Responses routing tied to the explicit OpenAI
|
||||
// protocol. Custom endpoints may use that protocol for unrelated compatible
|
||||
// models, so only GPT model IDs are auto-routed there.
|
||||
func (p *Provider) shouldUseResponsesAPI(model string) bool {
|
||||
if !strings.EqualFold(strings.TrimSpace(p.providerName), "openai") {
|
||||
return false
|
||||
}
|
||||
if isNativeOpenAIEndpoint(p.apiBase) {
|
||||
return true
|
||||
}
|
||||
model = strings.ToLower(strings.TrimSpace(model))
|
||||
model = strings.TrimPrefix(model, "openai/")
|
||||
return strings.HasPrefix(model, "gpt-") && !strings.HasPrefix(model, "gpt-oss")
|
||||
}
|
||||
|
||||
func (p *Provider) buildResponsesRequestBody(
|
||||
messages []Message,
|
||||
tools []ToolDefinition,
|
||||
model string,
|
||||
options map[string]any,
|
||||
) map[string]any {
|
||||
input, instructions := orc.TranslateMessages(p.prepareMessagesForRequest(messages))
|
||||
requestBody := map[string]any{
|
||||
"model": model,
|
||||
"input": input,
|
||||
// PicoClaw sends the complete retained history on every turn, so it does
|
||||
// not rely on server-side response state.
|
||||
"store": false,
|
||||
}
|
||||
|
||||
if instructions != "" {
|
||||
requestBody["instructions"] = instructions
|
||||
}
|
||||
|
||||
nativeSearch, _ := options["native_search"].(bool)
|
||||
nativeSearch = nativeSearch && isNativeSearchHost(p.apiBase)
|
||||
responseTools := orc.TranslateTools(tools, nativeSearch)
|
||||
if len(responseTools) > 0 {
|
||||
requestBody["tools"] = responseTools
|
||||
requestBody["tool_choice"] = "auto"
|
||||
}
|
||||
|
||||
if maxTokens, ok := common.AsInt(options["max_tokens"]); ok {
|
||||
requestBody["max_output_tokens"] = maxTokens
|
||||
}
|
||||
if cacheKey, ok := options["prompt_cache_key"].(string); ok && cacheKey != "" &&
|
||||
supportsPromptCacheKey(p.apiBase) {
|
||||
requestBody["prompt_cache_key"] = cacheKey
|
||||
}
|
||||
|
||||
maps.Copy(requestBody, p.extraBody)
|
||||
return requestBody
|
||||
}
|
||||
|
||||
func (p *Provider) Chat(
|
||||
ctx context.Context,
|
||||
messages []Message,
|
||||
@@ -468,14 +524,77 @@ func (p *Provider) Chat(
|
||||
return nil, fmt.Errorf("API base not configured")
|
||||
}
|
||||
|
||||
requestBody := p.buildRequestBody(messages, tools, model, options)
|
||||
if p.shouldUseResponsesAPI(model) {
|
||||
responsesModel := normalizeModel(model, p.apiBase)
|
||||
out, err := p.chatResponses(ctx, messages, tools, responsesModel, options)
|
||||
if err == nil {
|
||||
return out, nil
|
||||
}
|
||||
if isNativeOpenAIEndpoint(p.apiBase) || !shouldFallbackToChatCompletions(err) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
logger.WarnCF(
|
||||
"provider.openai_compat",
|
||||
"Responses API request failed; falling back to Chat Completions",
|
||||
map[string]any{
|
||||
"model": responsesModel,
|
||||
"error": err.Error(),
|
||||
},
|
||||
)
|
||||
fallback, fallbackErr := p.chatCompletions(ctx, messages, tools, model, options)
|
||||
if fallbackErr != nil {
|
||||
return nil, fmt.Errorf(
|
||||
"responses request failed; fallback chat/completions failed: %w",
|
||||
errors.Join(err, fallbackErr),
|
||||
)
|
||||
}
|
||||
return fallback, nil
|
||||
}
|
||||
|
||||
return p.chatCompletions(ctx, messages, tools, model, options)
|
||||
}
|
||||
|
||||
func shouldFallbackToChatCompletions(err error) bool {
|
||||
var httpErr *common.HTTPError
|
||||
return errors.As(err, &httpErr) &&
|
||||
(httpErr.StatusCode == http.StatusNotFound || httpErr.StatusCode == http.StatusMethodNotAllowed)
|
||||
}
|
||||
|
||||
func (p *Provider) chatCompletions(
|
||||
ctx context.Context,
|
||||
messages []Message,
|
||||
tools []ToolDefinition,
|
||||
model string,
|
||||
options map[string]any,
|
||||
) (*LLMResponse, error) {
|
||||
requestBody := p.buildRequestBody(messages, tools, model, options)
|
||||
return p.doRequest(ctx, "/chat/completions", requestBody, nil)
|
||||
}
|
||||
|
||||
func (p *Provider) chatResponses(
|
||||
ctx context.Context,
|
||||
messages []Message,
|
||||
tools []ToolDefinition,
|
||||
model string,
|
||||
options map[string]any,
|
||||
) (*LLMResponse, error) {
|
||||
requestBody := p.buildResponsesRequestBody(messages, tools, model, options)
|
||||
return p.doRequest(ctx, "/responses", requestBody, orc.ParseResponseBody)
|
||||
}
|
||||
|
||||
func (p *Provider) doRequest(
|
||||
ctx context.Context,
|
||||
path string,
|
||||
requestBody map[string]any,
|
||||
parse func(io.Reader) (*LLMResponse, error),
|
||||
) (*LLMResponse, error) {
|
||||
jsonData, err := json.Marshal(requestBody)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to marshal request: %w", err)
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "POST", p.apiBase+"/chat/completions", bytes.NewReader(jsonData))
|
||||
req, err := http.NewRequestWithContext(ctx, "POST", p.apiBase+path, bytes.NewReader(jsonData))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to create request: %w", err)
|
||||
}
|
||||
@@ -499,6 +618,9 @@ func (p *Provider) Chat(
|
||||
return nil, common.HandleErrorResponse(resp, p.apiBase)
|
||||
}
|
||||
|
||||
if parse != nil {
|
||||
return parse(resp.Body)
|
||||
}
|
||||
return common.ReadAndParseResponse(resp, p.apiBase)
|
||||
}
|
||||
|
||||
@@ -848,6 +970,10 @@ func (p *Provider) SupportsNativeSearch() bool {
|
||||
return isNativeSearchHost(p.apiBase)
|
||||
}
|
||||
|
||||
func isNativeOpenAIEndpoint(apiBase string) bool {
|
||||
return normalizedHostname(apiBase) == "api.openai.com"
|
||||
}
|
||||
|
||||
// isNativeOpenAIOrAzureEndpoint reports whether the given API base points to
|
||||
// OpenAI's own API or an Azure OpenAI deployment.
|
||||
func isNativeOpenAIOrAzureEndpoint(apiBase string) bool {
|
||||
|
||||
@@ -19,6 +19,164 @@ import (
|
||||
"github.com/sipeed/picoclaw/pkg/providers/protocoltypes"
|
||||
)
|
||||
|
||||
func TestProviderChat_OpenAIUsesResponsesAPI(t *testing.T) {
|
||||
var requestBody map[string]any
|
||||
var requestPath string
|
||||
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
requestPath = r.URL.Path
|
||||
if err := json.NewDecoder(r.Body).Decode(&requestBody); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
_, _ = io.WriteString(w, `{
|
||||
"status":"completed",
|
||||
"output":[{"type":"message","content":[{"type":"output_text","text":"from responses"}]}],
|
||||
"usage":{"input_tokens":12,"output_tokens":3,"total_tokens":15}
|
||||
}`)
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
p := NewProvider(
|
||||
"test-key",
|
||||
"https://api.openai.com/v1",
|
||||
"",
|
||||
WithProviderName("openai"),
|
||||
WithExtraBody(map[string]any{"metadata": map[string]any{"source": "test"}}),
|
||||
)
|
||||
p.httpClient.Transport = roundTripperFunc(func(r *http.Request) (*http.Response, error) {
|
||||
r.URL, _ = url.Parse(server.URL + r.URL.Path)
|
||||
return http.DefaultTransport.RoundTrip(r)
|
||||
})
|
||||
|
||||
result, err := p.Chat(
|
||||
t.Context(),
|
||||
[]Message{
|
||||
{Role: "system", Content: "Be concise."},
|
||||
{Role: "user", Content: "Hello"},
|
||||
},
|
||||
nil,
|
||||
"gpt-4.1",
|
||||
map[string]any{
|
||||
"max_tokens": 256,
|
||||
"temperature": 0.2,
|
||||
"prompt_cache_key": "agent-main",
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("Chat() error = %v", err)
|
||||
}
|
||||
if result.Content != "from responses" {
|
||||
t.Fatalf("Content = %q, want from responses", result.Content)
|
||||
}
|
||||
if result.Usage == nil || result.Usage.TotalTokens != 15 {
|
||||
t.Fatalf("Usage = %#v, want total 15", result.Usage)
|
||||
}
|
||||
if requestPath != "/v1/responses" {
|
||||
t.Fatalf("request path = %q, want /v1/responses", requestPath)
|
||||
}
|
||||
if requestBody["model"] != "gpt-4.1" {
|
||||
t.Fatalf("model = %v, want gpt-4.1", requestBody["model"])
|
||||
}
|
||||
if requestBody["store"] != false {
|
||||
t.Fatalf("store = %v, want false", requestBody["store"])
|
||||
}
|
||||
if requestBody["instructions"] != "Be concise." {
|
||||
t.Fatalf("instructions = %v, want Be concise.", requestBody["instructions"])
|
||||
}
|
||||
if _, ok := requestBody["input"]; !ok {
|
||||
t.Fatal("Responses request is missing input")
|
||||
}
|
||||
if _, ok := requestBody["messages"]; ok {
|
||||
t.Fatal("Responses request unexpectedly contains messages")
|
||||
}
|
||||
if requestBody["max_output_tokens"] != float64(256) {
|
||||
t.Fatalf("max_output_tokens = %v, want 256", requestBody["max_output_tokens"])
|
||||
}
|
||||
if _, ok := requestBody["temperature"]; ok {
|
||||
t.Fatalf("temperature should be omitted from Responses request, got %v", requestBody["temperature"])
|
||||
}
|
||||
if requestBody["prompt_cache_key"] != "agent-main" {
|
||||
t.Fatalf("prompt_cache_key = %v, want agent-main", requestBody["prompt_cache_key"])
|
||||
}
|
||||
metadata, ok := requestBody["metadata"].(map[string]any)
|
||||
if !ok || metadata["source"] != "test" {
|
||||
t.Fatalf("metadata = %#v, want source=test", requestBody["metadata"])
|
||||
}
|
||||
}
|
||||
|
||||
func TestProviderChat_OpenAIFallsBackWhenResponsesUnsupported(t *testing.T) {
|
||||
var paths []string
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
paths = append(paths, r.URL.Path)
|
||||
switch r.URL.Path {
|
||||
case "/responses":
|
||||
http.Error(w, `{"error":"not supported"}`, http.StatusNotFound)
|
||||
case "/chat/completions":
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
_, _ = io.WriteString(w, `{"choices":[{"message":{"content":"fallback"},"finish_reason":"stop"}]}`)
|
||||
default:
|
||||
http.Error(w, "unexpected path", http.StatusNotFound)
|
||||
}
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
p := NewProvider("test-key", server.URL, "", WithProviderName("openai"))
|
||||
result, err := p.Chat(t.Context(), []Message{{Role: "user", Content: "Hi"}}, nil, "gpt-4o", nil)
|
||||
if err != nil {
|
||||
t.Fatalf("Chat() error = %v", err)
|
||||
}
|
||||
if result.Content != "fallback" {
|
||||
t.Fatalf("Content = %q, want fallback", result.Content)
|
||||
}
|
||||
if strings.Join(paths, ",") != "/responses,/chat/completions" {
|
||||
t.Fatalf("paths = %v, want responses then chat/completions", paths)
|
||||
}
|
||||
}
|
||||
|
||||
func TestProviderChat_OpenAIDoesNotFallbackOnAuthFailure(t *testing.T) {
|
||||
var paths []string
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
paths = append(paths, r.URL.Path)
|
||||
http.Error(w, `{"error":"invalid key"}`, http.StatusUnauthorized)
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
p := NewProvider("bad-key", server.URL, "", WithProviderName("openai"))
|
||||
_, err := p.Chat(t.Context(), []Message{{Role: "user", Content: "Hi"}}, nil, "gpt-4o", nil)
|
||||
if err == nil {
|
||||
t.Fatal("Chat() error = nil, want authentication error")
|
||||
}
|
||||
if len(paths) != 1 || paths[0] != "/responses" {
|
||||
t.Fatalf("paths = %v, want only /responses", paths)
|
||||
}
|
||||
}
|
||||
|
||||
func TestProviderShouldUseResponsesAPI(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
providerName string
|
||||
apiBase string
|
||||
model string
|
||||
want bool
|
||||
}{
|
||||
{"official OpenAI endpoint", "openai", "https://api.openai.com/v1", "o3", true},
|
||||
{"OpenAI model through custom endpoint", "openai", "https://proxy.example/v1", "gpt-5.6-sol", true},
|
||||
{"non-OpenAI compatibility model", "openai", "https://proxy.example/v1", "Qwen3.5-35B-A3B", false},
|
||||
{"gpt-oss compatibility model", "openai", "https://proxy.example/v1", "gpt-oss-120b", false},
|
||||
{"named compatibility provider", "openrouter", "https://proxy.example/v1", "gpt-5.6-sol", false},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
p := &Provider{providerName: tt.providerName, apiBase: tt.apiBase}
|
||||
if got := p.shouldUseResponsesAPI(tt.model); got != tt.want {
|
||||
t.Fatalf("shouldUseResponsesAPI(%q) = %v, want %v", tt.model, got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestProviderChat_UsesMaxCompletionTokensForGLM(t *testing.T) {
|
||||
var requestBody map[string]any
|
||||
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
// Package openai_responses_common provides shared utilities for providers
|
||||
// that use the OpenAI Responses API (e.g., Azure, Codex).
|
||||
// that use the OpenAI Responses API (e.g., OpenAI, Azure, Codex).
|
||||
package openai_responses_common
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"strings"
|
||||
|
||||
@@ -202,12 +204,28 @@ func ParseResponseBody(body io.Reader) (*protocoltypes.LLMResponse, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return parseResponse(&apiResp), nil
|
||||
switch apiResp.Status {
|
||||
case responses.ResponseStatusCompleted, responses.ResponseStatusIncomplete:
|
||||
return parseResponse(&apiResp), nil
|
||||
case responses.ResponseStatusFailed:
|
||||
if msg := strings.TrimSpace(apiResp.Error.Message); msg != "" {
|
||||
return nil, errors.New(msg)
|
||||
}
|
||||
return nil, errors.New("openai responses request failed")
|
||||
default:
|
||||
return nil, fmt.Errorf(
|
||||
"openai responses returned unexpected or non-terminal status: %q",
|
||||
apiResp.Status,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// ParseResponseFromStruct converts a decoded responses.Response into an LLMResponse.
|
||||
// Used by providers that receive the Response struct directly (e.g., via streaming SDK).
|
||||
func ParseResponseFromStruct(resp *responses.Response) *protocoltypes.LLMResponse {
|
||||
if resp == nil {
|
||||
return &protocoltypes.LLMResponse{}
|
||||
}
|
||||
return parseResponse(resp)
|
||||
}
|
||||
|
||||
|
||||
@@ -471,18 +471,16 @@ func TestParseResponseBody_FailedStatus(t *testing.T) {
|
||||
"id": "resp_fail",
|
||||
"object": "response",
|
||||
"status": "%s",
|
||||
"error": {"message": "model failed"},
|
||||
"output": [],
|
||||
"usage": {"input_tokens": 0, "output_tokens": 0, "total_tokens": 0,
|
||||
"input_tokens_details": {"cached_tokens": 0},
|
||||
"output_tokens_details": {"reasoning_tokens": 0}}
|
||||
}`, string(responses.ResponseStatusFailed)))
|
||||
|
||||
result, err := ParseResponseBody(body)
|
||||
if err != nil {
|
||||
t.Fatalf("error: %v", err)
|
||||
}
|
||||
if result.FinishReason != "error" {
|
||||
t.Errorf("FinishReason = %q, want %q", result.FinishReason, "error")
|
||||
_, err := ParseResponseBody(body)
|
||||
if err == nil || err.Error() != "model failed" {
|
||||
t.Fatalf("error = %v, want model failed", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -497,12 +495,36 @@ func TestParseResponseBody_CanceledStatus(t *testing.T) {
|
||||
"output_tokens_details": {"reasoning_tokens": 0}}
|
||||
}`, string(responses.ResponseStatusCancelled)))
|
||||
|
||||
result, err := ParseResponseBody(body)
|
||||
if err != nil {
|
||||
t.Fatalf("error: %v", err)
|
||||
_, err := ParseResponseBody(body)
|
||||
if err == nil || !strings.Contains(err.Error(), "non-terminal status") {
|
||||
t.Fatalf("error = %v, want non-terminal status error", err)
|
||||
}
|
||||
if result.FinishReason != "canceled" {
|
||||
t.Errorf("FinishReason = %q, want %q", result.FinishReason, "canceled")
|
||||
}
|
||||
|
||||
func TestParseResponseBody_IncompleteMayHaveEmptyOutput(t *testing.T) {
|
||||
result, err := ParseResponseBody(strings.NewReader(`{
|
||||
"status":"incomplete",
|
||||
"output":[],
|
||||
"incomplete_details":{"reason":"max_output_tokens"},
|
||||
"usage":{"input_tokens":10,"output_tokens":5,"total_tokens":15}
|
||||
}`))
|
||||
if err != nil {
|
||||
t.Fatalf("ParseResponseBody() error = %v", err)
|
||||
}
|
||||
if result.FinishReason != "length" {
|
||||
t.Fatalf("FinishReason = %q, want length", result.FinishReason)
|
||||
}
|
||||
if result.Usage == nil || result.Usage.TotalTokens != 15 {
|
||||
t.Fatalf("Usage = %#v, want total 15", result.Usage)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseResponseBody_RejectsWrongEnvelope(t *testing.T) {
|
||||
_, err := ParseResponseBody(strings.NewReader(`{
|
||||
"choices":[{"message":{"content":"chat response"}}]
|
||||
}`))
|
||||
if err == nil || !strings.Contains(err.Error(), "unexpected or non-terminal status") {
|
||||
t.Fatalf("error = %v, want unexpected status error", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user