Skip to content

Commit

Permalink
modify: メイン機能デモ作成
Browse files Browse the repository at this point in the history
  • Loading branch information
kensiiwasaki committed Nov 21, 2023
1 parent 1231d6c commit f20baca
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions app/routes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,34 @@ export const action = async () => {
const openai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
});
const prompt = "こんにちは";
const prompt = `
今日の夜ご飯の主菜を考えてください
{
"title": "string",
"ingredients": [],
"instructions": "string"
}
のJSON形式で返してください
`;
const gptResponse = await openai.chat.completions.create({
messages: [{ role: "system", content: prompt }],
model: "gpt-3.5-turbo",
});
const content = gptResponse.choices[0].message.content;
const jsonObject = JSON.parse(content ? content : "");

return json({ response: gptResponse });
return json({ response: jsonObject });
};

export default function Index() {
const data = useLoaderData<typeof loader>();
const { signOut } = useClerk();
const actionData = useActionData<typeof action>();

const title = actionData ? actionData.response.title : "Waiting...";
const ingredients = actionData ? actionData.response.ingredients : [];
const instructions = actionData ? actionData.response.instructions : "";

console.log(data);

return (
Expand All @@ -58,11 +72,13 @@ export default function Index() {
<Form method="post">
<Button type="submit">プロンプト</Button>
</Form>
<p>
{actionData
? actionData.response.choices[0].message.content
: "Waiting..."}
</p>
<p>{title}</p>
<ul>
{ingredients.map((ingredient: string) => {
return <li key={ingredient}>{ingredient}</li>;
})}
</ul>
<p>{instructions}</p>
</SignedIn>

<SignedOut>
Expand Down

0 comments on commit f20baca

Please sign in to comment.