Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add parameter for image description; Refactor library core #13

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func main() {
MaxTokens: *maxTokens,
}).
SetPrompt(*prompt).
Execute(context.Background(), agency.NewMessage(agency.UserRole, agency.TextKind, []byte(content)))
Execute(context.Background(), agency.NewTextMessage(agency.UserRole, content))

if err != nil {
fmt.Println(err)
Expand Down
8 changes: 2 additions & 6 deletions examples/custom_operation/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@ func main() {
increment,
).Execute(
context.Background(),
agency.NewMessage(
agency.UserRole,
agency.TextKind,
[]byte("0"),
),
agency.NewTextMessage(agency.UserRole, "0"),
)
if err != nil {
panic(err)
Expand All @@ -36,5 +32,5 @@ func incrementFunc(ctx context.Context, msg agency.Message, _ *agency.OperationC
return nil, err
}
inc := strconv.Itoa(int(i) + 1)
return agency.NewMessage(agency.ToolRole, agency.TextKind, []byte(inc)), nil
return agency.NewTextMessage(agency.ToolRole, inc), nil
}
6 changes: 3 additions & 3 deletions examples/func_call/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Examples:
// test for first function call
answer, err := t2tOp.Execute(
ctx,
agency.NewMessage(agency.UserRole, agency.TextKind, []byte("what is the meaning of life?")),
agency.NewTextMessage(agency.UserRole, "what is the meaning of life?"),
)
if err != nil {
panic(err)
Expand All @@ -79,7 +79,7 @@ Examples:
// test for second function call
answer, err = t2tOp.Execute(
ctx,
agency.NewMessage(agency.UserRole, agency.TextKind, []byte("1+1?")),
agency.NewTextMessage(agency.UserRole, "1+1?"),
)
if err != nil {
panic(err)
Expand All @@ -89,7 +89,7 @@ Examples:
// test for both function calls at the same time
answer, err = t2tOp.Execute(
ctx,
agency.NewMessage(agency.UserRole, agency.TextKind, []byte("1+1 and what is the meaning of life?")),
agency.NewTextMessage(agency.UserRole, "1+1 and what is the meaning of life?"),
)
if err != nil {
panic(err)
Expand Down
2 changes: 1 addition & 1 deletion examples/image_to_stream/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func main() {
SetPrompt("describe what you see").
Execute(
context.Background(),
agency.NewMessage(agency.UserRole, agency.ImageKind, imgBytes),
agency.NewImageMessage(agency.UserRole, imgBytes, ""),
)
if err != nil {
panic(err)
Expand Down
5 changes: 3 additions & 2 deletions examples/image_to_text/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/sashabaranov/go-openai"
)

func main() {
func main() {
imgBytes, err := os.ReadFile("example.png")
if err != nil {
panic(err)
Expand All @@ -22,7 +22,8 @@ func main() {
SetPrompt("describe what you see").
Execute(
context.Background(),
agency.NewMessage(agency.UserRole, agency.ImageKind, imgBytes),
// FIXME description not implemented properly and lead to 400 error
agency.NewImageMessage(agency.UserRole, imgBytes, "example.png"),
)
if err != nil {
panic(err)
Expand Down
41 changes: 41 additions & 0 deletions examples/json_message/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package main

import (
"context"
"fmt"
"os"

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

"github.com/neurocult/agency"
"github.com/neurocult/agency/providers/openai"
)

type UserStruct struct {
Age int `json:"age"`
Name string `json:"name"`
City string `json:"city"`
}

func main() {
op := openai.
New(openai.Params{Key: os.Getenv("OPENAI_API_KEY")}).
TextToText(openai.TextToTextParams{Model: go_openai.GPT4oMini}).
SetPrompt("You are a poet that writes poetry about the user's data")

userMsg, err := agency.NewJSONTextMessage(
agency.UserRole,
UserStruct{Name: "John", Age: 30, City: "New York"},
)
if err != nil {
panic(err)
}

result, err := op.Execute(context.Background(), userMsg)
if err != nil {
panic(err)
}

fmt.Println(string(result.Content()))
}
2 changes: 1 addition & 1 deletion examples/logging/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func main() {
).
Execute(
context.Background(),
agency.NewMessage(agency.UserRole, agency.TextKind, []byte("Kazakhstan alga!")),
agency.NewTextMessage(agency.UserRole, "Kazakhstan alga!"),
Logger,
)

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 @@ -22,7 +22,7 @@ func main() {
).
Execute(
context.Background(),
agency.NewMessage(agency.UserRole, agency.TextKind, []byte("I love programming.")),
agency.NewTextMessage(agency.UserRole, "I love programming."),
)

if err != nil {
Expand Down
13 changes: 6 additions & 7 deletions examples/rag_vector_database/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func main() {
retrieve,
summarize,
voice,
).Execute(ctx, agency.NewMessage(agency.UserRole, agency.TextKind, []byte("programming")))
).Execute(ctx, agency.NewTextMessage(agency.UserRole, "programming"))
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -76,10 +76,9 @@ func RAGoperation(client *weaviate.Client) *agency.Operation {
content += string(bb)
}

return agency.NewMessage(
return agency.NewTextMessage(
agency.AssistantRole,
agency.TextKind,
[]byte(content),
content,
), nil
})
}
Expand All @@ -103,9 +102,9 @@ func prepareDB(openAPIKey string, ctx context.Context) (*weaviate.Client, error)
classObj := &models.Class{
Class: "Records",
Vectorizer: "text2vec-openai",
ModuleConfig: map[string]interface{}{
"text2vec-openai": map[string]interface{}{},
"generative-openai": map[string]interface{}{},
ModuleConfig: map[string]any{
"text2vec-openai": map[string]any{},
"generative-openai": map[string]any{},
},
}
if err = client.Schema().ClassCreator().WithClass(classObj).Do(context.Background()); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion examples/speech_to_text/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func main() {
Model: goopenai.Whisper1,
}).Execute(
context.Background(),
agency.NewMessage(agency.UserRole, agency.VoiceKind, data),
agency.NewVoiceMessage(agency.UserRole, data),
)

if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion examples/speech_to_text_multi_model/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func main() {
}

ctx := context.Background()
speechMsg := agency.NewMessage(agency.UserRole, agency.VoiceKind, sound)
speechMsg := agency.NewVoiceMessage(agency.UserRole, sound)

_, err = agency.NewProcess(
hear,
Expand Down
2 changes: 1 addition & 1 deletion examples/speech_to_text_to_image/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func main() {
Model: goopenai.CreateImageModelDallE2,
ImageSize: goopenai.CreateImageSize256x256,
}),
).Execute(context.Background(), agency.NewMessage(agency.UserRole, agency.VoiceKind, data))
).Execute(context.Background(), agency.NewVoiceMessage(agency.UserRole, data))
if err != nil {
panic(err)
}
Expand Down
2 changes: 1 addition & 1 deletion examples/text_to_image_dalle2/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func main() {
Style: "vivid",
}).Execute(
context.Background(),
agency.NewMessage(agency.UserRole, agency.TextKind, []byte("Halloween night at a haunted museum")),
agency.NewTextMessage(agency.UserRole, "Halloween night at a haunted museum"),
)
if err != nil {
panic(err)
Expand Down
10 changes: 5 additions & 5 deletions examples/text_to_speech/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import (
)

func main() {
input := agency.NewMessage(
input := agency.NewTextMessage(
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.`))
`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
6 changes: 1 addition & 5 deletions examples/text_to_stream/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,7 @@ func main() {
SetPrompt("Write a few sentences about topic").
Execute(
context.Background(),
agency.NewMessage(
agency.UserRole,
agency.TextKind,
[]byte("I love programming."),
),
agency.NewTextMessage(agency.UserRole, "I love programming."),
)
if err != nil {
panic(err)
Expand Down
10 changes: 3 additions & 7 deletions examples/translate_text/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"os"

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

"github.com/neurocult/agency"
"github.com/neurocult/agency/providers/openai"
Expand All @@ -16,15 +16,11 @@ func main() {
factory := openai.New(openai.Params{Key: os.Getenv("OPENAI_API_KEY")})

result, err := factory.
TextToText(openai.TextToTextParams{Model: goopenai.GPT4oMini}).
TextToText(openai.TextToTextParams{Model: go_openai.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."),
),
agency.NewTextMessage(agency.UserRole, "I love programming."),
)

if err != nil {
Expand Down
Loading