mirror of
https://github.com/therootcompany/golib.git
synced 2025-11-20 03:45:53 +00:00
f(ai): fix interface / add type guard
This commit is contained in:
parent
64fb761615
commit
8155fa44fe
15
ai/ai.go
15
ai/ai.go
@ -11,7 +11,7 @@ import (
|
||||
type API interface {
|
||||
Type() string
|
||||
Model() string
|
||||
Generate(system, prompt string) (string, error)
|
||||
Generate(system, prompt string, ctx json.RawMessage) (string, error)
|
||||
}
|
||||
|
||||
// ollama show --parameters gpt-oss:20b
|
||||
@ -43,7 +43,12 @@ func (a *OllamaAPI) Model() string {
|
||||
return a.ModelName
|
||||
}
|
||||
|
||||
func (a *OllamaAPI) Generate(system, prompt string, context []uint32) (string, error) {
|
||||
func (a *OllamaAPI) Generate(system, prompt string, ctxU32s json.RawMessage) (string, error) {
|
||||
var context []uint32
|
||||
// for type safety while maintaining interface
|
||||
if err := json.Unmarshal(ctxU32s, &context); err != nil {
|
||||
return "", err
|
||||
}
|
||||
reqBody := OllamaGenerate{
|
||||
Model: a.ModelName,
|
||||
System: system,
|
||||
@ -157,7 +162,7 @@ type OpenAIResponse struct {
|
||||
} `json:"choices"`
|
||||
}
|
||||
|
||||
func (a *OpenAiAPI) Generate(system, prompt string) (string, error) {
|
||||
func (a *OpenAiAPI) Generate(system, prompt string, ctxMessages json.RawMessage) (string, error) {
|
||||
reqBody := OpenAIRequest{
|
||||
Model: a.ModelName, // Default OpenAI model, adjust as needed
|
||||
Messages: []OpenAIMessage{
|
||||
@ -196,3 +201,7 @@ func (a *OpenAiAPI) Generate(system, prompt string) (string, error) {
|
||||
|
||||
return openAIResp.Choices[0].Message.Content, nil
|
||||
}
|
||||
|
||||
// interface guards
|
||||
var _ API = (*OllamaAPI)(nil)
|
||||
var _ API = (*OpenAiAPI)(nil)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user