From 0cbd599a9a241de071f596135f3884e5e506a385 Mon Sep 17 00:00:00 2001 From: Emil Valeev Date: Fri, 24 Nov 2023 16:08:17 +0600 Subject: [PATCH] refactor: remove 'pipe' words from comments --- README.md | 10 ++-- agency.go | 6 +-- examples/multi_agent/main.go | 71 ---------------------------- examples/rag_vector_database/main.go | 6 +-- messages.go | 1 - process.go | 8 ++-- 6 files changed, 15 insertions(+), 87 deletions(-) delete mode 100644 examples/multi_agent/main.go diff --git a/README.md b/README.md index c00f408..178ee89 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ func main() { panic(err) } - input := agency.NewUserMessage(text) + input := agency.UserMessage(text) answer, err := assistant.SetMessages(messages).Execute(ctx, input) if err != nil { panic(err) @@ -64,7 +64,7 @@ func main() { That's it! -See [examples](./examples/) to find out more complex usecases including RAGs and multimodal pipelines. +See [examples](./examples/) to find out more complex usecases including RAGs and multimodal operations. ## 🚀 Features @@ -72,9 +72,9 @@ See [examples](./examples/) to find out more complex usecases including RAGs and ✨ Write **clean code** and follow **clean architecture** by separating business logic from concrete implementations -✨ Easily create **custom pipes** by implementing simple interface +✨ Easily create **custom operations** by implementing simple interface -✨ **Compose pipes** together into **pipelines** with the ability to observe each step via **interceptors** +✨ **Compose operations** together into **processes** with the ability to observe each step via **interceptors** ✨ **OpenAI API bindings** (can be used for any openai-compatable API: text to text (completion), text to image, text to speech, speech to text @@ -97,6 +97,6 @@ In the next versions: - [ ] Support for external function calls - [ ] Metadata (tokens used, audio duration, etc) - [ ] More provider-adapters, not only openai -- [ ] Image to text pipes +- [ ] Image to text operations - [ ] Powerful API for autonomous agents - [ ] Tagging and JSON output parser diff --git a/agency.go b/agency.go index 5543e00..b13aa03 100644 --- a/agency.go +++ b/agency.go @@ -17,14 +17,14 @@ func (p *Operation) Config() *OperationConfig { return p.config } -// OperationConfig represents abstract pipe configuration. +// OperationConfig represents abstract operation configuration. // It contains fields for all possible modalities but nothing specific to concrete model implementations. type OperationConfig struct { Prompt string Messages []Message } -// NewOperation allows to create Pipe from a function. +// NewOperation allows to create an operation from a function. func NewOperation(handler OperationHandler) *Operation { return &Operation{ handler: handler, @@ -32,7 +32,7 @@ func NewOperation(handler OperationHandler) *Operation { } } -// Execute executes the whole pipeline. +// Execute executes operation handler with input message and current configuration. func (p *Operation) Execute(ctx context.Context, input Message) (Message, error) { output, err := p.handler(ctx, input, p.config) if err != nil { diff --git a/examples/multi_agent/main.go b/examples/multi_agent/main.go deleted file mode 100644 index 327c0e5..0000000 --- a/examples/multi_agent/main.go +++ /dev/null @@ -1,71 +0,0 @@ -package main - -import ( - "bufio" - "context" - "fmt" - "os" - - _ "github.com/joho/godotenv/autoload" - - "github.com/neurocult/agency" - "github.com/neurocult/agency/providers/openai" -) - -// FIXME this example probably does not work because interceptor is executed after and not before the pipe -func main() { - factory := openai. - New(openai.Params{Key: os.Getenv("OPENAI_API_KEY")}) - - poet := factory. - TextToText(openai.TextToTextParams{Model: "gpt-3.5-turbo"}). - SetPrompt("You are a poet, your task is to create poems on a given topic.") - - critic := factory. - TextToText(openai.TextToTextParams{Model: "gpt-3.5-turbo"}). - SetPrompt("You are a literary critic, your task is to criticize poetry.") - - translator := factory. - TextToText(openai.TextToTextParams{Model: "gpt-3.5-turbo"}). - SetPrompt("Translate English to Russian") - - reader := bufio.NewReader(os.Stdin) - - fmt.Print("Enter the word: ") - text, err := reader.ReadString('\n') - if err != nil { - panic(err) - } - fmt.Println("Thank you! Starting the loop...") - - ctx := context.Background() - input := agency.UserMessage(text) - history := []agency.Message{} - pipeLine := agency.NewProcess(poet, critic, translator) - - for i := 0; i < 2; i++ { - fmt.Printf("Iteration running: %d\n", i) - - output, err := pipeLine.Execute(ctx, input, func(in, out agency.Message, cfg *agency.OperationConfig) { - history = append(history, in) - cfg.Messages = history - }) - if err != nil { - panic(err) - } - - input = output - } - - // HACK: on last iteration when we say "input = output" we never append that input to the history - // so we have to do that after the for loop - history = append(history, input) - - // IDEA - // InterceptorParams{ in, out, cfg, pipes, idx } - // knowing len(pipes) and idx we can determine whether the iteration is last and append not only input but also output - - for i, msg := range history { - fmt.Printf("%d: %v\n\n", i, msg) - } -} diff --git a/examples/rag_vector_database/main.go b/examples/rag_vector_database/main.go index a552dec..949d993 100644 --- a/examples/rag_vector_database/main.go +++ b/examples/rag_vector_database/main.go @@ -25,7 +25,7 @@ func main() { } factory := openai.New(openai.Params{Key: openAPIKey}) - retrieve := RAGPipe(client) + retrieve := RAGoperation(client) summarize := factory.TextToText(openai.TextToTextParams{Model: "gpt-3.5-turbo"}).SetPrompt("summarize") voice := factory.TextToSpeech(openai.TextToSpeechParams{ Model: "tts-1", ResponseFormat: "mp3", Speed: 1, Voice: "onyx", @@ -45,8 +45,8 @@ func main() { } } -// RAGPipe retrieves relevant objects from vector store and builds a text message to pass further to the pipeline -func RAGPipe(client *weaviate.Client) *agency.Operation { +// RAGoperation retrieves relevant objects from vector store and builds a text message to pass further to the process +func RAGoperation(client *weaviate.Client) *agency.Operation { return agency.NewOperation(func(ctx context.Context, msg agency.Message, po *agency.OperationConfig) (agency.Message, error) { input := msg.String() diff --git a/messages.go b/messages.go index 390595e..f178aa3 100644 --- a/messages.go +++ b/messages.go @@ -7,7 +7,6 @@ type Message struct { Content []byte } -// TODO check if we need this func (m Message) String() string { return string(m.Content) } diff --git a/process.go b/process.go index 3c7dd11..0ba55ea 100644 --- a/process.go +++ b/process.go @@ -14,18 +14,18 @@ func NewProcess(operations ...*Operation) *Process { } } -// Interceptor is a function that is called after one pipe and before another. +// Interceptor is a function that is called after one operation and before another. type Interceptor func(in Message, out Message, cfg *OperationConfig) func (p *Process) Execute(ctx context.Context, input Message, interceptors ...Interceptor) (Message, error) { - for _, pipe := range p.operations { - output, err := pipe.Execute(ctx, input) + for _, operation := range p.operations { + output, err := operation.Execute(ctx, input) if err != nil { return Message{}, err } for _, interceptor := range interceptors { - interceptor(input, output, pipe.Config()) + interceptor(input, output, operation.Config()) } input = output