Skip to content

Commit 5060839

Browse files
committed
feat(ai-completion): use env variable extends apikey
1 parent fa9d61b commit 5060839

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

packages/common/js/completion.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,13 +188,17 @@ const generateBaseReference = () => {
188188
}
189189

190190
const fetchAiInlineCompletion = (codeBeforeCursor, codeAfterCursor) => {
191-
const { modelName, apiKey, url } = getMergeMeta('engine.plugins.pagecontroller')?.options?.AIModel || {}
192-
if (!modelName || !apiKey || !url) {
193-
throw new Error(`"modelName","apiKey","url" cannot be empty`)
191+
const { modelName, url, baseUrl } = getMergeMeta('engine.plugins.pagecontroller')?.options?.AIModel || {}
192+
const apiKey = import.meta.env.VITE_API_TPKEN
193+
if (!modelName || !apiKey) {
194+
throw new Error(`"modelName" & "apiKey" cannot be empty`)
195+
}
196+
if (!url && !baseUrl) {
197+
throw new Error(`"url" or "baseUrl" cannot be empty`)
194198
}
195199
const referenceContext = generateBaseReference()
196200
return getMetaApi(META_SERVICE.Http).post(
197-
url,
201+
url || `${baseUrl}/chat/completions`,
198202
{
199203
model: modelName,
200204
messages: [

packages/plugins/script/meta.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ export default {
99
enableAICompletion: true,
1010
AIModel: {
1111
modelName: 'internvl3-14b',
12-
apiKey: 'sk-1234',
13-
url: 'https://agent.opentiny.design/api/v1/ai/chat/completions'
12+
baseUrl: 'https://agent.opentiny.design/api/v1/ai',
13+
url: ''
1414
}
1515
},
1616
confirm: 'close' // 当点击插件栏切换或关闭前是否需要确认, 会调用插件中confirm值指定的方法,e.g. 此处指向 close方法,会调用插件的close方法执行确认逻辑

0 commit comments

Comments
 (0)