apphouse
Version:
Component library for React that uses observable state management and theme-able components.
90 lines (89 loc) • 2.88 kB
TypeScript
import OpenAI, { ClientOptions } from 'openai';
export interface SpeechCreateParams {
voice: string;
}
export declare const TEST_HOST = "http://127.0.0.1:5001/apphouse-cc674/us-central1/";
export declare const PROD_HOST: string;
export declare const DEFAULT_AUDIO_VOICE = "alloy";
interface OpenAiFunctions {
getThemeColorsV2: 'getThemeColorsV2';
getDocumentAppConfig: 'getDocumentAppConfig';
getDocumentAppForm: 'getDocumentAppForm';
getDocumentTemplate: 'getDocumentTemplate';
askOpenAi: 'askOpenAi';
getAiImage: 'getAiImage';
}
export interface AssistantResponse {
type: 'success' | 'error';
message: string;
}
interface OpenAiFetchProps {
/**
* If url is not provided, the function name will be used to construct the url
* @example https://us-central1-my-project.cloudfunctions.net/my-function
*/
url?: string;
/**
* The prompt to be sent to the openAi api
*/
prompt?: string;
/**
* The name of the function to be called
*/
functionName: keyof OpenAiFunctions;
}
/**
* OpenAi class to be used to fetch data from the openai api
*/
export declare class OpenAi {
response: any;
loading: boolean;
error: string | null;
host: string;
openaiClient?: OpenAI;
constructor(prod?: boolean, host?: string, configuration?: ClientOptions | undefined);
setHost(host: string): void;
/**
* Ask the openai api a question
* @param request the request to send to the openai api
* @param resource any extra background information to provide to the api
* @returns
*/
ask: (request: string, resource?: string) => Promise<any>;
fetch: (fetchProps: OpenAiFetchProps) => Promise<any>;
/**
* Initialize openAi Client
* @param config the openai client configuration
*/
init: (config: ClientOptions) => void;
/**
* Convert text to audio and start downloading mp3 file
* @param text The text to convert to audio
*/
toAudio: (text: string, voiceSelection: SpeechCreateParams['voice']) => Promise<{
blob: Blob;
url: string;
type?: undefined;
message?: undefined;
} | {
type: string;
message: string;
blob?: undefined;
url?: undefined;
} | undefined>;
/**
* Create a transcription of an audio file
* @param file the audio file to transcribe
* @returns the transcription of the audio file
*/
createAudioTranscription: (file: File) => Promise<AssistantResponse>;
}
export declare const openAi: OpenAi;
/**
* A hook to use the openai instance.
* Note: This is a singleton object and should be used with caution.
* This will be a global object and will be shared across the application.
* @returns the openai instance
*/
export declare const useOpenAi: (config?: ClientOptions) => OpenAi;
export {};