Skip to content

Commit 45d6627

Browse files
committed
fix(examples): after merging streaming
1 parent 03219d2 commit 45d6627

File tree

8 files changed

+35
-24
lines changed

8 files changed

+35
-24
lines changed

examples/image_to_stream/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
)
1313

1414
func main() {
15-
imgBytes, err := os.ReadFile("assets/test.jpg")
15+
imgBytes, err := os.ReadFile("example.png")
1616
if err != nil {
1717
panic(err)
1818
}

examples/image_to_text/main.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import (
1111
"github.com/sashabaranov/go-openai"
1212
)
1313

14-
func main() {
15-
imgBytes, err := os.ReadFile("../example.png")
14+
func main() {
15+
imgBytes, err := os.ReadFile("example.png")
1616
if err != nil {
1717
panic(err)
1818
}
@@ -28,5 +28,5 @@ func main() {
2828
panic(err)
2929
}
3030

31-
fmt.Println(result)
31+
fmt.Println(string(result.Content()))
3232
}

examples/logging/main.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,10 @@ func main() {
3232
}
3333

3434
func Logger(input, output agency.Message, cfg *agency.OperationConfig) {
35-
fmt.Printf("in: %v\nprompt: %v\nout: %v\n\n", input, cfg.Prompt, output)
35+
fmt.Printf(
36+
"in: %v\nprompt: %v\nout: %v\n\n",
37+
string(input.Content()),
38+
cfg.Prompt,
39+
string(output.Content()),
40+
)
3641
}

examples/prompt_template/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@ func main() {
2929
panic(err)
3030
}
3131

32-
fmt.Println(resultMsg)
32+
fmt.Println(string(resultMsg.Content()))
3333
}

examples/speech_to_text/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,5 @@ func main() {
3333
panic(err)
3434
}
3535

36-
fmt.Println(result)
36+
fmt.Println(string(result.Content()))
3737
}

examples/text_to_speech/main.go

+3-6
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,11 @@ import (
1212

1313
func main() {
1414
input := agency.NewMessage(
15-
1615
agency.UserRole,
1716
agency.TextKind,
18-
[]byte(`
19-
One does not simply walk into Mordor.
20-
Its black gates are guarded by more than just Orcs.
21-
There is evil there that does not sleep, and the Great Eye is ever watchful.
22-
`))
17+
[]byte(`One does not simply walk into Mordor.
18+
Its black gates are guarded by more than just Orcs.
19+
There is evil there that does not sleep, and the Great Eye is ever watchful.`))
2320

2421
msg, err := openai.New(openai.Params{Key: os.Getenv("OPENAI_API_KEY")}).
2522
TextToSpeech(openai.TextToSpeechParams{

examples/text_to_stream/main.go

+11-9
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,27 @@ func main() {
1717

1818
result, err := factory.
1919
TextToStream(openai.TextToStreamParams{
20-
TextToTextParams: openai.TextToTextParams{
21-
Model: goopenai.GPT3Dot5Turbo,
22-
},
20+
TextToTextParams: openai.TextToTextParams{Model: goopenai.GPT4oMini},
2321
StreamHandler: func(delta, total string, isFirst, isLast bool) error {
2422
if isFirst {
2523
fmt.Println("====Start streaming====")
2624
}
27-
2825
fmt.Print(delta)
29-
3026
if isLast {
3127
fmt.Println("\n====Finish streaming====")
3228
}
33-
3429
return nil
35-
}}).
30+
},
31+
}).
3632
SetPrompt("Write a few sentences about topic").
37-
Execute(context.Background(), agency.NewMessage(agency.UserRole, agency.TextKind, []byte("I love programming.")))
38-
33+
Execute(
34+
context.Background(),
35+
agency.NewMessage(
36+
agency.UserRole,
37+
agency.TextKind,
38+
[]byte("I love programming."),
39+
),
40+
)
3941
if err != nil {
4042
panic(err)
4143
}

examples/translate_text/main.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,16 @@ func main() {
1616
factory := openai.New(openai.Params{Key: os.Getenv("OPENAI_API_KEY")})
1717

1818
result, err := factory.
19-
TextToText(openai.TextToTextParams{Model: goopenai.GPT3Dot5Turbo}).
19+
TextToText(openai.TextToTextParams{Model: goopenai.GPT4oMini}).
2020
SetPrompt("You are a helpful assistant that translates English to French").
21-
Execute(context.Background(), agency.NewMessage(agency.UserRole, agency.TextKind, []byte("I love programming.")))
21+
Execute(
22+
context.Background(),
23+
agency.NewMessage(
24+
agency.UserRole,
25+
agency.TextKind,
26+
[]byte("I love programming."),
27+
),
28+
)
2229

2330
if err != nil {
2431
panic(err)

0 commit comments

Comments
 (0)