mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2026-09-22 16:00:51 +00:00
feat: change agent logic (#11835)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/rand"
|
||||
"encoding/hex"
|
||||
@@ -542,6 +543,9 @@ func (a AgentService) syncAgentsByAccount(account *model.AgentAccount) error {
|
||||
}
|
||||
|
||||
func verifyProvider(provider, baseURL, apiKey string) error {
|
||||
if provider == "minimax" {
|
||||
return verifyMinimax(baseURL, apiKey)
|
||||
}
|
||||
client := &http.Client{Timeout: 10 * time.Second}
|
||||
reqURL, headers := buildVerifyRequest(provider, baseURL, apiKey)
|
||||
request, err := http.NewRequest(http.MethodGet, reqURL, nil)
|
||||
@@ -562,6 +566,40 @@ func verifyProvider(provider, baseURL, apiKey string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func verifyMinimax(baseURL, apiKey string) error {
|
||||
client := &http.Client{Timeout: 10 * time.Second}
|
||||
base := strings.TrimRight(baseURL, "/")
|
||||
if !strings.Contains(base, "/v1") {
|
||||
base = base + "/v1"
|
||||
}
|
||||
reqURL := base + "/chat/completions"
|
||||
body := map[string]interface{}{
|
||||
"model": "MiniMax-M2.1",
|
||||
"messages": []map[string]string{
|
||||
{"role": "user", "content": "test"},
|
||||
},
|
||||
}
|
||||
payload, err := json.Marshal(body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
request, err := http.NewRequest(http.MethodPost, reqURL, bytes.NewBuffer(payload))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
request.Header.Set("Authorization", fmt.Sprintf("Bearer %s", apiKey))
|
||||
request.Header.Set("Content-Type", "application/json")
|
||||
resp, err := client.Do(request)
|
||||
if err != nil {
|
||||
return buserr.WithErr("ErrAgentAccountUnavailable", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode >= 400 {
|
||||
return buserr.WithErr("ErrAgentAccountUnavailable", fmt.Errorf("verify failed: %s", resp.Status))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func buildAgentItem(agent *model.Agent, appInstall *model.AppInstall, envMap map[string]interface{}) dto.AgentItem {
|
||||
item := dto.AgentItem{
|
||||
ID: agent.ID,
|
||||
@@ -875,11 +913,6 @@ type providerDefinition struct {
|
||||
|
||||
func providerDefinitions() map[string]providerDefinition {
|
||||
return map[string]providerDefinition{
|
||||
"ollama": {
|
||||
Sort: 1,
|
||||
BaseURL: "",
|
||||
Models: []dto.ProviderModelInfo{},
|
||||
},
|
||||
"deepseek": {
|
||||
Sort: 2,
|
||||
BaseURL: "https://api.deepseek.com/v1",
|
||||
@@ -924,9 +957,14 @@ func providerDefinitions() map[string]providerDefinition {
|
||||
{ID: "google/gemini-3-flash-preview", Name: "Gemini 3 Flash Preview"},
|
||||
},
|
||||
},
|
||||
"ollama": {
|
||||
Sort: 1,
|
||||
BaseURL: "",
|
||||
Models: []dto.ProviderModelInfo{},
|
||||
},
|
||||
"minimax": {
|
||||
Sort: 6,
|
||||
BaseURL: "https://api.minimax.chat/v1",
|
||||
BaseURL: "https://api.minimaxi.com/v1",
|
||||
Models: []dto.ProviderModelInfo{
|
||||
{ID: "minimax/Minimax-M2.1", Name: "Minimax M2.1"},
|
||||
},
|
||||
|
||||
@@ -117,7 +117,7 @@ const form = reactive({
|
||||
appVersion: '',
|
||||
webUIPort: 18789,
|
||||
bridgePort: 18790,
|
||||
provider: 'ollama',
|
||||
provider: 'deepseek',
|
||||
accountId: undefined as unknown as number,
|
||||
model: '',
|
||||
apiKey: '',
|
||||
|
||||
@@ -54,11 +54,11 @@ const providerOptions = ref<Array<{ label: string; value: string }>>([]);
|
||||
const providerBaseURL = ref<Record<string, string>>({});
|
||||
const loading = ref(false);
|
||||
const providerLabelMap: Record<string, string> = {
|
||||
deepseek: 'DeepSeek',
|
||||
openai: 'OpenAI',
|
||||
ollama: 'Ollama',
|
||||
minimax: 'MiniMax',
|
||||
qwen: 'Qwen',
|
||||
deepseek: 'DeepSeek',
|
||||
anthropic: 'Anthropic',
|
||||
gemini: 'Gemini',
|
||||
};
|
||||
@@ -85,6 +85,7 @@ const rules = reactive({
|
||||
provider: [Rules.requiredSelect],
|
||||
name: [Rules.requiredInput],
|
||||
apiKey: [Rules.requiredInput],
|
||||
baseURL: [Rules.requiredInput],
|
||||
});
|
||||
|
||||
const submit = async () => {
|
||||
@@ -135,7 +136,7 @@ interface OpenParams {
|
||||
remark?: string;
|
||||
}
|
||||
|
||||
const openDrawer = (params?: OpenParams) => {
|
||||
const openDrawer = async (params?: OpenParams) => {
|
||||
open.value = true;
|
||||
loading.value = false;
|
||||
if (params?.id) {
|
||||
@@ -154,10 +155,15 @@ const openDrawer = (params?: OpenParams) => {
|
||||
form.apiKey = '';
|
||||
form.remark = '';
|
||||
form.syncAgents = false;
|
||||
if (providerOptions.value.length === 0) {
|
||||
await loadProviders();
|
||||
}
|
||||
if (params?.provider) {
|
||||
form.provider = params.provider;
|
||||
handleProviderChange();
|
||||
} else if (providerOptions.value.length > 0) {
|
||||
form.provider = providerOptions.value[0].value;
|
||||
}
|
||||
handleProviderChange();
|
||||
};
|
||||
|
||||
const loadProviders = async () => {
|
||||
|
||||
@@ -102,7 +102,9 @@ const search = async () => {
|
||||
|
||||
const openCreate = () => {
|
||||
if (addRef.value?.open) {
|
||||
addRef.value.open();
|
||||
addRef.value.open({
|
||||
provider: 'deepseek',
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user