Skip to content

Commit

Permalink
fix: 修复maxsize溢出问题
Browse files Browse the repository at this point in the history
  • Loading branch information
chenweiyi committed Apr 16, 2024
1 parent 2947b44 commit 31e187e
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions packages/backend/src/service/thirdparty.mts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { ChatGPTAPI, ChatGPTUnofficialProxyAPI, ChatMessage } from 'chatgpt'
import debugLibrary from 'debug'
import proxy from 'https-proxy-agent'
import { isNil } from 'lodash-es'
import fetch from 'node-fetch'
import fetchApi from 'node-fetch'
import { getStore } from '../utils/store.mjs'

import { ISSEQuery } from '../controller/message.mjs'
import { hashString } from '../utils/util.mjs'

const debug = debugLibrary('service:thirdparty')
const chatgptApiMap = new Map<string, ChatGPTAPI | ChatGPTUnofficialProxyAPI>()
const chatgptApiMap = new Map<string, ChatGPTAPI>()

const getRestOptions = ({ parentMessageId }: { parentMessageId: string }) => {
return {
Expand Down Expand Up @@ -51,21 +51,25 @@ export async function responseChatgpt(
...options
}
// @ts-ignore
return fetch(url, mergedOptions)
return fetchApi(url, mergedOptions)
}
: undefined,
messageStore: getStore(sessionId)
}
debug('...chatOption: %o', chatOption)

const { fetch, messageStore, ...modelHash } = chatOption
// const { fetch, ...modelHash } = chatOption
const modelHashKey = hashString(modelHash)
let api: ChatGPTAPI | null = null
if (!chatgptApiMap.get(modelHashKey)) {
// @ts-ignore
const api = new ChatGPTAPI(chatOption)
chatgptApiMap.set(modelHashKey, api)
chatgptApiMap.set(modelHashKey, new ChatGPTAPI(chatOption))
}
api = chatgptApiMap.get(modelHashKey)
if (!api) {
throw new Error('api is null')
}
const api = chatgptApiMap.get(modelHashKey)
try {
debug('...input messages: %o', msg)
// @ts-ignore
Expand Down

0 comments on commit 31e187e

Please sign in to comment.