182 lines
5.3 KiB
Plaintext
182 lines
5.3 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "757905af-7f93-4dca-9526-063bc93a78c7",
|
|
"metadata": {},
|
|
"source": [
|
|
"# Sakana-ya (魚屋) Sushi\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "9a6721fb-efca-4412-a0a7-cc8e6c4ced76",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import os\n",
|
|
"from dotenv import load_dotenv\n",
|
|
"from openai import OpenAI\n",
|
|
"import gradio as gr\n",
|
|
"import json"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "b0fa458f-f73f-491c-b666-95db4b91f571",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"load_dotenv(override=True)\n",
|
|
"openai_api_key = os.getenv('OPENAI_API_KEY')\n",
|
|
"anthropic_api_key = os.getenv('ANTHROPIC_API_KEY')\n",
|
|
"google_api_key = os.getenv('GOOGLE_API_KEY')\n",
|
|
"\n",
|
|
"if openai_api_key:\n",
|
|
" print(f\"OpenAI API Key exists and begins {openai_api_key[:8]}\")\n",
|
|
"else:\n",
|
|
" print(\"OpenAI API Key not set\")\n",
|
|
" \n",
|
|
"if anthropic_api_key:\n",
|
|
" print(f\"Anthropic API Key exists and begins {anthropic_api_key[:7]}\")\n",
|
|
"else:\n",
|
|
" print(\"Anthropic API Key not set\")\n",
|
|
"\n",
|
|
"if google_api_key:\n",
|
|
" print(f\"Google API Key exists and begins {google_api_key[:8]}\")\n",
|
|
"else:\n",
|
|
" print(\"Google API Key not set\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "aa2846f2-e09c-421d-9774-c04961a79800",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"openai = OpenAI()\n",
|
|
"MODEL = 'gpt-4o-mini'"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "7672ecdf-cf50-4b96-887a-b0a4eb5bbbf5",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
" \n",
|
|
"menu = {\n",
|
|
" \"Nigiri (1 pc)\": {\n",
|
|
" \"Salmon\": 4.25,\n",
|
|
" \"Tuna\": 4.75,\n",
|
|
" \"Yellowtail\": 5.00,\n",
|
|
" \"Eel\": 5.25,\n",
|
|
" \"Tamago\": 3.00,\n",
|
|
" },\n",
|
|
" \"Sashimi (3 pc)\": {\n",
|
|
" \"Salmon\": 8.50,\n",
|
|
" \"Tuna\": 9.00,\n",
|
|
" \"Yellowtail\": 9.50,\n",
|
|
" \"Octopus\": 8.00,\n",
|
|
" },\n",
|
|
" \"Classic Rolls (6 pc)\": {\n",
|
|
" \"California\": 6.50,\n",
|
|
" \"Spicy Tuna\": 7.50,\n",
|
|
" \"Philadelphia\": 7.25,\n",
|
|
" \"Cucumber\": 4.50,\n",
|
|
" \"Avocado\": 4.75,\n",
|
|
" },\n",
|
|
" \"Specialty Rolls (8 pc)\": {\n",
|
|
" \"Dragon\": 13.50,\n",
|
|
" \"Rainbow\": 14.00,\n",
|
|
" \"Crunchy Shrimp\": 12.50,\n",
|
|
" \"Volcano\": 13.00,\n",
|
|
" \"Spider\": 14.50,\n",
|
|
" },\n",
|
|
" \"Appetizers\": {\n",
|
|
" \"Edamame\": 5.00,\n",
|
|
" \"Gyoza (5)\": 6.50,\n",
|
|
" \"Miso Soup\": 3.00,\n",
|
|
" \"Seaweed Salad\": 5.50,\n",
|
|
" },\n",
|
|
" \"Beverages\": {\n",
|
|
" \"Green Tea\": 2.50,\n",
|
|
" \"Ramune Soda\": 3.00,\n",
|
|
" \"Sparkling Water\": 2.75,\n",
|
|
" },\n",
|
|
" \"Desserts\": {\n",
|
|
" \"Mochi Ice Cream (2)\": 5.00,\n",
|
|
" \"Matcha Cheesecake\": 6.50,\n",
|
|
" },\n",
|
|
" }"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "99914500-3630-4fea-987c-d19c760994c6",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"def chat(message, history):\n",
|
|
" system_message = \"You are a helpful assistant for Sakana-ya (魚屋) Sushi restaurant.\\\n",
|
|
" Help out with information and if you dont know something just say you cant help with that.\"\n",
|
|
" system_message += json.dumps(menu)\n",
|
|
" system_message+=\"If something is not in the menu, we dont serve it.\\\n",
|
|
" If we dont have a dish just mention it that we dont offer it. \"\n",
|
|
"\n",
|
|
" sushi_exotic = [\n",
|
|
" {\"role\": \"user\", \"content\": \"Do you have aji?\"},\n",
|
|
" {\"role\": \"user\", \"content\": \"We currently dont have shun its available only during the season i.e in May.\"},\n",
|
|
" {\"role\": \"user\", \"content\": \"What about buri?\"},\n",
|
|
" {\"role\": \"user\", \"content\": \"Thats seasonal as well only during December. Do visit us during that time.\"},\n",
|
|
" \n",
|
|
" ]\n",
|
|
" \n",
|
|
" messages = [{\"role\": \"system\", \"content\": system_message}]+ sushi_exotic + history + [{\"role\": \"user\", \"content\": message}]\n",
|
|
" stream = openai.chat.completions.create(model=MODEL, messages=messages, stream=True)\n",
|
|
"\n",
|
|
" response = \"\"\n",
|
|
" for chunk in stream:\n",
|
|
" response += chunk.choices[0].delta.content or ''\n",
|
|
" yield response"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "a5c61d91-abee-4ada-9a42-ae87cf53fcff",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"gr.ChatInterface(fn=chat, type=\"messages\").launch()"
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "Python 3 (ipykernel)",
|
|
"language": "python",
|
|
"name": "python3"
|
|
},
|
|
"language_info": {
|
|
"codemirror_mode": {
|
|
"name": "ipython",
|
|
"version": 3
|
|
},
|
|
"file_extension": ".py",
|
|
"mimetype": "text/x-python",
|
|
"name": "python",
|
|
"nbconvert_exporter": "python",
|
|
"pygments_lexer": "ipython3",
|
|
"version": "3.11.13"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 5
|
|
}
|