-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create model service to allow dynamic model fetching for audio to tex…
…t functionality
- Loading branch information
1 parent
ddfdfbe
commit 91921f8
Showing
3 changed files
with
60 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { ChatCraftProvider } from "./ChatCraftProvider"; | ||
import { getSettings } from "./settings"; | ||
import { isSpeechToTextModel } from "./ai"; | ||
|
||
export class ModelService { | ||
static async getSpeechToTextClient() { | ||
const settings = getSettings(); | ||
const provider = settings.currentProvider; | ||
|
||
if (!provider.apiKey) { | ||
return null; | ||
} | ||
|
||
return provider.createClient(provider.apiKey).openai; | ||
} | ||
|
||
static async getSpeechToTextModel(provider: ChatCraftProvider): Promise<string | null> { | ||
if (!provider.apiKey) { | ||
return null; | ||
} | ||
const models: string[] = await provider.queryModels(provider.apiKey); | ||
const sttModel = models.find((model) => isSpeechToTextModel(model)); | ||
return sttModel || null; | ||
} | ||
|
||
static async isSpeechToTextSupported(provider: ChatCraftProvider): Promise<boolean> { | ||
if (!provider.apiKey) { | ||
return false; | ||
} | ||
const models: string[] = await provider.queryModels(provider.apiKey); | ||
return models.some((model) => isSpeechToTextModel(model)); | ||
} | ||
} |