Skip to content

Commit

Permalink
allow filling in the API Key of CustomModel mode (#561, previously de…
Browse files Browse the repository at this point in the history
…signed 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))
  • Loading branch information
josStorer committed Nov 13, 2023
1 parent 946cadc commit d0fbc9f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
8 changes: 7 additions & 1 deletion src/background/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,13 @@ async function executeApi(session, port, config) {
session.modelName,
)
} else if (customApiModelKeys.includes(session.modelName)) {
await generateAnswersWithCustomApi(port, session.question, session, '', config.customModelName)
await generateAnswersWithCustomApi(
port,
session.question,
session,
config.customApiKey,
config.customModelName,
)
} else if (azureOpenAiApiModelKeys.includes(session.modelName)) {
await generateAnswersWithAzureOpenaiApi(port, session.question, session)
} else if (claudeApiModelKeys.includes(session.modelName)) {
Expand Down
12 changes: 9 additions & 3 deletions src/config/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@ export const Models = {
chatgptApi4_8k_0613: { value: 'gpt-4', desc: 'ChatGPT (GPT-4-8k 0613)' },
chatgptApi4_32k: { value: 'gpt-4-32k', desc: 'ChatGPT (GPT-4-32k)' },
chatgptApi4_32k_0613: { value: 'gpt-4-32k', desc: 'ChatGPT (GPT-4-32k 0613)' },
chatgptApi4_128k_preview: { value: 'gpt-4-1106-preview', desc: 'ChatGPT (GPT-4-Turbo 128k Preview)' },
chatgptApi4_128k_preview: {
value: 'gpt-4-1106-preview',
desc: 'ChatGPT (GPT-4-Turbo 128k Preview)',
},
gptApiDavinci: { value: 'text-davinci-003', desc: 'GPT-3.5' },
customModel: { value: '', desc: 'Custom Model' },
azureOpenAi: { value: '', desc: 'ChatGPT (Azure)' },
Expand Down Expand Up @@ -149,11 +152,14 @@ export const defaultConfig = {
poeCustomBotName: '',

claudeApiKey: '',

customApiKey: '',

/** @type {keyof ModelMode}*/
modelMode: 'balanced',

customModelApiUrl: 'http://localhost:8000/chat/completions',
customModelName: 'rwkv',
customModelApiUrl: 'http://localhost:8000/v1/chat/completions',
customModelName: 'gpt-3.5-turbo',
githubThirdPartyUrl: 'http://127.0.0.1:3000/conversation',

// advanced
Expand Down
11 changes: 11 additions & 0 deletions src/popup/sections/GeneralPart.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,17 @@ export function GeneralPart({ config, updateConfig }) {
}}
/>
)}
{isUsingCustomModel(config) && (
<input
type="password"
value={config.customApiKey}
placeholder={t('API Key')}
onChange={(e) => {
const apiKey = e.target.value
updateConfig({ customApiKey: apiKey })
}}
/>
)}
{isUsingAzureOpenAi(config) && (
<input
type="password"
Expand Down
4 changes: 2 additions & 2 deletions src/services/apis/custom-api.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { getUserConfig } from '../../config/index.mjs'
import { fetchSSE } from '../../utils/fetch-sse.mjs'
import { getConversationPairs } from '../../utils/get-conversation-pairs.mjs'
import { isEmpty } from 'lodash-es'
import { getCustomApiPromptBase, pushRecord, setAbortController } from './shared.mjs'
import { pushRecord, setAbortController } from './shared.mjs'

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

Expand Down

0 comments on commit d0fbc9f

Please sign in to comment.