gera commited on
Commit
4cf0c03
·
1 Parent(s): e46e576

not messing up the chat history

Browse files
Files changed (1) hide show
  1. app.py +10 -9
app.py CHANGED
@@ -49,24 +49,25 @@ def chat(message, history, files, state):
49
  gr.Error("First upload a book")
50
  return ''
51
 
52
- if (not history) and message:
53
- prompt += f"**Questions**:{message}"
54
- state["prompt"] = prompt
55
-
56
- if history:
57
- history[0] = (prompt, history[0][1])
58
- else:
59
  message = prompt
60
 
61
  for human, assistant in history:
62
- if human:
 
 
63
  history_openai_format.append({"role": "user", "content": human })
64
  if assistant:
65
  history_openai_format.append({"role": "assistant", "content":assistant})
66
 
67
  if message:
68
  history_openai_format.append({"role": "user", "content": message})
69
-
 
 
70
  response = client.chat.completions.create(
71
  model=MODEL,
72
  messages= history_openai_format,
 
49
  gr.Error("First upload a book")
50
  return ''
51
 
52
+ if (not history):
53
+ if message:
54
+ prompt += f"**Questions**:{message}"
55
+ state["prompt"] = prompt
 
 
 
56
  message = prompt
57
 
58
  for human, assistant in history:
59
+ if not history_openai_format:
60
+ history_openai_format.append({"role": "user", "content": prompt})
61
+ elif human:
62
  history_openai_format.append({"role": "user", "content": human })
63
  if assistant:
64
  history_openai_format.append({"role": "assistant", "content":assistant})
65
 
66
  if message:
67
  history_openai_format.append({"role": "user", "content": message})
68
+ # return f"hola {len(history)}"
69
+ #
70
+ # def no():
71
  response = client.chat.completions.create(
72
  model=MODEL,
73
  messages= history_openai_format,