format with prettier 3

This commit is contained in:
Kyle Corbitt
2023-07-08 22:12:47 -07:00
parent 6b32619e87
commit a8db6cadfd
34 changed files with 201 additions and 480 deletions

View File

@@ -2,7 +2,11 @@ import { omit } from "lodash";
import { env } from "~/env.mjs";
import OpenAI from "openai";
import { type ChatCompletion, type ChatCompletionChunk, type CompletionCreateParams } from "openai/resources/chat";
import {
type ChatCompletion,
type ChatCompletionChunk,
type CompletionCreateParams,
} from "openai/resources/chat";
// console.log("creating openai client");
@@ -10,7 +14,7 @@ export const openai = new OpenAI({ apiKey: env.OPENAI_API_KEY });
export const mergeStreamedChunks = (
base: ChatCompletion | null,
chunk: ChatCompletionChunk
chunk: ChatCompletionChunk,
): ChatCompletion => {
if (base === null) {
return mergeStreamedChunks({ ...chunk, choices: [] }, chunk);
@@ -25,11 +29,14 @@ export const mergeStreamedChunks = (
if (choice.delta?.content)
baseChoice.message.content =
(baseChoice.message.content as string ?? "") + (choice.delta.content ?? "");
((baseChoice.message.content as string) ?? "") + (choice.delta.content ?? "");
if (choice.delta?.function_call) {
const fnCall = baseChoice.message.function_call ?? {};
fnCall.name = (fnCall.name as string ?? "") + (choice.delta.function_call.name as string ?? "");
fnCall.arguments = (fnCall.arguments as string ?? "") + (choice.delta.function_call.arguments as string ?? "");
fnCall.name =
((fnCall.name as string) ?? "") + ((choice.delta.function_call.name as string) ?? "");
fnCall.arguments =
((fnCall.arguments as string) ?? "") +
((choice.delta.function_call.arguments as string) ?? "");
}
} else {
choices.push({ ...omit(choice, "delta"), message: { role: "assistant", ...choice.delta } });