artificialguybr commited on
Commit
24155be
·
verified ·
1 Parent(s): dd4c56c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -0
app.py CHANGED
@@ -16,16 +16,19 @@ headers = {
16
  BASE_SYSTEM_MESSAGE = "I carefully provide accurate, factual, thoughtful, nuanced answers and am brilliant at reasoning."
17
 
18
  def clear_chat(chat_history_state, chat_message):
 
19
  chat_history_state = []
20
  chat_message = ''
21
  return chat_history_state, chat_message
22
 
23
  def user(message, history):
 
24
  history = history or []
25
  history.append({"role": "user", "content": message})
26
  return "", history
27
 
28
  def call_api(history, max_tokens, temperature, top_p, seed=42):
 
29
  payload = {
30
  "messages": history,
31
  "temperature": temperature,
@@ -39,15 +42,18 @@ def call_api(history, max_tokens, temperature, top_p, seed=42):
39
  for line in response.iter_lines():
40
  if line:
41
  decoded_line = line.decode("utf-8")
 
42
  if "data:" in decoded_line:
43
  json_data = json.loads(decoded_line.replace("data:", ""))
44
  if "choices" in json_data and len(json_data["choices"]) > 0:
45
  deltas = json_data["choices"][0].get("delta", {})
46
  if "content" in deltas:
47
  full_response += deltas["content"]
 
48
  return full_response
49
 
50
  def chat(history, system_message, max_tokens, temperature, top_p, top_k, repetition_penalty):
 
51
  system_message_to_use = system_message if system_message.strip() else BASE_SYSTEM_MESSAGE
52
  if history and "role" in history[-1] and history[-1]["role"] == "user":
53
  history.append({"role": "system", "content": system_message_to_use})
@@ -72,6 +78,7 @@ with gr.Blocks() as demo:
72
  chat_history_state = gr.State([])
73
 
74
  def update_chatbot(message, chat_history):
 
75
  chat_history, _ = user(message, chat_history)
76
  chat_history, _, _ = chat(chat_history, system_msg.value, max_tokens.value, temperature.value, top_p.value, 40, 1.1)
77
  return chat_history, chat_history, ""
 
16
  BASE_SYSTEM_MESSAGE = "I carefully provide accurate, factual, thoughtful, nuanced answers and am brilliant at reasoning."
17
 
18
  def clear_chat(chat_history_state, chat_message):
19
+ print("Clearing chat...")
20
  chat_history_state = []
21
  chat_message = ''
22
  return chat_history_state, chat_message
23
 
24
  def user(message, history):
25
+ print(f"User message: {message}")
26
  history = history or []
27
  history.append({"role": "user", "content": message})
28
  return "", history
29
 
30
  def call_api(history, max_tokens, temperature, top_p, seed=42):
31
+ print("Calling API...")
32
  payload = {
33
  "messages": history,
34
  "temperature": temperature,
 
42
  for line in response.iter_lines():
43
  if line:
44
  decoded_line = line.decode("utf-8")
45
+ print(f"API response line: {decoded_line}")
46
  if "data:" in decoded_line:
47
  json_data = json.loads(decoded_line.replace("data:", ""))
48
  if "choices" in json_data and len(json_data["choices"]) > 0:
49
  deltas = json_data["choices"][0].get("delta", {})
50
  if "content" in deltas:
51
  full_response += deltas["content"]
52
+ print(f"Full API response: {full_response}")
53
  return full_response
54
 
55
  def chat(history, system_message, max_tokens, temperature, top_p, top_k, repetition_penalty):
56
+ print("Starting chat...")
57
  system_message_to_use = system_message if system_message.strip() else BASE_SYSTEM_MESSAGE
58
  if history and "role" in history[-1] and history[-1]["role"] == "user":
59
  history.append({"role": "system", "content": system_message_to_use})
 
78
  chat_history_state = gr.State([])
79
 
80
  def update_chatbot(message, chat_history):
81
+ print("Updating chatbot...")
82
  chat_history, _ = user(message, chat_history)
83
  chat_history, _, _ = chat(chat_history, system_msg.value, max_tokens.value, temperature.value, top_p.value, 40, 1.1)
84
  return chat_history, chat_history, ""