Skip to content

Commit

Permalink
fix: parse utf8 for all openai fields (#1202)
Browse files Browse the repository at this point in the history
  • Loading branch information
julianpoy authored Dec 29, 2023
2 parents 614bb54 + d617e9a commit 3a25b45
Showing 1 changed file with 27 additions and 13 deletions.
40 changes: 27 additions & 13 deletions packages/trpc/src/services/chat/chatFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ export type RSRunnableFunction =
| ReturnType<typeof initOCRFormatRecipe>
| ReturnType<typeof initBuildRecipe>;

const parseUTF8 = (str: string) => {
return JSON.parse(JSON.stringify(str));
};

export const initBuildRecipe = (
userId: string,
result: Prisma.RecipeUncheckedCreateInput[],
Expand All @@ -29,21 +33,25 @@ export const initBuildRecipe = (
const recipe: Prisma.RecipeUncheckedCreateInput = {
userId,
fromUserId: null,
title: typeof args.title === "string" ? args.title : "Unnamed",
title:
typeof args.title === "string" ? parseUTF8(args.title) : "Unnamed",
description: "",
folder: "main",
source: "RecipeSage Cooking Assistant",
url: "",
rating: null,
yield: typeof args.yield === "string" ? args.yield : "",
yield: typeof args.yield === "string" ? parseUTF8(args.yield) : "",
activeTime:
typeof args.activeTime === "string" ? args.activeTime : "",
totalTime: typeof args.totalTime === "string" ? args.totalTime : "",
typeof args.activeTime === "string"
? parseUTF8(args.activeTime)
: "",
totalTime:
typeof args.totalTime === "string" ? parseUTF8(args.totalTime) : "",
ingredients: Array.isArray(args.ingredients)
? JSON.parse(JSON.stringify(args.ingredients.join("\n")))
? parseUTF8(args.ingredients.join("\n"))
: "",
instructions: Array.isArray(args.instructions)
? JSON.parse(JSON.stringify(args.instructions.join("\n")))
? parseUTF8(args.instructions.join("\n"))
: "",
notes: "",
};
Expand Down Expand Up @@ -122,22 +130,28 @@ export const initOCRFormatRecipe = (
const recipe: Prisma.RecipeUncheckedCreateInput = {
userId,
fromUserId: null,
title: typeof args.title === "string" ? args.title : "Unnamed",
title:
typeof args.title === "string" ? parseUTF8(args.title) : "Unnamed",
description:
typeof args.description === "string" ? args.description : "",
typeof args.description === "string"
? parseUTF8(args.description)
: "",
folder: "main",
source: "",
url: "",
rating: null,
yield: typeof args.yield === "string" ? args.yield : "",
yield: typeof args.yield === "string" ? parseUTF8(args.yield) : "",
activeTime:
typeof args.activeTime === "string" ? args.activeTime : "",
totalTime: typeof args.totalTime === "string" ? args.totalTime : "",
typeof args.activeTime === "string"
? parseUTF8(args.activeTime)
: "",
totalTime:
typeof args.totalTime === "string" ? parseUTF8(args.totalTime) : "",
ingredients: Array.isArray(args.ingredients)
? JSON.parse(JSON.stringify(args.ingredients.join("\n")))
? parseUTF8(args.ingredients.join("\n"))
: "",
instructions: Array.isArray(args.instructions)
? JSON.parse(JSON.stringify(args.instructions.join("\n")))
? parseUTF8(args.instructions.join("\n"))
: "",
notes: typeof args.notes === "string" ? args.notes : "",
};
Expand Down

0 comments on commit 3a25b45

Please sign in to comment.