-
Notifications
You must be signed in to change notification settings - Fork 495
Moved menu and coffee shop samples into top level samples folder #137
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
## Running the sample | ||
|
||
```bash | ||
npm i | ||
genkit start | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ | ||
"name": "coffee-shop", | ||
"version": "1.0.0", | ||
"description": "Samples for a coffeeshop", | ||
"main": "lib/index.js", | ||
"scripts": { | ||
"start": "node lib/index.js", | ||
"compile": "tsc", | ||
"build": "npm run build:clean && npm run compile", | ||
"build:clean": "rm -rf ./lib", | ||
"build:watch": "tsc --watch", | ||
"build-and-run": "npm run build && node lib/index.js" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"@genkit-ai/ai": "~0.5.0-rc.11", | ||
"@genkit-ai/core": "~0.5.0-rc.11", | ||
"@genkit-ai/dotprompt": "~0.5.0-rc.11", | ||
"@genkit-ai/flow": "~0.5.0-rc.11", | ||
"genkitx-chromadb": "~0.5.0-rc.11", | ||
"@genkit-ai/dev-local-vectorstore": "~0.5.0-rc.11", | ||
"@genkit-ai/firebase": "~0.5.0-rc.11", | ||
"@genkit-ai/googleai": "~0.5.0-rc.11", | ||
"genkitx-ollama": "~0.5.0-rc.11", | ||
"genkitx-pinecone": "~0.5.0-rc.11", | ||
"@genkit-ai/evaluator": "~0.5.0-rc.11", | ||
"@genkit-ai/vertexai": "~0.5.0-rc.11", | ||
"zod": "^3.22.4" | ||
}, | ||
"devDependencies": { | ||
"typescript": "^5.3.3" | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
## Menu Understanding Sample Application | ||
|
||
This sample demonstrates an application that can understand a restaurant menu and answer relevant questions about the items on the menu. | ||
|
||
There are 5 iterations of this sample application, growing in complexity and demonstrating utilization of many different Genkit features. | ||
|
||
To test each one out, open the Developer UI and exercise the prompts and flows. Each step contains one or more `example.json` files which you can use as inputs. | ||
|
||
### Prerequisites | ||
|
||
This example uses Vertex AI for language models and embeddings. | ||
|
||
### Prompts and Flows | ||
|
||
1. This step shows how to define prompts in code that can accept user input to their templates. | ||
2. This step illustrates how to wrap your llm calls and other application code into flows with strong input and output schemas. | ||
It also adds an example of tool usage to load the menu from a data file. | ||
3. This step adds session history and supports a multi-turn chat with the model. | ||
4. This step ingests the menu items into a vector database and uses retrieval to include releveant menu items in the prompt. | ||
5. This step illustrates how to combine models with different modalities. It uses a vision model to ingest the menu items from a photograph. | ||
|
||
## Running the sample | ||
|
||
```bash | ||
npm i | ||
genkit start | ||
``` |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
[ | ||
{ | ||
"title": "Mozzarella Sticks", | ||
"price": 8, | ||
"description": "Crispy fried mozzarella sticks served with marinara sauce." | ||
}, | ||
{ | ||
"title": "Chicken Wings", | ||
"price": 10, | ||
"description": "Crispy fried chicken wings tossed in your choice of sauce." | ||
}, | ||
{ | ||
"title": "Nachos", | ||
"price": 12, | ||
"description": "Crispy tortilla chips topped with melted cheese, chili, sour cream, and salsa." | ||
}, | ||
{ | ||
"title": "Onion Rings", | ||
"price": 7, | ||
"description": "Crispy fried onion rings served with ranch dressing." | ||
}, | ||
{ | ||
"title": "French Fries", | ||
"price": 5, | ||
"description": "Crispy fried french fries." | ||
}, | ||
{ | ||
"title": "Mashed Potatoes", | ||
"price": 6, | ||
"description": "Creamy mashed potatoes." | ||
}, | ||
{ | ||
"title": "Coleslaw", | ||
"price": 4, | ||
"description": "Homemade coleslaw." | ||
}, | ||
{ | ||
"title": "Classic Cheeseburger", | ||
"price": 12, | ||
"description": "A juicy beef patty topped with melted American cheese, lettuce, tomato, and onion on a toasted bun." | ||
}, | ||
{ | ||
"title": "Bacon Cheeseburger", | ||
"price": 14, | ||
"description": "A classic cheeseburger with the addition of crispy bacon." | ||
}, | ||
{ | ||
"title": "Mushroom Swiss Burger", | ||
"price": 15, | ||
"description": "A beef patty topped with sautéed mushrooms, melted Swiss cheese, and a creamy horseradish sauce." | ||
}, | ||
{ | ||
"title": "Chicken Sandwich", | ||
"price": 13, | ||
"description": "A crispy chicken breast on a toasted bun with lettuce, tomato, and your choice of sauce." | ||
}, | ||
{ | ||
"title": "Pulled Pork Sandwich", | ||
"price": 14, | ||
"description": "Slow-cooked pulled pork on a toasted bun with coleslaw and barbecue sauce." | ||
}, | ||
{ | ||
"title": "Reuben Sandwich", | ||
"price": 15, | ||
"description": "Thinly sliced corned beef, Swiss cheese, sauerkraut, and Thousand Island dressing on rye bread." | ||
}, | ||
{ | ||
"title": "House Salad", | ||
"price": 8, | ||
"description": "Mixed greens with your choice of dressing." | ||
}, | ||
{ | ||
"title": "Caesar Salad", | ||
"price": 9, | ||
"description": "Romaine lettuce with croutons, Parmesan cheese, and Caesar dressing." | ||
}, | ||
{ | ||
"title": "Greek Salad", | ||
"price": 10, | ||
"description": "Mixed greens with feta cheese, olives, tomatoes, cucumbers, and red onions." | ||
}, | ||
{ | ||
"title": "Chocolate Lava Cake", | ||
"price": 8, | ||
"description": "A warm, gooey chocolate cake with a molten chocolate center." | ||
}, | ||
{ | ||
"title": "Apple Pie", | ||
"price": 7, | ||
"description": "A classic apple pie with a flaky crust and warm apple filling." | ||
}, | ||
{ | ||
"title": "Cheesecake", | ||
"price": 8, | ||
"description": "A creamy cheesecake with a graham cracker crust." | ||
} | ||
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"name": "menu", | ||
"version": "1.0.0", | ||
"description": "Samples for a menu understanding app", | ||
"main": "lib/index.js", | ||
"scripts": { | ||
"start": "node lib/index.js", | ||
"compile": "tsc", | ||
"build": "npm run build:clean && npm run compile", | ||
"build:clean": "rm -rf ./lib", | ||
"build:watch": "tsc --watch", | ||
"build-and-run": "npm run build && node lib/index.js" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"@genkit-ai/ai": "~0.5.0-rc.11", | ||
"@genkit-ai/core": "~0.5.0-rc.11", | ||
"@genkit-ai/dotprompt": "~0.5.0-rc.11", | ||
"@genkit-ai/flow": "~0.5.0-rc.11", | ||
"@genkit-ai/dev-local-vectorstore": "~0.5.0-rc.11", | ||
"@genkit-ai/firebase": "~0.5.0-rc.11", | ||
"@genkit-ai/evaluator": "~0.5.0-rc.11", | ||
"@genkit-ai/vertexai": "~0.5.0-rc.11", | ||
"zod": "^3.22.4" | ||
}, | ||
"devDependencies": { | ||
"typescript": "^5.3.3" | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"input": { | ||
"question": "Which of your burgers would you recommend for someone like me who loves bacon?" | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/** | ||
* Copyright 2024 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { definePrompt } from '@genkit-ai/ai'; | ||
import { GenerateRequest } from '@genkit-ai/ai/model'; | ||
import { defineDotprompt } from '@genkit-ai/dotprompt'; | ||
import { geminiPro } from '@genkit-ai/vertexai'; | ||
import { MenuQuestionInput, MenuQuestionInputSchema } from '../types'; | ||
|
||
// Define a prompt to handle a customer question about the menu. | ||
// This prompt uses definePrompt directly. | ||
|
||
export const s01_vanillaPrompt = definePrompt( | ||
{ | ||
name: 's01_vanillaPrompt', | ||
inputSchema: MenuQuestionInputSchema, | ||
}, | ||
async (input: MenuQuestionInput): Promise<GenerateRequest> => { | ||
const promptText = ` | ||
You are acting as a helpful AI assistant named "Walt" that can answer | ||
questions about the food available on the menu at Walt's Burgers. | ||
Customer says: ${input.question} | ||
`; | ||
|
||
return { | ||
messages: [{ role: 'user', content: [{ text: promptText }] }], | ||
config: { temperature: 0.3 }, | ||
}; | ||
} | ||
); | ||
|
||
// Define another prompt which uses the Dotprompt library | ||
// that also gives us a type-safe handlebars template system, | ||
// and well-defined output schemas. | ||
|
||
export const s01_staticMenuDotPrompt = defineDotprompt( | ||
{ | ||
name: 's01_staticMenuDotPrompt', | ||
model: geminiPro, | ||
input: { schema: MenuQuestionInputSchema }, | ||
output: { format: 'text' }, | ||
}, | ||
` | ||
You are acting as a helpful AI assistant named "Walt" that can answer | ||
questions about the food available on the menu at Walt's Burgers. | ||
Here is today's menu: | ||
|
||
- The Regular Burger $12 | ||
The classic charbroiled to perfection with your choice of cheese | ||
|
||
- The Fancy Burger $13 | ||
Classic burger topped with bacon & Blue Cheese | ||
|
||
- The Bacon Burger $13 | ||
Bacon cheeseburger with your choice of cheese. | ||
|
||
- Everything Burger $14 | ||
Heinz 57 sauce, American cheese, bacon, fried egg & crispy onion bits | ||
|
||
- Chicken Breast Sandwich $12 | ||
Tender juicy chicken breast on a brioche roll. | ||
Grilled, blackened, or fried | ||
|
||
Our fresh 1/2 lb. beef patties are made using choice cut | ||
brisket, short rib & sirloin. Served on a toasted | ||
brioche roll with chips. Served with lettuce, tomato & pickles. | ||
Onions upon request. Substitute veggie patty $2 | ||
|
||
Answer this customer's question, in a concise and helpful manner, | ||
as long as it is about food. | ||
|
||
Question: | ||
{{question}} ? | ||
` | ||
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"question": "I'd like to try something spicy. What do you recommend?" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* Copyright 2024 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { defineFlow } from '@genkit-ai/flow'; | ||
import { AnswerOutputSchema, MenuQuestionInputSchema } from '../types'; | ||
import { s02_dataMenuPrompt } from './prompts'; | ||
|
||
// Define a flow which generates a response from the prompt. | ||
|
||
export const s02_menuQuestionFlow = defineFlow( | ||
{ | ||
name: 's02_menuQuestion', | ||
inputSchema: MenuQuestionInputSchema, | ||
outputSchema: AnswerOutputSchema, | ||
}, | ||
async (input) => { | ||
return s02_dataMenuPrompt | ||
.generate({ | ||
input: { question: input.question }, | ||
}) | ||
.then((response) => { | ||
return { answer: response.text() }; | ||
}); | ||
} | ||
); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes sense to me, thinking through the process, if someone is just testing they can
genkit start
here and build and run using the published versions. If they're doing local development the best process would be to bump their localpackage.json
file to the next patch/RC version and the validate that it's getting picked up in these samples, but they shouldn't have to adjust the imports since they're getting ~'d in, is that right?