zhangjf commited on
Commit
11af774
·
1 Parent(s): 0bfc8e3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -2
app.py CHANGED
@@ -23,7 +23,7 @@ def ask(question, history, behavior):
23
  raw_length = num_tokens_from_messages(messages)
24
  messages=forget_long_term(messages)
25
  if len(messages)==0:
26
- response = 'Your query is too long and expensive: {raw_length}>500 tokens'
27
  else:
28
  response = openai.ChatCompletion.create(
29
  model="gpt-3.5-turbo",
@@ -56,7 +56,7 @@ def num_tokens_from_messages(messages, model="gpt-3.5-turbo"):
56
  raise NotImplementedError(f"""num_tokens_from_messages() is not presently implemented for model {model}.
57
  See https://github.com/openai/openai-python/blob/main/chatml.md for information on how messages are converted to tokens.""")
58
 
59
- def forget_long_term(messages, max_num_tokens=500):
60
  while num_tokens_from_messages(messages)>max_num_tokens:
61
  if messages[0]["role"]=="system" and not len(messages[0]["content"])>=max_num_tokens:
62
  messages = messages[:1] + messages[2:]
 
23
  raw_length = num_tokens_from_messages(messages)
24
  messages=forget_long_term(messages)
25
  if len(messages)==0:
26
+ response = f'Your query is too long and expensive: {raw_length}>2000 tokens'
27
  else:
28
  response = openai.ChatCompletion.create(
29
  model="gpt-3.5-turbo",
 
56
  raise NotImplementedError(f"""num_tokens_from_messages() is not presently implemented for model {model}.
57
  See https://github.com/openai/openai-python/blob/main/chatml.md for information on how messages are converted to tokens.""")
58
 
59
+ def forget_long_term(messages, max_num_tokens=2000):
60
  while num_tokens_from_messages(messages)>max_num_tokens:
61
  if messages[0]["role"]=="system" and not len(messages[0]["content"])>=max_num_tokens:
62
  messages = messages[:1] + messages[2:]