mirror of
https://github.com/coaidev/coai.git
synced 2025-05-30 10:20:21 +09:00
update anonymous response waiting feature
This commit is contained in:
parent
821fba5756
commit
981d2e185d
@ -27,17 +27,21 @@ export class Conversation {
|
|||||||
public async send(content: string): Promise<void> {
|
public async send(content: string): Promise<void> {
|
||||||
this.state.value = true;
|
this.state.value = true;
|
||||||
this.addMessageFromUser(content);
|
this.addMessageFromUser(content);
|
||||||
const res = await axios.post("https://api.fystart.cn/gpt", {
|
try {
|
||||||
"id": this.id,
|
const res = await axios.post("https://api.fystart.cn/gpt", {
|
||||||
"message": content,
|
"id": this.id,
|
||||||
}, {
|
"message": content,
|
||||||
headers: { "Content-Type": "application/json" },
|
}, {
|
||||||
method: "POST",
|
headers: { "Content-Type": "application/json" },
|
||||||
});
|
method: "POST",
|
||||||
if (res.data.status === true) {
|
});
|
||||||
this.addMessageFromAI(res.data.message);
|
if (res.data.status === true) {
|
||||||
|
this.addMessageFromAI(res.data.message);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.debug(e);
|
||||||
|
this.addMessageFromAI("网络错误,请稍后再试");
|
||||||
}
|
}
|
||||||
this.state.value = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public addMessage(message: Message): void {
|
public addMessage(message: Message): void {
|
||||||
@ -74,6 +78,7 @@ export class Conversation {
|
|||||||
cursor++;
|
cursor++;
|
||||||
this.refresh();
|
this.refresh();
|
||||||
if (cursor > content.length) {
|
if (cursor > content.length) {
|
||||||
|
this.state.value = false;
|
||||||
clearInterval(interval);
|
clearInterval(interval);
|
||||||
}
|
}
|
||||||
}, 35);
|
}, 35);
|
||||||
|
@ -30,3 +30,12 @@
|
|||||||
transform: translateY(0);
|
transform: translateY(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@keyframes RotateAnimation {
|
||||||
|
0% {
|
||||||
|
transform: rotate(0deg);
|
||||||
|
}
|
||||||
|
100% {
|
||||||
|
transform: rotate(359deg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
16
app/src/components/icons/loading.vue
Normal file
16
app/src/components/icons/loading.vue
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
const props = defineProps<{
|
||||||
|
loading: boolean,
|
||||||
|
}>();
|
||||||
|
</script>
|
||||||
|
<template>
|
||||||
|
<svg viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg" :class="{'loading': props.loading}">
|
||||||
|
<path fill="currentColor" d="M784.512 230.272v-50.56a32 32 0 1 1 64 0v149.056a32 32 0 0 1-32 32H667.52a32 32 0 1 1 0-64h92.992A320 320 0 1 0 524.8 833.152a320 320 0 0 0 320-320h64a384 384 0 0 1-384 384 384 384 0 0 1-384-384 384 384 0 0 1 643.712-282.88z"></path>
|
||||||
|
</svg>
|
||||||
|
</template>
|
||||||
|
<style scoped>
|
||||||
|
@import "/src/assets/style/anim.css";
|
||||||
|
.loading {
|
||||||
|
animation: RotateAnimation 1s linear infinite;
|
||||||
|
}
|
||||||
|
</style>
|
@ -5,6 +5,7 @@ import Openai from "../components/icons/openai.vue";
|
|||||||
import { MdPreview } from 'md-editor-v3';
|
import { MdPreview } from 'md-editor-v3';
|
||||||
import {Conversation} from "../assets/script/conversation";
|
import {Conversation} from "../assets/script/conversation";
|
||||||
import {nextTick, onMounted, ref} from "vue";
|
import {nextTick, onMounted, ref} from "vue";
|
||||||
|
import Loading from "../components/icons/loading.vue";
|
||||||
|
|
||||||
const conversation = new Conversation(1, refreshScrollbar);
|
const conversation = new Conversation(1, refreshScrollbar);
|
||||||
const state = conversation.getState(), length = conversation.getLength(), messages = conversation.getMessages();
|
const state = conversation.getState(), length = conversation.getLength(), messages = conversation.getMessages();
|
||||||
@ -14,7 +15,7 @@ const chatEl = ref<HTMLElement | undefined>();
|
|||||||
|
|
||||||
async function send() {
|
async function send() {
|
||||||
let val = input.value.trim();
|
let val = input.value.trim();
|
||||||
if (val) {
|
if (val && !state.value) {
|
||||||
input.value = "";
|
input.value = "";
|
||||||
await conversation.send(val);
|
await conversation.send(val);
|
||||||
}
|
}
|
||||||
@ -67,7 +68,10 @@ onMounted(() => {
|
|||||||
<div class="input-wrapper">
|
<div class="input-wrapper">
|
||||||
<div class="input">
|
<div class="input">
|
||||||
<input type="text" placeholder="写点什么" v-model="input" ref="inputEl" />
|
<input type="text" placeholder="写点什么" v-model="input" ref="inputEl" />
|
||||||
<div class="button" @click="send"><post /></div>
|
<div class="button" @click="send">
|
||||||
|
<loading v-if="state" :loading="state" />
|
||||||
|
<post v-else />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
2
main.go
2
main.go
@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"chat/api"
|
"chat/api"
|
||||||
"chat/connection"
|
"chat/connection"
|
||||||
|
"chat/middleware"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
@ -16,6 +17,7 @@ func main() {
|
|||||||
|
|
||||||
app := gin.Default()
|
app := gin.Default()
|
||||||
{
|
{
|
||||||
|
app.Use(middleware.CORSMiddleware())
|
||||||
app.POST("/api/anonymous", api.AnonymousAPI)
|
app.POST("/api/anonymous", api.AnonymousAPI)
|
||||||
}
|
}
|
||||||
if err := app.Run(":" + viper.GetString("server.port")); err != nil {
|
if err := app.Run(":" + viper.GetString("server.port")); err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user