Skip to content

Commit

Permalink
fix: api server chat completion error for remote model (janhq#2671)
Browse files Browse the repository at this point in the history
* fix: api server chat completion error for remote model

Signed-off-by: James <[email protected]>

* fix: duplicate setting in local api server

Signed-off-by: James <[email protected]>

---------

Signed-off-by: James <[email protected]>
Co-authored-by: James <[email protected]>
  • Loading branch information
namchuai and James authored Apr 10, 2024
1 parent c9332d6 commit 69f73b8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 18 deletions.
6 changes: 5 additions & 1 deletion core/src/node/helper/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ export const getEngineConfiguration = async (engineId: string) => {
const settingDirectoryPath = join(
getJanDataFolderPath(),
'settings',
'@janhq',
engineId === 'openai' ? 'inference-openai-extension' : 'inference-groq-extension',
'settings.json'
)
Expand All @@ -141,12 +142,15 @@ export const getEngineConfiguration = async (engineId: string) => {
const settings: SettingComponentProps[] = JSON.parse(content)
const apiKeyId = engineId === 'openai' ? 'openai-api-key' : 'groq-api-key'
const keySetting = settings.find((setting) => setting.key === apiKeyId)
let fullUrl = settings.find((setting) => setting.key === 'chat-completions-endpoint')
?.controllerProps.value

let apiKey = keySetting?.controllerProps.value
if (typeof apiKey !== 'string') apiKey = ''
if (typeof fullUrl !== 'string') fullUrl = ''

return {
api_key: apiKey,
full_url: undefined,
full_url: fullUrl,
}
}
40 changes: 23 additions & 17 deletions web/screens/LocalServer/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client'

import React, { useCallback, useEffect, useState } from 'react'
import React, { useCallback, useEffect, useMemo, useState } from 'react'

import ScrollToBottom from 'react-scroll-to-bottom'

Expand Down Expand Up @@ -45,7 +45,7 @@ import { loadModelErrorAtom, useActiveModel } from '@/hooks/useActiveModel'
import { useLogs } from '@/hooks/useLogs'

import { getConfigurationsData } from '@/utils/componentSettings'
import { toSettingParams } from '@/utils/modelParam'
import { toRuntimeParams, toSettingParams } from '@/utils/modelParam'

import EngineSetting from '../Chat/EngineSetting'

Expand Down Expand Up @@ -74,7 +74,13 @@ const LocalServerScreen = () => {
const selectedModel = useAtomValue(selectedModelAtom)

const modelEngineParams = toSettingParams(selectedModel?.settings)
const modelRuntimeParams = toRuntimeParams(selectedModel?.settings)

const componentDataEngineSetting = getConfigurationsData(modelEngineParams)
const componentDataRuntimeSetting = getConfigurationsData(
modelRuntimeParams,
selectedModel
)

const [isCorsEnabled, setIsCorsEnabled] = useAtom(apiServerCorsEnabledAtom)
const [isVerboseEnabled, setIsVerboseEnabled] = useAtom(
Expand Down Expand Up @@ -120,6 +126,17 @@ const LocalServerScreen = () => {
handleChangePrefix(prefix)
}, [handleChangePrefix, prefix])

const engineSettings = useMemo(
() => componentDataEngineSetting.filter((x) => x.key !== 'prompt_template'),
[componentDataEngineSetting]
)

const modelSettings = useMemo(() => {
return componentDataRuntimeSetting.filter(
(x) => x.key !== 'prompt_template'
)
}, [componentDataRuntimeSetting])

const onStartServerClick = async () => {
if (selectedModel == null) return
try {
Expand Down Expand Up @@ -474,32 +491,21 @@ const LocalServerScreen = () => {
</div>
)}

{componentDataEngineSetting.filter((x) => x.key === 'prompt_template')
.length !== 0 && (
{modelSettings.length !== 0 && (
<div className="mt-4">
<CardSidebar title="Model Parameters" asChild>
<div className="px-2 py-4">
<ModelSetting componentProps={componentDataEngineSetting} />
{/* <SettingComponentBuilder
enabled={!serverEnabled}
componentProps={componentDataEngineSetting}
onValueUpdated={function (
key: string,
value: string | number | boolean
): void {
throw new Error('Function not implemented.')
}}
/> */}
<ModelSetting componentProps={modelSettings} />
</div>
</CardSidebar>
</div>
)}

{componentDataEngineSetting.length !== 0 && (
{engineSettings.length !== 0 && (
<div className="my-4">
<CardSidebar title="Engine Parameters" asChild>
<div className="px-2 py-4">
<EngineSetting componentData={componentDataEngineSetting} />
<EngineSetting componentData={engineSettings} />
</div>
</CardSidebar>
</div>
Expand Down

0 comments on commit 69f73b8

Please sign in to comment.