diff --git a/addition/web/utils.go b/addition/web/utils.go
index e1af5d2..c882532 100644
--- a/addition/web/utils.go
+++ b/addition/web/utils.go
@@ -7,7 +7,7 @@ import (
)
func UsingWebSegment(instance *conversation.Conversation) []globals.Message {
- segment := conversation.CopyMessage(instance.GetMessageSegment(12))
+ segment := conversation.CopyMessage(instance.GetChatMessage())
if instance.IsEnableWeb() {
segment = ChatWithWeb(func(message []globals.Message, token int) (string, error) {
diff --git a/app/src/api/connection.ts b/app/src/api/connection.ts
index dc6f26a..3927eef 100644
--- a/app/src/api/connection.ts
+++ b/app/src/api/connection.ts
@@ -4,6 +4,7 @@ import { getMemory } from "@/utils/memory.ts";
export const endpoint = `${ws_api}/chat`;
export type StreamMessage = {
+ conversation?: number;
keyword?: string;
quota?: number;
message: string;
@@ -97,6 +98,9 @@ export class Connection {
}
protected triggerCallback(message: StreamMessage): void {
+ if (this.id === -1 && message.conversation) {
+ this.setId(message.conversation);
+ }
this.callback && this.callback(message);
}
diff --git a/app/src/components/admin/MenuBar.tsx b/app/src/components/admin/MenuBar.tsx
index a4e75f9..25943f5 100644
--- a/app/src/components/admin/MenuBar.tsx
+++ b/app/src/components/admin/MenuBar.tsx
@@ -1,7 +1,7 @@
import { useDispatch, useSelector } from "react-redux";
import { closeMenu, selectMenu } from "@/store/menu.ts";
import React, { useMemo } from "react";
-import { LayoutDashboard, Radio, Settings, Users } from "lucide-react";
+import {CandlestickChart, LayoutDashboard, Radio, Settings, Users} from "lucide-react";
import router from "@/router.tsx";
import { useLocation } from "react-router-dom";
import { useTranslation } from "react-i18next";
@@ -53,9 +53,14 @@ function MenuBar() {
path={"/broadcast"}
/>
}
- path={"/settings"}
+ path={"/channel"}
+ />
+ }
+ path={"/prize"}
/>
);
diff --git a/app/src/components/admin/UserTable.tsx b/app/src/components/admin/UserTable.tsx
index 025b7da..1ea38c1 100644
--- a/app/src/components/admin/UserTable.tsx
+++ b/app/src/components/admin/UserTable.tsx
@@ -92,7 +92,7 @@ function OperationMenu({ id }: OperationMenuProps) {
}}
/>
-
+
diff --git a/app/src/dialogs/SettingsDialog.tsx b/app/src/dialogs/SettingsDialog.tsx
index 0120c6e..c268789 100644
--- a/app/src/dialogs/SettingsDialog.tsx
+++ b/app/src/dialogs/SettingsDialog.tsx
@@ -34,6 +34,7 @@ import {
SelectValue,
} from "@/components/ui/select.tsx";
import { langs, setLanguage } from "@/i18n.ts";
+import {cn} from "@/components/ui/lib/utils.ts";
function SettingsDialog() {
const { t, i18n } = useTranslation();
@@ -140,7 +141,7 @@ function SettingsDialog() {
{t("settings.history")}
import("@/routes/Article.tsx"));
const Admin = lazy(() => import("@/routes/Admin.tsx"));
const Dashboard = lazy(() => import("@/routes/admin/DashBoard.tsx"));
-const Settings = lazy(() => import("@/routes/admin/Settings.tsx"));
+const Channel = lazy(() => import("@/routes/admin/Channel.tsx"));
+const Prize = lazy(() => import("@/routes/admin/Prize.tsx"));
const Users = lazy(() => import("@/routes/admin/Users.tsx"));
const Broadcast = lazy(() => import("@/routes/admin/Broadcast.tsx"));
@@ -85,11 +86,20 @@ const router = createBrowserRouter([
),
},
{
- id: "admin-settings",
- path: "settings",
+ id: "admin-channel",
+ path: "channel",
element: (
-
+
+
+ ),
+ },
+ {
+ id: "admin-prize",
+ path: "prize",
+ element: (
+
+
),
},
diff --git a/app/src/routes/admin/Channel.tsx b/app/src/routes/admin/Channel.tsx
new file mode 100644
index 0000000..22f14d0
--- /dev/null
+++ b/app/src/routes/admin/Channel.tsx
@@ -0,0 +1,5 @@
+function Channel() {
+ return <>>;
+}
+
+export default Channel;
diff --git a/app/src/routes/admin/Prize.tsx b/app/src/routes/admin/Prize.tsx
new file mode 100644
index 0000000..d338af6
--- /dev/null
+++ b/app/src/routes/admin/Prize.tsx
@@ -0,0 +1,5 @@
+function Prize() {
+ return <>>;
+}
+
+export default Prize;
diff --git a/app/src/routes/admin/Settings.tsx b/app/src/routes/admin/Settings.tsx
deleted file mode 100644
index 9d60730..0000000
--- a/app/src/routes/admin/Settings.tsx
+++ /dev/null
@@ -1,5 +0,0 @@
-function Settings() {
- return <>>;
-}
-
-export default Settings;
diff --git a/globals/types.go b/globals/types.go
index 89c0844..d46aa1a 100644
--- a/globals/types.go
+++ b/globals/types.go
@@ -9,11 +9,12 @@ type Message struct {
}
type ChatSegmentResponse struct {
- Quota float32 `json:"quota"`
- Keyword string `json:"keyword"`
- Message string `json:"message"`
- End bool `json:"end"`
- Plan bool `json:"plan"`
+ Conversation int64 `json:"conversation"`
+ Quota float32 `json:"quota"`
+ Keyword string `json:"keyword"`
+ Message string `json:"message"`
+ End bool `json:"end"`
+ Plan bool `json:"plan"`
}
type GenerationSegmentResponse struct {
diff --git a/manager/chat.go b/manager/chat.go
index a33ac6b..563f162 100644
--- a/manager/chat.go
+++ b/manager/chat.go
@@ -63,6 +63,9 @@ func ChatHandler(conn *Connection, user *auth.User, instance *conversation.Conve
db := conn.GetDB()
cache := conn.GetCache()
check, plan := auth.CanEnableModelWithSubscription(db, cache, user, model)
+ conn.Send(globals.ChatSegmentResponse{
+ Conversation: instance.GetId(),
+ })
if !check {
conn.Send(globals.ChatSegmentResponse{
diff --git a/manager/conversation/conversation.go b/manager/conversation/conversation.go
index bdf7212..6a767f5 100644
--- a/manager/conversation/conversation.go
+++ b/manager/conversation/conversation.go
@@ -10,17 +10,18 @@ import (
)
const defaultConversationName = "new chat"
+const defaultConversationContext = 8
type Conversation struct {
- Auth bool `json:"auth"`
- UserID int64 `json:"user_id"`
- Id int64 `json:"id"`
- Name string `json:"name"`
- Message []globals.Message `json:"message"`
- Model string `json:"model"`
- EnableWeb bool `json:"enable_web"`
- Shared bool `json:"shared"`
- IgnoreContext bool `json:"ignore_context"`
+ Auth bool `json:"auth"`
+ UserID int64 `json:"user_id"`
+ Id int64 `json:"id"`
+ Name string `json:"name"`
+ Message []globals.Message `json:"message"`
+ Model string `json:"model"`
+ EnableWeb bool `json:"enable_web"`
+ Shared bool `json:"shared"`
+ Context int `json:"context"`
}
type FormMessage struct {
@@ -29,17 +30,18 @@ type FormMessage struct {
Web bool `json:"web"`
Model string `json:"model"`
IgnoreContext bool `json:"ignore_context"`
+ Context int `json:"context"`
}
func NewAnonymousConversation() *Conversation {
return &Conversation{
- Auth: false,
- UserID: -1,
- Id: -1,
- Name: defaultConversationName,
- Message: []globals.Message{},
- Model: globals.GPT3Turbo,
- IgnoreContext: false,
+ Auth: false,
+ UserID: -1,
+ Id: -1,
+ Name: defaultConversationName,
+ Message: []globals.Message{},
+ Model: globals.GPT3Turbo,
+ Context: defaultConversationContext,
}
}
@@ -89,8 +91,8 @@ func (c *Conversation) IsEnableWeb() bool {
return c.EnableWeb
}
-func (c *Conversation) IsIgnoreContext() bool {
- return c.IgnoreContext
+func (c *Conversation) GetContextLength() int {
+ return c.Context
}
func (c *Conversation) SetModel(model string) {
@@ -104,8 +106,8 @@ func (c *Conversation) SetEnableWeb(enable bool) {
c.EnableWeb = enable
}
-func (c *Conversation) SetIgnoreContext(ignore bool) {
- c.IgnoreContext = ignore
+func (c *Conversation) SetContextLength(context int) {
+ c.Context = context
}
func (c *Conversation) GetName() string {
@@ -142,20 +144,16 @@ func (c *Conversation) GetMessageLength() int {
}
func (c *Conversation) GetMessageSegment(length int) []globals.Message {
- if c.IsIgnoreContext() {
- if len(c.Message) >= 1 {
- // get latest message
- return []globals.Message{c.Message[len(c.Message)-1]}
- }
- // empty
- return []globals.Message{}
- }
if length > len(c.Message) {
return c.Message
}
return c.Message[len(c.Message)-length:]
}
+func (c *Conversation) GetChatMessage() []globals.Message {
+ return c.GetMessageSegment(c.GetContextLength())
+}
+
func CopyMessage(message []globals.Message) []globals.Message {
return utils.DeepCopy[[]globals.Message](message) // deep copy
}
@@ -224,7 +222,14 @@ func (c *Conversation) AddMessageFromByte(data []byte) (string, error) {
c.AddMessageFromUser(form.Message)
c.SetModel(form.Model)
c.SetEnableWeb(form.Web)
- c.SetIgnoreContext(form.IgnoreContext)
+
+ if form.IgnoreContext {
+ form.Context = 1
+ } else if form.Context <= 0 {
+ form.Context = defaultConversationContext
+ }
+
+ c.SetContextLength(form.Context)
return form.Message, nil
}
@@ -236,7 +241,13 @@ func (c *Conversation) AddMessageFromForm(form *FormMessage) error {
c.AddMessageFromUser(form.Message)
c.SetModel(form.Model)
c.SetEnableWeb(form.Web)
- c.SetIgnoreContext(form.IgnoreContext)
+ if form.IgnoreContext {
+ form.Context = 1
+ } else if form.Context <= 0 {
+ form.Context = defaultConversationContext
+ }
+
+ c.SetContextLength(form.Context)
return nil
}