aiqtech commited on
Commit
bf14d40
ยท
verified ยท
1 Parent(s): b6f8016

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -10
app.py CHANGED
@@ -11,12 +11,14 @@ if not hf_token:
11
 
12
  # ๋ชจ๋ธ ์ •๋ณด ํ™•์ธ
13
  api = HfApi(token=hf_token)
 
14
  try:
15
- model_info = api.model_info("meta-llama/Meta-Llama-3-70B-Instruct")
16
- print(f"๋ชจ๋ธ ์ •๋ณด: {model_info}")
17
  except Exception as e:
18
- print(f"๋ชจ๋ธ ์ •๋ณด๋ฅผ ๊ฐ€์ ธ์˜ค๋Š” ๋ฐ ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค: {e}")
19
  # ๋Œ€์ฒด ๋ชจ๋ธ์„ ์‚ฌ์šฉํ•˜๊ฑฐ๋‚˜ ์˜ค๋ฅ˜ ์ฒ˜๋ฆฌ๋ฅผ ์ˆ˜ํ–‰ํ•˜์„ธ์š”.
 
 
20
 
21
  # InferenceClient ์ดˆ๊ธฐํ™”
22
  client = InferenceClient("meta-llama/Meta-Llama-3-70B-Instruct", token=hf_token)
@@ -70,14 +72,17 @@ def respond(
70
  temperature=temperature,
71
  top_p=top_p,
72
  ):
73
- if message is not None and hasattr(message, 'choices') and len(message.choices) > 0:
74
- delta = message.choices[0].delta
75
- if delta is not None and hasattr(delta, 'content') and delta.content is not None:
76
- token = delta.content.strip("<|END_OF_TURN_TOKEN|>")
77
- response += token
78
- yield response
 
 
 
79
  else:
80
- print("Received unexpected message format:", message)
81
  except Exception as e:
82
  print(f"Error during chat completion: {e}")
83
  yield f"์ฃ„์†กํ•ฉ๋‹ˆ๋‹ค. ์‘๋‹ต ์ƒ์„ฑ ์ค‘ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค: {str(e)}"
 
11
 
12
  # ๋ชจ๋ธ ์ •๋ณด ํ™•์ธ
13
  api = HfApi(token=hf_token)
14
+
15
  try:
16
+ client = InferenceClient("meta-llama/Meta-Llama-3-70B-Instruct", token=hf_token)
 
17
  except Exception as e:
18
+ print(f"Error initializing InferenceClient: {e}")
19
  # ๋Œ€์ฒด ๋ชจ๋ธ์„ ์‚ฌ์šฉํ•˜๊ฑฐ๋‚˜ ์˜ค๋ฅ˜ ์ฒ˜๋ฆฌ๋ฅผ ์ˆ˜ํ–‰ํ•˜์„ธ์š”.
20
+ # ์˜ˆ: client = InferenceClient("gpt2", token=hf_token)
21
+
22
 
23
  # InferenceClient ์ดˆ๊ธฐํ™”
24
  client = InferenceClient("meta-llama/Meta-Llama-3-70B-Instruct", token=hf_token)
 
72
  temperature=temperature,
73
  top_p=top_p,
74
  ):
75
+ if message is not None:
76
+ if hasattr(message, 'choices') and len(message.choices) > 0:
77
+ delta = message.choices[0].delta
78
+ if hasattr(delta, 'content') and delta.content is not None:
79
+ token = delta.content.strip("<|END_OF_TURN_TOKEN|>")
80
+ response += token
81
+ yield response
82
+ else:
83
+ print("Received message without choices:", message)
84
  else:
85
+ print("Received None message")
86
  except Exception as e:
87
  print(f"Error during chat completion: {e}")
88
  yield f"์ฃ„์†กํ•ฉ๋‹ˆ๋‹ค. ์‘๋‹ต ์ƒ์„ฑ ์ค‘ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค: {str(e)}"