2bbf42b741
Remove Agent Desk users, roles, login sessions, tokens, and local permission persistence. Expose the backend as an embeddable ai-agent module with host-provided subject lookup and operation authorization callbacks, and complete the frontend/backend repository split.
38 lines
1.0 KiB
Go
38 lines
1.0 KiB
Go
package ai
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/mlogclub/simple/sqls"
|
|
openai "github.com/openai/openai-go/v3"
|
|
"github.com/openai/openai-go/v3/option"
|
|
|
|
"code.tczkiot.com/wlw/ai-agent/internal/models"
|
|
"code.tczkiot.com/wlw/ai-agent/internal/pkg/enums"
|
|
"code.tczkiot.com/wlw/ai-agent/internal/pkg/errorsx"
|
|
"code.tczkiot.com/wlw/ai-agent/internal/repositories"
|
|
)
|
|
|
|
func newOpenAIClient(config models.AIConfig) openai.Client {
|
|
opts := []option.RequestOption{
|
|
option.WithAPIKey(config.APIKey),
|
|
option.WithBaseURL(config.BaseURL),
|
|
}
|
|
if config.TimeoutMS > 0 {
|
|
opts = append(opts, option.WithRequestTimeout(time.Duration(config.TimeoutMS)*time.Millisecond))
|
|
}
|
|
if config.MaxRetryCount >= 0 {
|
|
opts = append(opts, option.WithMaxRetries(config.MaxRetryCount))
|
|
}
|
|
|
|
return openai.NewClient(opts...)
|
|
}
|
|
|
|
func GetEnabledAIConfig(modelType enums.AIModelType) (*models.AIConfig, error) {
|
|
item := repositories.AIConfigRepository.GetEnabled(sqls.DB(), modelType)
|
|
if item == nil {
|
|
return nil, errorsx.BusinessErrorI18n(2005, "error.aiConfig.noneEnabled")
|
|
}
|
|
return item, nil
|
|
}
|