Seth0330 commited on
Commit
67ac695
·
verified ·
1 Parent(s): 0405f80

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -9
app.py CHANGED
@@ -41,7 +41,6 @@ if uploaded_files:
41
  try:
42
  content = json.load(f)
43
  st.session_state.json_data[f.name] = content
44
- # For summary in system prompt
45
  if isinstance(content, dict):
46
  keys = list(content.keys())
47
  elif isinstance(content, list) and content and isinstance(content[0], dict):
@@ -72,7 +71,6 @@ else:
72
 
73
  # --- Functions for querying JSON files
74
  def search_json(file_name, key, value):
75
- """Return all records in the given JSON file (list of dicts) where key == value."""
76
  try:
77
  data = st.session_state.json_data[file_name]
78
  if isinstance(data, list):
@@ -89,7 +87,6 @@ def search_json(file_name, key, value):
89
  return {"error": str(e)}
90
 
91
  def list_keys(file_name):
92
- """Return all top-level keys of the JSON file."""
93
  try:
94
  data = st.session_state.json_data[file_name]
95
  if isinstance(data, dict):
@@ -102,7 +99,6 @@ def list_keys(file_name):
102
  return {"error": str(e)}
103
 
104
  def count_key_occurrences(file_name, key):
105
- """Count number of occurrences of a given key in the JSON file."""
106
  try:
107
  data = st.session_state.json_data[file_name]
108
  if isinstance(data, dict):
@@ -173,7 +169,6 @@ def send_message():
173
  user_input = st.session_state.temp_input
174
  if user_input and user_input.strip():
175
  st.session_state.messages.append({"role": "user", "content": user_input})
176
- # Limit history for context size
177
  chat_messages = st.session_state.messages
178
  if len(chat_messages) > 10:
179
  chat_messages = [chat_messages[0]] + chat_messages[-9:]
@@ -196,8 +191,6 @@ def send_message():
196
  )
197
  chat_resp.raise_for_status()
198
  response_json = chat_resp.json()
199
- st.write("RAW LLM RESPONSE:", response_json) # DEBUG
200
-
201
  msg = response_json["choices"][0]["message"]
202
 
203
  # If OpenAI requests a function call
@@ -205,7 +198,6 @@ def send_message():
205
  func_name = msg["function_call"]["name"]
206
  args_json = msg["function_call"]["arguments"]
207
  args = json.loads(args_json)
208
- st.write("Function Call:", func_name, "Args:", args) # DEBUG
209
 
210
  if func_name == "search_json":
211
  result = search_json(
@@ -242,7 +234,6 @@ def send_message():
242
  )
243
  final_resp.raise_for_status()
244
  final_json = final_resp.json()
245
- st.write("RAW FINAL RESPONSE:", final_json) # DEBUG
246
  answer = final_json["choices"][0]["message"]["content"]
247
  st.session_state.messages.append({"role": "assistant", "content": answer})
248
  else:
 
41
  try:
42
  content = json.load(f)
43
  st.session_state.json_data[f.name] = content
 
44
  if isinstance(content, dict):
45
  keys = list(content.keys())
46
  elif isinstance(content, list) and content and isinstance(content[0], dict):
 
71
 
72
  # --- Functions for querying JSON files
73
  def search_json(file_name, key, value):
 
74
  try:
75
  data = st.session_state.json_data[file_name]
76
  if isinstance(data, list):
 
87
  return {"error": str(e)}
88
 
89
  def list_keys(file_name):
 
90
  try:
91
  data = st.session_state.json_data[file_name]
92
  if isinstance(data, dict):
 
99
  return {"error": str(e)}
100
 
101
  def count_key_occurrences(file_name, key):
 
102
  try:
103
  data = st.session_state.json_data[file_name]
104
  if isinstance(data, dict):
 
169
  user_input = st.session_state.temp_input
170
  if user_input and user_input.strip():
171
  st.session_state.messages.append({"role": "user", "content": user_input})
 
172
  chat_messages = st.session_state.messages
173
  if len(chat_messages) > 10:
174
  chat_messages = [chat_messages[0]] + chat_messages[-9:]
 
191
  )
192
  chat_resp.raise_for_status()
193
  response_json = chat_resp.json()
 
 
194
  msg = response_json["choices"][0]["message"]
195
 
196
  # If OpenAI requests a function call
 
198
  func_name = msg["function_call"]["name"]
199
  args_json = msg["function_call"]["arguments"]
200
  args = json.loads(args_json)
 
201
 
202
  if func_name == "search_json":
203
  result = search_json(
 
234
  )
235
  final_resp.raise_for_status()
236
  final_json = final_resp.json()
 
237
  answer = final_json["choices"][0]["message"]["content"]
238
  st.session_state.messages.append({"role": "assistant", "content": answer})
239
  else: