Local model compatibility testing completed

This commit is contained in:
Liujian
2025-03-11 19:44:55 +08:00
parent 9fc48341f7
commit a9d5585ef9
18 changed files with 147 additions and 180 deletions
+11 -1
View File
@@ -9,9 +9,10 @@ import (
var (
client *api.Client
ProviderLocal = "LocalModel"
)
func ResetOllamaAddress(address string) error {
func ResetLocalAddress(address string) error {
u, err := url.Parse(address)
if err != nil {
return err
@@ -19,3 +20,12 @@ func ResetOllamaAddress(address string) error {
client = api.NewClient(u, http.DefaultClient)
return nil
}
var (
LocalConfig = "{\n \"temperature\": \"\",\n \"top_p\": \"\",\n \"max_tokens\": \"\"\n}"
LocalSvg = `<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="50" height="50" viewBox="0 0 50 50">
<image id="椭圆_1_拷贝" data-name="椭圆 1 拷贝" x="5" y="4" width="42" height="38" xlink:href="data:img/png;base64,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"/>
</svg>
`
)
-102
View File
@@ -1,102 +0,0 @@
package ai_provider_local
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"
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"
width="4096.000000pt" height="4096.000000pt" viewBox="0 0 4096.000000 4096.000000"
preserveAspectRatio="xMidYMid meet">
<g transform="translate(0.000000,4096.000000) scale(0.100000,-0.100000)"
fill="#000000" stroke="none">
<path d="M13179 36749 c-194 -28 -496 -139 -712 -260 -834 -469 -1516 -1636
-1861 -3184 -82 -368 -134 -683 -181 -1100 -155 -1374 -116 -2661 120 -4025
19 -107 36 -222 37 -254 l3 -59 -85 -70 c-507 -412 -773 -667 -1123 -1076
-593 -691 -1055 -1493 -1378 -2390 -158 -436 -305 -1018 -369 -1458 -50 -343
-76 -868 -67 -1348 8 -424 25 -600 93 -1004 160 -947 479 -1747 1023 -2559 67
-101 125 -190 128 -198 3 -8 -20 -57 -52 -110 -361 -605 -691 -1540 -840
-2379 -130 -732 -145 -929 -145 -1930 0 -984 14 -1180 131 -1840 145 -815 441
-1680 760 -2221 72 -122 221 -353 275 -427 61 -84 66 -60 -98 -442 -319 -737
-582 -1679 -708 -2530 -76 -520 -92 -755 -88 -1295 l3 -385 170 -128 c368
-277 840 -604 1260 -872 192 -123 754 -464 823 -499 l33 -17 -30 53 c-143 256
-255 663 -312 1134 -27 227 -37 770 -20 1045 55 860 262 1792 567 2546 95 235
188 434 390 830 l194 382 0 238 c0 131 -5 258 -11 282 -15 68 -97 227 -159
310 -32 42 -117 137 -189 211 -327 336 -485 590 -670 1079 -420 1109 -532
2591 -300 3966 165 982 482 1778 902 2267 179 210 274 395 307 601 16 98 8
331 -14 411 -56 201 -125 309 -385 603 -625 705 -989 1568 -1097 2598 -22 211
-26 749 -6 960 103 1110 491 2126 1144 3000 768 1028 1809 1699 2963 1909 189
35 330 46 581 46 248 0 407 -12 634 -46 272 -41 483 -32 634 28 153 60 312
167 389 261 64 79 141 208 197 333 168 375 252 512 529 859 231 289 523 574
816 795 633 477 1341 822 2052 999 403 100 458 106 1043 106 513 0 557 -3 780
-46 928 -181 1875 -656 2640 -1325 171 -149 358 -355 570 -629 218 -280 285
-390 419 -687 170 -378 274 -502 526 -623 235 -113 391 -125 815 -61 337 51
628 58 915 21 968 -122 1847 -558 2609 -1295 886 -858 1491 -2062 1670 -3323
44 -307 51 -416 51 -782 0 -268 -5 -389 -18 -515 -76 -697 -281 -1344 -601
-1898 -170 -295 -327 -507 -576 -777 -258 -280 -368 -570 -331 -875 27 -220
129 -428 317 -645 164 -190 270 -354 398 -615 337 -685 559 -1640 617 -2653
15 -266 7 -870 -16 -1102 -81 -859 -254 -1586 -510 -2146 -150 -330 -269 -500
-556 -799 -76 -80 -164 -178 -194 -219 -61 -80 -138 -232 -154 -302 -6 -24
-11 -150 -11 -280 l0 -235 223 -445 c364 -724 509 -1097 672 -1734 121 -470
193 -879 241 -1365 22 -222 30 -814 15 -1036 -36 -514 -138 -960 -296 -1291
-30 -62 -50 -113 -46 -113 13 0 622 368 836 505 404 258 925 620 1280 887
l150 113 3 355 c6 699 -34 1099 -188 1872 -154 772 -365 1445 -654 2091 -35
78 -72 168 -82 200 -16 52 -17 61 -4 82 8 12 66 98 128 191 471 700 784 1566
971 2689 95 572 105 768 98 1845 -6 789 -9 860 -52 1171 -103 737 -234 1310
-420 1834 -125 354 -338 813 -549 1186 l-20 37 146 218 c319 479 532 894 714
1396 185 509 320 1129 376 1728 16 179 16 1003 0 1250 -43 628 -153 1174 -366
1815 -387 1165 -1000 2160 -1862 3020 -201 200 -331 317 -585 523 -103 83
-189 158 -192 167 -9 21 5 122 52 389 197 1106 247 2336 145 3551 -163 1958
-769 3565 -1637 4343 -144 130 -205 177 -344 269 -393 260 -825 367 -1298 323
-1300 -123 -2362 -1541 -2860 -3819 -98 -448 -201 -1110 -224 -1434 -5 -71
-14 -134 -20 -140 -14 -14 -51 4 -269 130 -1321 760 -2750 1079 -4137 922
-939 -106 -1883 -422 -2736 -917 -197 -114 -258 -145 -274 -138 -15 5 -19 29
-35 236 -23 291 -128 947 -215 1341 -211 957 -522 1775 -912 2399 -176 283
-323 469 -543 691 -228 230 -396 360 -642 497 -114 63 -325 151 -422 176 -194
51 -651 81 -827 55z m377 -1961 c67 -44 217 -198 286 -294 211 -295 383 -645
554 -1123 189 -529 357 -1317 424 -1988 39 -394 59 -905 60 -1498 l0 -290
-170 -251 -169 -251 -383 -6 c-600 -9 -872 -46 -1466 -197 -130 -33 -246 -60
-258 -60 -33 0 -41 21 -63 176 -72 505 -105 1010 -105 1634 0 690 42 1222 139
1793 185 1089 584 2047 976 2341 75 56 106 59 175 14z m14019 -13 c244 -174
522 -666 720 -1275 338 -1039 471 -2402 369 -3780 -26 -359 -83 -831 -105
-871 -5 -11 -19 -19 -31 -19 -12 0 -136 29 -277 64 -596 150 -851 184 -1454
193 l-378 6 -170 251 -170 251 6 535 c9 882 40 1296 141 1890 154 902 418
1698 748 2251 180 302 409 549 509 549 19 0 52 -16 92 -45z"/>
<path d="M20150 22433 c-389 -29 -834 -89 -1069 -144 -413 -97 -967 -296
-1322 -474 -1280 -645 -2169 -1692 -2469 -2910 -74 -300 -75 -307 -75 -820 0
-487 2 -515 51 -735 99 -440 295 -889 550 -1256 341 -492 803 -911 1349 -1225
621 -356 1384 -585 2131 -641 238 -18 2130 -18 2368 0 1169 87 2281 576 3042
1336 374 374 627 760 829 1261 61 152 91 248 139 441 69 281 71 309 71 819 0
513 -1 520 -75 822 -182 739 -580 1413 -1176 1993 -406 395 -826 686 -1368
950 -661 322 -1372 512 -2091 560 -317 21 -762 32 -885 23z m836 -1333 c270
-25 670 -109 961 -201 379 -121 793 -317 1099 -522 344 -229 767 -645 979
-962 192 -287 321 -603 394 -970 66 -325 57 -531 -35 -900 -90 -355 -301 -716
-603 -1028 -256 -264 -501 -434 -906 -627 -447 -213 -794 -305 -1335 -352
-208 -18 -1977 -18 -2180 0 -543 49 -1161 251 -1615 527 -255 155 -563 423
-743 647 -257 319 -394 631 -478 1088 -24 132 -26 161 -21 315 7 250 61 509
163 782 130 352 389 722 755 1078 297 289 572 480 974 674 558 270 1171 433
1740 461 192 10 700 4 851 -10z"/>
<path d="M19620 19334 c-30 -8 -73 -26 -95 -39 -62 -36 -166 -152 -202 -225
-89 -178 -81 -322 28 -508 56 -93 217 -247 354 -336 66 -43 137 -90 158 -104
59 -39 72 -72 70 -177 -1 -49 -11 -142 -22 -205 -75 -411 -74 -408 -56 -476
35 -131 161 -296 262 -345 41 -20 72 -24 252 -33 254 -12 330 -3 432 50 89 47
169 132 199 210 46 123 43 299 -10 561 -33 165 -39 284 -16 336 18 42 66 86
151 137 107 65 204 141 294 231 141 142 198 248 208 394 7 99 -6 164 -54 262
-59 122 -193 236 -315 269 -73 19 -286 19 -363 -1 -80 -21 -201 -79 -328 -159
-58 -36 -110 -66 -117 -66 -6 0 -60 29 -120 65 -151 89 -260 143 -327 160 -76
20 -308 19 -383 -1z"/>
<path d="M13766 22188 c-238 -24 -521 -166 -723 -361 -254 -246 -405 -551
-458 -927 -19 -140 -19 -328 0 -418 67 -322 293 -638 578 -812 150 -91 358
-151 582 -170 381 -31 677 88 965 386 156 162 237 282 330 491 116 261 130
333 130 674 l0 227 -69 144 c-39 79 -93 178 -121 221 -66 99 -201 241 -303
318 -99 75 -296 172 -402 198 -149 38 -327 48 -509 29z"/>
<path d="M26855 22189 c-136 -14 -237 -44 -371 -109 -146 -71 -252 -149 -366
-269 -109 -114 -173 -210 -259 -388 l-69 -142 0 -228 c0 -343 14 -414 130
-676 96 -216 211 -380 382 -542 271 -259 556 -364 913 -335 140 12 322 51 423
91 264 105 523 353 643 615 90 198 114 319 106 531 -12 317 -114 629 -291 888
-68 100 -209 246 -304 315 -150 109 -351 203 -502 234 -96 20 -318 27 -435 15z"/>
</g>
</svg>
`
)
+4 -2
View File
@@ -4,6 +4,8 @@ import (
"context"
"net/http"
ai_provider_local "github.com/APIParkLab/APIPark/ai-provider/local"
"github.com/APIParkLab/APIPark/model/plugin_model"
ai_api "github.com/APIParkLab/APIPark/module/ai-api"
ai_api_dto "github.com/APIParkLab/APIPark/module/ai-api/dto"
@@ -48,7 +50,7 @@ func (i *imlAPIController) Create(ctx *gin.Context, serviceId string, input *ai_
}
}
if input.AiModel != nil {
provider := "ollama"
provider := ai_provider_local.ProviderLocal
if input.AiModel.Type != "local" {
provider = input.AiModel.Provider
}
@@ -107,7 +109,7 @@ func (i *imlAPIController) Edit(ctx *gin.Context, serviceId string, apiId string
}
//var upstream *string
if input.AiModel != nil {
provider := "ollama"
provider := ai_provider_local.ProviderLocal
if input.AiModel.Type != "local" {
provider = input.AiModel.Provider
}
+2 -2
View File
@@ -245,7 +245,7 @@ func (i *imlLocalModelController) initAILocalService(ctx context.Context, model
}
serviceId := uuid.NewString()
prefix := fmt.Sprintf("/%s", serviceId[:8])
providerId := "ollama"
providerId := ai_provider_local.ProviderLocal
err = i.transaction.Transaction(ctx, func(ctx context.Context) error {
_, err = i.serviceModule.Create(ctx, teamID, &service_dto.CreateService{
Id: serviceId,
@@ -276,7 +276,7 @@ func (i *imlLocalModelController) initAILocalService(ctx context.Context, model
}
aiModel := &ai_api_dto.AiModel{
Id: model,
Config: ai_provider_local.OllamaConfig,
Config: ai_provider_local.LocalConfig,
Provider: providerId,
Type: "local",
}
+4 -4
View File
@@ -296,7 +296,7 @@ func (i *imlServiceController) editAIService(ctx *gin.Context, id string, input
if input.Provider == nil {
return nil, fmt.Errorf("provider is required")
}
if *input.Provider != "ollama" {
if *input.Provider != ai_provider_local.ProviderLocal {
_, has := model_runtime.GetProvider(*input.Provider)
if !has {
return nil, fmt.Errorf("provider not found")
@@ -330,7 +330,7 @@ func (i *imlServiceController) createAIService(ctx *gin.Context, teamID string,
modelId := ""
modelCfg := ""
modelType := "online"
if *input.Provider == "ollama" {
if *input.Provider == ai_provider_local.ProviderLocal {
modelType = "local"
list, err := i.aiLocalModel.SimpleList(ctx)
if err != nil {
@@ -340,7 +340,7 @@ func (i *imlServiceController) createAIService(ctx *gin.Context, teamID string,
return nil, fmt.Errorf("no local model")
}
modelId = list[0].Id
modelCfg = ai_provider_local.OllamaConfig
modelCfg = ai_provider_local.LocalConfig
} else {
pv, err := i.providerModule.Provider(ctx, *input.Provider)
if err != nil {
@@ -367,7 +367,7 @@ func (i *imlServiceController) createAIService(ctx *gin.Context, teamID string,
return err
}
prefix := strings.Replace(input.Prefix, ":", "_", -1)
path := fmt.Sprintf("/%s/chat", strings.Trim(prefix, "/"))
path := fmt.Sprintf("/%s/chat/completions", strings.Trim(prefix, "/"))
timeout := 300000
retry := 0
aiPrompt := &ai_api_dto.AiPrompt{
+18 -2
View File
@@ -5,13 +5,15 @@ import (
"encoding/json"
"errors"
"fmt"
ai_model "github.com/APIParkLab/APIPark/service/ai-model"
"net/http"
"strings"
"github.com/eolinker/eosc/log"
ai_provider_local "github.com/APIParkLab/APIPark/ai-provider/local"
model_runtime "github.com/APIParkLab/APIPark/ai-provider/model-runtime"
ai_model "github.com/APIParkLab/APIPark/service/ai-model"
"github.com/eolinker/eosc/log"
ai_api_dto "github.com/APIParkLab/APIPark/module/ai-api/dto"
ai_api "github.com/APIParkLab/APIPark/service/ai-api"
@@ -239,6 +241,18 @@ func (i *imlAPIModule) List(ctx context.Context, keyword string, serviceId strin
if err != nil {
return item
}
item.ModelType = ai_api_dto.ModelType(aiModel.Type)
if item.ModelType == ai_api_dto.ModelTypeLocal {
item.Model = ai_api_dto.ModelItem{
Id: aiModel.Id,
Name: aiModel.Id,
}
item.Provider = ai_api_dto.ProviderItem{
Id: ai_provider_local.ProviderLocal,
Name: ai_provider_local.ProviderLocal,
Logo: "",
}
} else {
p, has := model_runtime.GetProvider(aiModel.Provider)
if has {
item.Provider = ai_api_dto.ProviderItem{
@@ -260,6 +274,8 @@ func (i *imlAPIModule) List(ctx context.Context, keyword string, serviceId strin
Name: "unknown",
}
}
}
return item
}), nil
}
+8 -8
View File
@@ -82,8 +82,8 @@ func (i *imlBalanceModule) Create(ctx context.Context, input *ai_balance_dto.Cre
modelName = input.Model
base = fmt.Sprintf("%s://%s", p.URI().Scheme(), p.URI().Host())
case ai_balance_dto.ModelTypeLocal:
input.Provider = "ollama"
providerName = "Ollama"
input.Provider = ai_provider_local.ProviderLocal
providerName = ai_provider_local.ProviderLocal
modelName = input.Model
v, has := i.settingService.Get(ctx, "system.ai_model.ollama_address")
if !has {
@@ -119,7 +119,7 @@ func newRelease(item *ai_balance.Balance, base string) *gateway.DynamicRelease {
cfg := make(map[string]interface{})
cfg["provider"] = item.Provider
cfg["model"] = item.Model
cfg["model_config"] = ai_provider_local.OllamaConfig
cfg["model_config"] = ai_provider_local.LocalConfig
cfg["base"] = base
cfg["priority"] = item.Priority
return &gateway.DynamicRelease{
@@ -155,7 +155,7 @@ func (i *imlBalanceModule) Sort(ctx context.Context, input *ai_balance_dto.Sort)
releases := make([]*gateway.DynamicRelease, 0, len(list))
for _, item := range list {
base := v
if item.Provider != "ollama" {
if item.Provider != ai_provider_local.ProviderLocal {
p, has := model_runtime.GetProvider(item.Provider)
if !has {
continue
@@ -259,7 +259,7 @@ func (i *imlBalanceModule) syncGateway(ctx context.Context, clusterId string, re
}
func (i *imlBalanceModule) getLocalBalances(ctx context.Context, v string) ([]*gateway.DynamicRelease, error) {
balances, err := i.balanceService.Search(ctx, "", map[string]interface{}{"provider": "ollama"}, "priority asc")
balances, err := i.balanceService.Search(ctx, "", map[string]interface{}{"provider": ai_provider_local.ProviderLocal}, "priority asc")
if err != nil {
return nil, err
}
@@ -274,7 +274,7 @@ func (i *imlBalanceModule) getLocalBalances(ctx context.Context, v string) ([]*g
releases := make([]*gateway.DynamicRelease, 0, len(balances))
for _, item := range balances {
base := v
if item.Provider != "ollama" {
if item.Provider != ai_provider_local.ProviderLocal {
p, has := model_runtime.GetProvider(item.Provider)
if !has {
continue
@@ -298,12 +298,12 @@ func (i *imlBalanceModule) getBalances(ctx context.Context) ([]*gateway.DynamicR
releases := make([]*gateway.DynamicRelease, 0, len(balances))
for _, item := range balances {
base := v
if item.Provider != "ollama" {
if item.Provider != ai_provider_local.ProviderLocal {
p, has := model_runtime.GetProvider(item.Provider)
if !has {
continue
}
base = fmt.Sprintf("%s://%s", p.URI().Scheme(), p.URI().Host())
base = fmt.Sprintf("%s://%s%s", p.URI().Scheme(), p.URI().Host(), p.URI().Path())
}
releases = append(releases, newRelease(item, base))
}
+55 -27
View File
@@ -4,7 +4,6 @@ import (
"context"
"errors"
"fmt"
"strings"
ai_balance "github.com/APIParkLab/APIPark/service/ai-balance"
@@ -73,8 +72,8 @@ func (i *imlLocalModel) SimpleList(ctx context.Context) ([]*ai_local_dto.SimpleI
return &ai_local_dto.SimpleItem{
Id: s.Id,
Name: s.Name,
DefaultConfig: ai_provider_local.OllamaConfig,
Logo: ai_provider_local.OllamaSvg,
DefaultConfig: ai_provider_local.LocalConfig,
Logo: ai_provider_local.LocalSvg,
}
}, func(l *ai_local.LocalModel) bool {
if l.State != ai_local_dto.LocalModelStateNormal.Int() && l.State != ai_local_dto.LocalModelStateDisable.Int() {
@@ -118,7 +117,7 @@ func (i *imlLocalModel) Search(ctx context.Context, keyword string) ([]*ai_local
APICount: count,
CanDelete: count < 1 && s.State != ai_local_dto.LocalModelStateDeploying.Int(),
UpdateTime: auto.TimeLabel(s.UpdateAt),
Provider: "ollama",
Provider: ai_provider_local.ProviderLocal,
}
}), nil
}
@@ -249,7 +248,7 @@ func (i *imlLocalModel) pullHook(fn ...func() error) func(msg ai_provider_local.
cfg := make(map[string]interface{})
cfg["provider"] = "ollama"
cfg["model"] = msg.Model
cfg["model_config"] = ai_provider_local.OllamaConfig
cfg["model_config"] = ai_provider_local.LocalConfig
cfg["priority"] = 0
cfg["base"] = v
@@ -322,7 +321,7 @@ func (i *imlLocalModel) Deploy(ctx context.Context, model string, session string
err = i.localModelService.Create(ctx, &ai_local.CreateLocalModel{
Id: model,
Name: model,
Provider: "ollama",
Provider: ai_provider_local.ProviderLocal,
State: ai_local_dto.LocalModelStateDeploying.Int(),
})
@@ -451,7 +450,7 @@ func (i *imlLocalModel) Enable(ctx context.Context, model string) error {
cfg := make(map[string]interface{})
cfg["provider"] = "ollama"
cfg["model"] = info.Id
cfg["model_config"] = ai_provider_local.OllamaConfig
cfg["model_config"] = ai_provider_local.LocalConfig
cfg["priority"] = 0
cfg["base"] = v
@@ -513,7 +512,7 @@ func (i *imlLocalModel) OnInit() {
})
models, version := ai_provider_local.ModelsCanInstall()
for _, model := range models {
delete(oldModels, model.Id)
if v, ok := oldModels[model.Id]; ok {
if v.Version == version {
continue
@@ -542,6 +541,7 @@ func (i *imlLocalModel) OnInit() {
return
}
}
delete(oldModels, model.Id)
}
for id := range oldModels {
err = i.localModelPackageService.Delete(ctx, id)
@@ -549,29 +549,57 @@ func (i *imlLocalModel) OnInit() {
return
}
}
installModels, err := ai_provider_local.ModelsInstalled()
if err != nil {
return
}
for _, model := range installModels {
id := strings.TrimSuffix(model.Name, ":latest")
name := strings.TrimSuffix(model.Name, ":latest")
_, err = i.localModelService.Get(ctx, id)
if err != nil {
if !errors.Is(err, gorm.ErrRecordNotFound) {
return
}
err = i.localModelService.Create(ctx, &ai_local.CreateLocalModel{
Id: id,
Name: name,
State: 1,
//installModels, err := ai_provider_local.ModelsInstalled()
//if err != nil {
// return
//}
//for _, model := range installModels {
//
// id := strings.TrimSuffix(model.Name, ":latest")
// name := strings.TrimSuffix(model.Name, ":latest")
// _, err = i.localModelService.Get(ctx, id)
// if err != nil {
// if !errors.Is(err, gorm.ErrRecordNotFound) {
// return
// }
// err = i.localModelService.Create(ctx, &ai_local.CreateLocalModel{
// Id: id,
// Name: name,
// State: 1,
// })
// if err != nil {
// return
// }
// }
//}
i.transaction.Transaction(ctx, func(ctx context.Context) error {
localModels, err := i.localModelService.Search(ctx, "", map[string]interface{}{
"provider": "ollama",
})
if err != nil {
return
return err
}
if len(localModels) == 0 {
return nil
}
err = i.localModelService.UpdateProvider(ctx, ai_provider_local.ProviderLocal, utils.SliceToSlice(localModels, func(s *ai_local.LocalModel) string {
return s.Id
})...)
if err != nil {
return err
}
apis, err := i.aiAPIService.Search(ctx, "", map[string]interface{}{
"provider": "ollama",
})
if err != nil {
return err
}
return i.aiAPIService.UpdateAIProvider(ctx, ai_provider_local.ProviderLocal, utils.SliceToSlice(apis, func(s *ai_api.API) string {
return s.ID
})...)
})
})
}
@@ -596,7 +624,7 @@ func (i *imlLocalModel) getLocalModels(ctx context.Context, v string) ([]*gatewa
cfg := make(map[string]interface{})
cfg["provider"] = "ollama"
cfg["model"] = l.Id
cfg["model_config"] = ai_provider_local.OllamaConfig
cfg["model_config"] = ai_provider_local.LocalConfig
cfg["base"] = v
releases = append(releases, &gateway.DynamicRelease{
BasicItem: &gateway.BasicItem{
+5 -5
View File
@@ -337,11 +337,11 @@ func (i *imlProviderModule) SimpleConfiguredProviders(ctx context.Context, all b
healthProvider := make(map[string]struct{})
if all {
healthProvider["ollama"] = struct{}{}
healthProvider[ai_provider_local.ProviderLocal] = struct{}{}
items = append(items, &ai_dto.SimpleProviderItem{
Id: "ollama",
Name: "Ollama",
Logo: ai_provider_local.OllamaSvg,
Id: ai_provider_local.ProviderLocal,
Name: ai_provider_local.ProviderLocal,
Logo: ai_provider_local.LocalSvg,
Configured: true,
DefaultConfig: "",
Status: ai_dto.ProviderEnabled,
@@ -792,7 +792,7 @@ type imlAIApiModule struct {
func (i *imlAIApiModule) APIs(ctx context.Context, keyword string, providerId string, start int64, end int64, page int, pageSize int, sortCondition string, asc bool, models []string, serviceIds []string) ([]*ai_dto.APIItem, *ai_dto.Condition, int64, error) {
modelItems := make([]*ai_dto.BasicInfo, 0)
if providerId == "ollama" {
if providerId == ai_provider_local.ProviderLocal {
items, err := i.aiLocalModelService.Search(ctx, "", nil, "update_at desc")
if err != nil {
return nil, nil, 0, err
+2 -1
View File
@@ -1,6 +1,7 @@
package service_dto
import (
ai_provider_local "github.com/APIParkLab/APIPark/ai-provider/local"
"github.com/APIParkLab/APIPark/service/service"
"github.com/eolinker/go-common/auto"
)
@@ -151,7 +152,7 @@ func ToService(model *service.Service) *Service {
provider := auto.UUID(model.AdditionalConfig["provider"])
s.Provider = &provider
s.ProviderType = "local"
if provider.Id != "ollama" {
if provider.Id != ai_provider_local.ProviderLocal {
s.ProviderType = "online"
}
modelId := model.AdditionalConfig["model"]
+2 -2
View File
@@ -49,7 +49,7 @@ func (i *imlSettingModule) Set(ctx context.Context, input *system_dto.InputSetti
}
}
if input.OllamaAddress != nil {
ai_provider_local.ResetOllamaAddress(*input.OllamaAddress)
ai_provider_local.ResetLocalAddress(*input.OllamaAddress)
}
return nil
})
@@ -61,7 +61,7 @@ func (i *imlSettingModule) OnInit() {
address, has := i.settingService.Get(ctx, "system.ai_model.ollama_address")
if has {
ai_provider_local.ResetOllamaAddress(address)
ai_provider_local.ResetLocalAddress(address)
}
})
+5
View File
@@ -23,6 +23,11 @@ type imlAPIService struct {
universally.IServiceDelete
}
func (i *imlAPIService) UpdateAIProvider(ctx context.Context, providerId string, ids ...string) error {
_, err := i.store.UpdateField(ctx, "provider", providerId, "uuid in (?)", ids)
return err
}
func (i *imlAPIService) CountByProvider(ctx context.Context, provider string) (int64, error) {
return i.store.Count(ctx, "", map[string]interface{}{"provider": provider})
}
+1
View File
@@ -17,6 +17,7 @@ type IAPIService interface {
CountMapByModel(ctx context.Context, keyword string, conditions map[string]interface{}) (map[string]int64, error)
CountByModel(ctx context.Context, model string) (int64, error)
CountByProvider(ctx context.Context, provider string) (int64, error)
UpdateAIProvider(ctx context.Context, providerId string, ids ...string) error
DeleteByService(ctx context.Context, serviceId string) error
}
+5
View File
@@ -20,6 +20,11 @@ type imlLocalModelService struct {
universally.IServiceDelete
}
func (i *imlLocalModelService) UpdateProvider(ctx context.Context, provider string, ids ...string) error {
_, err := i.store.UpdateWhere(ctx, map[string]interface{}{"provider": provider}, map[string]interface{}{"uuid": ids})
return err
}
func (i *imlLocalModelService) DefaultModel(ctx context.Context) (*LocalModel, error) {
info, err := i.store.First(ctx, map[string]interface{}{"state": 1})
if err != nil {
+1
View File
@@ -14,6 +14,7 @@ type ILocalModelService interface {
universally.IServiceEdit[EditLocalModel]
universally.IServiceDelete
DefaultModel(ctx context.Context) (*LocalModel, error)
UpdateProvider(ctx context.Context, provider string, ids ...string) error
}
type ILocalModelPackageService interface {
+1 -1
View File
@@ -80,7 +80,7 @@ func (s *imlClusterService) GetLabels(ctx context.Context, ids ...string) map[st
}
return map[string]string{o.UUID: o.Name}
}
list, err := s.store.ListQuery(ctx, "uuid in ?", []interface{}{ids}, "id")
list, err := s.store.ListQuery(ctx, "uuid in (?)", []interface{}{ids}, "id")
if err != nil {
return nil
}
+1 -1
View File
@@ -46,7 +46,7 @@ func (s *imlServiceGetSoftDelete[T, E]) List(ctx context.Context, uuids ...strin
where = append(where, "uuid = ?")
args = append(args, uuids[0])
} else {
where = append(where, "uuid in ?")
where = append(where, "uuid in (?)")
args = append(args, uuids)
}
}
+1 -1
View File
@@ -59,7 +59,7 @@ func (s *imlServiceGet[T, E]) List(ctx context.Context, uuids ...string) ([]*T,
where = append(where, "uuid = ?")
args = append(args, uuids[0])
} else {
where = append(where, "uuid in ?")
where = append(where, "uuid in (?)")
args = append(args, uuids)
}
}