Skip to content

Commit 03219d2

Browse files
committed
feat(examples): replace gpt3.5 with gpt4o-mini (better and cheaper)
1 parent b91d13f commit 03219d2

File tree

10 files changed

+32
-25
lines changed

10 files changed

+32
-25
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import (
3434
func main() {
3535
assistant := openai.
3636
New(openai.Params{Key: os.Getenv("OPENAI_API_KEY")}).
37-
TextToText(openai.TextToTextParams{Model: "gpt-3.5-turbo"}).
37+
TextToText(openai.TextToTextParams{Model: "gpt-4o-mini"}).
3838
SetPrompt("You are helpful assistant.")
3939

4040
messages := []agency.Message{}

examples/chat/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
func main() {
1616
assistant := openai.
1717
New(openai.Params{Key: os.Getenv("OPENAI_API_KEY")}).
18-
TextToText(openai.TextToTextParams{Model: "gpt-3.5-turbo"}).
18+
TextToText(openai.TextToTextParams{Model: "gpt-4o-mini"}).
1919
SetPrompt("You are helpful assistant.")
2020

2121
messages := []agency.Message{}
@@ -36,7 +36,7 @@ func main() {
3636
panic(err)
3737
}
3838

39-
fmt.Println("Assistant: ", answer)
39+
fmt.Println("Assistant:", string(answer.Content()))
4040

4141
messages = append(messages, input, answer)
4242
}

examples/cli/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ import (
1313
)
1414

1515
// usage example: go to the repo root and execute
16-
// go run examples/cli/main.go -prompt "You are professional translator, translate everything you see to Russian" -model "gpt-3.5-turbo" -maxTokens=1000 "I love winter"
16+
// go run examples/cli/main.go -prompt "You are professional translator, translate everything you see to Russian" -model "gpt-4o-mini" -maxTokens=1000 "I love winter"
1717
func main() {
1818
provider := openai.New(openai.Params{Key: os.Getenv("OPENAI_API_KEY")})
1919

2020
temp := flag.Float64("temp", 0.0, "Temperature value")
2121
maxTokens := flag.Int("maxTokens", 0, "Maximum number of tokens")
22-
model := flag.String("model", "gpt-3.5-turbo", "Model name")
22+
model := flag.String("model", "gpt-4o-mini", "Model name")
2323
prompt := flag.String("prompt", "You are a helpful assistant", "System message")
2424

2525
flag.Parse()
@@ -45,5 +45,5 @@ func main() {
4545
os.Exit(1)
4646
}
4747

48-
fmt.Println(result)
48+
fmt.Println(result.Content())
4949
}

examples/custom_operation/main.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,22 @@ func main() {
1212
increment := agency.NewOperation(incrementFunc)
1313

1414
msg, err := agency.NewProcess(
15-
increment, increment, increment,
16-
).Execute(context.Background(), agency.NewMessage(agency.UserRole, agency.TextKind, []byte("0")))
17-
15+
increment,
16+
increment,
17+
increment,
18+
).Execute(
19+
context.Background(),
20+
agency.NewMessage(
21+
agency.UserRole,
22+
agency.TextKind,
23+
[]byte("0"),
24+
),
25+
)
1826
if err != nil {
1927
panic(err)
2028
}
2129

22-
fmt.Println(msg)
30+
fmt.Println(string(msg.Content()))
2331
}
2432

2533
func incrementFunc(ctx context.Context, msg agency.Message, _ *agency.OperationConfig) (agency.Message, error) {

examples/func_call/main.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"os"
88

99
_ "github.com/joho/godotenv/autoload"
10+
go_openai "github.com/sashabaranov/go-openai"
1011
"github.com/sashabaranov/go-openai/jsonschema"
1112

1213
"github.com/neurocult/agency"
@@ -17,13 +18,14 @@ func main() {
1718
t2tOp := openai.
1819
New(openai.Params{Key: os.Getenv("OPENAI_API_KEY")}).
1920
TextToText(openai.TextToTextParams{
20-
Model: "gpt-3.5-turbo",
21+
Model: go_openai.GPT4oMini,
2122
FuncDefs: []openai.FuncDef{
2223
// function without parameters
2324
{
2425
Name: "GetMeaningOfLife",
2526
Description: "Answer questions about meaning of life",
2627
Body: func(ctx context.Context, _ []byte) (agency.Message, error) {
28+
// because we don't need any arguments
2729
return agency.NewTextMessage(agency.ToolRole, "42"), nil
2830
},
2931
},
@@ -96,5 +98,10 @@ Examples:
9698
}
9799

98100
func printAnswer(message agency.Message) {
99-
fmt.Printf("Role: %s; Type: %s; Data: %s\n", message.Role(), message.Kind(), agency.GetStringContent(message))
101+
fmt.Printf(
102+
"Role: %s; Type: %s; Data: %s\n",
103+
message.Role(),
104+
message.Kind(),
105+
string(message.Content()),
106+
)
100107
}

examples/logging/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313

1414
func main() {
1515
factory := openai.New(openai.Params{Key: os.Getenv("OPENAI_API_KEY")})
16-
params := openai.TextToTextParams{Model: "gpt-3.5-turbo"}
16+
params := openai.TextToTextParams{Model: "gpt-4o-mini"}
1717

1818
_, err := agency.NewProcess(
1919
factory.TextToText(params).SetPrompt("explain what that means"),

examples/prompt_template/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func main() {
1515
factory := openai.New(openai.Params{Key: os.Getenv("OPENAI_API_KEY")})
1616

1717
resultMsg, err := factory.
18-
TextToText(openai.TextToTextParams{Model: "gpt-3.5-turbo"}).
18+
TextToText(openai.TextToTextParams{Model: "gpt-4o-mini"}).
1919
SetPrompt(
2020
"You are a helpful assistant that translates %s to %s",
2121
"English", "French",

examples/rag_vector_database/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func main() {
2727

2828
factory := openai.New(openai.Params{Key: openAPIKey})
2929
retrieve := RAGoperation(client)
30-
summarize := factory.TextToText(openai.TextToTextParams{Model: "gpt-3.5-turbo"}).SetPrompt("summarize")
30+
summarize := factory.TextToText(openai.TextToTextParams{Model: "gpt-4o-mini"}).SetPrompt("summarize")
3131
voice := factory.TextToSpeech(openai.TextToSpeechParams{
3232
Model: "tts-1", ResponseFormat: "mp3", Speed: 1, Voice: "onyx",
3333
})

examples/speech_to_text_multi_model/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ func main() {
3131
// step2
3232
translate := factory.
3333
TextToText(openai.TextToTextParams{
34-
Model: "gpt-3.5-turbo",
34+
Model: "gpt-4o-mini",
3535
Temperature: openai.Temperature(0.5),
3636
}).
3737
SetPrompt("translate to russian")
3838

3939
// step 3
4040
uppercase := factory.
4141
TextToText(openai.TextToTextParams{
42-
Model: "gpt-3.5-turbo",
42+
Model: "gpt-4o-mini",
4343
Temperature: openai.Temperature(1),
4444
}).
4545
SetPrompt("uppercase every letter of the text")

messages.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,3 @@ func NewJsonMessage(role Role, content any) (BaseMessage, error) {
7474
kind: TextKind,
7575
}, nil
7676
}
77-
78-
func GetStringContent(msg Message) string {
79-
if msg.Kind() == TextKind {
80-
return string(msg.Content())
81-
}
82-
83-
return ""
84-
}

0 commit comments

Comments
 (0)