Files
Memoh/internal/chat/openai.go
T
2026-01-26 23:06:54 +08:00

55 lines
1.3 KiB
Go

package chat
import (
"context"
"fmt"
"strings"
"time"
"github.com/firebase/genkit/go/genkit"
)
// OpenAIProvider wraps Genkit's OpenAI provider
type OpenAIProvider struct {
g *genkit.Genkit
apiKey string
baseURL string
timeout time.Duration
}
func NewOpenAIProvider(apiKey, baseURL string, timeout time.Duration) (*OpenAIProvider, error) {
if baseURL == "" {
baseURL = "https://api.openai.com/v1"
}
baseURL = strings.TrimRight(baseURL, "/")
if timeout <= 0 {
timeout = 30 * time.Second
}
// For now, we'll create a simple HTTP client-based implementation
// since Genkit Go plugins require initialization at startup
return &OpenAIProvider{
apiKey: apiKey,
baseURL: baseURL,
timeout: timeout,
}, nil
}
func (p *OpenAIProvider) Chat(ctx context.Context, req Request) (Result, error) {
// Use direct HTTP API call since Genkit plugins need to be initialized at startup
return Result{}, fmt.Errorf("openai provider not yet implemented - please use openai-compat provider")
}
func (p *OpenAIProvider) StreamChat(ctx context.Context, req Request) (<-chan StreamChunk, <-chan error) {
chunkChan := make(chan StreamChunk, 10)
errChan := make(chan error, 1)
go func() {
defer close(chunkChan)
defer close(errChan)
errChan <- fmt.Errorf("openai streaming not yet implemented")
}()
return chunkChan, errChan
}