UNPKG

instabuilds-sdk

Version:

A TypeScript SDK for interacting with AI services such as ChatGPT, Claude, DALL-E, and more.

1 lines 4.34 kB
{"version":3,"sources":["../src/index.ts","../src/services/chatgpt.ts"],"sourcesContent":["\n// import Claude from './services/claude';\n// import DALLE from './services/dalle';\n// import DeepL from './services/deepl';\n// import ElevenLabs from './services/elevenlabs';\n// import Gemini from './services/gemini';\nimport ChatGPT from './services/chatgpt.js';\nimport { SDKConfig } from './types/config.js';\n\n/**\n * The main class for interacting with various AI services.\n * @class\n */\nclass MyAPISDK {\n /** ChatGPT service instance */\n chatgpt: ChatGPT;\n // /** Claude service instance */\n // claude: Claude;\n // /** DALL-E service instance */\n // dalle: DALLE;\n // /** DeepL service instance */\n // deepl: DeepL;\n // /** ElevenLabs service instance */\n // elevenlabs: ElevenLabs;\n // /** Gemini service instance */\n // gemini: Gemini;\n\n /**\n * Creates an instance of MyAPISDK.\n * @param {SDKConfig} config - The configuration object for the SDK.\n */\n constructor(config: SDKConfig) {\n this.chatgpt = new ChatGPT(config);\n // this.claude = new Claude(config);\n // this.dalle = new DALLE(config);\n // this.deepl = new DeepL(config);\n // this.elevenlabs = new ElevenLabs(config);\n // this.gemini = new Gemini(config);\n }\n}\n\nexport default MyAPISDK;\n\nexport { ChatGPT, MyAPISDK }","import axios from 'axios';\nimport { AxiosInstance } from 'axios';\n\nimport { SDKConfig } from '../types/config.js';\nimport { ChatGPTInput } from '../types/input-types.js';\nimport { ChatGPTResponse } from '../types/api-responses.js';\n\n/**\n * ChatGPT service class for interacting with the ChatGPT API.\n * @class\n */\nclass ChatGPT {\n /**\n * The Axios instance for making HTTP requests.\n * @private\n */\n private client: AxiosInstance;\n\n /**\n * Creates an instance of ChatGPT service.\n * @param {SDKConfig} config - The configuration object for the service.\n */\n constructor(config: SDKConfig) {\n this.client = axios.create({\n baseURL: config.baseUrl || 'https://api.yourdomain.com',\n headers: {\n 'Authorization': `Bearer ${config.apiKey}`,\n 'Content-Type': 'application/json'\n }\n });\n }\n\n /**\n * Sends a completion request to the ChatGPT API.\n * @param {ChatGPTInput} input - The input for the completion request.\n * @returns {Promise<ChatGPTResponse>} A promise that resolves to the ChatGPT API response.\n * @throws {Error} If there's an error with the API request.\n */\n async completion(input: ChatGPTInput): Promise<ChatGPTResponse> {\n try {\n const response = await this.client.post<ChatGPTResponse>('/api/v1/gpt/completion', input);\n return response.data;\n } catch (error) {\n throw new Error(`ChatGPT API Error: ${(error as Error).message}`);\n }\n }\n\n /**\n * Sends a single question to the ChatGPT API.\n * @param {string} question - The question to ask.\n * @param {ChatGPTInput['options']} [options] - Optional parameters for the request.\n * @returns {Promise<ChatGPTResponse>} A promise that resolves to the ChatGPT API response.\n * @throws {Error} If there's an error with the API request.\n */\n async ask(question: string, options?: ChatGPTInput['options']): Promise<ChatGPTResponse> {\n return this.completion({ messages: [{ role: 'user', content: question }], options });\n }\n}\n\nexport default ChatGPT;"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAkB;AAWlB,IAAM,UAAN,MAAc;AAAA;AAAA;AAAA;AAAA;AAAA,EAWZ,YAAY,QAAmB;AAC7B,SAAK,SAAS,aAAAA,QAAM,OAAO;AAAA,MACzB,SAAS,OAAO,WAAW;AAAA,MAC3B,SAAS;AAAA,QACP,iBAAiB,UAAU,OAAO,MAAM;AAAA,QACxC,gBAAgB;AAAA,MAClB;AAAA,IACF,CAAC;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,WAAW,OAA+C;AAC9D,QAAI;AACF,YAAM,WAAW,MAAM,KAAK,OAAO,KAAsB,0BAA0B,KAAK;AACxF,aAAO,SAAS;AAAA,IAClB,SAAS,OAAO;AACd,YAAM,IAAI,MAAM,sBAAuB,MAAgB,OAAO,EAAE;AAAA,IAClE;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,MAAM,IAAI,UAAkB,SAA6D;AACvF,WAAO,KAAK,WAAW,EAAE,UAAU,CAAC,EAAE,MAAM,QAAQ,SAAS,SAAS,CAAC,GAAG,QAAQ,CAAC;AAAA,EACrF;AACF;AAEA,IAAO,kBAAQ;;;AD9Cf,IAAM,WAAN,MAAe;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAkBb,YAAY,QAAmB;AAC7B,SAAK,UAAU,IAAI,gBAAQ,MAAM;AAAA,EAMnC;AACF;AAEA,IAAO,cAAQ;","names":["axios"]}