Skip to content

Commit

Permalink
Bug: fix generate title function (#933)
Browse files Browse the repository at this point in the history
  • Loading branch information
ianlcassidy committed Jun 20, 2024
1 parent cd03c6a commit 3bf8484
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
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)
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

0 comments on commit 3bf8484

Please sign in to comment.