mirror of
https://github.com/wassname/chatGPTBox.git
synced 2026-08-19 12:00:17 +08:00
feat: retry button
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import BingAIClient from '../clients/BingAIClient'
|
||||
import { getUserConfig } from '../../config/index.mjs'
|
||||
import { pushRecord } from './shared.mjs'
|
||||
|
||||
/**
|
||||
* @param {Runtime.Port} port
|
||||
@@ -63,7 +64,7 @@ export async function generateAnswersWithBingWebApi(
|
||||
session.bingWeb.clientId = response.clientId
|
||||
session.bingWeb.invocationId = response.invocationId
|
||||
|
||||
session.conversationRecords.push({ question: question, answer: answer })
|
||||
pushRecord(session, question, answer)
|
||||
console.debug('conversation history', { content: session.conversationRecords })
|
||||
port.onMessage.removeListener(stopListener)
|
||||
port.postMessage({ answer: answer, done: true, session: session })
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
import { fetchSSE } from '../../utils/fetch-sse'
|
||||
import { isEmpty } from 'lodash-es'
|
||||
import { chatgptWebModelKeys, getUserConfig, Models } from '../../config/index.mjs'
|
||||
import { pushRecord } from './shared.mjs'
|
||||
|
||||
async function request(token, method, path, data) {
|
||||
const apiUrl = (await getUserConfig()).customChatGptWebApiUrl
|
||||
@@ -105,7 +106,7 @@ export async function generateAnswersWithChatgptWebApi(port, question, session,
|
||||
onMessage(message) {
|
||||
console.debug('sse message', message)
|
||||
if (message === '[DONE]') {
|
||||
session.conversationRecords.push({ question: question, answer: answer })
|
||||
pushRecord(session, question, answer)
|
||||
console.debug('conversation history', { content: session.conversationRecords })
|
||||
port.postMessage({ answer: null, done: true, session: session })
|
||||
return
|
||||
|
||||
@@ -9,6 +9,7 @@ import { getUserConfig, maxResponseTokenLength } from '../../config/index.mjs'
|
||||
import { fetchSSE } from '../../utils/fetch-sse'
|
||||
import { getConversationPairs } from '../../utils/get-conversation-pairs'
|
||||
import { isEmpty } from 'lodash-es'
|
||||
import { pushRecord } from './shared.mjs'
|
||||
|
||||
const getCustomApiPromptBase = async () => {
|
||||
return `I am a helpful, creative, clever, and very friendly assistant. I am familiar with various languages in the world.`
|
||||
@@ -59,7 +60,7 @@ export async function generateAnswersWithCustomApi(port, question, session, apiK
|
||||
onMessage(message) {
|
||||
console.debug('sse message', message)
|
||||
if (message === '[DONE]') {
|
||||
session.conversationRecords.push({ question: question, answer: answer })
|
||||
pushRecord(session, question, answer)
|
||||
console.debug('conversation history', { content: session.conversationRecords })
|
||||
port.postMessage({ answer: null, done: true, session: session })
|
||||
return
|
||||
|
||||
@@ -4,6 +4,7 @@ import { maxResponseTokenLength, Models, getUserConfig } from '../../config/inde
|
||||
import { fetchSSE } from '../../utils/fetch-sse'
|
||||
import { getConversationPairs } from '../../utils/get-conversation-pairs'
|
||||
import { isEmpty } from 'lodash-es'
|
||||
import { pushRecord } from './shared.mjs'
|
||||
|
||||
const getChatgptPromptBase = async () => {
|
||||
return `You are a helpful, creative, clever, and very friendly assistant. You are familiar with various languages in the world.`
|
||||
@@ -72,7 +73,7 @@ export async function generateAnswersWithGptCompletionApi(
|
||||
onMessage(message) {
|
||||
console.debug('sse message', message)
|
||||
if (message === '[DONE]') {
|
||||
session.conversationRecords.push({ question: question, answer: answer })
|
||||
pushRecord(session, question, answer)
|
||||
console.debug('conversation history', { content: session.conversationRecords })
|
||||
port.postMessage({ answer: null, done: true, session: session })
|
||||
return
|
||||
@@ -148,7 +149,7 @@ export async function generateAnswersWithChatgptApi(port, question, session, api
|
||||
onMessage(message) {
|
||||
console.debug('sse message', message)
|
||||
if (message === '[DONE]') {
|
||||
session.conversationRecords.push({ question: question, answer: answer })
|
||||
pushRecord(session, question, answer)
|
||||
console.debug('conversation history', { content: session.conversationRecords })
|
||||
port.postMessage({ answer: null, done: true, session: session })
|
||||
return
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
export function pushRecord(session, question, answer) {
|
||||
const recordLength = session.conversationRecords.length
|
||||
let lastRecord
|
||||
if (recordLength > 0) lastRecord = session.conversationRecords[recordLength - 1]
|
||||
|
||||
if (session.isRetry && lastRecord && lastRecord.question === question) lastRecord.answer = answer
|
||||
else session.conversationRecords.push({ question: question, answer: answer })
|
||||
}
|
||||
Reference in New Issue
Block a user