mirror of
https://github.com/APIParkLab/APIPark.git
synced 2026-06-04 10:13:53 +08:00
update api: simple local models
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
package ai
|
||||
package ai_provider_local
|
||||
|
||||
var (
|
||||
ollamaSvg = `<?xml version="1.0" standalone="no"?>
|
||||
OllamaBase = "http://apipark-ollama:11434"
|
||||
OllamaConfig = "{\n \"mirostat\": 0,\n \"mirostat_eta\": 0.1,\n \"mirostat_tau\": 5.0,\n \"num_ctx\": 4096,\n \"repeat_last_n\":64,\n \"repeat_penalty\": 1.1,\n \"temperature\": 0.7,\n \"seed\": 42,\n \"num_predict\": 42,\n \"top_k\": 40,\n \"top_p\": 0.9,\n \"min_p\": 0.5\n}\n"
|
||||
OllamaSvg = `<?xml version="1.0" standalone="no"?>
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
|
||||
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
|
||||
<svg version="1.0" xmlns="http://www.w3.org/2000/svg"
|
||||
@@ -37,10 +37,6 @@ import (
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
var (
|
||||
ollamaConfig = "{\n \"mirostat\": 0,\n \"mirostat_eta\": 0.1,\n \"mirostat_tau\": 5.0,\n \"num_ctx\": 4096,\n \"repeat_last_n\":64,\n \"repeat_penalty\": 1.1,\n \"temperature\": 0.7,\n \"seed\": 42,\n \"num_predict\": 42,\n \"top_k\": 40,\n \"top_p\": 0.9,\n \"min_p\": 0.5\n}\n"
|
||||
)
|
||||
|
||||
var _ ILocalModelController = &imlLocalModelController{}
|
||||
|
||||
type imlLocalModelController struct {
|
||||
@@ -231,7 +227,7 @@ func (i *imlLocalModelController) initAILocalService(ctx context.Context, model
|
||||
}
|
||||
aiModel := &ai_api_dto.AiModel{
|
||||
Id: model,
|
||||
Config: ollamaConfig,
|
||||
Config: ai_provider_local.OllamaConfig,
|
||||
Provider: providerId,
|
||||
Type: "local",
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
ai_provider_local "github.com/APIParkLab/APIPark/ai-provider/local"
|
||||
|
||||
subscribe_dto "github.com/APIParkLab/APIPark/module/subscribe/dto"
|
||||
|
||||
"github.com/APIParkLab/APIPark/module/subscribe"
|
||||
@@ -55,9 +57,9 @@ import (
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
var (
|
||||
ollamaConfig = "{\n \"mirostat\": 0,\n \"mirostat_eta\": 0.1,\n \"mirostat_tau\": 5.0,\n \"num_ctx\": 4096,\n \"repeat_last_n\":64,\n \"repeat_penalty\": 1.1,\n \"temperature\": 0.7,\n \"seed\": 42,\n \"num_predict\": 42,\n \"top_k\": 40,\n \"top_p\": 0.9,\n \"min_p\": 0.5\n}\n"
|
||||
)
|
||||
//var (
|
||||
// ollamaConfig = "{\n \"mirostat\": 0,\n \"mirostat_eta\": 0.1,\n \"mirostat_tau\": 5.0,\n \"num_ctx\": 4096,\n \"repeat_last_n\":64,\n \"repeat_penalty\": 1.1,\n \"temperature\": 0.7,\n \"seed\": 42,\n \"num_predict\": 42,\n \"top_k\": 40,\n \"top_p\": 0.9,\n \"min_p\": 0.5\n}\n"
|
||||
//)
|
||||
|
||||
var (
|
||||
_ IServiceController = (*imlServiceController)(nil)
|
||||
@@ -343,7 +345,7 @@ func (i *imlServiceController) createAIService(ctx *gin.Context, teamID string,
|
||||
return nil, fmt.Errorf("no local model")
|
||||
}
|
||||
modelId = list[0].Id
|
||||
modelCfg = ollamaConfig
|
||||
modelCfg = ai_provider_local.OllamaConfig
|
||||
} else {
|
||||
pv, err := i.providerModule.Provider(ctx, *input.Provider)
|
||||
if err != nil {
|
||||
|
||||
@@ -6,6 +6,8 @@ import (
|
||||
"fmt"
|
||||
"sort"
|
||||
|
||||
ai_provider_local "github.com/APIParkLab/APIPark/ai-provider/local"
|
||||
|
||||
model_runtime "github.com/APIParkLab/APIPark/ai-provider/model-runtime"
|
||||
|
||||
"gorm.io/gorm"
|
||||
@@ -93,18 +95,18 @@ func (i *imlBalanceModule) Create(ctx context.Context, input *ai_balance_dto.Cre
|
||||
|
||||
}
|
||||
|
||||
var (
|
||||
ollamaConfig = "{\n \"mirostat\": 0,\n \"mirostat_eta\": 0.1,\n \"mirostat_tau\": 5.0,\n \"num_ctx\": 4096,\n \"repeat_last_n\":64,\n \"repeat_penalty\": 1.1,\n \"temperature\": 0.7,\n \"seed\": 42,\n \"num_predict\": 42,\n \"top_k\": 40,\n \"top_p\": 0.9,\n \"min_p\": 0.5\n}\n"
|
||||
ollamaBase = "http://apipark-ollama:11434"
|
||||
)
|
||||
//var (
|
||||
// ollamaConfig = "{\n \"mirostat\": 0,\n \"mirostat_eta\": 0.1,\n \"mirostat_tau\": 5.0,\n \"num_ctx\": 4096,\n \"repeat_last_n\":64,\n \"repeat_penalty\": 1.1,\n \"temperature\": 0.7,\n \"seed\": 42,\n \"num_predict\": 42,\n \"top_k\": 40,\n \"top_p\": 0.9,\n \"min_p\": 0.5\n}\n"
|
||||
// ollamaBase = "http://apipark-ollama:11434"
|
||||
//)
|
||||
|
||||
func newRelease(item *ai_balance.Balance) *gateway.DynamicRelease {
|
||||
|
||||
cfg := make(map[string]interface{})
|
||||
cfg["provider"] = item.Id
|
||||
cfg["model"] = item.Model
|
||||
cfg["model_config"] = ollamaConfig
|
||||
cfg["base"] = ollamaBase
|
||||
cfg["model_config"] = ai_provider_local.OllamaConfig
|
||||
cfg["base"] = ai_provider_local.OllamaBase
|
||||
return &gateway.DynamicRelease{
|
||||
BasicItem: &gateway.BasicItem{
|
||||
ID: item.Id,
|
||||
|
||||
@@ -62,6 +62,7 @@ type SimpleItem struct {
|
||||
Id string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
DefaultConfig string `json:"default_config"`
|
||||
Logo string `json:"logo"`
|
||||
}
|
||||
|
||||
type LocalModelItem struct {
|
||||
|
||||
@@ -54,8 +54,8 @@ type imlLocalModel struct {
|
||||
}
|
||||
|
||||
var (
|
||||
ollamaConfig = "{\n \"mirostat\": 0,\n \"mirostat_eta\": 0.1,\n \"mirostat_tau\": 5.0,\n \"num_ctx\": 4096,\n \"repeat_last_n\":64,\n \"repeat_penalty\": 1.1,\n \"temperature\": 0.7,\n \"seed\": 42,\n \"num_predict\": 42,\n \"top_k\": 40,\n \"top_p\": 0.9,\n \"min_p\": 0.5\n}\n"
|
||||
ollamaBase = "http://apipark-ollama:11434"
|
||||
// ollamaConfig = "{\n \"mirostat\": 0,\n \"mirostat_eta\": 0.1,\n \"mirostat_tau\": 5.0,\n \"num_ctx\": 4096,\n \"repeat_last_n\":64,\n \"repeat_penalty\": 1.1,\n \"temperature\": 0.7,\n \"seed\": 42,\n \"num_predict\": 42,\n \"top_k\": 40,\n \"top_p\": 0.9,\n \"min_p\": 0.5\n}\n"
|
||||
ollamaBase = "http://apipark-ollama:11434"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -79,7 +79,8 @@ func (i *imlLocalModel) SimpleList(ctx context.Context) ([]*ai_local_dto.SimpleI
|
||||
return &ai_local_dto.SimpleItem{
|
||||
Id: s.Id,
|
||||
Name: s.Name,
|
||||
DefaultConfig: ollamaConfig,
|
||||
DefaultConfig: ai_provider_local.OllamaConfig,
|
||||
Logo: ai_provider_local.OllamaSvg,
|
||||
}
|
||||
}, func(l *ai_local.LocalModel) bool {
|
||||
if l.State != ai_local_dto.LocalModelStateNormal.Int() && l.State != ai_local_dto.LocalModelStateDisable.Int() {
|
||||
@@ -234,7 +235,7 @@ func (i *imlLocalModel) pullHook() func(msg ai_provider_local.PullMessage) error
|
||||
cfg := make(map[string]interface{})
|
||||
cfg["provider"] = "ollama"
|
||||
cfg["model"] = msg.Model
|
||||
cfg["model_config"] = ollamaConfig
|
||||
cfg["model_config"] = ai_provider_local.OllamaConfig
|
||||
cfg["priority"] = 0
|
||||
cfg["base"] = ollamaBase
|
||||
|
||||
@@ -488,7 +489,7 @@ func (i *imlLocalModel) getLocalModels(ctx context.Context) ([]*gateway.DynamicR
|
||||
cfg := make(map[string]interface{})
|
||||
cfg["provider"] = "ollama"
|
||||
cfg["model"] = l.Id
|
||||
cfg["model_config"] = ollamaConfig
|
||||
cfg["model_config"] = ai_provider_local.OllamaSvg
|
||||
cfg["base"] = ollamaBase
|
||||
releases = append(releases, &gateway.DynamicRelease{
|
||||
BasicItem: &gateway.BasicItem{
|
||||
|
||||
+3
-1
@@ -8,6 +8,8 @@ import (
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
ai_provider_local "github.com/APIParkLab/APIPark/ai-provider/local"
|
||||
|
||||
"github.com/eolinker/go-common/register"
|
||||
"github.com/eolinker/go-common/server"
|
||||
|
||||
@@ -243,7 +245,7 @@ func (i *imlProviderModule) SimpleConfiguredProviders(ctx context.Context, all b
|
||||
items = append(items, &ai_dto.SimpleProviderItem{
|
||||
Id: "ollama",
|
||||
Name: "Ollama",
|
||||
Logo: ollamaSvg,
|
||||
Logo: ai_provider_local.OllamaSvg,
|
||||
Configured: true,
|
||||
DefaultConfig: "",
|
||||
Status: ai_dto.ProviderEnabled,
|
||||
|
||||
Reference in New Issue
Block a user