Skip to content

Commit

Permalink
fix(examples): after merging streaming
Browse files Browse the repository at this point in the history
  • Loading branch information
emil14 committed Dec 30, 2024
1 parent 03219d2 commit 45d6627
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 24 deletions.
2 changes: 1 addition & 1 deletion examples/image_to_stream/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

func main() {
imgBytes, err := os.ReadFile("assets/test.jpg")
imgBytes, err := os.ReadFile("example.png")
if err != nil {
panic(err)
}
Expand Down
6 changes: 3 additions & 3 deletions examples/image_to_text/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"github.com/sashabaranov/go-openai"
)

func main() {
imgBytes, err := os.ReadFile("../example.png")
func main() {
imgBytes, err := os.ReadFile("example.png")
if err != nil {
panic(err)
}
Expand All @@ -28,5 +28,5 @@ func main() {
panic(err)
}

fmt.Println(result)
fmt.Println(string(result.Content()))
}
7 changes: 6 additions & 1 deletion examples/logging/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,10 @@ func main() {
}

func Logger(input, output agency.Message, cfg *agency.OperationConfig) {
fmt.Printf("in: %v\nprompt: %v\nout: %v\n\n", input, cfg.Prompt, output)
fmt.Printf(
"in: %v\nprompt: %v\nout: %v\n\n",
string(input.Content()),
cfg.Prompt,
string(output.Content()),
)
}
2 changes: 1 addition & 1 deletion examples/prompt_template/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ func main() {
panic(err)
}

fmt.Println(resultMsg)
fmt.Println(string(resultMsg.Content()))
}
2 changes: 1 addition & 1 deletion examples/speech_to_text/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ func main() {
panic(err)
}

fmt.Println(result)
fmt.Println(string(result.Content()))
}
9 changes: 3 additions & 6 deletions examples/text_to_speech/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,11 @@ import (

func main() {
input := agency.NewMessage(

agency.UserRole,
agency.TextKind,
[]byte(`
One does not simply walk into Mordor.
Its black gates are guarded by more than just Orcs.
There is evil there that does not sleep, and the Great Eye is ever watchful.
`))
[]byte(`One does not simply walk into Mordor.
Its black gates are guarded by more than just Orcs.
There is evil there that does not sleep, and the Great Eye is ever watchful.`))

msg, err := openai.New(openai.Params{Key: os.Getenv("OPENAI_API_KEY")}).
TextToSpeech(openai.TextToSpeechParams{
Expand Down
20 changes: 11 additions & 9 deletions examples/text_to_stream/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,27 @@ func main() {

result, err := factory.
TextToStream(openai.TextToStreamParams{
TextToTextParams: openai.TextToTextParams{
Model: goopenai.GPT3Dot5Turbo,
},
TextToTextParams: openai.TextToTextParams{Model: goopenai.GPT4oMini},
StreamHandler: func(delta, total string, isFirst, isLast bool) error {
if isFirst {
fmt.Println("====Start streaming====")
}

fmt.Print(delta)

if isLast {
fmt.Println("\n====Finish streaming====")
}

return nil
}}).
},
}).
SetPrompt("Write a few sentences about topic").
Execute(context.Background(), agency.NewMessage(agency.UserRole, agency.TextKind, []byte("I love programming.")))

Execute(
context.Background(),
agency.NewMessage(
agency.UserRole,
agency.TextKind,
[]byte("I love programming."),
),
)
if err != nil {
panic(err)
}
Expand Down
11 changes: 9 additions & 2 deletions examples/translate_text/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,16 @@ func main() {
factory := openai.New(openai.Params{Key: os.Getenv("OPENAI_API_KEY")})

result, err := factory.
TextToText(openai.TextToTextParams{Model: goopenai.GPT3Dot5Turbo}).
TextToText(openai.TextToTextParams{Model: goopenai.GPT4oMini}).
SetPrompt("You are a helpful assistant that translates English to French").
Execute(context.Background(), agency.NewMessage(agency.UserRole, agency.TextKind, []byte("I love programming.")))
Execute(
context.Background(),
agency.NewMessage(
agency.UserRole,
agency.TextKind,
[]byte("I love programming."),
),
)

if err != nil {
panic(err)
Expand Down

0 comments on commit 45d6627

Please sign in to comment.