Update app.py
Browse files
app.py
CHANGED
@@ -40,44 +40,20 @@ print(top_results)
|
|
40 |
|
41 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
42 |
|
43 |
-
# def respond(message, history):
|
44 |
-
# response = ""
|
45 |
-
|
46 |
-
# messages = [{"role": "system", "content": "You are a chatbot that helps users create characters for role playing games."}]
|
47 |
-
|
48 |
-
# if history:
|
49 |
-
# messages.extend(history)
|
50 |
-
|
51 |
-
# messages.append({"role": "user", "content": message})
|
52 |
-
|
53 |
-
# stream = client.chat_completion(
|
54 |
-
# messages,
|
55 |
-
# max_tokens=100,
|
56 |
-
# temperature=1.2,
|
57 |
-
# stream=True
|
58 |
-
# )
|
59 |
-
|
60 |
-
# for message in stream:
|
61 |
-
# token = message.choices[0].delta.content
|
62 |
-
|
63 |
-
# if token is not None:
|
64 |
-
# response += token
|
65 |
-
# yield response
|
66 |
|
67 |
def respond(message, history):
|
68 |
response = ""
|
69 |
|
70 |
-
# Retrieve top chunks based on the current user message
|
71 |
top_chunks = get_top_chunks(message)
|
72 |
context = "\n".join(top_chunks)
|
73 |
|
74 |
-
# Add knowledge as part of system instructions
|
75 |
messages = [
|
76 |
{
|
77 |
"role": "system",
|
78 |
"content": (
|
79 |
"You are a chatbot that helps users create characters for role-playing games. "
|
80 |
"Use the following knowledge to inform your answers:\n\n" + context
|
|
|
81 |
)
|
82 |
}
|
83 |
]
|
@@ -89,7 +65,7 @@ def respond(message, history):
|
|
89 |
|
90 |
stream = client.chat_completion(
|
91 |
messages,
|
92 |
-
max_tokens=
|
93 |
temperature=1.2,
|
94 |
stream=True
|
95 |
)
|
|
|
40 |
|
41 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
|
44 |
def respond(message, history):
|
45 |
response = ""
|
46 |
|
|
|
47 |
top_chunks = get_top_chunks(message)
|
48 |
context = "\n".join(top_chunks)
|
49 |
|
|
|
50 |
messages = [
|
51 |
{
|
52 |
"role": "system",
|
53 |
"content": (
|
54 |
"You are a chatbot that helps users create characters for role-playing games. "
|
55 |
"Use the following knowledge to inform your answers:\n\n" + context
|
56 |
+
"Make sure to finish all your sentences before you run out of tokens."
|
57 |
)
|
58 |
}
|
59 |
]
|
|
|
65 |
|
66 |
stream = client.chat_completion(
|
67 |
messages,
|
68 |
+
max_tokens=500,
|
69 |
temperature=1.2,
|
70 |
stream=True
|
71 |
)
|