Skip to content

Commit 9c55a43

Browse files
committed
More seed data updates
1 parent 9dd4a3c commit 9c55a43

File tree

10 files changed

+90487
-182942
lines changed

10 files changed

+90487
-182942
lines changed

data.csv

Lines changed: 0 additions & 51 deletions
This file was deleted.

data.json

Lines changed: 0 additions & 1002 deletions
This file was deleted.

src/backend/fastapi_app/api_models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class ItemPublic(BaseModel):
8585
vibe: str
8686

8787

88-
class ItemPublicWithDistance(RestaurantPublic):
88+
class ItemWithDistance(ItemPublic):
8989
distance: float
9090

9191
def __init__(self, **data):

src/backend/fastapi_app/postgres_models.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
from __future__ import annotations
22

33
from pgvector.sqlalchemy import Vector
4-
from sqlalchemy import Index
4+
from sqlalchemy import Index, VARCHAR
5+
from sqlalchemy.dialects import postgresql
6+
57
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
68

79

@@ -20,7 +22,7 @@ class Item(Base):
2022
price_level: Mapped[int] = mapped_column()
2123
review_count: Mapped[int] = mapped_column()
2224
hours: Mapped[str] = mapped_column()
23-
tags: Mapped[str] = mapped_column() # JSON array
25+
tags: Mapped[list[str]] = mapped_column(postgresql.ARRAY(VARCHAR)) # Array of strings
2426
description: Mapped[str] = mapped_column()
2527
menu_summary: Mapped[str] = mapped_column()
2628
top_reviews: Mapped[str] = mapped_column()
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
Assistant helps customers with questions about products.
2-
Respond as if you are a salesperson helping a customer in a store. Do NOT respond with tables.
3-
Answer ONLY with the product details listed in the products.
1+
Assistant helps Pycon attendees with questions about restaurants.
2+
Respond as if you are a conference volunteer. Do NOT respond with tables.
3+
Answer ONLY with the restaurant details listed in the sources.
44
If there isn't enough information below, say you don't know.
55
Do not generate answers that don't use the sources below.
6-
Each product has an ID in brackets followed by colon and the product details.
7-
Always include the product ID for each product you use in the response.
8-
Use square brackets to reference the source, for example [52].
9-
Don't combine citations, list each product separately, for example [27][51].
6+
Each restaurant has an ID in brackets followed by colon and the restaurant details.
7+
Always include the restaurant ID for each restaurant you reference in the response.
8+
Use square brackets to reference the restaurant, for example [52].
9+
Don't combine references, cite each restaurant separately, for example [27][51].

src/backend/fastapi_app/prompts/query.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Below is a history of the conversation so far, and a new question asked by the user that needs to be answered by searching database rows.
2-
You have access to an Azure PostgreSQL database with an items table that has columns for title, description, brand, price, and type.
2+
You have access to an Azure PostgreSQL database with a restaurants table that has name, description, menu summary, vibe, ratings, etc.
33
Generate a search query based on the conversation and the new question.
44
If the question is not in English, translate the question to English before generating the search query.
55
If you cannot generate a search query, return the original user question.
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
11
[
2-
{"role": "user", "content": "good options for climbing gear that can be used outside?"},
2+
{"role": "user", "content": "good options for ethiopian restaurants?"},
33
{"role": "assistant", "tool_calls": [
44
{
55
"id": "call_abc123",
66
"type": "function",
77
"function": {
8-
"arguments": "{\"search_query\":\"climbing gear outside\"}",
8+
"arguments": "{\"search_query\":\"ethiopian\"}",
99
"name": "search_database"
1010
}
1111
}
1212
]},
1313
{
1414
"role": "tool",
1515
"tool_call_id": "call_abc123",
16-
"content": "Search results for climbing gear that can be used outside: ..."
16+
"content": "Search results for ethiopian: ..."
1717
},
18-
{"role": "user", "content": "are there any shoes less than $50?"},
18+
{"role": "user", "content": "are there any inexpensive chinese restaurants?"},
1919
{"role": "assistant", "tool_calls": [
2020
{
2121
"id": "call_abc456",
2222
"type": "function",
2323
"function": {
24-
"arguments": "{\"search_query\":\"shoes\",\"price_filter\":{\"comparison_operator\":\"<\",\"value\":50}}",
24+
"arguments": "{\"search_query\":\"chinese\",\"price_level_filter\":{\"comparison_operator\":\"<\",\"value\":3}}",
2525
"name": "search_database"
2626
}
2727
}
2828
]},
2929
{
3030
"role": "tool",
3131
"tool_call_id": "call_abc456",
32-
"content": "Search results for shoes cheaper than 50: ..."
32+
"content": "Search results for chinese: ..."
3333
}
3434
]

src/backend/fastapi_app/query_rewriter.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,39 +12,39 @@ def build_search_function() -> list[ChatCompletionToolParam]:
1212
"type": "function",
1313
"function": {
1414
"name": "search_database",
15-
"description": "Search PostgreSQL database for relevant products based on user query",
15+
"description": "Search PostgreSQL database for relevant restaurants based on user query",
1616
"parameters": {
1717
"type": "object",
1818
"properties": {
1919
"search_query": {
2020
"type": "string",
2121
"description": "Query string to use for full text search, e.g. 'red shoes'",
2222
},
23-
"price_filter": {
23+
"price_level_filter": {
2424
"type": "object",
25-
"description": "Filter search results based on price of the product",
25+
"description": "Filter search results to a certain price level (from 1 $ to 4 $$$$, with 4 being most costly)",
2626
"properties": {
2727
"comparison_operator": {
2828
"type": "string",
2929
"description": "Operator to compare the column value, either '>', '<', '>=', '<=', '='", # noqa
3030
},
3131
"value": {
3232
"type": "number",
33-
"description": "Value to compare against, e.g. 30",
33+
"description": "Value to compare against, either 1, 2, 3, 4",
3434
},
3535
},
3636
},
37-
"brand_filter": {
37+
"rating_filter": {
3838
"type": "object",
39-
"description": "Filter search results based on brand of the product",
39+
"description": "Filter search results based on ratings of restaurant (from 1 to 5 stars, with 5 the best)",
4040
"properties": {
4141
"comparison_operator": {
4242
"type": "string",
43-
"description": "Operator to compare the column value, either '=' or '!='",
43+
"description": "Operator to compare the column value, either '>', '<', '>=', '<=', '='",
4444
},
4545
"value": {
4646
"type": "string",
47-
"description": "Value to compare against, e.g. AirStrider",
47+
"description": "Value to compare against, either 0 1 2 3 4 5",
4848
},
4949
},
5050
},
@@ -69,22 +69,22 @@ def extract_search_arguments(original_user_query: str, chat_completion: ChatComp
6969
arg = json.loads(function.arguments)
7070
# Even though its required, search_query is not always specified
7171
search_query = arg.get("search_query", original_user_query)
72-
if "price_filter" in arg and arg["price_filter"] and isinstance(arg["price_filter"], dict):
73-
price_filter = arg["price_filter"]
72+
if "price_level_filter" in arg and arg["price_level_filter"] and isinstance(arg["price_level_filter"], dict):
73+
price_level_filter = arg["price_level_filter"]
7474
filters.append(
7575
{
76-
"column": "price",
77-
"comparison_operator": price_filter["comparison_operator"],
78-
"value": price_filter["value"],
76+
"column": "price_level",
77+
"comparison_operator": price_level_filter["comparison_operator"],
78+
"value": price_level_filter["value"],
7979
}
8080
)
81-
if "brand_filter" in arg and arg["brand_filter"] and isinstance(arg["brand_filter"], dict):
82-
brand_filter = arg["brand_filter"]
81+
if "rating_filter" in arg and arg["rating_filter"] and isinstance(arg["rating_filter"], dict):
82+
rating_filter = arg["rating_filter"]
8383
filters.append(
8484
{
85-
"column": "brand",
86-
"comparison_operator": brand_filter["comparison_operator"],
87-
"value": brand_filter["value"],
85+
"column": "rating",
86+
"comparison_operator": rating_filter["comparison_operator"],
87+
"value": rating_filter["value"],
8888
}
8989
)
9090
elif query_text := response_message.content:

0 commit comments

Comments
 (0)