Skip to content
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

Bug: fix generate title function #933

Merged
merged 4 commits into from
Jun 20, 2024
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
1 change: 1 addition & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ AZURE_COSMOSDB_CONVERSATIONS_CONTAINER=conversations
AZURE_COSMOSDB_ACCOUNT_KEY=
AZURE_COSMOSDB_ENABLE_FEEDBACK=False
# Chat with data: common settings
DATASOURCE_TYPE=
SEARCH_TOP_K=5
SEARCH_STRICTNESS=3
SEARCH_ENABLE_IN_DOMAIN=True
Expand Down
9 changes: 5 additions & 4 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -836,9 +836,9 @@ async def ensure_cosmos():
return jsonify({"error": "CosmosDB is not working"}), 500


async def generate_title(conversation_messages):
async def generate_title(conversation_messages) -> str:
## make sure the messages are sorted by _ts descending
title_prompt = 'Summarize the conversation so far into a 4-word or less title. Do not use any quotation marks or punctuation. Respond with a json object in the format {{"title": string}}. Do not include any other commentary or description.'
title_prompt = "Summarize the conversation so far into a 4-word or less title. Do not use any quotation marks or punctuation. Do not include any other commentary or description."

messages = [
{"role": msg["role"], "content": msg["content"]}
Expand All @@ -847,14 +847,15 @@ async def generate_title(conversation_messages):
messages.append({"role": "user", "content": title_prompt})

try:
azure_openai_client = init_openai_client(use_data=False)
sarah-widder marked this conversation as resolved.
Show resolved Hide resolved
azure_openai_client = init_openai_client()
response = await azure_openai_client.chat.completions.create(
model=app_settings.azure_openai.model, messages=messages, temperature=1, max_tokens=64
)

title = json.loads(response.choices[0].message.content)["title"]
title = response.choices[0].message.content
return title
except Exception as e:
logging.exception("Exception while generating title", e)
return messages[-2]["content"]


Expand Down
Loading