Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a new recipe for the Inngest integration #4

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixes
charlypoly committed Jan 6, 2025
commit bef2cd9cafecfa25338d99af798a1605217e21dd
10 changes: 5 additions & 5 deletions integrations/inngest/dinner-generator-rag/README.md
Original file line number Diff line number Diff line change
@@ -54,12 +54,12 @@ npm run inngest

3. Open the Inngest DevServer UI at http://127.0.0.1:8288 and trigger a new runs from the _Functions_ tab using the following event data:

```typescript
```json
{
data: {
participantsCount: 4,
preferences: ["gluten-free", "vegan"],
cuisine_type: "Italian"
"data": {
"participantsCount": 4,
"preferences": ["no nuts", "vegan"],
"cuisine_type": "Italian"
}
}
```
39 changes: 12 additions & 27 deletions integrations/inngest/dinner-generator-rag/src/inngest/functions.ts
Original file line number Diff line number Diff line change
@@ -47,10 +47,12 @@ export const generateMeal = inngest.createFunction(
},
});

let ingredientsAlternatives: any[] = [];

// run some conditional AI steps
if (allergiesAnalysis.choices[0].message.content !== "not allergies") {
// Query relevant recipes based on cusine type preference
const ingredientsAlternatives = await step.run(
ingredientsAlternatives = await step.run(
"query-ingredients-alternatives",
async () => {
const collection = client.collections.get(
@@ -65,32 +67,6 @@ export const generateMeal = inngest.createFunction(
return result.objects;
}
);

const updatedRecipes = await step.ai.infer("Update recipes", {
model: openai({ model: "gpt-4" }),
body: {
messages: [
{
role: "user",
content: `Update the following recipes based on the provided ingredients alternatives:
<ingredients-alternatives>
${ingredientsAlternatives
.map((r) => r.properties.ingredients_alternatives)
.join(", ")}
</ingredients-alternatives>

<recipes>
${relevantRecipes}
</recipes>
`,
},
],
},
});

relevantRecipes = updatedRecipes.choices[0].message.content!.match(
/<updated-recipes>(.*?)<\/updated-recipes>/s
)![1];
}

// Generate meal plan using step.ai.wrap()
@@ -111,6 +87,15 @@ export const generateMeal = inngest.createFunction(

Use these recipes as inspiration:
${relevantRecipes}

${
ingredientsAlternatives.length > 0 &&
`Some allergies to ${
allergiesAnalysis.choices[0].message.content
} were detected, here are some ingredients alternatives to take into account: ${ingredientsAlternatives
.map((r) => r.properties.ingredients_alternatives)
.join(", ")}`
}

Include:
1. Appetizers