Skip to content

Commit

Permalink
feat(examples): replace gpt3.5 with gpt4o-mini (better and cheaper)
Browse files Browse the repository at this point in the history
  • Loading branch information
emil14 committed Dec 30, 2024
1 parent b91d13f commit 03219d2
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 25 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
func main() {
assistant := openai.
New(openai.Params{Key: os.Getenv("OPENAI_API_KEY")}).
TextToText(openai.TextToTextParams{Model: "gpt-3.5-turbo"}).
TextToText(openai.TextToTextParams{Model: "gpt-4o-mini"}).
SetPrompt("You are helpful assistant.")

messages := []agency.Message{}
Expand Down
4 changes: 2 additions & 2 deletions examples/chat/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
func main() {
assistant := openai.
New(openai.Params{Key: os.Getenv("OPENAI_API_KEY")}).
TextToText(openai.TextToTextParams{Model: "gpt-3.5-turbo"}).
TextToText(openai.TextToTextParams{Model: "gpt-4o-mini"}).
SetPrompt("You are helpful assistant.")

messages := []agency.Message{}
Expand All @@ -36,7 +36,7 @@ func main() {
panic(err)
}

fmt.Println("Assistant: ", answer)
fmt.Println("Assistant:", string(answer.Content()))

messages = append(messages, input, answer)
}
Expand Down
6 changes: 3 additions & 3 deletions examples/cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ import (
)

// usage example: go to the repo root and execute
// 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"
// 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"
func main() {
provider := openai.New(openai.Params{Key: os.Getenv("OPENAI_API_KEY")})

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

flag.Parse()
Expand All @@ -45,5 +45,5 @@ func main() {
os.Exit(1)
}

fmt.Println(result)
fmt.Println(result.Content())
}
16 changes: 12 additions & 4 deletions examples/custom_operation/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,22 @@ func main() {
increment := agency.NewOperation(incrementFunc)

msg, err := agency.NewProcess(
increment, increment, increment,
).Execute(context.Background(), agency.NewMessage(agency.UserRole, agency.TextKind, []byte("0")))

increment,
increment,
increment,
).Execute(
context.Background(),
agency.NewMessage(
agency.UserRole,
agency.TextKind,
[]byte("0"),
),
)
if err != nil {
panic(err)
}

fmt.Println(msg)
fmt.Println(string(msg.Content()))
}

func incrementFunc(ctx context.Context, msg agency.Message, _ *agency.OperationConfig) (agency.Message, error) {
Expand Down
11 changes: 9 additions & 2 deletions examples/func_call/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"

_ "github.com/joho/godotenv/autoload"
go_openai "github.com/sashabaranov/go-openai"
"github.com/sashabaranov/go-openai/jsonschema"

"github.com/neurocult/agency"
Expand All @@ -17,13 +18,14 @@ func main() {
t2tOp := openai.
New(openai.Params{Key: os.Getenv("OPENAI_API_KEY")}).
TextToText(openai.TextToTextParams{
Model: "gpt-3.5-turbo",
Model: go_openai.GPT4oMini,
FuncDefs: []openai.FuncDef{
// function without parameters
{
Name: "GetMeaningOfLife",
Description: "Answer questions about meaning of life",
Body: func(ctx context.Context, _ []byte) (agency.Message, error) {
// because we don't need any arguments
return agency.NewTextMessage(agency.ToolRole, "42"), nil
},
},
Expand Down Expand Up @@ -96,5 +98,10 @@ Examples:
}

func printAnswer(message agency.Message) {
fmt.Printf("Role: %s; Type: %s; Data: %s\n", message.Role(), message.Kind(), agency.GetStringContent(message))
fmt.Printf(
"Role: %s; Type: %s; Data: %s\n",
message.Role(),
message.Kind(),
string(message.Content()),
)
}
2 changes: 1 addition & 1 deletion examples/logging/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

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

_, err := agency.NewProcess(
factory.TextToText(params).SetPrompt("explain what that means"),
Expand Down
2 changes: 1 addition & 1 deletion examples/prompt_template/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func main() {
factory := openai.New(openai.Params{Key: os.Getenv("OPENAI_API_KEY")})

resultMsg, err := factory.
TextToText(openai.TextToTextParams{Model: "gpt-3.5-turbo"}).
TextToText(openai.TextToTextParams{Model: "gpt-4o-mini"}).
SetPrompt(
"You are a helpful assistant that translates %s to %s",
"English", "French",
Expand Down
2 changes: 1 addition & 1 deletion examples/rag_vector_database/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func main() {

factory := openai.New(openai.Params{Key: openAPIKey})
retrieve := RAGoperation(client)
summarize := factory.TextToText(openai.TextToTextParams{Model: "gpt-3.5-turbo"}).SetPrompt("summarize")
summarize := factory.TextToText(openai.TextToTextParams{Model: "gpt-4o-mini"}).SetPrompt("summarize")
voice := factory.TextToSpeech(openai.TextToSpeechParams{
Model: "tts-1", ResponseFormat: "mp3", Speed: 1, Voice: "onyx",
})
Expand Down
4 changes: 2 additions & 2 deletions examples/speech_to_text_multi_model/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ func main() {
// step2
translate := factory.
TextToText(openai.TextToTextParams{
Model: "gpt-3.5-turbo",
Model: "gpt-4o-mini",
Temperature: openai.Temperature(0.5),
}).
SetPrompt("translate to russian")

// step 3
uppercase := factory.
TextToText(openai.TextToTextParams{
Model: "gpt-3.5-turbo",
Model: "gpt-4o-mini",
Temperature: openai.Temperature(1),
}).
SetPrompt("uppercase every letter of the text")
Expand Down
8 changes: 0 additions & 8 deletions messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,3 @@ func NewJsonMessage(role Role, content any) (BaseMessage, error) {
kind: TextKind,
}, nil
}

func GetStringContent(msg Message) string {
if msg.Kind() == TextKind {
return string(msg.Content())
}

return ""
}

0 comments on commit 03219d2

Please sign in to comment.