Skip to content

Commit

Permalink
Merge pull request #4480 from janhq/chore/correct-mistral-ai-request-…
Browse files Browse the repository at this point in the history
…transformation-template

chore: remote provider error handling and chore bug fix
  • Loading branch information
louis-jan authored Jan 17, 2025
2 parents f0bd239 + b81516a commit 0547cac
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 52 deletions.
8 changes: 6 additions & 2 deletions core/src/browser/extensions/engines/helpers/sse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,12 @@ export function requestInference(
const toParse = cachedLines + line
if (!line.includes('data: [DONE]')) {
const data = JSON.parse(toParse.replace('data: ', ''))
if ('error' in data) {
subscriber.error(data.error)
if (
'error' in data ||
'message' in data ||
'detail' in data
) {
subscriber.error(data.error ?? data)
subscriber.complete()
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"transform_req": {
"chat_completions": {
"url": "https://api.mistral.ai/v1/chat/completions",
"template": "{{tojson(input_request)}}"
"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 %} }"
}
},
"transform_resp": {
Expand Down
2 changes: 1 addition & 1 deletion extensions/inference-cortex-extension/bin/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.9-rc3
1.0.9-rc4
54 changes: 6 additions & 48 deletions web/screens/Settings/MyModels/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ import {

import MyModelList from './MyModelList'

import { extensionManager } from '@/extension'

import {
downloadedModelsAtom,
showEngineListModelAtom,
Expand All @@ -52,9 +50,6 @@ const MyModels = () => {
showEngineListModelAtom
)

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

const isLocalEngine = useCallback(
Expand Down Expand Up @@ -97,45 +92,6 @@ const MyModels = () => {
setSearchText(input)
}, [])

useEffect(() => {
const getAllSettings = async () => {
const extensionsMenu: {
name?: string
setting: string
apiKey: string
provider: string
}[] = []
const extensions = extensionManager.getAll()

for (const extension of extensions) {
if (typeof extension.getSettings === 'function') {
const settings = await extension.getSettings()

if (
(settings && settings.length > 0) ||
(await extension.installationState()) !== 'NotRequired'
) {
extensionsMenu.push({
name: extension.productName,
setting: extension.name,
apiKey:
'apiKey' in extension && typeof extension.apiKey === 'string'
? extension.apiKey
: '',
provider:
'provider' in extension &&
typeof extension.provider === 'string'
? extension.provider
: '',
})
}
}
}
setExtensionHasSettings(extensionsMenu)
}
getAllSettings()
}, [])

const findByEngine = filteredDownloadedModels.map((x) => {
// Legacy engine support - they will be grouped under Cortex LlamaCPP
if (x.engine === InferenceEngine.nitro)
Expand All @@ -158,17 +114,19 @@ const MyModels = () => {
}
})

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

useEffect(() => {
setShowEngineListModel((prev) => [
...prev,
...(getEngineStatusReady as InferenceEngine[]),
])
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [setShowEngineListModel, extensionHasSettings])
}, [setShowEngineListModel, engines])

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

0 comments on commit 0547cac

Please sign in to comment.