Skip to content

Commit 0547cac

Browse files
authored
Merge pull request #4480 from janhq/chore/correct-mistral-ai-request-transformation-template
chore: remote provider error handling and chore bug fix
2 parents f0bd239 + b81516a commit 0547cac

File tree

4 files changed

+14
-52
lines changed

4 files changed

+14
-52
lines changed

core/src/browser/extensions/engines/helpers/sse.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,12 @@ export function requestInference(
9191
const toParse = cachedLines + line
9292
if (!line.includes('data: [DONE]')) {
9393
const data = JSON.parse(toParse.replace('data: ', ''))
94-
if ('error' in data) {
95-
subscriber.error(data.error)
94+
if (
95+
'error' in data ||
96+
'message' in data ||
97+
'detail' in data
98+
) {
99+
subscriber.error(data.error ?? data)
96100
subscriber.complete()
97101
return
98102
}

extensions/engine-management-extension/resources/mistral.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"transform_req": {
1111
"chat_completions": {
1212
"url": "https://api.mistral.ai/v1/chat/completions",
13-
"template": "{{tojson(input_request)}}"
13+
"template": "{ {% set first = true %} {% for key, value in input_request %} {% if key == \"messages\" or key == \"model\" or key == \"temperature\" or key == \"store\" or key == \"max_tokens\" or key == \"stream\" or key == \"presence_penalty\" or key == \"metadata\" or key == \"frequency_penalty\" or key == \"tools\" or key == \"tool_choice\" or key == \"logprobs\" or key == \"top_logprobs\" or key == \"logit_bias\" or key == \"n\" or key == \"modalities\" or key == \"prediction\" or key == \"response_format\" or key == \"service_tier\" or key == \"seed\" or key == \"stop\" or key == \"stream_options\" or key == \"top_p\" or key == \"parallel_tool_calls\" or key == \"user\" %} {% if not first %},{% endif %} \"{{ key }}\": {{ tojson(value) }} {% set first = false %} {% endif %} {% endfor %} }"
1414
}
1515
},
1616
"transform_resp": {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.0.9-rc3
1+
1.0.9-rc4

web/screens/Settings/MyModels/index.tsx

Lines changed: 6 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ import {
3636

3737
import MyModelList from './MyModelList'
3838

39-
import { extensionManager } from '@/extension'
40-
4139
import {
4240
downloadedModelsAtom,
4341
showEngineListModelAtom,
@@ -52,9 +50,6 @@ const MyModels = () => {
5250
showEngineListModelAtom
5351
)
5452

55-
const [extensionHasSettings, setExtensionHasSettings] = useState<
56-
{ name?: string; setting: string; apiKey: string; provider: string }[]
57-
>([])
5853
const { engines } = useGetEngines()
5954

6055
const isLocalEngine = useCallback(
@@ -97,45 +92,6 @@ const MyModels = () => {
9792
setSearchText(input)
9893
}, [])
9994

100-
useEffect(() => {
101-
const getAllSettings = async () => {
102-
const extensionsMenu: {
103-
name?: string
104-
setting: string
105-
apiKey: string
106-
provider: string
107-
}[] = []
108-
const extensions = extensionManager.getAll()
109-
110-
for (const extension of extensions) {
111-
if (typeof extension.getSettings === 'function') {
112-
const settings = await extension.getSettings()
113-
114-
if (
115-
(settings && settings.length > 0) ||
116-
(await extension.installationState()) !== 'NotRequired'
117-
) {
118-
extensionsMenu.push({
119-
name: extension.productName,
120-
setting: extension.name,
121-
apiKey:
122-
'apiKey' in extension && typeof extension.apiKey === 'string'
123-
? extension.apiKey
124-
: '',
125-
provider:
126-
'provider' in extension &&
127-
typeof extension.provider === 'string'
128-
? extension.provider
129-
: '',
130-
})
131-
}
132-
}
133-
}
134-
setExtensionHasSettings(extensionsMenu)
135-
}
136-
getAllSettings()
137-
}, [])
138-
13995
const findByEngine = filteredDownloadedModels.map((x) => {
14096
// Legacy engine support - they will be grouped under Cortex LlamaCPP
14197
if (x.engine === InferenceEngine.nitro)
@@ -158,17 +114,19 @@ const MyModels = () => {
158114
}
159115
})
160116

161-
const getEngineStatusReady: InferenceEngine[] = extensionHasSettings
162-
?.filter((e) => e.apiKey.length > 0)
163-
.map((x) => x.provider as InferenceEngine)
117+
const getEngineStatusReady: InferenceEngine[] = Object.entries(engines ?? {})
118+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
119+
?.filter(([_, value]) => (value?.[0]?.api_key?.length ?? 0) > 0)
120+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
121+
.map(([key, _]) => key as InferenceEngine)
164122

165123
useEffect(() => {
166124
setShowEngineListModel((prev) => [
167125
...prev,
168126
...(getEngineStatusReady as InferenceEngine[]),
169127
])
170128
// eslint-disable-next-line react-hooks/exhaustive-deps
171-
}, [setShowEngineListModel, extensionHasSettings])
129+
}, [setShowEngineListModel, engines])
172130

173131
return (
174132
<div {...getRootProps()} className="h-full w-full">

0 commit comments

Comments
 (0)