mirror of
https://github.com/wassname/chatGPTBox.git
synced 2026-08-05 12:50:41 +08:00
support moonshot
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
import { generateAnswersWithChatgptApiCompat } from './openai-api.mjs'
|
||||
|
||||
/**
|
||||
* @param {Browser.Runtime.Port} port
|
||||
* @param {string} question
|
||||
* @param {Session} session
|
||||
* @param {string} apiKey
|
||||
* @param {string} modelName
|
||||
*/
|
||||
export async function generateAnswersWithMoonshotCompletionApi(
|
||||
port,
|
||||
question,
|
||||
session,
|
||||
apiKey,
|
||||
modelName,
|
||||
) {
|
||||
const baseUrl = 'https://api.moonshot.cn'
|
||||
return generateAnswersWithChatgptApiCompat(baseUrl, port, question, session, apiKey, modelName)
|
||||
}
|
||||
@@ -95,6 +95,25 @@ export async function generateAnswersWithGptCompletionApi(
|
||||
* @param {string} modelName
|
||||
*/
|
||||
export async function generateAnswersWithChatgptApi(port, question, session, apiKey, modelName) {
|
||||
const config = await getUserConfig()
|
||||
return generateAnswersWithChatgptApiCompat(
|
||||
config.customOpenAiApiUrl,
|
||||
port,
|
||||
question,
|
||||
session,
|
||||
apiKey,
|
||||
modelName,
|
||||
)
|
||||
}
|
||||
|
||||
export async function generateAnswersWithChatgptApiCompat(
|
||||
baseUrl,
|
||||
port,
|
||||
question,
|
||||
session,
|
||||
apiKey,
|
||||
modelName,
|
||||
) {
|
||||
const { controller, messageListener, disconnectListener } = setAbortController(port)
|
||||
|
||||
const config = await getUserConfig()
|
||||
@@ -104,10 +123,9 @@ export async function generateAnswersWithChatgptApi(port, question, session, api
|
||||
)
|
||||
prompt.unshift({ role: 'system', content: await getChatSystemPromptBase() })
|
||||
prompt.push({ role: 'user', content: question })
|
||||
const apiUrl = config.customOpenAiApiUrl
|
||||
|
||||
let answer = ''
|
||||
await fetchSSE(`${apiUrl}/v1/chat/completions`, {
|
||||
await fetchSSE(`${baseUrl}/v1/chat/completions`, {
|
||||
method: 'POST',
|
||||
signal: controller.signal,
|
||||
headers: {
|
||||
|
||||
Reference in New Issue
Block a user