Skip to content

Commit

Permalink
Use GPT-4o mainly for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
otiai10 committed May 13, 2024
1 parent f9d6f9a commit 8284fad
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 13 deletions.
6 changes: 4 additions & 2 deletions chatgpt/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"os"

"github.com/otiai10/openaigo"
"github.com/otiai10/openaigo/functioncall"
)

Expand Down Expand Up @@ -36,10 +37,10 @@ var funcs = functioncall.Funcs{
func ExampleAI() {

key := os.Getenv("OPENAI_API_KEY")
ai := New(key, "gpt-4-0613")
ai := New(key, openaigo.GPT4o)
ai.Functions = funcs
conv := []Message{
User("Should I bring my umbrella tomorrow?"),
User("Should I bring my umbrella tomorrow? You can use functions to get necessary information."),
}
res, err := ai.Chat(context.Background(), conv)
if err != nil {
Expand All @@ -49,6 +50,7 @@ func ExampleAI() {
if i != 0 {
fmt.Print("->")
}
// fmt.Printf("%s (%s): %s\n", m.Role, m.Name, m.Content) // DEBUG
fmt.Printf("[%d]%s", i, m.Role)
continue
// fmt.Printf("[%d] ", i)
Expand Down
2 changes: 1 addition & 1 deletion completion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
func TestClient_Completion(t *testing.T) {
client := NewClient("")
client.BaseURL = mockserver.URL
res, err := client.Completion(nil, CompletionRequestBody{})
res, err := client.Completion_Legacy(nil, CompletionRequestBody{})
Expect(t, err).ToBe(nil)
Expect(t, res).TypeOf("openaigo.CompletionResponse")

Expand Down
2 changes: 1 addition & 1 deletion endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func (client *Client) RetrieveModel(ctx context.Context, model string) (resp Mod
// Completion: POST https://api.openai.com/v1/completions
// Creates a completion for the provided prompt and parameters
// See https://beta.openai.com/docs/api-reference/completions/create
func (client *Client) Completion(ctx context.Context, body CompletionRequestBody) (resp CompletionResponse, err error) {
func (client *Client) Completion_Legacy(ctx context.Context, body CompletionRequestBody) (resp CompletionResponse, err error) {
p := "/completions"
return call(ctx, client, http.MethodPost, p, body, resp, nil)
}
Expand Down
2 changes: 1 addition & 1 deletion functioncall/invoke.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func (funcs Funcs) Call(invocation Invocation) string {
func (funcs Funcs) invoke(invocation Invocation) any {
f, ok := funcs[invocation.Name()]
if !ok {
return fmt.Sprintf("function not found: %s", invocation.Name())
return fmt.Sprintf("function not found: `%s`", invocation.Name())
}
v := reflect.ValueOf(f.Value)
if !v.IsValid() || v.IsZero() {
Expand Down
18 changes: 10 additions & 8 deletions testapp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@ var (
Name: "completion",
Run: func() (any, error) {
client := openaigo.NewClient(OPENAI_API_KEY)
request := openaigo.CompletionRequestBody{
Model: openaigo.GPT3_5Turbo_Instruct,
Prompt: []string{"Say this is a test"},
request := openaigo.ChatCompletionRequestBody{
Model: openaigo.GPT4o,
Messages: []openaigo.Message{
{Role: "user", Content: "What is the capital of Japan?"},
},
}
return client.Completion(nil, request)
return client.ChatCompletion(nil, request)
},
},
{
Expand Down Expand Up @@ -84,7 +86,7 @@ var (
Run: func() (any, error) {
client := openaigo.NewClient(OPENAI_API_KEY)
request := openaigo.ChatRequest{
Model: openaigo.GPT3_5Turbo,
Model: openaigo.GPT4o,
Messages: []openaigo.Message{
{Role: "user", Content: "Hello!"},
},
Expand All @@ -98,7 +100,7 @@ var (
Run: func() (any, error) {
client := openaigo.NewClient(OPENAI_API_KEY)
request := openaigo.ChatRequest{
Model: openaigo.GPT4,
Model: openaigo.GPT4o,
Messages: []openaigo.Message{
{Role: "user", Content: "Who are you?"},
},
Expand All @@ -122,7 +124,7 @@ var (
}
}
request := openaigo.ChatCompletionRequestBody{
Model: openaigo.GPT3_5Turbo_0613,
Model: openaigo.GPT4o,
StreamCallback: calback,
Messages: []openaigo.Message{
{
Expand Down Expand Up @@ -162,7 +164,7 @@ var (
}
client := openaigo.NewClient(OPENAI_API_KEY)
request := openaigo.ChatRequest{
Model: openaigo.GPT3_5Turbo_0613,
Model: openaigo.GPT4o_20240513,
Messages: conversation,
Functions: funcs,
}
Expand Down

0 comments on commit 8284fad

Please sign in to comment.