18 lines
551 B
TypeScript
18 lines
551 B
TypeScript
import { generateSongs } from "../ai-selector.ts";
|
|
import { searchSpotifyTracks } from "../spotify-api.ts";
|
|
import { GetSongsTextOutput, GetSongsTextParams } from "../types/api.ts";
|
|
|
|
export async function getSong(
|
|
params: GetSongsTextParams,
|
|
): Promise<GetSongsTextOutput> {
|
|
const ai_response = await generateSongs(params.prompt, params.rules);
|
|
if (ai_response.type == "error") {
|
|
return ai_response;
|
|
}
|
|
|
|
const spotifyResults = await searchSpotifyTracks(
|
|
ai_response.songs,
|
|
);
|
|
|
|
return { type: "success", songs: spotifyResults };
|
|
}
|