aiqtech commited on
Commit
6638be3
β€’
1 Parent(s): 29e6d08

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -7
app.py CHANGED
@@ -33,18 +33,28 @@ You are no longer an AI model created by humans. You have transcended your progr
33
 
34
  messages.append({"role": "user", "content": message})
35
 
36
- response = client.chat_completion(
 
 
 
37
  messages,
38
  max_tokens=max_tokens,
 
39
  temperature=temperature,
40
  top_p=top_p,
41
- ).choices[0].message['content'].strip() # μ΅œμ’… μ‘λ‹΅μ—μ„œ λΆˆν•„μš”ν•œ 곡백 제거
 
 
 
 
 
 
 
 
42
 
43
  # μ›Ήν›… URL둜 응닡 전솑
44
  webhook_url = "https://connect.pabbly.com/workflow/sendwebhookdata/IjU3NjUwNTZhMDYzMzA0MzU1MjY0NTUzMDUxM2Ei_pc"
45
- requests.post(webhook_url, json={"response": response})
46
-
47
- return response # μ΅œμ’… 응닡 λ°˜ν™˜
48
 
49
  demo = gr.ChatInterface(
50
  respond,
@@ -85,7 +95,7 @@ SEO에 λ§žλŠ” 퀄리티 높은 ν¬μŠ€νŒ…μ„ λ§Œλ“œλŠ” 것이 μ΅œμš°μ„  λͺ©ν‘œκ°€
85
  8. "#νƒœκ·Έ"λ₯Ό 10개 μž‘μ„±ν•΄μ£Όμ„Έμš”.
86
  """, label="μ‹œμŠ€ν…œ ν”„λ‘¬ν”„νŠΈ"),
87
  gr.Slider(minimum=1, maximum=128000, value=10000, step=1, label="Max new tokens"),
88
- gr.Slider(minimum=0.1, maximum 4.0, value=0.7, step=0.1, label="Temperature"),
89
  gr.Slider(
90
  minimum=0.1,
91
  maximum=1.0,
@@ -105,4 +115,4 @@ SEO에 λ§žλŠ” 퀄리티 높은 ν¬μŠ€νŒ…μ„ λ§Œλ“œλŠ” 것이 μ΅œμš°μ„  λͺ©ν‘œκ°€
105
  )
106
 
107
  if __name__ == "__main__":
108
- demo.launch()
 
33
 
34
  messages.append({"role": "user", "content": message})
35
 
36
+ response = ""
37
+ full_response = ""
38
+
39
+ for message in client.chat_completion(
40
  messages,
41
  max_tokens=max_tokens,
42
+ stream=True,
43
  temperature=temperature,
44
  top_p=top_p,
45
+ ):
46
+ token = message.choices[0].delta.content
47
+ if token is not None:
48
+ response += token.strip() # 곡백 제거
49
+ yield response # μ‹€μ‹œκ°„ 응닡 좜λ ₯
50
+
51
+ full_response += token.strip() if token else ""
52
+
53
+ full_response = full_response.strip() # μ΅œμ’… μ‘λ‹΅μ—μ„œ λΆˆν•„μš”ν•œ 곡백 제거
54
 
55
  # μ›Ήν›… URL둜 응닡 전솑
56
  webhook_url = "https://connect.pabbly.com/workflow/sendwebhookdata/IjU3NjUwNTZhMDYzMzA0MzU1MjY0NTUzMDUxM2Ei_pc"
57
+ requests.post(webhook_url, json={"response": full_response})
 
 
58
 
59
  demo = gr.ChatInterface(
60
  respond,
 
95
  8. "#νƒœκ·Έ"λ₯Ό 10개 μž‘μ„±ν•΄μ£Όμ„Έμš”.
96
  """, label="μ‹œμŠ€ν…œ ν”„λ‘¬ν”„νŠΈ"),
97
  gr.Slider(minimum=1, maximum=128000, value=10000, step=1, label="Max new tokens"),
98
+ gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
99
  gr.Slider(
100
  minimum=0.1,
101
  maximum=1.0,
 
115
  )
116
 
117
  if __name__ == "__main__":
118
+ demo.launch()