mirror of
https://github.com/openai/openai-go.git
synced 2026-04-01 17:17:14 +09:00
141 lines
3.5 KiB
Go
141 lines
3.5 KiB
Go
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
|
|
package conversations_test
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/openai/openai-go/v3"
|
|
"github.com/openai/openai-go/v3/conversations"
|
|
"github.com/openai/openai-go/v3/internal/testutil"
|
|
"github.com/openai/openai-go/v3/option"
|
|
"github.com/openai/openai-go/v3/responses"
|
|
)
|
|
|
|
func TestItemNewWithOptionalParams(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.Conversations.Items.New(
|
|
context.TODO(),
|
|
"conv_123",
|
|
conversations.ItemNewParams{
|
|
Items: []responses.ResponseInputItemUnionParam{{
|
|
OfMessage: &responses.EasyInputMessageParam{
|
|
Content: responses.EasyInputMessageContentUnionParam{
|
|
OfString: openai.String("string"),
|
|
},
|
|
Role: responses.EasyInputMessageRoleUser,
|
|
Phase: responses.EasyInputMessagePhaseCommentary,
|
|
Type: responses.EasyInputMessageTypeMessage,
|
|
},
|
|
}},
|
|
Include: []responses.ResponseIncludable{responses.ResponseIncludableFileSearchCallResults},
|
|
},
|
|
)
|
|
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 TestItemGetWithOptionalParams(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.Conversations.Items.Get(
|
|
context.TODO(),
|
|
"conv_123",
|
|
"msg_abc",
|
|
conversations.ItemGetParams{
|
|
Include: []responses.ResponseIncludable{responses.ResponseIncludableFileSearchCallResults},
|
|
},
|
|
)
|
|
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 TestItemListWithOptionalParams(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.Conversations.Items.List(
|
|
context.TODO(),
|
|
"conv_123",
|
|
conversations.ItemListParams{
|
|
After: openai.String("after"),
|
|
Include: []responses.ResponseIncludable{responses.ResponseIncludableFileSearchCallResults},
|
|
Limit: openai.Int(0),
|
|
Order: conversations.ItemListParamsOrderAsc,
|
|
},
|
|
)
|
|
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 TestItemDelete(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.Conversations.Items.Delete(
|
|
context.TODO(),
|
|
"conv_123",
|
|
"msg_abc",
|
|
)
|
|
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())
|
|
}
|
|
}
|