Skip to content

Commit

Permalink
fix(components): 修改mj newbing bug 新增百度gpt
Browse files Browse the repository at this point in the history
  • Loading branch information
mjjh1717 committed Jul 25, 2023
1 parent 4c6a861 commit b30c6f5
Show file tree
Hide file tree
Showing 15 changed files with 672 additions and 66 deletions.
71 changes: 40 additions & 31 deletions src/views/cellRoom/midjourney/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,12 @@ async function getRoomMessageList(params: RoomMidjourneyRequest) {
const imgUrl_c = `${baseURL}${item.compressedImageUrl}`
const imgUrl_o = `${baseURL}${item.originalImageUrl}`
const time = new Date().getTime()
item.compressedImageUrl = `${imgUrl_c}?time=${time}`
item.originalImageUrl = `${imgUrl_o}?time=${time}`
item.compressedImageUrlPlus = `${imgUrl_c}?time=${time}`
item.originalImageUrlPlus = `${imgUrl_o}?time=${time}`
}
else {
item.compressedImageUrl = `${baseURL}${item.compressedImageUrl}`
item.originalImageUrl = `${baseURL}${item.originalImageUrl}`
item.compressedImageUrlPlus = `${baseURL}${item.compressedImageUrl}`
item.originalImageUrlPlus = `${baseURL}${item.originalImageUrl}`
}
return item
})
Expand Down Expand Up @@ -147,17 +147,23 @@ function getScrollData(e: any) {
loadingMore()
}
const sendData = ref(null)
const sendData = ref<string | null>(null)
const isSend = ref(false)
const showModal = ref(false)
const showModalUrl = ref('')
function handleEnter(event: KeyboardEvent) {
if (event.code === 'Enter' && event.ctrlKey) {
event.preventDefault()
sendClick()
if (event.code === 'Enter') {
if (event.ctrlKey) {
sendData.value = `${sendData.value}\n`
}
else {
event.preventDefault()
sendClick()
}
}
}
// 对话点击
async function sendClick() {
if (sendData.value) {
Expand Down Expand Up @@ -199,12 +205,12 @@ async function getNewData() {
const imgUrl_c = `${baseURL}${item.compressedImageUrl}`
const imgUrl_o = `${baseURL}${item.originalImageUrl}`
const time = new Date().getTime()
item.compressedImageUrl = `${imgUrl_c}?time=${time}`
item.originalImageUrl = `${imgUrl_o}?time=${time}`
item.compressedImageUrlPlus = `${imgUrl_c}?time=${time}`
item.originalImageUrlPlus = `${imgUrl_o}?time=${time}`
}
else {
item.compressedImageUrl = `${baseURL}${item.compressedImageUrl}`
item.originalImageUrl = `${baseURL}${item.originalImageUrl}`
item.compressedImageUrlPlus = `${baseURL}${item.compressedImageUrl}`
item.originalImageUrlPlus = `${baseURL}${item.originalImageUrl}`
}
return item
})
Expand Down Expand Up @@ -235,12 +241,12 @@ async function variationClick(msgId: number | undefined, index: number) {
const imgUrl_c = `${baseURL}${data.compressedImageUrl}`
const imgUrl_o = `${baseURL}${data.originalImageUrl}`
const time = new Date().getTime()
data.compressedImageUrl = `${imgUrl_c}?time=${time}`
data.originalImageUrl = `${imgUrl_o}?time=${time}`
data.compressedImageUrlPlus = `${imgUrl_c}?time=${time}`
data.originalImageUrlPlus = `${imgUrl_o}?time=${time}`
}
else {
data.compressedImageUrl = `${baseURL}${data.compressedImageUrl}`
data.originalImageUrl = `${baseURL}${data.originalImageUrl}`
data.compressedImageUrlPlus = `${baseURL}${data.compressedImageUrl}`
data.originalImageUrlPlus = `${baseURL}${data.originalImageUrl}`
}
for (const index in messageList.value) {
if (messageList.value[index].id === msgId)
Expand All @@ -263,12 +269,12 @@ async function upscaleClick(msgId: number | undefined, index: number) {
const imgUrl_c = `${baseURL}${data.compressedImageUrl}`
const imgUrl_o = `${baseURL}${data.originalImageUrl}`
const time = new Date().getTime()
data.compressedImageUrl = `${imgUrl_c}?time=${time}`
data.originalImageUrl = `${imgUrl_o}?time=${time}`
data.compressedImageUrlPlus = `${imgUrl_c}?time=${time}`
data.originalImageUrlPlus = `${imgUrl_o}?time=${time}`
}
else {
data.compressedImageUrl = `${baseURL}${data.compressedImageUrl}`
data.originalImageUrl = `${baseURL}${data.originalImageUrl}`
data.compressedImageUrlPlus = `${baseURL}${data.compressedImageUrl}`
data.originalImageUrlPlus = `${baseURL}${data.originalImageUrl}`
}
for (const index in messageList.value) {
if (messageList.value[index].id === msgId)
Expand Down Expand Up @@ -450,12 +456,12 @@ async function newMessageInterval(id: string, time = 10000) {
const imgUrl_c = `${baseURL}${data.compressedImageUrl}`
const imgUrl_o = `${baseURL}${data.originalImageUrl}`
const time = new Date().getTime()
data.compressedImageUrl = `${imgUrl_c}?time=${time}`
data.originalImageUrl = `${imgUrl_o}?time=${time}`
data.compressedImageUrlPlus = `${imgUrl_c}?time=${time}`
data.originalImageUrlPlus = `${imgUrl_o}?time=${time}`
}
else {
data.compressedImageUrl = `${baseURL}${data.compressedImageUrl}`
data.originalImageUrl = `${baseURL}${data.originalImageUrl}`
data.compressedImageUrlPlus = `${baseURL}${data.compressedImageUrl}`
data.originalImageUrlPlus = `${baseURL}${data.originalImageUrl}`
}
for (const index in messageList.value) {
if (String(messageList.value[index].id) === id)
Expand All @@ -469,12 +475,12 @@ async function newMessageInterval(id: string, time = 10000) {
const imgUrl_c = `${baseURL}${data.compressedImageUrl}`
const imgUrl_o = `${baseURL}${data.originalImageUrl}`
const time = new Date().getTime()
data.compressedImageUrl = `${imgUrl_c}?time=${time}`
data.originalImageUrl = `${imgUrl_o}?time=${time}`
data.compressedImageUrlPlus = `${imgUrl_c}?time=${time}`
data.originalImageUrlPlus = `${imgUrl_o}?time=${time}`
}
else {
data.compressedImageUrl = `${baseURL}${data.compressedImageUrl}`
data.originalImageUrl = `${baseURL}${data.originalImageUrl}`
data.compressedImageUrlPlus = `${baseURL}${data.compressedImageUrl}`
data.originalImageUrlPlus = `${baseURL}${data.originalImageUrl}`
}
for (const index in messageList.value) {
Expand Down Expand Up @@ -629,20 +635,23 @@ function getTimeDate(newDate: string, oldDate: string) {
:src="getTimeImgUrl(item.compressedImageUrl)"
fallback-src="https://07akioni.oss-cn-beijing.aliyuncs.com/07akioni.jpeg"
/> -->
<!-- {{ item.compressedImageUrlPlus }}
{{ item.originalImageUrlPlus }} -->
<n-image
v-if="item.compressedImageUrl"
lazy
mt-10
b-rd-4
:show-toolbar="false"
:width="200"
:height="200"
:src="item.compressedImageUrl"
:src="item.compressedImageUrlPlus"
fallback-src="https://07akioni.oss-cn-beijing.aliyuncs.com/07akioni.jpeg"
/>
<!-- <n-button v-if="item.status === 'MJ_SUCCESS'" absolute bottom-0 right-0 type="primary" size="tiny" color="#767c82" @click="showModal = true; showModalUrl = `${baseURL}${item.originalImageUrl}?time=${new Date().getTime()}`">
查看原图
</n-button> -->
<n-button absolute bottom-0 right-0 type="primary" size="tiny" color="#767c82" @click="showModal = true; showModalUrl = String(item.originalImageUrl)">
<n-button v-if="item.originalImageUrl" absolute bottom-0 right-0 type="primary" size="tiny" color="#767c82" @click="showModal = true; showModalUrl = String(item.originalImageUrlPlus)">
查看原图
</n-button>
</div>
Expand Down Expand Up @@ -736,7 +745,7 @@ function getTimeDate(newDate: string, oldDate: string) {
:disabled="isSend"
show-count size="large"
:autosize="{ minRows: 1, maxRows: 7 }"
placeholder="来说点啥吧..... ( Ctrl + Enter = 发送 ) "
placeholder="来说点啥吧..... ( Ctrl + Enter = 换行 ) "
@keypress="handleEnter"
/>
<!-- :color="`${roomData.color}`" -->
Expand Down
8 changes: 8 additions & 0 deletions src/views/cellRoom/midjourney/types/apiTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ export interface RoomMidjourneyMsgVO {
* 压缩图片地址
*/
compressedImageUrl?: string
/**
* 处理过后的压缩图片地址
*/
compressedImageUrlPlus?: string
/**
* 创建时间
*/
Expand Down Expand Up @@ -123,6 +127,10 @@ export interface RoomMidjourneyMsgVO {
* 原始图片地址
*/
originalImageUrl?: string
/**
* 处理过后的原始图片地址
*/
originalImageUrlPlus?: string
/**
* 用户输入
*/
Expand Down
6 changes: 4 additions & 2 deletions src/views/cellRoom/newBing/api.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* @Author: mjjh
* @LastEditTime: 2023-07-04 22:02:33
* @FilePath: \ai-beehive-web\src\views\cellRoom\newBing\api.ts
* @LastEditTime: 2023-07-26 01:01:26
* @FilePath: \chatgpt-shuowen\src\views\cellRoom\newBing\api.ts
* @Description: 登录注册逻辑
*/
import type { RoomNewBingListRequest, sendRequest } from './types/apiTypes'
Expand All @@ -22,6 +22,7 @@ async function loadData(postData: sendRequest, returnData: Function) {
signal: controller.signal,
})
// 异常情况返回异常状态

if (response.status !== 200) {
const reader = (response as any).body.getReader()
const { value } = await reader.read()
Expand All @@ -33,6 +34,7 @@ async function loadData(postData: sendRequest, returnData: Function) {
let data = ''
while (true) {
const { done, value } = await reader.read()

if (done) {
returnData(data, done)
break
Expand Down
44 changes: 33 additions & 11 deletions src/views/cellRoom/newBing/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,20 @@ function getScrollData(e: any) {
loadingMore()
}
const sendData = ref(null)
const sendData = ref<string | null>(null)
const sendReturnData = ref(null)
const isSend = ref(false)
const isNewTopic = ref(false)
function handleEnter(event: KeyboardEvent) {
if (event.code === 'Enter' && event.ctrlKey) {
event.preventDefault()
sendClick()
if (event.code === 'Enter') {
if (event.ctrlKey) {
sendData.value = `${sendData.value}\n`
}
else {
event.preventDefault()
sendClick()
}
}
}
Expand Down Expand Up @@ -174,7 +179,8 @@ async function getNewData() {
}
const { data } = await api.getRoomNewBingList(pushData)
if (data.length < 2)
// todo
if (data.length < 1)
break
// 往栈存数据
Expand All @@ -201,12 +207,18 @@ async function changData(talkdata: any, done = false) {
const lastIndex = talkdata.lastIndexOf('\n', talkdata.length - 2)
try {
if (lastIndex !== -1)
sendReturnData.value = JSON.parse(talkdata.substring(lastIndex)).data.content
if (lastIndex !== -1) { sendReturnData.value = JSON.parse(talkdata.substring(lastIndex)).data.content }
else {
// await getNewData()
// 重置数据
sendData.value = null
sendReturnData.value = null
isSend.value = false
}
}
catch (error) {
// json转换错误 (我只要不打印就没人知道,,,,,)
// console.error('error', error)
console.error('error', error)
}
}
}
Expand Down Expand Up @@ -263,6 +275,11 @@ async function changData(talkdata: any, done = false) {
</n-ellipsis>
<div flex justify-start m-r-70>
<MdEditor v-model="item.content" preview-only :theme="themeStyle" rd-10 inline-block break-all card-shadow />
<div w-50 flex items-center ml-10>
<span>{{ item.numUserMessagesInConversation }}</span>
<span>{{ item.maxNumUserMessagesInConversation }}</span>
</div>
</div>
</div>
</div>
Expand Down Expand Up @@ -316,13 +333,18 @@ async function changData(talkdata: any, done = false) {
</div>
</div>
<!-- 与输入框的距离 -->
<!-- <div h-500 /> -->
<div h-50 />
</div>
<div>
<!-- todo NAutoComplete / 提示 -->
<!-- v-model:value="searchValue" -->
<!-- :on-input="searchClick" -->
<div p-10 flex items-center>
<div p-10 flex items-center relative>
<div absolute top--30 flex content-between>
<n-tag v-for="(item, index) of (messageList[messageList.length - 1]?.suggestResponses ?? [])" :key="index" m-r-10 :bordered="false" type="info" @click="sendData = item, sendClick()">
{{ item }}
</n-tag>
</div>
<div>
<!-- :rail-style="railStyle" -->
<n-switch v-model:value="isNewTopic" size="large" w-100>
Expand All @@ -340,7 +362,7 @@ async function changData(talkdata: any, done = false) {
:disabled="isSend"
show-count size="large"
:autosize="{ minRows: 1, maxRows: 8 }"
placeholder="来说点啥吧..... ( Ctrl + Enter = 发送 ) "
placeholder="来说点啥吧..... ( Ctrl + Enter = 换行 ) "
@keypress="handleEnter"
/>
<!-- :color="`${roomData.color}`" -->
Expand Down
22 changes: 20 additions & 2 deletions src/views/cellRoom/newBing/types/apiTypes.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*
* @Author: mjjh
* @LastEditTime: 2023-07-26 00:43:49
* @FilePath: \chatgpt-shuowen\src\views\cellRoom\newBing\types\apiTypes.ts
* @Description:
*/
export interface RoomNewBingListRequest {
cursor: string
isAsc: boolean
Expand Down Expand Up @@ -29,8 +35,8 @@ export interface RoomNewBingResponse {
*/
export interface RoomNewBingMsgVO {
/**
* 消息内容
*/
* 消息内容
*/
content?: string
/**
* 创建时间
Expand All @@ -40,6 +46,18 @@ export interface RoomNewBingMsgVO {
* 主键
*/
id?: number
/**
* 最大提问次数
*/
maxNumUserMessagesInConversation?: number
/**
* 累计提问次数
*/
numUserMessagesInConversation?: number
/**
* 建议
*/
suggestResponses?: string[]
/**
* 消息类型
*/
Expand Down
15 changes: 10 additions & 5 deletions src/views/cellRoom/openaiChat/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,19 @@ function getScrollData(e: any) {
loadingMore()
}
const sendData = ref(null)
const sendData = ref<string | null>(null)
const sendReturnData = ref(null)
const isSend = ref(false)
function handleEnter(event: KeyboardEvent) {
if (event.code === 'Enter' && event.ctrlKey) {
event.preventDefault()
sendClick()
if (event.code === 'Enter') {
if (event.ctrlKey) {
sendData.value = `${sendData.value}\n`
}
else {
event.preventDefault()
sendClick()
}
}
}
Expand Down Expand Up @@ -301,7 +306,7 @@ async function changData(talkdata: any, done = false) {
:disabled="isSend"
show-count size="large"
:autosize="{ minRows: 1, maxRows: 8 }"
placeholder="来说点啥吧..... ( Ctrl + Enter = 发送 ) "
placeholder="来说点啥吧..... ( Ctrl + Enter = 换行 ) "
@keypress="handleEnter"
/>
<!-- :color="`${roomData.color}`" -->
Expand Down
Loading

0 comments on commit b30c6f5

Please sign in to comment.