ai-fetcher
Version:
A Node.js package that provides integration with popular language models. It is designed to facilitate easy and efficient ai-fetching tasks for your application.
69 lines (68 loc) • 3.67 kB
TypeScript
import { OpenAIChatModel, OpenAIMessage, OpenAIChatResult, OpenAISpeechModel, OpenAITTSResult, OpenAITTSVoice } from "../types";
export declare class OpenAI {
/**
* Initialize a new OpenAI chat instance
* @param apiKey: string - The user's OpenAI authentication key
* @param model (Optional): OpenAIChatModel - one of the available chat model provided by OpenAI. Defaults to "gpt-40-mini", the cheapest one
* @returns An instance of OpenAI Chat model
*/
static chat(apiKey: string, model?: OpenAIChatModel): Chat;
/**
* Initialize a new OpenAI TTS instance
* @param apiKey: string - The user's OpenAI authentication key
* @returns An instance of OpenAI TTS model
*/
static textToSpeech(apiKey: string): TextToSpeech;
}
export declare class Chat {
private apiKey;
private headers;
readonly model: OpenAIChatModel;
readonly endpoint: string;
/**
* Constructs a new instance of OpenAI Chat class
* @param openAIKey: string - The user's OpenAI authentication key
* @param model: OpenAIChatModel - one of the available chat model provided by OpenAI
*/
constructor(openAIKey: string, model: OpenAIChatModel);
/**
*
* @param messages: OpenAIMessage[] - an array of OpenAIMessages representing the conversation history.
* @param system (Optional): string - The system prompt or content that guides the model's behavior.
* @returns A proimise that resolves to a OpenAIChatResult containing the generated chat output.
* @throws An error if the API request fails
*/
generate(messages: OpenAIMessage[], system?: string): Promise<OpenAIChatResult>;
}
export declare class TextToSpeech {
private apiKey;
private headers;
readonly model: OpenAISpeechModel;
readonly endpoint: string;
/**
* Constructs a new instance of OpenAI TTS class
* @param openAIKey: string - The user's OpenAI authentication key
*/
constructor(openAIKey: string);
/**
*
* @param text: string | undefined - The text that you want to convert to speech.
* @param returnType (Optional): "filename" | "buffer" | "base64" - Specifies the format in which the result should be returned.
* @param filename (Optional): string - The name of the file to save the speech when `returnType` is "filename". Defaults to "speech.mp3".
* @param voice (Optional): OpenAITTSVoice - The voice model to use for the speech synthesis. Defaults to "alloy"
* @returns A promise that resolves to the result of the conversion, depending on the `returnType`
* - If `returnType` is "filename", the promise resolves to the file path of the saved audio.
* - If `returnType` is "buffer", the promise resolves to a `Buffer` containing the audio data.
* - If `returnType` is "base64", the promise resolves to a Base64-encoded string of the audio data.
* - If no valid `returnType` is specified, it returns `undefined`.
* @throws Error - Throws an error if the input `text` is undefined or if there is a failure during the request to the API.
*/
convert(text: string | undefined, returnType?: "filename" | "buffer" | "base64", filename?: string, voice?: OpenAITTSVoice): Promise<OpenAITTSResult>;
}
/**
* Processes and validates the given filename, ensuring that it has the correct format and file extension.
*
* @param originalFilename: string - The original filename or file path provided by the user.
* @returns string - The processed filename with a valid ".mp3" extension and proper path structure.
*/
export declare const processFilename: (originalFilename: string) => string;