diff options
Diffstat (limited to 'src/generic.ts')
| -rw-r--r-- | src/generic.ts | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/generic.ts b/src/generic.ts index ac6b55b..50b19c3 100644 --- a/src/generic.ts +++ b/src/generic.ts @@ -1,6 +1,6 @@ import OpenAI from "openai"; import { MAX_TOKENS, RESPONSE_LENGTH } from "./logic/constants"; -import type { AIModelAPI, ChatMessage, InputToken, OChoice } from "./types"; +import type { AIModelAPI, InputToken } from "./types"; import type { AsyncRes } from "sortug"; import type { ResponseCreateParamsBase, @@ -11,7 +11,7 @@ import type { type Props = { baseURL: string; - apiKey: string; + apiKey: string | undefined; model?: string; maxTokens?: number; tokenizer?: (text: string) => number; @@ -25,9 +25,12 @@ export default class OpenAIAPI implements AIModelAPI { model; constructor(props: Props) { + if (!props.apiKey) throw new Error("NO API KEY"); + console.log({ props }); this.apiKey = props.apiKey; this.baseURL = props.baseURL; this.api = new OpenAI({ baseURL: this.baseURL, apiKey: this.apiKey }); + console.log(this.api); this.model = props.model || ""; if (props.maxTokens) this.maxTokens = props.maxTokens; if (props.tokenizer) this.tokenizer = props.tokenizer; @@ -55,9 +58,10 @@ export default class OpenAIAPI implements AIModelAPI { // images can be URLs or base64 dataurl thingies // public async send( - input: string | ResponseInput, + inpt: string | InputToken[], sys?: string, ): AsyncRes<string> { + const input = typeof inpt === "string" ? inpt : this.buildInput(inpt); const params = sys ? { instructions: sys, input } : { input }; const res = await this.apiCall(params); if ("error" in res) return res; @@ -71,10 +75,11 @@ export default class OpenAIAPI implements AIModelAPI { } public async stream( - input: string, + inpt: string | InputToken[], handle: (c: string) => void, sys?: string, ) { + const input = typeof inpt === "string" ? inpt : this.buildInput(inpt); const params = sys ? { instructions: sys, input } : { input }; await this.apiCallStream(params, handle); } |
