Skip to content

Commit

Permalink
Improved method for generating conversation topic, replacing text-dav…
Browse files Browse the repository at this point in the history
…inci-003 model with gpt-3.5-turbo model
  • Loading branch information
WongSaang committed Mar 8, 2023
1 parent b9ff0c0 commit a65f516
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions chat/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,25 +54,28 @@ def gen_title(request):
conversation_id = request.data.get('conversationId')
conversation_obj = Conversation.objects.get(id=conversation_id)
message = Message.objects.filter(conversation_id=conversation_id).order_by('created_at').first()
prompt = f'''Generate a title of ten words or less from the following text:
[{message.message}]
Title:
'''

messages = [
{"role": "user", "content": 'Generate a short title for the following content, no more than 10 words: \n\n "%s"' % message.message},
]

model = get_current_model()

myOpenai = get_openai()
try:
openai_response = myOpenai.Completion.create(
model='text-davinci-003',
prompt=prompt,
openai_response = myOpenai.ChatCompletion.create(
model=model['name'],
messages=messages,
max_tokens=256,
temperature=0.5,
max_tokens=60,
top_p=1.0,
frequency_penalty=0.8,
presence_penalty=0.0
top_p=1,
frequency_penalty=0,
presence_penalty=0,
)
completion_text = openai_response['choices'][0]['text']
completion_text = openai_response['choices'][0]['message']['content']
title = completion_text.strip().replace('"', '')
except:
except Exception as e:
print(e)
title = 'Untitled Conversation'
# update the conversation title
conversation_obj.topic = title
Expand Down

0 comments on commit a65f516

Please sign in to comment.