103 lines
2.5 KiB
Go
103 lines
2.5 KiB
Go
package llm
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
)
|
|
|
|
// Gateway provides LLM functionality
|
|
type Gateway interface {
|
|
Generate(ctx context.Context, prompt string, options *GenerateOptions) (*GenerateResponse, error)
|
|
}
|
|
|
|
// GenerateOptions contains options for generation
|
|
type GenerateOptions struct {
|
|
Temperature float64
|
|
MaxTokens int
|
|
Tools []Tool
|
|
TenantID string
|
|
UserID string
|
|
ConversationHistory []Message
|
|
}
|
|
|
|
// Tool represents a callable tool/function
|
|
type Tool struct {
|
|
Name string
|
|
Description string
|
|
Parameters map[string]interface{}
|
|
}
|
|
|
|
// Message represents a conversation message
|
|
type Message struct {
|
|
Role string // "user" or "assistant"
|
|
Content string
|
|
}
|
|
|
|
// GenerateResponse contains the LLM response
|
|
type GenerateResponse struct {
|
|
Text string
|
|
Tools []ToolCall
|
|
Emotion *Emotion
|
|
Gestures []string
|
|
}
|
|
|
|
// ToolCall represents a tool call request
|
|
type ToolCall struct {
|
|
Name string
|
|
Arguments map[string]interface{}
|
|
}
|
|
|
|
// Emotion represents emotional state for avatar
|
|
type Emotion struct {
|
|
Valence float64 // -1.0 to 1.0
|
|
Arousal float64 // 0.0 to 1.0
|
|
}
|
|
|
|
// MockLLMGateway is a mock implementation for development
|
|
type MockLLMGateway struct{}
|
|
|
|
// NewMockLLMGateway creates a new mock LLM gateway
|
|
func NewMockLLMGateway() *MockLLMGateway {
|
|
return &MockLLMGateway{}
|
|
}
|
|
|
|
// Generate generates a response using mock LLM
|
|
func (g *MockLLMGateway) Generate(ctx context.Context, prompt string, options *GenerateOptions) (*GenerateResponse, error) {
|
|
// Mock implementation
|
|
return &GenerateResponse{
|
|
Text: "I understand. How can I assist you with your banking needs today?",
|
|
Emotion: &Emotion{
|
|
Valence: 0.5,
|
|
Arousal: 0.3,
|
|
},
|
|
Gestures: []string{"nod"},
|
|
}, nil
|
|
}
|
|
|
|
// OpenAIGateway integrates with OpenAI (example - requires API key)
|
|
type OpenAIGateway struct {
|
|
apiKey string
|
|
model string
|
|
}
|
|
|
|
// NewOpenAIGateway creates a new OpenAI gateway
|
|
func NewOpenAIGateway(apiKey, model string) *OpenAIGateway {
|
|
return &OpenAIGateway{
|
|
apiKey: apiKey,
|
|
model: model,
|
|
}
|
|
}
|
|
|
|
// Generate generates using OpenAI API
|
|
func (g *OpenAIGateway) Generate(ctx context.Context, prompt string, options *GenerateOptions) (*GenerateResponse, error) {
|
|
// TODO: Implement OpenAI API integration
|
|
// This would involve:
|
|
// 1. Building the prompt with system message, conversation history
|
|
// 2. Adding tool definitions if tools are provided
|
|
// 3. Making API call to OpenAI
|
|
// 4. Parsing response and extracting tool calls
|
|
// 5. Mapping to GenerateResponse format
|
|
return nil, fmt.Errorf("not implemented - requires OpenAI API integration")
|
|
}
|
|
|