Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -16,32 +16,32 @@ models = {
|
|
16 |
def get_client(model):
|
17 |
return InferenceClient(model=model, token=hf_token)
|
18 |
|
19 |
-
def respond(message,
|
20 |
stop_event.clear()
|
21 |
-
client =
|
22 |
|
23 |
-
messages = [{"role": "system", "content": system_message}]
|
24 |
-
messages.extend([{"role": "user" if i % 2 == 0 else "assistant", "content": m} for h in
|
25 |
messages.append({"role": "user", "content": message})
|
26 |
|
27 |
-
response = ""
|
28 |
try:
|
29 |
-
|
30 |
-
|
31 |
-
|
|
|
32 |
temperature=temperature,
|
33 |
top_p=top_p,
|
34 |
stream=True
|
35 |
):
|
36 |
if stop_event.is_set():
|
37 |
break
|
38 |
-
if
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
response += token
|
44 |
yield response
|
|
|
45 |
except Exception as e:
|
46 |
yield f"오류 발생: {str(e)}"
|
47 |
|
|
|
16 |
def get_client(model):
|
17 |
return InferenceClient(model=model, token=hf_token)
|
18 |
|
19 |
+
def respond(message, history, system_message, max_tokens, temperature, top_p, selected_model):
|
20 |
stop_event.clear()
|
21 |
+
client = InferenceClient(model=selected_model, token=hf_token)
|
22 |
|
23 |
+
messages = [{"role": "system", "content": system_message + "\n사용자의 입력에만 직접적으로 답변하세요. 추가 질문을 생성하거나 사용자의 입력을 확장하지 마세요."}]
|
24 |
+
messages.extend([{"role": "user" if i % 2 == 0 else "assistant", "content": m} for h in history for i, m in enumerate(h) if m])
|
25 |
messages.append({"role": "user", "content": message})
|
26 |
|
|
|
27 |
try:
|
28 |
+
response = ""
|
29 |
+
for chunk in client.text_generation(
|
30 |
+
prompt="\n".join([f"{m['role']}: {m['content']}" for m in messages]),
|
31 |
+
max_new_tokens=max_tokens,
|
32 |
temperature=temperature,
|
33 |
top_p=top_p,
|
34 |
stream=True
|
35 |
):
|
36 |
if stop_event.is_set():
|
37 |
break
|
38 |
+
if chunk:
|
39 |
+
response += chunk
|
40 |
+
# 응답의 시작 부분에서 사용자 입력의 반복을 제거
|
41 |
+
if response.startswith(message):
|
42 |
+
response = response[len(message):].lstrip()
|
|
|
43 |
yield response
|
44 |
+
|
45 |
except Exception as e:
|
46 |
yield f"오류 발생: {str(e)}"
|
47 |
|