yao/agent/output/adapters/openai/factory.go
Max 91aa109f5b Add streaming support and message handling in DefaultStreamHandler
- Implemented a state management system for handling different streaming chunk types, including stream start, group start, text, thinking, tool calls, metadata, errors, and stream end.
- Introduced a new Send method in the context to facilitate message sending to the client.
- Enhanced the output package with message sending capabilities, including support for message groups and flushing.
- Improved error handling and message ID generation for better streaming reliability and user feedback.
2025-11-15 17:40:03 +08:00

28 lines
679 B
Go

package openai
import (
"github.com/yaoapp/yao/agent/context"
"github.com/yaoapp/yao/agent/output/message"
)
// Factory is the factory for creating OpenAI writers and adapters
type Factory struct {
options []Option
}
// NewFactory creates a new OpenAI factory with options
func NewFactory(options ...Option) *Factory {
return &Factory{
options: options,
}
}
// CreateWriter creates an OpenAI writer
func (f *Factory) CreateWriter(ctx *context.Context) (message.Writer, error) {
return NewWriter(ctx)
}
// CreateAdapter creates an OpenAI adapter
func (f *Factory) CreateAdapter(ctx *context.Context) (message.Adapter, error) {
return NewAdapter(f.options...), nil
}