Skip to content

Commit

Permalink
refactor: remove 'pipe' words from comments
Browse files Browse the repository at this point in the history
  • Loading branch information
emil14 committed Nov 24, 2023
1 parent f1d842f commit 0cbd599
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 87 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -64,17 +64,17 @@ 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

**Pure Go**: fast and lightweight, statically typed, no need to mess with Python or JavaScript

✨ 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

Expand All @@ -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
6 changes: 3 additions & 3 deletions agency.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@ 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,
config: &OperationConfig{},
}
}

// 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 {
Expand Down
71 changes: 0 additions & 71 deletions examples/multi_agent/main.go

This file was deleted.

6 changes: 3 additions & 3 deletions examples/rag_vector_database/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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()

Expand Down
1 change: 0 additions & 1 deletion messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ type Message struct {
Content []byte
}

// TODO check if we need this
func (m Message) String() string {
return string(m.Content)
}
Expand Down
8 changes: 4 additions & 4 deletions process.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0cbd599

Please sign in to comment.