Skip to content

Add new data from Rohit's branch #5

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 2 commits into from
May 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 1 addition & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@
"ms-python.vscode-pylance",
"ms-python.vscode-python-envs",
"charliermarsh.ruff",
"mtxr.sqltools",
"mtxr.sqltools-driver-pg",
// TODO: Add PostgreSQL extension once its in marketplace
"esbenp.prettier-vscode",
"mechatroner.rainbow-csv",
"ms-vscode.vscode-node-azure-pack",
Expand Down
32 changes: 13 additions & 19 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
{
"sqltools.connections": [
"pgsql.connections": [
{
"previewLimit": 50,
"id": "92CC1089-BAD0-44A4-B071-A50A6EC12B67",
"groupId": "F3347CD6-9995-4EE9-8D98-D88DB010FA5B",
"authenticationType": "SqlLogin",
"connectTimeout": 15,
"applicationName": "vscode-pgsql",
"clientEncoding": "utf8",
"sslmode": "prefer",
"server": "localhost",
"port": 5432,
"driver": "PostgreSQL",
"name": "local",
"user": "admin",
"password": "",
"savePassword": true,
"database": "postgres",
"username": "admin",
"password": "postgres"
},
{
"name": "Azure database",
"driver": "PostgreSQL",
"server": "<HOSTNAME>.postgres.database.azure.com",
"port": 5432,
"database": "postgres",
"username": "<USERNAME>",
"askForPassword": true,
"pgOptions": {
"ssl": true
}
"profileName": "local-pg",
"expiresOn": 0
}
],
"python.testing.pytestArgs": [
Expand Down
11 changes: 9 additions & 2 deletions convert_csv_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import json

# Read CSV file - Using the correct dialect to handle quotes properly
with open("data.csv", encoding="utf-8") as csv_file:
with open("pittsburgh_restaurants.csv", encoding="utf-8") as csv_file:
# Use the csv.reader with proper quoting parameters
csv_reader = csv.reader(csv_file, quoting=csv.QUOTE_ALL, doublequote=True, escapechar="\\")
header = next(csv_reader) # Get the header row
Expand Down Expand Up @@ -42,10 +42,17 @@
item[header[i]] = value
# remove is_open column
del item["is_open"]
del item["hours"]
del item["neighborhood"]
del item["tags"]
del item["vibe"]
del item["top_reviews"]
if item["price_level"] == "":
item["price_level"] = 2.0 # Assume 2.0 if empty
json_data.append(item)

# Write to JSON file
with open("data.json", "w", encoding="utf-8") as f:
with open("src/backend/fastapi_app/seed_data.json", "w", encoding="utf-8") as f:
json.dump(json_data, f, indent=4, ensure_ascii=False)

print(f"Successfully converted CSV data to JSON format with {len(json_data)} records")
201 changes: 201 additions & 0 deletions pittsburgh_restaurants.csv

Large diffs are not rendered by default.

11 changes: 3 additions & 8 deletions src/backend/fastapi_app/api_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,17 @@ class ChatRequest(BaseModel):


class ItemPublic(BaseModel):
id: int
id: str
name: str
location: str
cuisine: str
rating: int
price_level: int
review_count: int
hours: str
tags: list[str]
description: str
menu_summary: str
top_reviews: str
vibe: str

def to_str_for_rag(self):
return f"Name:{self.name} Description:{self.description} Location:{self.location} Cuisine:{self.cuisine} Rating:{self.rating} Price Level:{self.price_level} Review Count:{self.review_count} Hours:{self.hours} Tags:{self.tags} Menu Summary:{self.menu_summary} Top Reviews:{self.top_reviews} Vibe:{self.vibe}" # noqa: E501
return f"Name:{self.name} Description:{self.description} Cuisine:{self.cuisine} Rating:{self.rating} Price Level:{self.price_level} Review Count:{self.review_count} Menu Summary:{self.menu_summary}" # noqa: E501


class ItemWithDistance(ItemPublic):
Expand All @@ -75,7 +70,7 @@ class ThoughtStep(BaseModel):


class RAGContext(BaseModel):
data_points: dict[int, ItemPublic]
data_points: dict[str, ItemPublic]
thoughts: list[ThoughtStep]
followup_questions: Optional[list[str]] = None

Expand Down
14 changes: 4 additions & 10 deletions src/backend/fastapi_app/postgres_models.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from __future__ import annotations

from pgvector.sqlalchemy import Vector
from sqlalchemy import VARCHAR, Index
from sqlalchemy.dialects import postgresql
from sqlalchemy import Index
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column


Expand All @@ -13,19 +12,14 @@ class Base(DeclarativeBase):

class Item(Base):
__tablename__ = "items"
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
id: Mapped[str] = mapped_column(primary_key=True)
name: Mapped[str] = mapped_column()
location: Mapped[str] = mapped_column()
cuisine: Mapped[str] = mapped_column()
rating: Mapped[int] = mapped_column()
price_level: Mapped[int] = mapped_column()
review_count: Mapped[int] = mapped_column()
hours: Mapped[str] = mapped_column()
tags: Mapped[list[str]] = mapped_column(postgresql.ARRAY(VARCHAR)) # Array of strings
description: Mapped[str] = mapped_column()
menu_summary: Mapped[str] = mapped_column()
top_reviews: Mapped[str] = mapped_column()
vibe: Mapped[str] = mapped_column()

# Embeddings for different models:
embedding_3l: Mapped[Vector] = mapped_column(Vector(1024), nullable=True) # text-embedding-3-large
Expand All @@ -42,10 +36,10 @@ def to_dict(self, include_embedding: bool = False):
return model_dict

def to_str_for_rag(self):
return f"Name:{self.name} Description:{self.description} Location:{self.location} Cuisine:{self.cuisine} Rating:{self.rating} Price Level:{self.price_level} Review Count:{self.review_count} Hours:{self.hours} Tags:{self.tags} Menu Summary:{self.menu_summary} Top Reviews:{self.top_reviews} Vibe:{self.vibe}" # noqa: E501
return f"Name:{self.name} Description:{self.description} Cuisine:{self.cuisine} Rating:{self.rating} Price Level:{self.price_level} Review Count:{self.review_count} Menu Summary:{self.menu_summary}" # noqa: E501

def to_str_for_embedding(self):
return f"Name: {self.name} Description: {self.description} Cuisine: {self.cuisine} Tags: {self.tags} Menu Summary: {self.menu_summary} Top Reviews: {self.top_reviews} Vibe: {self.vibe}" # noqa: E501
return f"Name: {self.name} Description: {self.description} Cuisine: {self.cuisine} Menu Summary: {self.menu_summary}" # noqa: E501


"""
Expand Down
2 changes: 2 additions & 0 deletions src/backend/fastapi_app/rag_advanced.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ async def prepare_context(self) -> tuple[list[ItemPublic], list[ThoughtStep]]:
most_recent_response = run_results.new_items[-1]
if isinstance(most_recent_response, ToolCallOutputItem):
search_results = most_recent_response.output
if not isinstance(search_results, SearchResults):
raise ValueError(f"Error retrieving search results: {search_results}")
else:
raise ValueError("Error retrieving search results, model did not call tool properly")

Expand Down
Loading
Loading