fixed bug markmap generation

This commit is contained in:
RockYang 2024-06-04 16:21:08 +08:00
parent 66ccb387e8
commit d52dfbfef4
6 changed files with 63 additions and 63 deletions

View File

@ -183,45 +183,29 @@ func (h *MarkMapHandler) sendMessage(client *types.WsClient, prompt string, mode
utils.ReplyChunkMessage(client, types.WsMessage{Type: types.WsEnd}) utils.ReplyChunkMessage(client, types.WsMessage{Type: types.WsEnd})
} else { } else {
body, err := io.ReadAll(response.Body) body, _ := io.ReadAll(response.Body)
if err != nil { return fmt.Errorf("请求 OpenAI API 失败:%s", string(body))
return fmt.Errorf("读取响应失败: %v", err)
}
var res types.ApiError
err = json.Unmarshal(body, &res)
if err != nil {
return fmt.Errorf("解析响应失败: %v", err)
}
// OpenAI API 调用异常处理
if strings.Contains(res.Error.Message, "This key is associated with a deactivated account") {
// remove key
h.DB.Where("value = ?", apiKey).Delete(&model.ApiKey{})
return errors.New("请求 OpenAI API 失败API KEY 所关联的账户被禁用。")
} else if strings.Contains(res.Error.Message, "You exceeded your current quota") {
return errors.New("请求 OpenAI API 失败API KEY 触发并发限制,请稍后再试。")
} else {
return fmt.Errorf("请求 OpenAI API 失败:%v", res.Error.Message)
}
} }
// 扣减算力 // 扣减算力
res = h.DB.Model(&model.User{}).Where("id", userId).UpdateColumn("power", gorm.Expr("power - ?", chatModel.Power)) if chatModel.Power > 0 {
if res.Error == nil { res = h.DB.Model(&model.User{}).Where("id", userId).UpdateColumn("power", gorm.Expr("power - ?", chatModel.Power))
// 记录算力消费日志 if res.Error == nil {
var u model.User // 记录算力消费日志
h.DB.Where("id", userId).First(&u) var u model.User
h.DB.Create(&model.PowerLog{ h.DB.Where("id", userId).First(&u)
UserId: u.Id, h.DB.Create(&model.PowerLog{
Username: u.Username, UserId: u.Id,
Type: types.PowerConsume, Username: u.Username,
Amount: chatModel.Power, Type: types.PowerConsume,
Mark: types.PowerSub, Amount: chatModel.Power,
Balance: u.Power, Mark: types.PowerSub,
Model: chatModel.Value, Balance: u.Power,
Remark: fmt.Sprintf("AI绘制思维导图模型名称%s, ", chatModel.Value), Model: chatModel.Value,
CreatedAt: time.Now(), Remark: fmt.Sprintf("AI绘制思维导图模型名称%s, ", chatModel.Value),
}) CreatedAt: time.Now(),
})
}
} }
return nil return nil
@ -235,7 +219,7 @@ func (h *MarkMapHandler) doRequest(req types.ApiRequest, chatModel model.ChatMod
} }
// use the last unused key // use the last unused key
if apiKey.Id == 0 { if apiKey.Id == 0 {
res = h.DB.Where("platform", types.OpenAI). res = h.DB.Where("platform", types.OpenAI.Value).
Where("type", "chat"). Where("type", "chat").
Where("enabled", true).Order("last_used_at ASC").First(apiKey) Where("enabled", true).Order("last_used_at ASC").First(apiKey)
} }

View File

@ -153,10 +153,7 @@ func (s *Service) Image(task types.DallTask, sync bool) (string, error) {
} else { } else {
request = request.SetHeader("Authorization", "Bearer "+apiKey.Value) request = request.SetHeader("Authorization", "Bearer "+apiKey.Value)
} }
r, err := request.SetHeader("Authorization", "Bearer "+apiKey.Value). r, err := request.SetBody(reqBody).SetErrorResult(&errRes).SetSuccessResult(&res).Post(apiKey.ApiURL)
SetBody(reqBody).
SetErrorResult(&errRes).
SetSuccessResult(&res).Post(apiKey.ApiURL)
if err != nil { if err != nil {
return "", fmt.Errorf("error with send request: %v", err) return "", fmt.Errorf("error with send request: %v", err)
} }

View File

@ -54,7 +54,7 @@ type apiErrRes struct {
func OpenAIRequest(db *gorm.DB, prompt string) (string, error) { func OpenAIRequest(db *gorm.DB, prompt string) (string, error) {
var apiKey model.ApiKey var apiKey model.ApiKey
res := db.Where("platform = ?", types.OpenAI.Value).Where("type", "chat").Where("enabled = ?", true).First(&apiKey) res := db.Where("platform IN ?", []string{types.OpenAI.Value, types.Azure.Value}).Where("type", "chat").Where("enabled = ?", true).First(&apiKey)
if res.Error != nil { if res.Error != nil {
return "", fmt.Errorf("error with fetch OpenAI API KEY%v", res.Error) return "", fmt.Errorf("error with fetch OpenAI API KEY%v", res.Error)
} }

View File

@ -6,19 +6,20 @@
// * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
import {createRouter, createWebHistory} from "vue-router"; import {createRouter, createWebHistory} from "vue-router";
import {ref} from "vue";
import {httpGet} from "@/utils/http";
const routes = [ const routes = [
{ {
name: 'Index', name: 'Index',
path: '/', path: '/',
meta: {title: process.env.VUE_APP_TITLE}, meta: {title: "首页"},
component: () => import('@/views/Index.vue'), component: () => import('@/views/Index.vue'),
}, },
{ {
name: 'home', name: 'home',
path: '/home', path: '/home',
redirect: '/chat', redirect: '/chat',
meta: {title: '首页'},
component: () => import('@/views/Home.vue'), component: () => import('@/views/Home.vue'),
children: [ children: [
{ {
@ -273,11 +274,22 @@ const router = createRouter({
routes: routes, routes: routes,
}) })
const active = ref(false)
const title = ref('')
httpGet("/api/config/license").then(res => {
active.value = res.data.de_copy
}).catch(() => {})
httpGet("/api/config/get?key=system").then(res => {
title.value = res.data.title
}).catch(()=>{})
let prevRoute = null let prevRoute = null
// dynamic change the title when router change // dynamic change the title when router change
router.beforeEach((to, from, next) => { router.beforeEach((to, from, next) => {
if (to.meta.title) { if (!active.value) {
document.title = `${to.meta.title} | ${process.env.VUE_APP_TITLE}` document.title = `${to.meta.title} | ${process.env.VUE_APP_TITLE}`
} else {
document.title = `${to.meta.title} | ${title.value}`
} }
prevRoute = from prevRoute = from
next() next()

View File

@ -46,19 +46,21 @@
<span class="username">{{ loginUser.nickname }}</span> <span class="username">{{ loginUser.nickname }}</span>
</el-dropdown-item> </el-dropdown-item>
<el-dropdown-item> <div v-if="!licenseConfig.de_copy">
<i class="iconfont icon-book"></i> <el-dropdown-item>
<a href="https://github.com/yangjian102621/chatgpt-plus" target="_blank"> <i class="iconfont icon-book"></i>
用户手册 <a href="https://github.com/yangjian102621/chatgpt-plus" target="_blank">
</a> 用户手册
</el-dropdown-item> </a>
</el-dropdown-item>
<el-dropdown-item> <el-dropdown-item>
<i class="iconfont icon-github"></i> <i class="iconfont icon-github"></i>
<a href="https://ai.r9it.com/docs/" target="_blank"> <a href="https://ai.r9it.com/docs/" target="_blank">
Geek-AI {{ version }} Geek-AI {{ version }}
</a> </a>
</el-dropdown-item> </el-dropdown-item>
</div>
<el-divider style="margin: 2px 0"/> <el-divider style="margin: 2px 0"/>
<el-dropdown-item @click="logout"> <el-dropdown-item @click="logout">
<i class="iconfont icon-logout"></i> <i class="iconfont icon-logout"></i>

View File

@ -26,8 +26,11 @@
</el-button> </el-button>
</a> </a>
</span> </span>
<el-button @click="router.push('/login')" round>登录</el-button>
<el-button @click="router.push('/register')" round>注册</el-button> <span v-if="!isLogin">
<el-button @click="router.push('/login')" round>登录</el-button>
<el-button @click="router.push('/register')" round>注册</el-button>
</span>
</div> </div>
</el-menu> </el-menu>
</div> </div>
@ -69,6 +72,7 @@ import FooterBar from "@/components/FooterBar.vue";
import {httpGet} from "@/utils/http"; import {httpGet} from "@/utils/http";
import {ElMessage} from "element-plus"; import {ElMessage} from "element-plus";
import {isMobile} from "@/utils/libs"; import {isMobile} from "@/utils/libs";
import {checkSession} from "@/action/session";
const router = useRouter() const router = useRouter()
@ -83,6 +87,7 @@ const licenseConfig = ref({})
// const size = Math.max(window.innerWidth * 0.5, window.innerHeight * 0.8) // const size = Math.max(window.innerWidth * 0.5, window.innerHeight * 0.8)
const winHeight = window.innerHeight - 150 const winHeight = window.innerHeight - 150
const bgClass = ref('fixed-bg') const bgClass = ref('fixed-bg')
const isLogin = ref(false)
onMounted(() => { onMounted(() => {
httpGet("/api/config/get?key=system").then(res => { httpGet("/api/config/get?key=system").then(res => {
@ -100,11 +105,11 @@ onMounted(() => {
}).catch(e => { }).catch(e => {
ElMessage.error("获取 License 配置:" + e.message) ElMessage.error("获取 License 配置:" + e.message)
}) })
init()
})
const init = () => { checkSession().then(() => {
} isLogin.value = true
}).catch(()=>{})
})
</script> </script>
<style lang="stylus" scoped> <style lang="stylus" scoped>