Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,43 +1,45 @@
|
|
1 |
import gradio as gr
|
2 |
-
from huggingface_hub import InferenceClient
|
3 |
|
4 |
-
|
5 |
-
|
6 |
-
"""
|
7 |
-
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
8 |
|
9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
def respond(
|
11 |
-
|
12 |
-
history
|
13 |
system_message,
|
14 |
max_tokens,
|
15 |
temperature,
|
16 |
top_p,
|
17 |
):
|
18 |
-
|
19 |
-
|
20 |
-
for val in history:
|
21 |
-
if val[0]:
|
22 |
-
messages.append({"role": "user", "content": val[0]})
|
23 |
-
if val[1]:
|
24 |
-
messages.append({"role": "assistant", "content": val[1]})
|
25 |
-
|
26 |
-
messages.append({"role": "user", "content": message})
|
27 |
-
|
28 |
-
response = ""
|
29 |
-
|
30 |
-
for message in client.chat_completion(
|
31 |
-
messages,
|
32 |
-
max_tokens=max_tokens,
|
33 |
-
stream=True,
|
34 |
-
temperature=temperature,
|
35 |
-
top_p=top_p,
|
36 |
-
):
|
37 |
-
token = message.choices[0].delta.content
|
38 |
-
|
39 |
-
response += token
|
40 |
-
yield response
|
41 |
|
42 |
|
43 |
"""
|
|
|
1 |
import gradio as gr
|
|
|
2 |
|
3 |
+
from db import get_db
|
4 |
+
from chain import get_chain
|
|
|
|
|
5 |
|
6 |
|
7 |
+
vectordb = get_db(
|
8 |
+
chunk_size=1000,
|
9 |
+
chunk_overlap=200,
|
10 |
+
model_path = 'intfloat/multilingual-e5-large-instruct',
|
11 |
+
)
|
12 |
+
|
13 |
+
chain = get_chain(
|
14 |
+
vectordb,
|
15 |
+
repo_id="HuggingFaceH4/zephyr-7b-beta",
|
16 |
+
task="text-generation",
|
17 |
+
max_new_tokens=512,
|
18 |
+
top_k=30,
|
19 |
+
temperature=0.1,
|
20 |
+
repetition_penalty=1.03,
|
21 |
+
search_type="mmr",
|
22 |
+
k=3,
|
23 |
+
fetch_k=5,
|
24 |
+
template="""Use the following sentences of context to answer the question at the end.
|
25 |
+
If you don't know the answer, that is if the answer is not in the context, then just say that you don't know, don't try to make up an answer.
|
26 |
+
Always say "Thanks for asking!" at the end of the answer.
|
27 |
+
|
28 |
+
{context}
|
29 |
+
|
30 |
+
Question: {question}
|
31 |
+
Helpful Answer:"""
|
32 |
+
)
|
33 |
+
|
34 |
def respond(
|
35 |
+
question,
|
36 |
+
_, # Ignore the message history parameter since we are doing one-off invocations
|
37 |
system_message,
|
38 |
max_tokens,
|
39 |
temperature,
|
40 |
top_p,
|
41 |
):
|
42 |
+
return rag_chain.invoke({'question': question})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
|
44 |
|
45 |
"""
|