增加AI辅助功能 (#1808)

* feature: 增加两个辅助AI,小奇和小淼

* feature:调整AI自动反写部分
This commit is contained in:
PiexlMax(奇淼
2024-07-02 22:53:59 +08:00
committed by GitHub
parent 128e810f77
commit 59cfe96fe3
11 changed files with 288 additions and 52 deletions

View File

@@ -2,6 +2,8 @@ package system
import (
"fmt"
"github.com/goccy/go-json"
"io"
"net/url"
"strings"
@@ -9,6 +11,7 @@ import (
"github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
"github.com/flipped-aurora/gin-vue-admin/server/model/system"
"github.com/flipped-aurora/gin-vue-admin/server/utils"
"github.com/flipped-aurora/gin-vue-admin/server/utils/request"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
@@ -304,6 +307,48 @@ func (autoApi *AutoCodeApi) InstallPlugin(c *gin.Context) {
}}, c)
}
func (autoApi *AutoCodeApi) LLMAuto(c *gin.Context) {
prompt := c.Query("prompt")
mode := c.Query("mode")
params := make(map[string]string)
params["prompt"] = prompt
params["mode"] = mode
path := strings.ReplaceAll(global.GVA_CONFIG.AutoCode.AiPath, "{FUNC}", "api/chat/ai")
res, err := request.HttpRequest(
path,
"POST",
nil,
params,
nil,
)
if err != nil {
global.GVA_LOG.Error("大模型生成失败!", zap.Error(err))
response.FailWithMessage("大模型生成失败"+err.Error(), c)
return
}
var resStruct response.Response
b, err := io.ReadAll(res.Body)
defer res.Body.Close()
if err != nil {
global.GVA_LOG.Error("大模型生成失败!", zap.Error(err))
response.FailWithMessage("大模型生成失败"+err.Error(), c)
return
}
err = json.Unmarshal(b, &resStruct)
if err != nil {
global.GVA_LOG.Error("大模型生成失败!", zap.Error(err))
response.FailWithMessage("大模型生成失败"+err.Error(), c)
return
}
if resStruct.Code == 7 {
global.GVA_LOG.Error("大模型生成失败!"+resStruct.Msg, zap.Error(err))
response.FailWithMessage("大模型生成失败"+resStruct.Msg, c)
return
}
response.OkWithData(resStruct.Data, c)
}
// PubPlug
// @Tags AutoCode
// @Summary 打包插件