mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-23 15:26:42 +02:00
✨ feat(bot-services): add API key support to TranscriptionService
- Add apiKey option to TranscriptionModuleOptions - Send X-API-Key header in all STT requests when configured - Support config via module options, stt.apiKey, or STT_API_KEY env var - Update CLAUDE.md documentation with API key usage example Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
32f84678f9
commit
0f24e085f6
3 changed files with 38 additions and 2 deletions
|
|
@ -27,6 +27,7 @@ export class TranscriptionService {
|
|||
private readonly logger = new Logger(TranscriptionService.name);
|
||||
private readonly sttUrl: string;
|
||||
private readonly defaultLanguage: string;
|
||||
private readonly apiKey: string;
|
||||
|
||||
constructor(
|
||||
@Optional() private configService: ConfigService,
|
||||
|
|
@ -41,6 +42,12 @@ export class TranscriptionService {
|
|||
|
||||
this.defaultLanguage = options?.defaultLanguage || 'de';
|
||||
|
||||
this.apiKey =
|
||||
options?.apiKey ||
|
||||
this.configService?.get<string>('stt.apiKey') ||
|
||||
this.configService?.get<string>('STT_API_KEY') ||
|
||||
'';
|
||||
|
||||
this.logger.log(`STT Service URL: ${this.sttUrl}`);
|
||||
}
|
||||
|
||||
|
|
@ -64,8 +71,14 @@ export class TranscriptionService {
|
|||
}
|
||||
|
||||
try {
|
||||
const headers: Record<string, string> = {};
|
||||
if (this.apiKey) {
|
||||
headers['X-API-Key'] = this.apiKey;
|
||||
}
|
||||
|
||||
const response = await fetch(`${this.sttUrl}/transcribe`, {
|
||||
method: 'POST',
|
||||
headers,
|
||||
body: formData,
|
||||
});
|
||||
|
||||
|
|
@ -102,8 +115,14 @@ export class TranscriptionService {
|
|||
}
|
||||
|
||||
try {
|
||||
const headers: Record<string, string> = {};
|
||||
if (this.apiKey) {
|
||||
headers['X-API-Key'] = this.apiKey;
|
||||
}
|
||||
|
||||
const response = await fetch(`${this.sttUrl}/transcribe`, {
|
||||
method: 'POST',
|
||||
headers,
|
||||
body: formData,
|
||||
});
|
||||
|
||||
|
|
@ -124,7 +143,12 @@ export class TranscriptionService {
|
|||
*/
|
||||
async checkHealth(): Promise<boolean> {
|
||||
try {
|
||||
const response = await fetch(`${this.sttUrl}/health`);
|
||||
const headers: Record<string, string> = {};
|
||||
if (this.apiKey) {
|
||||
headers['X-API-Key'] = this.apiKey;
|
||||
}
|
||||
|
||||
const response = await fetch(`${this.sttUrl}/health`, { headers });
|
||||
return response.ok;
|
||||
} catch {
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ export interface TranscriptionOptions {
|
|||
export interface TranscriptionModuleOptions {
|
||||
sttUrl?: string;
|
||||
defaultLanguage?: string;
|
||||
apiKey?: string;
|
||||
}
|
||||
|
||||
export const STT_MODULE_OPTIONS = 'STT_MODULE_OPTIONS';
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue