mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-04 15:14:10 +00:00
feat: configure embedding servers and transcript agents
This commit is contained in:
@@ -1,15 +1,18 @@
|
||||
import { getGemmaOpenAiBaseUrl } from '@shumai/core/src/search/gemma-embedding-endpoint'
|
||||
import {
|
||||
embeddingServerService,
|
||||
LOCAL_EMBEDDING_PROVIDER,
|
||||
} from '@shumai/core/src/search/embedding-server'
|
||||
import { transcriptLanguageCodeSchema, transcriptLanguagesSchema } from '@shumai/dtos'
|
||||
import { z } from 'zod'
|
||||
|
||||
const transcriptEndpoint = () => `${getGemmaOpenAiBaseUrl()}/audio/transcriptions`
|
||||
|
||||
export function isLocalTranscriptionEnabled(): boolean {
|
||||
return process.env.EMBEDDING_PROVIDER === 'gemma-embedding-2-openai'
|
||||
export async function isLocalTranscriptionEnabled(teamId?: string): Promise<boolean> {
|
||||
const { provider } = await embeddingServerService.resolveRuntimeConfig(teamId)
|
||||
return provider === LOCAL_EMBEDDING_PROVIDER
|
||||
}
|
||||
|
||||
export async function listLocalTranscriptionLanguages() {
|
||||
const response = await fetch(`${transcriptEndpoint()}/languages`, {
|
||||
export async function listLocalTranscriptionLanguages(teamId?: string) {
|
||||
const { transcriptionEndpoint } = await embeddingServerService.resolveRuntimeConfig(teamId)
|
||||
const response = await fetch(`${transcriptionEndpoint}/languages`, {
|
||||
signal: AbortSignal.timeout(5_000),
|
||||
})
|
||||
if (!response.ok) throw new Error(`Transcription languages endpoint returned ${response.status}`)
|
||||
@@ -34,11 +37,13 @@ export class LocalTranscriptionError extends Error {
|
||||
}
|
||||
|
||||
export async function transcribeLocalAudio({
|
||||
teamId,
|
||||
audio,
|
||||
language,
|
||||
model,
|
||||
signal,
|
||||
}: {
|
||||
teamId?: string
|
||||
audio: Blob
|
||||
language: string | null
|
||||
model: string
|
||||
@@ -51,7 +56,8 @@ export async function transcribeLocalAudio({
|
||||
if (language) form.set('language', language)
|
||||
|
||||
const timeout = AbortSignal.timeout(90 * 60 * 1000)
|
||||
const response = await fetch(transcriptEndpoint(), {
|
||||
const { transcriptionEndpoint } = await embeddingServerService.resolveRuntimeConfig(teamId)
|
||||
const response = await fetch(transcriptionEndpoint, {
|
||||
method: 'POST',
|
||||
body: form,
|
||||
redirect: 'error',
|
||||
|
||||
Reference in New Issue
Block a user