sample-app-aoai-chatGPT icon indicating copy to clipboard operation
sample-app-aoai-chatGPT copied to clipboard

[Feature Request] Could be configurable the prompt message for generating Chat History title by environment variable.

Open riwaida opened this issue 1 year ago • 1 comments

Currently, chat history title is generated by following prompt message. So, generated title will be always English title. I hope that it can be configurable value by environment variable.

"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."

The message is hardcoded at the code https://github.com/microsoft/sample-app-aoai-chatGPT/blob/main/app.py#L890 as title_prompt.

 def generate_title(conversation_messages):
    ## 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.'

    messages = [{'role': msg['role'], 'content': msg['content']} for msg in conversation_messages]
    messages.append({'role': 'user', 'content': title_prompt})

    try:
        ## Submit prompt to Chat Completions for response
        base_url = AZURE_OPENAI_ENDPOINT if AZURE_OPENAI_ENDPOINT else f"https://{azure_openai_resource}.openai.azure.com/"
        openai.api_type = "azure"
        openai.api_base = base_url
        openai.api_version = "2023-03-15-preview"
        openai.api_key = AZURE_OPENAI_KEY
        completion = openai.ChatCompletion.create(    
            engine=AZURE_OPENAI_MODEL,
            messages=messages,
            temperature=1,
            max_tokens=64 
        )
        title = json.loads(completion['choices'][0]['message']['content'])['title']
        return title
    except Exception as e:
        return messages[-2]['content']

riwaida avatar Jan 26 '24 06:01 riwaida

Hello,

I made a pull request regarding your point (see mention). Let's hope that it will be validated and merged.

nrobert avatar Jan 30 '24 08:01 nrobert