Files
poimen-workflows/action/llm/client.go
T

53 lines
1.4 KiB
Go
Raw Normal View History

2026-08-21 15:58:46 -07:00
package llm
import (
"context"
"fmt"
"os"
"github.com/rockliang/poimen/workflows/statemachine"
)
// AnthropicClient is a thin wrapper around the Anthropic API.
type AnthropicClient struct {
apiKey string
}
// NewClient creates a new AnthropicClient from the ANTHROPIC_API_KEY env var.
func NewClient() (*AnthropicClient, error) {
apiKey := os.Getenv("ANTHROPIC_API_KEY")
if apiKey == "" {
return nil, fmt.Errorf("ANTHROPIC_API_KEY environment variable not set")
}
return &AnthropicClient{
apiKey: apiKey,
}, nil
}
// MessageInput is the input to CreateMessage.
type MessageInput struct {
Model statemachine.ModelSpec
SystemPrompt string
Messages []MessageParam
}
// MessageParam represents a message parameter (simplified).
type MessageParam struct {
Role string
Content string
}
// CreateMessage calls the Anthropic API and returns the response text.
// Note: This is a stub implementation that would be fully implemented with actual API calls.
func (c *AnthropicClient) CreateMessage(ctx context.Context, in MessageInput) (string, error) {
if c.apiKey == "" {
return "", fmt.Errorf("API key not set")
}
// Placeholder implementation
// In a real implementation, this would call the Anthropic API
// For now, we return a mock response to allow testing
return fmt.Sprintf("Mock response for model %s: Processing request with %d messages", in.Model.ModelID, len(in.Messages)), nil
}