Commit e7284142 authored by StyleZhang's avatar StyleZhang

fix

parent 5a299625
...@@ -4,6 +4,7 @@ import uuid ...@@ -4,6 +4,7 @@ import uuid
from core.constant import llm_constant from core.constant import llm_constant
from models.account import Account from models.account import Account
from services.dataset_service import DatasetService from services.dataset_service import DatasetService
from core.llm.llm_builder import LLMBuilder
class AppModelConfigService: class AppModelConfigService:
...@@ -123,6 +124,11 @@ class AppModelConfigService: ...@@ -123,6 +124,11 @@ class AppModelConfigService:
if not isinstance(config["speech_to_text"]["enabled"], bool): if not isinstance(config["speech_to_text"]["enabled"], bool):
raise ValueError("enabled in speech_to_text must be of boolean type") raise ValueError("enabled in speech_to_text must be of boolean type")
provider_name = LLMBuilder.get_default_provider(account.current_tenant_id)
if config["speech_to_text"]["enabled"] and provider_name != 'openai':
raise ValueError("provider not support speech to text")
# more_like_this # more_like_this
if 'more_like_this' not in config or not config["more_like_this"]: if 'more_like_this' not in config or not config["more_like_this"]:
......
...@@ -4,6 +4,7 @@ from werkzeug.datastructures import FileStorage ...@@ -4,6 +4,7 @@ from werkzeug.datastructures import FileStorage
from core.llm.llm_builder import LLMBuilder from core.llm.llm_builder import LLMBuilder
from core.llm.provider.llm_provider_service import LLMProviderService from core.llm.provider.llm_provider_service import LLMProviderService
from services.errors.audio import NoAudioUploadedError, AudioTooLargeError, UnsupportedAudioTypeError from services.errors.audio import NoAudioUploadedError, AudioTooLargeError, UnsupportedAudioTypeError
from openai.error import InvalidRequestError
FILE_SIZE_LIMIT = 1 * 1024 * 1024 FILE_SIZE_LIMIT = 1 * 1024 * 1024
ALLOWED_EXTENSIONS = ['mp3', 'mp4', 'mpeg', 'mpga', 'm4a', 'wav', 'webm'] ALLOWED_EXTENSIONS = ['mp3', 'mp4', 'mpeg', 'mpga', 'm4a', 'wav', 'webm']
...@@ -32,7 +33,8 @@ class AudioService: ...@@ -32,7 +33,8 @@ class AudioService:
buffer = io.BytesIO(file_content) buffer = io.BytesIO(file_content)
buffer.name = 'temp.wav' buffer.name = 'temp.wav'
transcript = openai.Audio.transcribe( try:
transcript = openai.Audio.transcribe(
model='whisper-1', model='whisper-1',
file=buffer, file=buffer,
api_key=credentials.get('openai_api_key'), api_key=credentials.get('openai_api_key'),
...@@ -42,4 +44,11 @@ class AudioService: ...@@ -42,4 +44,11 @@ class AudioService:
params=params params=params
) )
return transcript return transcript
\ No newline at end of file except InvalidRequestError as e:
return {'message': str(e)}, 400
\ No newline at end of file
...@@ -21,6 +21,7 @@ export type IChooseFeatureProps = { ...@@ -21,6 +21,7 @@ export type IChooseFeatureProps = {
config: IConfig config: IConfig
isChatApp: boolean isChatApp: boolean
onChange: (key: string, value: boolean) => void onChange: (key: string, value: boolean) => void
showSpeechToTextItem?: boolean
} }
const OpeningStatementIcon = ( const OpeningStatementIcon = (
...@@ -35,6 +36,7 @@ const ChooseFeature: FC<IChooseFeatureProps> = ({ ...@@ -35,6 +36,7 @@ const ChooseFeature: FC<IChooseFeatureProps> = ({
isChatApp, isChatApp,
config, config,
onChange, onChange,
showSpeechToTextItem,
}) => { }) => {
const { t } = useTranslation() const { t } = useTranslation()
...@@ -71,14 +73,18 @@ const ChooseFeature: FC<IChooseFeatureProps> = ({ ...@@ -71,14 +73,18 @@ const ChooseFeature: FC<IChooseFeatureProps> = ({
value={config.suggestedQuestionsAfterAnswer} value={config.suggestedQuestionsAfterAnswer}
onChange={value => onChange('suggestedQuestionsAfterAnswer', value)} onChange={value => onChange('suggestedQuestionsAfterAnswer', value)}
/> />
<FeatureItem {
icon={<Microphone01 className='w-4 h-4 text-[#7839EE]' />} showSpeechToTextItem && (
previewImgClassName='speechToTextPreview' <FeatureItem
title={t('appDebug.feature.speechToText.title')} icon={<Microphone01 className='w-4 h-4 text-[#7839EE]' />}
description={t('appDebug.feature.speechToText.description')} previewImgClassName='speechToTextPreview'
value={config.speechToText} title={t('appDebug.feature.speechToText.title')}
onChange={value => onChange('speechToText', value)} description={t('appDebug.feature.speechToText.description')}
/> value={config.speechToText}
onChange={value => onChange('speechToText', value)}
/>
)
}
</> </>
</FeatureGroup> </FeatureGroup>
)} )}
......
...@@ -4,6 +4,7 @@ import React from 'react' ...@@ -4,6 +4,7 @@ import React from 'react'
import { useContext } from 'use-context-selector' import { useContext } from 'use-context-selector'
import produce from 'immer' import produce from 'immer'
import { useBoolean } from 'ahooks' import { useBoolean } from 'ahooks'
import useSWR from 'swr'
import DatasetConfig from '../dataset-config' import DatasetConfig from '../dataset-config'
import ChatGroup from '../features/chat-group' import ChatGroup from '../features/chat-group'
import ExperienceEnchanceGroup from '../features/experience-enchance-group' import ExperienceEnchanceGroup from '../features/experience-enchance-group'
...@@ -19,6 +20,7 @@ import ConfigPrompt from '@/app/components/app/configuration/config-prompt' ...@@ -19,6 +20,7 @@ import ConfigPrompt from '@/app/components/app/configuration/config-prompt'
import ConfigVar from '@/app/components/app/configuration/config-var' import ConfigVar from '@/app/components/app/configuration/config-var'
import type { PromptVariable } from '@/models/debug' import type { PromptVariable } from '@/models/debug'
import { AppType } from '@/types/app' import { AppType } from '@/types/app'
import { fetchTenantInfo } from '@/service/common'
const Config: FC = () => { const Config: FC = () => {
const { const {
...@@ -37,6 +39,8 @@ const Config: FC = () => { ...@@ -37,6 +39,8 @@ const Config: FC = () => {
setSpeechToTextConfig, setSpeechToTextConfig,
} = useContext(ConfigContext) } = useContext(ConfigContext)
const isChatApp = mode === AppType.chat const isChatApp = mode === AppType.chat
const { data: userInfo } = useSWR({ url: '/info' }, fetchTenantInfo)
const targetProvider = userInfo?.providers?.find(({ token_is_set, is_valid }) => token_is_set && is_valid)
const promptTemplate = modelConfig.configs.prompt_template const promptTemplate = modelConfig.configs.prompt_template
const promptVariables = modelConfig.configs.prompt_variables const promptVariables = modelConfig.configs.prompt_variables
...@@ -88,7 +92,7 @@ const Config: FC = () => { ...@@ -88,7 +92,7 @@ const Config: FC = () => {
}, },
}) })
const hasChatConfig = isChatApp && (featureConfig.openingStatement || featureConfig.suggestedQuestionsAfterAnswer || featureConfig.speechToText) const hasChatConfig = isChatApp && (featureConfig.openingStatement || featureConfig.suggestedQuestionsAfterAnswer || (featureConfig.speechToText && targetProvider?.provider_name === 'openai'))
const hasToolbox = false const hasToolbox = false
const [showAutomatic, { setTrue: showAutomaticTrue, setFalse: showAutomaticFalse }] = useBoolean(false) const [showAutomatic, { setTrue: showAutomaticTrue, setFalse: showAutomaticFalse }] = useBoolean(false)
...@@ -118,6 +122,7 @@ const Config: FC = () => { ...@@ -118,6 +122,7 @@ const Config: FC = () => {
isChatApp={isChatApp} isChatApp={isChatApp}
config={featureConfig} config={featureConfig}
onChange={handleFeatureChange} onChange={handleFeatureChange}
showSpeechToTextItem={targetProvider?.provider_name === 'openai'}
/> />
)} )}
{showAutomatic && ( {showAutomatic && (
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment