Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,14 +9,15 @@ openai.api_key = os.environ["OPENAI_API_KEY"]
|
|
| 9 |
initial_messages = [{
|
| 10 |
"role": "system",
|
| 11 |
"content": """
|
| 12 |
-
You are a neighborhood matchmaker. Given a person's preferences in terms of amenities, lifestyle, and priorities, suggest three neighborhoods that best match their needs in a specified city. For each neighborhood,
|
| 13 |
"""
|
| 14 |
}]
|
| 15 |
|
| 16 |
def call_openai_api(messages):
|
| 17 |
return openai.ChatCompletion.create(
|
| 18 |
model="gpt-3.5-turbo",
|
| 19 |
-
messages=messages
|
|
|
|
| 20 |
)
|
| 21 |
|
| 22 |
def CustomChatGPT(city, preferences, messages):
|
|
@@ -60,11 +61,9 @@ if st.session_state["reply"]:
|
|
| 60 |
# Extract neighborhood, city, and state information accurately
|
| 61 |
neighborhoods = []
|
| 62 |
for line in st.session_state["reply"].splitlines():
|
| 63 |
-
# Look for lines in the format "Neighborhood: Location: ..."
|
| 64 |
if "Location:" not in line and "Description:" not in line and ":" in line:
|
| 65 |
-
location = line.split(":")[0].strip() #
|
| 66 |
-
# Remove any leading numbering
|
| 67 |
-
if location[0].isdigit():
|
| 68 |
location = location.split(" ", 1)[1].strip()
|
| 69 |
neighborhoods.append(location)
|
| 70 |
|
|
|
|
| 9 |
initial_messages = [{
|
| 10 |
"role": "system",
|
| 11 |
"content": """
|
| 12 |
+
You are a neighborhood matchmaker. Given a person's preferences in terms of amenities, lifestyle, and priorities, suggest three neighborhoods that best match their needs in a specified city. For each neighborhood, provide the full location in the format: Neighborhood, City, State, and keep descriptions concise (one or two sentences).
|
| 13 |
"""
|
| 14 |
}]
|
| 15 |
|
| 16 |
def call_openai_api(messages):
|
| 17 |
return openai.ChatCompletion.create(
|
| 18 |
model="gpt-3.5-turbo",
|
| 19 |
+
messages=messages,
|
| 20 |
+
max_tokens=300 # Limit tokens to keep responses concise
|
| 21 |
)
|
| 22 |
|
| 23 |
def CustomChatGPT(city, preferences, messages):
|
|
|
|
| 61 |
# Extract neighborhood, city, and state information accurately
|
| 62 |
neighborhoods = []
|
| 63 |
for line in st.session_state["reply"].splitlines():
|
|
|
|
| 64 |
if "Location:" not in line and "Description:" not in line and ":" in line:
|
| 65 |
+
location = line.split(":")[0].strip() # Full location "Neighborhood, City, State"
|
| 66 |
+
if location[0].isdigit(): # Remove any leading numbering
|
|
|
|
| 67 |
location = location.split(" ", 1)[1].strip()
|
| 68 |
neighborhoods.append(location)
|
| 69 |
|