Compare commits

...

4 Commits

Author SHA1 Message Date
carey036
f235e42f8f Merge ed502e0b7f into fdd7bf41c0 2024-09-25 12:56:06 +00:00
抒情熊
fdd7bf41c0 feat: support multipart/form-data format request (#1690)
Some checks failed
CI / Unit tests (push) Has been cancelled
CI / commit_lint (push) Has been cancelled
* "add parser multipart/form-data"

* chore: fix impl

* chore: update impl

---------

Co-authored-by: JustSong <songquanpeng@foxmail.com>
2024-09-22 17:32:47 +08:00
carey036
ed502e0b7f Merge pull request #6 from songquanpeng/main
xxx
2024-07-03 22:20:16 +08:00
carey036
4688917db7 feat: add chat page for berry 2024-04-30 17:33:57 +08:00
5 changed files with 57 additions and 6 deletions

View File

@@ -31,15 +31,15 @@ func UnmarshalBodyReusable(c *gin.Context, v any) error {
contentType := c.Request.Header.Get("Content-Type")
if strings.HasPrefix(contentType, "application/json") {
err = json.Unmarshal(requestBody, &v)
c.Request.Body = io.NopCloser(bytes.NewBuffer(requestBody))
} else {
// skip for now
// TODO: someday non json request have variant model, we will need to implementation this
c.Request.Body = io.NopCloser(bytes.NewBuffer(requestBody))
err = c.ShouldBind(&v)
}
if err != nil {
return err
}
// Reset request body
c.Request.Body = io.NopCloser(bytes.NewBuffer(requestBody))
return nil
}

View File

@@ -12,7 +12,7 @@ import (
)
type ModelRequest struct {
Model string `json:"model"`
Model string `json:"model" form:"model"`
}
func Distribute() func(c *gin.Context) {

View File

@@ -8,11 +8,12 @@ import {
IconKey,
IconGardenCart,
IconUser,
IconUserScan
IconUserScan,
IconFileTextAi
} from '@tabler/icons-react';
// constant
const icons = { IconDashboard, IconSitemap, IconArticle, IconCoin, IconAdjustments, IconKey, IconGardenCart, IconUser, IconUserScan };
const icons = { IconDashboard, IconSitemap, IconArticle, IconCoin, IconAdjustments, IconKey, IconGardenCart, IconUser, IconUserScan,IconFileTextAi };
// ==============================|| DASHBOARD MENU ITEMS ||============================== //
@@ -29,6 +30,14 @@ const panel = {
breadcrumbs: false,
isAdmin: false
},
{
id: 'chat',
title: '聊天',
type: 'item',
url: '/panel/chat',
icon: icons.IconFileTextAi,
breadcrumbs: false
},
{
id: 'channel',
title: '渠道',

View File

@@ -9,6 +9,7 @@ const Log = Loadable(lazy(() => import('views/Log')));
const Redemption = Loadable(lazy(() => import('views/Redemption')));
const Setting = Loadable(lazy(() => import('views/Setting')));
const Token = Loadable(lazy(() => import('views/Token')));
const Chat = Loadable(lazy(() => import('views/Chat')));
const Topup = Loadable(lazy(() => import('views/Topup')));
const User = Loadable(lazy(() => import('views/User')));
const Profile = Loadable(lazy(() => import('views/Profile')));
@@ -39,6 +40,10 @@ const MainRoutes = {
path: 'log',
element: <Log />
},
{
path: 'chat',
element: <Chat />
},
{
path: 'redemption',
element: <Redemption />

View File

@@ -0,0 +1,37 @@
import React, { useEffect, useState } from "react";
import { API } from 'utils/api';
import { showError, showSuccess } from 'utils/common';
const Chat = () => {
const [value, setValue] = useState([]);
const [isLoading, setIsLoading] = useState(true); // 加载状态
const loadTokens = async () => {
setIsLoading(true); // 开始加载
const res = await API.get(`/api/token/?p=0`);
const { success, message, data } = res.data;
setValue(data);
setIsLoading(false); // 加载完成
};
useEffect(() => {
loadTokens();
}, []);
if (isLoading) {
return <div>Loading...</div>;
} else if (value.length) {
const siteInfo = JSON.parse(localStorage.getItem("siteInfo"));
const chatLink = siteInfo.chat_link + `#/?settings={"key":"sk-${value[0]?.key}","url":"${siteInfo.server_address}"}`;
return (
<iframe
src={chatLink}
style={{ width: "100%", height: "85vh", border: "none" }}
/>
);
} else {
showError("未找到可用令牌,请先创建令牌");
}
};
export default Chat;