feat: initial commit for MediaGen AI project
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { StorageService } from './storage.service';
|
||||
import { OpenRouterService } from './openrouter.service';
|
||||
import { ReplicateService } from './replicate.service';
|
||||
import { AudioGenerationConfig, GenerationConfig, OpenRouterModel, ReferenceMedia, VideoGenerationConfig, VideoScriptResponse } from '../models/openrouter.models';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class AiProviderService {
|
||||
constructor(
|
||||
private storage: StorageService,
|
||||
private openRouter: OpenRouterService,
|
||||
private replicate: ReplicateService
|
||||
) {}
|
||||
|
||||
private getActiveService() {
|
||||
const provider = this.storage.getActiveProvider();
|
||||
return provider === 'replicate' ? this.replicate : this.openRouter;
|
||||
}
|
||||
|
||||
setVideoStatusCallback(cb: ((status: string, detail?: string) => void) | null) {
|
||||
this.openRouter.setVideoStatusCallback(cb);
|
||||
this.replicate.setVideoStatusCallback(cb);
|
||||
}
|
||||
|
||||
async generateImage(config: GenerationConfig): Promise<string> {
|
||||
config.apiKey = config.apiKey || this.storage.getApiKey();
|
||||
return this.getActiveService().generateImage(config);
|
||||
}
|
||||
|
||||
async generateVideo(config: VideoGenerationConfig): Promise<{ videoUrl?: string; content?: string; realCost?: number }> {
|
||||
config.apiKey = config.apiKey || this.storage.getApiKey();
|
||||
return this.getActiveService().generateVideo(config);
|
||||
}
|
||||
|
||||
async generateAudio(config: AudioGenerationConfig): Promise<{ audioUrl?: string; content?: string }> {
|
||||
config.apiKey = config.apiKey || this.storage.getApiKey();
|
||||
return this.getActiveService().generateAudio(config);
|
||||
}
|
||||
|
||||
async enhancePrompt(prompt: string, apiKey: string): Promise<string> {
|
||||
const activeApiKey = apiKey || this.storage.getApiKey();
|
||||
return this.getActiveService().enhancePrompt(prompt, activeApiKey);
|
||||
}
|
||||
|
||||
async generateVideoScript(concept: string, durationSeconds: number, apiKey: string, referenceImages?: string[], referenceItems?: ReferenceMedia[]): Promise<VideoScriptResponse> {
|
||||
const activeApiKey = apiKey || this.storage.getApiKey();
|
||||
return this.getActiveService().generateVideoScript(concept, durationSeconds, activeApiKey, referenceImages, referenceItems);
|
||||
}
|
||||
|
||||
async getModels(apiKey?: string): Promise<OpenRouterModel[]> {
|
||||
if (this.storage.getActiveProvider() === 'replicate') {
|
||||
return this.replicate.getModels();
|
||||
}
|
||||
const activeApiKey = apiKey || this.storage.getApiKey('openrouter');
|
||||
return this.openRouter.getModels(activeApiKey);
|
||||
}
|
||||
|
||||
getImageModels(models: OpenRouterModel[]): OpenRouterModel[] {
|
||||
return this.getActiveService().getImageModels(models);
|
||||
}
|
||||
|
||||
getVideoModels(models: OpenRouterModel[]): OpenRouterModel[] {
|
||||
return this.getActiveService().getVideoModels(models);
|
||||
}
|
||||
|
||||
getAudioModels(models: OpenRouterModel[]): OpenRouterModel[] {
|
||||
return this.getActiveService().getAudioModels(models);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user