Skip to content

Commit d0fbc9f

Browse files
committed
allow filling in the API Key of CustomModel mode (#561, previously designed for local offline model or custom server, now you can also use it for regular openai API calls and freely fill in the model name(#563))
1 parent 946cadc commit d0fbc9f

File tree

4 files changed

+29
-6
lines changed

4 files changed

+29
-6
lines changed

src/background/index.mjs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,13 @@ async function executeApi(session, port, config) {
111111
session.modelName,
112112
)
113113
} else if (customApiModelKeys.includes(session.modelName)) {
114-
await generateAnswersWithCustomApi(port, session.question, session, '', config.customModelName)
114+
await generateAnswersWithCustomApi(
115+
port,
116+
session.question,
117+
session,
118+
config.customApiKey,
119+
config.customModelName,
120+
)
115121
} else if (azureOpenAiApiModelKeys.includes(session.modelName)) {
116122
await generateAnswersWithAzureOpenaiApi(port, session.question, session)
117123
} else if (claudeApiModelKeys.includes(session.modelName)) {

src/config/index.mjs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,10 @@ export const Models = {
9898
chatgptApi4_8k_0613: { value: 'gpt-4', desc: 'ChatGPT (GPT-4-8k 0613)' },
9999
chatgptApi4_32k: { value: 'gpt-4-32k', desc: 'ChatGPT (GPT-4-32k)' },
100100
chatgptApi4_32k_0613: { value: 'gpt-4-32k', desc: 'ChatGPT (GPT-4-32k 0613)' },
101-
chatgptApi4_128k_preview: { value: 'gpt-4-1106-preview', desc: 'ChatGPT (GPT-4-Turbo 128k Preview)' },
101+
chatgptApi4_128k_preview: {
102+
value: 'gpt-4-1106-preview',
103+
desc: 'ChatGPT (GPT-4-Turbo 128k Preview)',
104+
},
102105
gptApiDavinci: { value: 'text-davinci-003', desc: 'GPT-3.5' },
103106
customModel: { value: '', desc: 'Custom Model' },
104107
azureOpenAi: { value: '', desc: 'ChatGPT (Azure)' },
@@ -149,11 +152,14 @@ export const defaultConfig = {
149152
poeCustomBotName: '',
150153

151154
claudeApiKey: '',
155+
156+
customApiKey: '',
157+
152158
/** @type {keyof ModelMode}*/
153159
modelMode: 'balanced',
154160

155-
customModelApiUrl: 'http://localhost:8000/chat/completions',
156-
customModelName: 'rwkv',
161+
customModelApiUrl: 'http://localhost:8000/v1/chat/completions',
162+
customModelName: 'gpt-3.5-turbo',
157163
githubThirdPartyUrl: 'http://127.0.0.1:3000/conversation',
158164

159165
// advanced

src/popup/sections/GeneralPart.jsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,17 @@ export function GeneralPart({ config, updateConfig }) {
285285
}}
286286
/>
287287
)}
288+
{isUsingCustomModel(config) && (
289+
<input
290+
type="password"
291+
value={config.customApiKey}
292+
placeholder={t('API Key')}
293+
onChange={(e) => {
294+
const apiKey = e.target.value
295+
updateConfig({ customApiKey: apiKey })
296+
}}
297+
/>
298+
)}
288299
{isUsingAzureOpenAi(config) && (
289300
<input
290301
type="password"

src/services/apis/custom-api.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { getUserConfig } from '../../config/index.mjs'
99
import { fetchSSE } from '../../utils/fetch-sse.mjs'
1010
import { getConversationPairs } from '../../utils/get-conversation-pairs.mjs'
1111
import { isEmpty } from 'lodash-es'
12-
import { getCustomApiPromptBase, pushRecord, setAbortController } from './shared.mjs'
12+
import { pushRecord, setAbortController } from './shared.mjs'
1313

1414
/**
1515
* @param {Browser.Runtime.Port} port
@@ -26,7 +26,7 @@ export async function generateAnswersWithCustomApi(port, question, session, apiK
2626
session.conversationRecords.slice(-config.maxConversationContextLength),
2727
false,
2828
)
29-
prompt.unshift({ role: 'system', content: await getCustomApiPromptBase() })
29+
// prompt.unshift({ role: 'system', content: await getCustomApiPromptBase() })
3030
prompt.push({ role: 'user', content: question })
3131
const apiUrl = config.customModelApiUrl
3232

0 commit comments

Comments
 (0)