Skip to content

Commit

Permalink
dummy data pt2
Browse files Browse the repository at this point in the history
  • Loading branch information
wyattchris committed Jun 5, 2024
1 parent f74c2c0 commit 6f0628e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
7 changes: 2 additions & 5 deletions src/server/api/routers/dummy.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import { z } from "zod";

import dummyCreate from "~/server/dummyData";
import {
createTRPCRouter,
publicProcedure,
} from "~/server/api/trpc";
import { createTRPCRouter, publicProcedure } from "~/server/api/trpc";

export const dummy = createTRPCRouter({
testDummy: publicProcedure
testDummy: publicProcedure
.input(z.object({ name: z.string() }))
.mutation(async ({ ctx, input }) => {
await dummyCreate();
Expand Down
8 changes: 6 additions & 2 deletions src/server/dummyData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ const openai = new OpenAI({
});

async function generateDummyData(model: string, fields: string[]) {
console.log(`Generating dummy data for model ${model} with fields: ${fields.join(", ")}`);
console.log(
`Generating dummy data for model ${model} with fields: ${fields.join(", ")}`,
);
try {
const response = await openai.chat.completions.create({
model: "gpt-3.5-turbo",
Expand Down Expand Up @@ -57,7 +59,9 @@ async function dummyCreate() {
const model = prisma[modelName as keyof typeof prisma];
if (model) {
// @ts-ignore
await prisma[modelName.toLocaleLowerCase()].create({ data: JSON.parse(dummyData) });
await prisma[modelName.toLocaleLowerCase()].create({
data: JSON.parse(dummyData),
});
console.log(`Data inserted for model ${modelName}`);
} else {
console.error(
Expand Down

0 comments on commit 6f0628e

Please sign in to comment.