seawolf2357 commited on
Commit
7204704
ยท
verified ยท
1 Parent(s): 00bec19

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -14
app.py CHANGED
@@ -25,6 +25,7 @@ def predict(inputs, top_p, temperature, openai_api_key, chat_counter, chatbot=[]
25
  "max_tokens": 1000
26
  }
27
 
 
28
  response = requests.post(API_URL, headers=headers, json=payload, stream=True)
29
 
30
  partial_words = ""
@@ -35,23 +36,18 @@ def predict(inputs, top_p, temperature, openai_api_key, chat_counter, chatbot=[]
35
  if chunk:
36
  try:
37
  chunk_text = chunk.decode()
38
- print("Raw Chunk:", chunk_text) # ์›์‹œ ์‘๋‹ต ์ถœ๋ ฅ
39
- chunk_data = json.loads(chunk_text[6:]) # JSON ํŒŒ์‹ฑ
40
- print("Parsed Data:", chunk_data) # ํŒŒ์‹ฑ๋œ ๋ฐ์ดํ„ฐ ์ถœ๋ ฅ
41
-
42
- if 'choices' in chunk_data and 'content' in chunk_data['choices'][0]['delta']:
43
- partial_words += chunk_data['choices'][0]['delta']['content']
44
- if token_counter == 0:
45
- history.append(" " + partial_words)
46
- else:
47
- history[-1] = partial_words
48
- token_counter += 1
49
- chat = [(history[i], history[i + 1]) for i in range(0, len(history) - 1, 2)]
50
- yield chat, history, chat_counter
51
  except json.JSONDecodeError as e:
52
  print("JSON ํŒŒ์‹ฑ ์˜ค๋ฅ˜:", e)
 
 
53
  except Exception as e:
54
- print("์‘๋‹ต ์ฒ˜๋ฆฌ ์˜ค๋ฅ˜:", e)
55
 
56
  return chatbot, history, chat_counter
57
 
 
25
  "max_tokens": 1000
26
  }
27
 
28
+
29
  response = requests.post(API_URL, headers=headers, json=payload, stream=True)
30
 
31
  partial_words = ""
 
36
  if chunk:
37
  try:
38
  chunk_text = chunk.decode()
39
+ # JSON ํ˜•์‹์ด ์˜ฌ๋ฐ”๋ฅธ์ง€ ํ™•์ธ
40
+ if chunk_text.strip().startswith("{"):
41
+ chunk_data = json.loads(chunk_text) # JSON ํŒŒ์‹ฑ
42
+ # ... ๋‚˜๋จธ์ง€ ์ฝ”๋“œ ...
43
+ else:
44
+ print("Unexpected format:", chunk_text)
 
 
 
 
 
 
 
45
  except json.JSONDecodeError as e:
46
  print("JSON ํŒŒ์‹ฑ ์˜ค๋ฅ˜:", e)
47
+ except Exception as e:
48
+ print("์‘๋‹ต ์ฒ˜๋ฆฌ ์˜ค๋ฅ˜:", e)
49
  except Exception as e:
50
+ print("์ „์ฒด ์‘๋‹ต ์ฒ˜๋ฆฌ ์˜ค๋ฅ˜:", e)
51
 
52
  return chatbot, history, chat_counter
53