|
@@ -20,7 +20,7 @@ app.translate_messages = [
|
|
|
]
|
|
|
app.suggest_messages = [
|
|
|
{"role": "system",
|
|
|
- "content": "Please suggest the best response based on the previous conversations and the user's request."}
|
|
|
+ "content": "Please suggest reply messages based on the previous conversations and the user's request."}
|
|
|
]
|
|
|
UPLOAD_FOLDER = 'files'
|
|
|
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
|
|
@@ -37,6 +37,8 @@ def test():
|
|
|
def gpt():
|
|
|
# chat_messages = app.chat_messages.copy()
|
|
|
use_video = False
|
|
|
+ suggest = False
|
|
|
+ num_choices = 1
|
|
|
json_payload = request.get_json()
|
|
|
if not json_payload:
|
|
|
json_payload = []
|
|
@@ -44,16 +46,20 @@ def gpt():
|
|
|
if isinstance(json_payload, dict):
|
|
|
has_named_params = 'payload' in json_payload
|
|
|
if 'payload' in json_payload:
|
|
|
+ if 'num_choices' in json_payload:
|
|
|
+ num_choices = 5 if json_payload['num_choices'] > 5 else json_payload['num_choices']
|
|
|
if 'use_video' in json_payload:
|
|
|
use_video = json_payload['use_video'] == "1"
|
|
|
if 'translate' in json_payload:
|
|
|
chat_messages = app.translate_messages.copy()
|
|
|
- json_payload['payload'][0]['content'] = json_payload['payload'][0]['content'] + f" (Translate to {json_payload['translate']})"
|
|
|
+ json_payload['payload'][-1]['content'] = json_payload['payload'][-1]['content'] + f" (Translate to {json_payload['translate']})"
|
|
|
elif 'suggest' in json_payload:
|
|
|
- if json_payload['suggest'] == "1":
|
|
|
+ suggest = json_payload['suggest'] == "1"
|
|
|
+ if suggest:
|
|
|
chat_messages = app.suggest_messages.copy()
|
|
|
else:
|
|
|
chat_messages = app.chat_messages.copy()
|
|
|
+ json_payload['payload'][-1]['content'] = json_payload['payload'][-1]['content'] + f" What can I say to him/her?"
|
|
|
else:
|
|
|
chat_messages = app.chat_messages.copy()
|
|
|
json_payload = json_payload['payload']
|
|
@@ -99,12 +105,17 @@ def gpt():
|
|
|
app.logger.info(chat_messages)
|
|
|
result = {}
|
|
|
try:
|
|
|
+ n = num_choices
|
|
|
json_response = openai.ChatCompletion.create(model="gpt-3.5-turbo", # GPT-3.5 Turbo engine
|
|
|
messages=chat_messages,
|
|
|
- max_tokens=600, temperature=0.7)
|
|
|
+ max_tokens=600, temperature=0.7, n = n)
|
|
|
app.logger.info(json_response.choices[0].message)
|
|
|
if has_named_params:
|
|
|
- if use_video:
|
|
|
+ if suggest:
|
|
|
+ choices = json_response.choices
|
|
|
+ messages = [i.message for i in choices]
|
|
|
+ result = {"url": "", "message": messages}
|
|
|
+ elif use_video:
|
|
|
# TODO: to be implemented
|
|
|
result = {"url": url_for('download_file', name="test.mp4", _external=True), "message": json_response.choices[0].message}
|
|
|
else:
|