Skip to content

Commit

Permalink
feat: update quota tooltip and article generation style mobile adapte…
Browse files Browse the repository at this point in the history
…r, edit message and delete message alpha version (#51)
  • Loading branch information
zmh-program committed Jan 26, 2024
1 parent 06ccf4e commit a3a9e5a
Show file tree
Hide file tree
Showing 25 changed files with 270 additions and 141 deletions.
22 changes: 8 additions & 14 deletions adapter/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ type ChatProps struct {
RequestProps

Model string
Plan bool
Infinity bool
Message []globals.Message
Token int
PresencePenalty *float32
Expand All @@ -56,7 +54,7 @@ func createChatRequest(conf globals.ChannelConfig, props *ChatProps, hook global
Message: props.Message,
Token: utils.Multi(
props.Token == 0,
utils.Multi(props.Infinity || props.Plan, nil, utils.ToPtr(2500)),
utils.ToPtr(2500),
&props.Token,
),
PresencePenalty: props.PresencePenalty,
Expand All @@ -74,7 +72,7 @@ func createChatRequest(conf globals.ChannelConfig, props *ChatProps, hook global
Message: props.Message,
Token: utils.Multi(
props.Token == 0,
utils.Multi(props.Infinity || props.Plan, nil, utils.ToPtr(2500)),
utils.ToPtr(2500),
&props.Token,
),
PresencePenalty: props.PresencePenalty,
Expand Down Expand Up @@ -136,7 +134,7 @@ func createChatRequest(conf globals.ChannelConfig, props *ChatProps, hook global
return dashscope.NewChatInstanceFromConfig(conf).CreateStreamChatRequest(&dashscope.ChatProps{
Model: model,
Message: props.Message,
Token: utils.Multi(props.Infinity || props.Plan, 2048, props.Token),
Token: props.Token,
Temperature: props.Temperature,
TopP: props.TopP,
TopK: props.TopK,
Expand Down Expand Up @@ -164,7 +162,7 @@ func createChatRequest(conf globals.ChannelConfig, props *ChatProps, hook global
return skylark.NewChatInstanceFromConfig(conf).CreateStreamChatRequest(&skylark.ChatProps{
Model: model,
Message: props.Message,
Token: utils.Multi(props.Token == 0, 4096, props.Token),
Token: props.Token,
TopP: props.TopP,
TopK: props.TopK,
Temperature: props.Temperature,
Expand All @@ -178,7 +176,7 @@ func createChatRequest(conf globals.ChannelConfig, props *ChatProps, hook global
return zhinao.NewChatInstanceFromConfig(conf).CreateStreamChatRequest(&zhinao.ChatProps{
Model: model,
Message: props.Message,
Token: utils.Multi(props.Infinity || props.Plan, nil, utils.ToPtr(2048)),
Token: &props.Token,
TopP: props.TopP,
TopK: props.TopK,
Temperature: props.Temperature,
Expand All @@ -193,13 +191,9 @@ func createChatRequest(conf globals.ChannelConfig, props *ChatProps, hook global

case globals.OneAPIChannelType:
return oneapi.NewChatInstanceFromConfig(conf).CreateStreamChatRequest(&oneapi.ChatProps{
Model: model,
Message: props.Message,
Token: utils.Multi(
props.Token == 0,
utils.Multi(props.Plan || props.Infinity, nil, utils.ToPtr(2500)),
&props.Token,
),
Model: model,
Message: props.Message,
Token: &props.Token,
PresencePenalty: props.PresencePenalty,
FrequencyPenalty: props.FrequencyPenalty,
Temperature: props.Temperature,
Expand Down
8 changes: 3 additions & 5 deletions addition/generation/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@ func CreateGeneration(group, model, prompt, path string, plan bool, hook func(bu
buffer := utils.NewBuffer(model, message, channel.ChargeInstance.GetCharge(model))

err := channel.NewChatRequest(group, &adapter.ChatProps{
Model: model,
Message: message,
Plan: plan,
Infinity: true,
Buffer: *buffer,
Model: model,
Message: message,
Buffer: *buffer,
}, func(data string) error {
buffer.Write(data)
hook(buffer, data)
Expand Down
43 changes: 43 additions & 0 deletions app/src/api/conversation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,27 @@ export class Conversation {
this.sendRestartEvent();
break;

case "edit":
const index = ev.index ?? -1;
const message = ev.message ?? "";

if (this.isValidIndex(index)) {
this.data[index].content = message;
this.sendEditEvent(index, message);
this.triggerCallback();
}
break;

case "remove":
const idx = ev.index ?? -1;

if (this.isValidIndex(idx)) {
delete this.data[idx];
this.sendRemoveEvent(idx);
this.triggerCallback();
}
break;

default:
console.debug(
`[conversation] unknown event: ${ev.event} (from: ${ev.id})`,
Expand All @@ -82,6 +103,10 @@ export class Conversation {
this.sendEvent("stop");
}

public isValidIndex(idx: number): boolean {
return idx >= 0 && idx < this.data.length;
}

public sendRestartEvent() {
this.sendEvent("restart");
}
Expand All @@ -90,6 +115,24 @@ export class Conversation {
this.sendEvent("mask", JSON.stringify(mask.context));
}

public sendEditEvent(id: number, message: string) {
this.sendEvent(
"edit",
JSON.stringify({
message: `${id}:${message}`,
}),
);
}

public sendRemoveEvent(id: number) {
this.sendEvent(
"remove",
JSON.stringify({
message: `${id}`,
}),
);
}

public sendShareEvent(refer: string) {
this.sendEvent("share", refer);
}
Expand Down
6 changes: 6 additions & 0 deletions app/src/assets/pages/article.less
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@
align-items: center;
}

.article-action {
@media (max-width: 768px) {
flex-direction: column;
}
}

.article-content {
display: flex;
flex-direction: column;
Expand Down
1 change: 0 additions & 1 deletion app/src/assets/pages/chat.less
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@

.content-wrapper {
display: flex;
flex-direction: row;
max-width: 100%;

.message-toolbar {
Expand Down
4 changes: 2 additions & 2 deletions app/src/components/EditorProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
DialogTitle,
DialogTrigger,
} from "./ui/dialog.tsx";
import { Maximize, Image, MenuSquare, PanelRight, XSquare } from "lucide-react";
import { Maximize, Image, MenuSquare, PanelRight, Eraser } from "lucide-react";
import { useTranslation } from "react-i18next";
import "@/assets/common/editor.less";
import { Textarea } from "./ui/textarea.tsx";
Expand Down Expand Up @@ -64,7 +64,7 @@ function RichEditor({ value, onChange, maxLength }: RichEditorProps) {
className={`h-8 w-8 p-0`}
onClick={() => value && onChange("")}
>
<XSquare className={`h-3.5 w-3.5`} />
<Eraser className={`h-3.5 w-3.5`} />
</Button>
<div className={`grow`} />
<Toggle
Expand Down
Loading

0 comments on commit a3a9e5a

Please sign in to comment.