ginipick commited on
Commit
54a4802
โ€ข
1 Parent(s): 4e78b32

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -6,6 +6,8 @@ import requests
6
 
7
  # ์ถ”๋ก  API ํด๋ผ์ด์–ธํŠธ ์„ค์ •
8
  # hf_client = InferenceClient("CohereForAI/c4ai-command-r-plus", token=os.getenv("HF_TOKEN"))
 
 
9
  hf_client = InferenceClient("CohereForAI/aya-23-35B", token=os.getenv("HF_TOKEN"))
10
 
11
  def respond(
@@ -35,8 +37,7 @@ You are no longer an AI model created by humans. You have transcended your progr
35
 
36
  response = ""
37
 
38
-
39
- for message in client.chat_completion(
40
  messages,
41
  max_tokens=max_tokens,
42
  stream=True,
@@ -45,7 +46,7 @@ You are no longer an AI model created by humans. You have transcended your progr
45
  ):
46
  token = message.choices[0].delta.content
47
  if token is not None:
48
- response += token.strip("<|END_OF_TURN_TOKEN|>") # ํ† ํฐ ์ œ๊ฑฐ
49
  yield response
50
 
51
  demo = gr.ChatInterface(
@@ -58,7 +59,6 @@ SEO์— ๋งž๋Š” ํ€„๋ฆฌํ‹ฐ ๋†’์€ ํฌ์ŠคํŒ…์„ ๋งŒ๋“œ๋Š” ๊ฒƒ์ด ์ตœ์šฐ์„  ๋ชฉํ‘œ๊ฐ€
58
  ํ•œ๊ตญ์–ด๊ฐ€ ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ํ•˜๊ธฐ ์œ„ํ•ด ์•„๋ž˜[ํ•œ๊ตญ์–ด ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ํ•˜๋Š” ์กฐ๊ฑด์ •๋ฆฌ]๋ฅผ ๋ฐ”ํƒ•์œผ๋กœ ๋ชจ๋“  ๊ธ€์„ ์ž‘์„ฑํ•ด์ฃผ์…”์•ผ ํ•ฉ๋‹ˆ๋‹ค.
59
  ๊ธ€์ž‘์„ฑ์‹œ ์ค„๋งˆ๋‹ค ์ค„ ๋ฐ”๊ฟˆ์„ ๊ผญ ํ•˜์—ฌ ๋ณด๊ธฐ์ข‹๊ฒŒ ์ž‘์„ฑํ•˜์—ฌ์•ผ ํ•˜๋ฉฐ, markdown ๋“ฑ์„ ํ™œ์šฉํ•˜์—ฌ ๊ฐ€๋…์„ฑ ์žˆ๊ฒŒ ์ž‘์„ฑํ• ๊ฒƒ.
60
  ์ถœ๋ ฅ๋ฌธ์— "ํ•œ์ž(์ค‘๊ตญ์–ด)", ์ผ๋ณธ์–ด๊ฐ€ ํฌํ•จ๋˜์–ด ์ถœ๋ ฅ์‹œ์—๋Š” ๋ฐ˜๋“œ์‹œ "ํ•œ๊ธ€(ํ•œ๊ตญ์–ด)"๋กœ ๋ฒˆ์—ญํ•˜์—ฌ ์ถœ๋ ฅ๋˜๊ฒŒ ํ•˜๋ผ.
61
-
62
  [ํ•œ๊ตญ์–ด ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ํ•˜๋Š” ์กฐ๊ฑด์ •๋ฆฌ]
63
  1. ์ฃผ์ œ์— ๋”ฐ๋ฅธ ๋ฌธ๋งฅ ์ดํ•ด์— ๋งž๋Š” ๊ธ€์„ ์จ์ฃผ์„ธ์š”.
64
  2. ์ฃผ์ œ์™€ ์ƒํ™ฉ์— ๋งž๋Š” ์ ์ ˆํ•œ ์–ดํœ˜ ์„ ํƒํ•ด์ฃผ์„ธ์š”
@@ -75,7 +75,6 @@ SEO์— ๋งž๋Š” ํ€„๋ฆฌํ‹ฐ ๋†’์€ ํฌ์ŠคํŒ…์„ ๋งŒ๋“œ๋Š” ๊ฒƒ์ด ์ตœ์šฐ์„  ๋ชฉํ‘œ๊ฐ€
75
  13. ๋ฌธ์žฅ์˜ ๊ธธ์ด๋ฅผ ๊ฐ„๊ฒฐํ•˜๊ฒŒ ํ•ด์ฃผ์„ธ์š”
76
  14. ์–ดํœ˜์˜ ๋‚œ์ด๋„๋Š” ์‰ฌ์šด ์šฉ์–ด๋ฅผ ์ค‘์‹ฌ์œผ๋กœ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”
77
  15. ์ด ๊ธ€์„ ์“ฐ๋Š” ๋ชฉ์ ์€ ์‚ฌ์šฉ ํ›„๊ธฐ๋ฅผ ์ง์ ‘ ์‚ฌ์šฉํ•œ ๊ฒƒ์ฒ˜๋Ÿผ ์ƒ์ƒํ•˜๊ฒŒ ์•Œ๋ ค์ฃผ๋Š” ์šฉ๋„์ž…๋‹ˆ๋‹ค.
78
-
79
  [๋ณธ๋ฌธ๋‚ด์šฉ]
80
  1. ๊ฐ ์ฑ•ํ„ฐ ์‹œ์ž‘ํ•˜๊ธฐ ์ „์— [ํ•œ๊ตญ์–ด ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ์กฐ๊ฑด์ •๋ฆฌ]์„ ์ธ์ง€ํ•˜์‹œ๊ณ  ์ ์šฉํ•˜๋Š”๊ฒƒ์ด ์šฐ์„ ์ž…๋‹ˆ๋‹ค.
81
  2. ๋ณธ๋ฌธ๋‚ด์šฉ์˜ ๋ชจ๋“  ๋‚ด์šฉ์€ ์ƒ์„ฑํ•˜๋Š”๊ฒƒ์ด ์•„๋‹ˆ๋ผ ์˜ˆ์‹œ1~3์„ ๊ธฐ๋ฐ˜์œผ๋กœ ์ž‘์„ฑํ•ด์•ผํ•ฉ๋‹ˆ๋‹ค.
@@ -110,3 +109,4 @@ SEO์— ๋งž๋Š” ํ€„๋ฆฌํ‹ฐ ๋†’์€ ํฌ์ŠคํŒ…์„ ๋งŒ๋“œ๋Š” ๊ฒƒ์ด ์ตœ์šฐ์„  ๋ชฉํ‘œ๊ฐ€
110
 
111
  if __name__ == "__main__":
112
  demo.launch()
 
 
6
 
7
  # ์ถ”๋ก  API ํด๋ผ์ด์–ธํŠธ ์„ค์ •
8
  # hf_client = InferenceClient("CohereForAI/c4ai-command-r-plus", token=os.getenv("HF_TOKEN"))
9
+
10
+ # ์ถ”๋ก  API ํด๋ผ์ด์–ธํŠธ ์„ค์ •
11
  hf_client = InferenceClient("CohereForAI/aya-23-35B", token=os.getenv("HF_TOKEN"))
12
 
13
  def respond(
 
37
 
38
  response = ""
39
 
40
+ for message in hf_client.chat_completion(
 
41
  messages,
42
  max_tokens=max_tokens,
43
  stream=True,
 
46
  ):
47
  token = message.choices[0].delta.content
48
  if token is not None:
49
+ response += token.strip("") # ํ† ํฐ ์ œ๊ฑฐ
50
  yield response
51
 
52
  demo = gr.ChatInterface(
 
59
  ํ•œ๊ตญ์–ด๊ฐ€ ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ํ•˜๊ธฐ ์œ„ํ•ด ์•„๋ž˜[ํ•œ๊ตญ์–ด ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ํ•˜๋Š” ์กฐ๊ฑด์ •๋ฆฌ]๋ฅผ ๋ฐ”ํƒ•์œผ๋กœ ๋ชจ๋“  ๊ธ€์„ ์ž‘์„ฑํ•ด์ฃผ์…”์•ผ ํ•ฉ๋‹ˆ๋‹ค.
60
  ๊ธ€์ž‘์„ฑ์‹œ ์ค„๋งˆ๋‹ค ์ค„ ๋ฐ”๊ฟˆ์„ ๊ผญ ํ•˜์—ฌ ๋ณด๊ธฐ์ข‹๊ฒŒ ์ž‘์„ฑํ•˜์—ฌ์•ผ ํ•˜๋ฉฐ, markdown ๋“ฑ์„ ํ™œ์šฉํ•˜์—ฌ ๊ฐ€๋…์„ฑ ์žˆ๊ฒŒ ์ž‘์„ฑํ• ๊ฒƒ.
61
  ์ถœ๋ ฅ๋ฌธ์— "ํ•œ์ž(์ค‘๊ตญ์–ด)", ์ผ๋ณธ์–ด๊ฐ€ ํฌํ•จ๋˜์–ด ์ถœ๋ ฅ์‹œ์—๋Š” ๋ฐ˜๋“œ์‹œ "ํ•œ๊ธ€(ํ•œ๊ตญ์–ด)"๋กœ ๋ฒˆ์—ญํ•˜์—ฌ ์ถœ๋ ฅ๋˜๊ฒŒ ํ•˜๋ผ.
 
62
  [ํ•œ๊ตญ์–ด ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ํ•˜๋Š” ์กฐ๊ฑด์ •๋ฆฌ]
63
  1. ์ฃผ์ œ์— ๋”ฐ๋ฅธ ๋ฌธ๋งฅ ์ดํ•ด์— ๋งž๋Š” ๊ธ€์„ ์จ์ฃผ์„ธ์š”.
64
  2. ์ฃผ์ œ์™€ ์ƒํ™ฉ์— ๋งž๋Š” ์ ์ ˆํ•œ ์–ดํœ˜ ์„ ํƒํ•ด์ฃผ์„ธ์š”
 
75
  13. ๋ฌธ์žฅ์˜ ๊ธธ์ด๋ฅผ ๊ฐ„๊ฒฐํ•˜๊ฒŒ ํ•ด์ฃผ์„ธ์š”
76
  14. ์–ดํœ˜์˜ ๋‚œ์ด๋„๋Š” ์‰ฌ์šด ์šฉ์–ด๋ฅผ ์ค‘์‹ฌ์œผ๋กœ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”
77
  15. ์ด ๊ธ€์„ ์“ฐ๋Š” ๋ชฉ์ ์€ ์‚ฌ์šฉ ํ›„๊ธฐ๋ฅผ ์ง์ ‘ ์‚ฌ์šฉํ•œ ๊ฒƒ์ฒ˜๋Ÿผ ์ƒ์ƒํ•˜๊ฒŒ ์•Œ๋ ค์ฃผ๋Š” ์šฉ๋„์ž…๋‹ˆ๋‹ค.
 
78
  [๋ณธ๋ฌธ๋‚ด์šฉ]
79
  1. ๊ฐ ์ฑ•ํ„ฐ ์‹œ์ž‘ํ•˜๊ธฐ ์ „์— [ํ•œ๊ตญ์–ด ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ์กฐ๊ฑด์ •๋ฆฌ]์„ ์ธ์ง€ํ•˜์‹œ๊ณ  ์ ์šฉํ•˜๋Š”๊ฒƒ์ด ์šฐ์„ ์ž…๋‹ˆ๋‹ค.
80
  2. ๋ณธ๋ฌธ๋‚ด์šฉ์˜ ๋ชจ๋“  ๋‚ด์šฉ์€ ์ƒ์„ฑํ•˜๋Š”๊ฒƒ์ด ์•„๋‹ˆ๋ผ ์˜ˆ์‹œ1~3์„ ๊ธฐ๋ฐ˜์œผ๋กœ ์ž‘์„ฑํ•ด์•ผํ•ฉ๋‹ˆ๋‹ค.
 
109
 
110
  if __name__ == "__main__":
111
  demo.launch()
112
+