Skip to content

Commit

Permalink
refactor: remove zod
Browse files Browse the repository at this point in the history
  • Loading branch information
agrattan0820 committed Oct 12, 2023
1 parent 70188f9 commit 2e8ddb7
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 10 deletions.
3 changes: 1 addition & 2 deletions apps/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
"ioredis": "^5.3.2",
"morgan": "^1.10.0",
"replicate": "^0.20.1",
"socket.io": "^4.7.2",
"zod": "^3.22.4"
"socket.io": "^4.7.2"
},
"devDependencies": {
"@jest/globals": "^29.7.0",
Expand Down
11 changes: 7 additions & 4 deletions apps/server/src/services/generation.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
} from "database";
import { GameRoundGeneration, QuestionGenerations } from "../types";
import { replicate } from "../replicate";
import { z } from "zod";

export async function getGameRoundGenerations({
gameId,
Expand Down Expand Up @@ -233,7 +232,9 @@ export async function setGenerationAsSubmitted({
return updatedGenerations[0];
}

const replicateAPISchema = z.array(z.string()).length(2);
function isReplicateResponse(res: object): res is [string, string] {
return Array.isArray(res) && res.length === 2 && typeof res[0] === "string";
}

export async function getReplicateAIImages({ prompt }: { prompt: string }) {
const output = await replicate.run(
Expand All @@ -245,7 +246,9 @@ export async function getReplicateAIImages({ prompt }: { prompt: string }) {

console.log("Received images:", output);

const resultingImages = replicateAPISchema.parse(output);
if (!isReplicateResponse(output)) {
throw new Error("Did not receive the correct amount of images");
}

return resultingImages;
return output;
}
69 changes: 65 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2e8ddb7

Please sign in to comment.