Skip to content

Commit

Permalink
fix: fix chunk err
Browse files Browse the repository at this point in the history
  • Loading branch information
boxizen committed May 5, 2023
1 parent 047057a commit bbeae87
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/components/Setting/Account/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export default function () {
</Form.Item>
<Form.Item
label={t('Model')}
name="Model"
name="model"
style={{ marginBottom: 12 }}
>
<Select>
Expand Down
8 changes: 7 additions & 1 deletion src/electron/apis/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ export default async (req: any, res: any) => {
res.end()
})
} catch (e) {
res.write(e)
if (e instanceof Error) {
res.write(e.message)
res.end()
} else {
res.write(JSON.stringify(e))
res.end()
}
}
}
17 changes: 10 additions & 7 deletions src/electron/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { getChatList, getPluginPrompt } from './client/store'
const { Configuration, OpenAIApi } = require('openai')
const store = new Store()
let openai = null as any
let prevBasePath: string
let prevApiKey: string

function getContextual(prompt: PresetType) {
const num = (store.get(StoreKey.Set_Contexual) as number) || 0
Expand Down Expand Up @@ -62,22 +64,23 @@ export function generatePayload(content: string, prompt: PresetType) {
}

export function getAiInstance() {
if (openai) {
return openai
}

const basePath = store.get(StoreKey.Set_BasePath) as string
const apiKey = store.get(StoreKey.Set_ApiKey) as string
Logger.log('store apikey', apiKey)
Logger.log('basePath', basePath)

if (openai && prevApiKey === apiKey && prevBasePath === basePath) {
return openai
}

if (apiKey) {
const _basePath = basePath || 'https://closeai.deno.dev'
openai = new OpenAIApi(
new Configuration({
apiKey,
basePath: (basePath || 'https://closeai.deno.dev') + '/v1',
basePath: _basePath + '/v1',
})
)
prevApiKey = apiKey
prevBasePath = _basePath
return openai
}
return null
Expand Down

0 comments on commit bbeae87

Please sign in to comment.