refactoring

This commit is contained in:
mudler
2024-01-21 11:09:47 +01:00
parent d22154e9be
commit 3790a872ea
6 changed files with 89 additions and 18 deletions

View File

@@ -1,18 +1,23 @@
package agent
import (
"fmt"
"github.com/mudler/local-agent-framework/llm"
"github.com/sashabaranov/go-openai"
)
type llmOptions struct {
APIURL string
APIKey string
Model string
}
type options struct {
LLMAPI llmOptions
Character Character
LLMAPI llmOptions
character Character
randomIdentityGuidance string
randomIdentity bool
}
type Agent struct {
@@ -29,7 +34,7 @@ func defaultOptions() *options {
APIURL: "http://localhost:8080",
Model: "echidna",
},
Character: Character{
character: Character{
Name: "John Doe",
Age: 0,
Occupation: "Unemployed",
@@ -59,13 +64,18 @@ func New(opts ...Option) (*Agent, error) {
return nil, err
}
client := llm.NewClient("", options.LLMAPI.APIURL)
client := llm.NewClient(options.LLMAPI.APIKey, options.LLMAPI.APIURL)
a := &Agent{
options: options,
client: client,
Character: options.Character,
Character: options.character,
}
return a, nil
if a.options.randomIdentity {
err = a.generateIdentity("")
}
return a, err
}
func WithLLMAPIURL(url string) Option {
@@ -75,6 +85,13 @@ func WithLLMAPIURL(url string) Option {
}
}
func WithLLMAPIKey(key string) Option {
return func(o *options) error {
o.LLMAPI.APIKey = key
return nil
}
}
func WithModel(model string) Option {
return func(o *options) error {
o.LLMAPI.Model = model
@@ -84,7 +101,7 @@ func WithModel(model string) Option {
func WithCharacter(c Character) Option {
return func(o *options) error {
o.Character = c
o.character = c
return nil
}
}
@@ -95,7 +112,15 @@ func FromFile(path string) Option {
if err != nil {
return err
}
o.Character = *c
o.character = *c
return nil
}
}
func WithRandomIdentity(guidance ...string) Option {
return func(o *options) error {
o.randomIdentityGuidance = fmt.Sprint(guidance)
o.randomIdentity = true
return nil
}
}