update api: simple local models

This commit is contained in:
Liujian
2025-02-17 10:45:34 +08:00
parent b4aeb435c6
commit cd0982ce20
7 changed files with 29 additions and 23 deletions
+8 -6
View File
@@ -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,
+1
View File
@@ -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 {
+6 -5
View File
@@ -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
View File
@@ -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,
-101
View File
@@ -1,101 +0,0 @@
package ai
var (
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>
`
)