mirror of
https://github.com/openai/openai-go.git
synced 2026-04-01 09:07:22 +09:00
* codegen metadata * chore(internal): refactor stream event processing to be more future proof * feat(api): manual updates * release: 1.12.0 --------- Co-authored-by: stainless-app[bot] <142633134+stainless-app[bot]@users.noreply.github.com> Co-authored-by: David Meadows <dmeadows@stainless.com>
168 lines
4.7 KiB
Go
168 lines
4.7 KiB
Go
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
|
|
package responses_test
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/openai/openai-go"
|
|
"github.com/openai/openai-go/internal/testutil"
|
|
"github.com/openai/openai-go/option"
|
|
"github.com/openai/openai-go/responses"
|
|
"github.com/openai/openai-go/shared"
|
|
)
|
|
|
|
func TestResponseNewWithOptionalParams(t *testing.T) {
|
|
baseURL := "http://localhost:4010"
|
|
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
|
|
baseURL = envURL
|
|
}
|
|
if !testutil.CheckTestServer(t, baseURL) {
|
|
return
|
|
}
|
|
client := openai.NewClient(
|
|
option.WithBaseURL(baseURL),
|
|
option.WithAPIKey("My API Key"),
|
|
)
|
|
_, err := client.Responses.New(context.TODO(), responses.ResponseNewParams{
|
|
Background: openai.Bool(true),
|
|
Include: []responses.ResponseIncludable{responses.ResponseIncludableCodeInterpreterCallOutputs},
|
|
Input: responses.ResponseNewParamsInputUnion{
|
|
OfString: openai.String("string"),
|
|
},
|
|
Instructions: openai.String("instructions"),
|
|
MaxOutputTokens: openai.Int(0),
|
|
MaxToolCalls: openai.Int(0),
|
|
Metadata: shared.Metadata{
|
|
"foo": "string",
|
|
},
|
|
Model: shared.ResponsesModel("gpt-4o"),
|
|
ParallelToolCalls: openai.Bool(true),
|
|
PreviousResponseID: openai.String("previous_response_id"),
|
|
Prompt: responses.ResponsePromptParam{
|
|
ID: "id",
|
|
Variables: map[string]responses.ResponsePromptVariableUnionParam{
|
|
"foo": {
|
|
OfString: openai.String("string"),
|
|
},
|
|
},
|
|
Version: openai.String("version"),
|
|
},
|
|
PromptCacheKey: openai.String("prompt-cache-key-1234"),
|
|
Reasoning: shared.ReasoningParam{
|
|
Effort: shared.ReasoningEffortLow,
|
|
GenerateSummary: shared.ReasoningGenerateSummaryAuto,
|
|
Summary: shared.ReasoningSummaryAuto,
|
|
},
|
|
SafetyIdentifier: openai.String("safety-identifier-1234"),
|
|
ServiceTier: responses.ResponseNewParamsServiceTierAuto,
|
|
Store: openai.Bool(true),
|
|
Temperature: openai.Float(1),
|
|
Text: responses.ResponseTextConfigParam{
|
|
Format: responses.ResponseFormatTextConfigUnionParam{
|
|
OfText: &shared.ResponseFormatTextParam{},
|
|
},
|
|
},
|
|
ToolChoice: responses.ResponseNewParamsToolChoiceUnion{
|
|
OfToolChoiceMode: openai.Opt(responses.ToolChoiceOptionsNone),
|
|
},
|
|
Tools: []responses.ToolUnionParam{{
|
|
OfFunction: &responses.FunctionToolParam{
|
|
Name: "name",
|
|
Parameters: map[string]any{
|
|
"foo": "bar",
|
|
},
|
|
Strict: openai.Bool(true),
|
|
Description: openai.String("description"),
|
|
},
|
|
}},
|
|
TopLogprobs: openai.Int(0),
|
|
TopP: openai.Float(1),
|
|
Truncation: responses.ResponseNewParamsTruncationAuto,
|
|
User: openai.String("user-1234"),
|
|
})
|
|
if err != nil {
|
|
var apierr *openai.Error
|
|
if errors.As(err, &apierr) {
|
|
t.Log(string(apierr.DumpRequest(true)))
|
|
}
|
|
t.Fatalf("err should be nil: %s", err.Error())
|
|
}
|
|
}
|
|
|
|
func TestResponseGetWithOptionalParams(t *testing.T) {
|
|
baseURL := "http://localhost:4010"
|
|
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
|
|
baseURL = envURL
|
|
}
|
|
if !testutil.CheckTestServer(t, baseURL) {
|
|
return
|
|
}
|
|
client := openai.NewClient(
|
|
option.WithBaseURL(baseURL),
|
|
option.WithAPIKey("My API Key"),
|
|
)
|
|
_, err := client.Responses.Get(
|
|
context.TODO(),
|
|
"resp_677efb5139a88190b512bc3fef8e535d",
|
|
responses.ResponseGetParams{
|
|
Include: []responses.ResponseIncludable{responses.ResponseIncludableCodeInterpreterCallOutputs},
|
|
StartingAfter: openai.Int(0),
|
|
},
|
|
)
|
|
if err != nil {
|
|
var apierr *openai.Error
|
|
if errors.As(err, &apierr) {
|
|
t.Log(string(apierr.DumpRequest(true)))
|
|
}
|
|
t.Fatalf("err should be nil: %s", err.Error())
|
|
}
|
|
}
|
|
|
|
func TestResponseDelete(t *testing.T) {
|
|
baseURL := "http://localhost:4010"
|
|
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
|
|
baseURL = envURL
|
|
}
|
|
if !testutil.CheckTestServer(t, baseURL) {
|
|
return
|
|
}
|
|
client := openai.NewClient(
|
|
option.WithBaseURL(baseURL),
|
|
option.WithAPIKey("My API Key"),
|
|
)
|
|
err := client.Responses.Delete(context.TODO(), "resp_677efb5139a88190b512bc3fef8e535d")
|
|
if err != nil {
|
|
var apierr *openai.Error
|
|
if errors.As(err, &apierr) {
|
|
t.Log(string(apierr.DumpRequest(true)))
|
|
}
|
|
t.Fatalf("err should be nil: %s", err.Error())
|
|
}
|
|
}
|
|
|
|
func TestResponseCancel(t *testing.T) {
|
|
baseURL := "http://localhost:4010"
|
|
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
|
|
baseURL = envURL
|
|
}
|
|
if !testutil.CheckTestServer(t, baseURL) {
|
|
return
|
|
}
|
|
client := openai.NewClient(
|
|
option.WithBaseURL(baseURL),
|
|
option.WithAPIKey("My API Key"),
|
|
)
|
|
_, err := client.Responses.Cancel(context.TODO(), "resp_677efb5139a88190b512bc3fef8e535d")
|
|
if err != nil {
|
|
var apierr *openai.Error
|
|
if errors.As(err, &apierr) {
|
|
t.Log(string(apierr.DumpRequest(true)))
|
|
}
|
|
t.Fatalf("err should be nil: %s", err.Error())
|
|
}
|
|
}
|