Update app.py
Browse files
app.py
CHANGED
@@ -22,10 +22,6 @@ collection = client.get_or_create_collection("patents")
|
|
22 |
|
23 |
collection.add(documents=docs,ids=ids)
|
24 |
|
25 |
-
def text_embedding(text)-> None:
|
26 |
-
model = SentenceTransformer('sentence-transformers/all-MiniLM-L6-v2')
|
27 |
-
return model.encode(text)
|
28 |
-
|
29 |
def gen_context(query):
|
30 |
vector = text_embedding(query).tolist()
|
31 |
|
@@ -37,13 +33,8 @@ def gen_context(query):
|
|
37 |
|
38 |
def chat_completion(user_prompt):
|
39 |
length = 1000
|
40 |
-
system_prompt = """\
|
41 |
-
|
42 |
-
final_prompt = f"""<s>[INST]<<SYS>>
|
43 |
-
{system_prompt}
|
44 |
-
<</SYS>>
|
45 |
-
|
46 |
-
{user_prompt}[/INST]"""
|
47 |
|
48 |
return client.text_generation(prompt=final_prompt,max_new_tokens = length).strip()
|
49 |
|
@@ -51,28 +42,7 @@ You are a helpful AI assistant that can answer questions on the patents dataset.
|
|
51 |
|
52 |
client = InferenceClient(model = "mistralai/Mixtral-8x7B-Instruct-v0.1")
|
53 |
|
54 |
-
|
55 |
-
length = 1000
|
56 |
-
|
57 |
-
context = gen_context(query)
|
58 |
-
|
59 |
-
user_prompt = f"""
|
60 |
-
Based on the context:
|
61 |
-
{context}
|
62 |
-
Answer the below query:
|
63 |
-
{query}
|
64 |
-
"""
|
65 |
-
system_prompt = """\
|
66 |
-
You are a helpful AI assistant that can answer questions on the patents dataset. Answer based on the context provided.If you cannot find the correct answer, say I don't know. Be concise and just include the response"""
|
67 |
-
final_prompt = f"""<s>[INST]<<SYS>>
|
68 |
-
{system_prompt}
|
69 |
-
<</SYS>>
|
70 |
-
|
71 |
-
{user_prompt}[/INST]"""
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
return client.text_generation(prompt=final_prompt,max_new_tokens = length).strip()
|
76 |
|
77 |
demo = gr.Interface(fn=chat_completion,
|
78 |
inputs=[gr.Textbox(label="Query", lines=2)],
|
|
|
22 |
|
23 |
collection.add(documents=docs,ids=ids)
|
24 |
|
|
|
|
|
|
|
|
|
25 |
def gen_context(query):
|
26 |
vector = text_embedding(query).tolist()
|
27 |
|
|
|
33 |
|
34 |
def chat_completion(user_prompt):
|
35 |
length = 1000
|
36 |
+
system_prompt = """\You are a helpful AI assistant that can answer questions on the patents dataset. Answer based on the context provided.If you cannot find the correct answer, say I don't know. Be concise and just include the response"""
|
37 |
+
final_prompt = f"""<s>[INST]<<SYS>>{system_prompt}<</SYS>>{user_prompt}[/INST]"""
|
|
|
|
|
|
|
|
|
|
|
38 |
|
39 |
return client.text_generation(prompt=final_prompt,max_new_tokens = length).strip()
|
40 |
|
|
|
42 |
|
43 |
client = InferenceClient(model = "mistralai/Mixtral-8x7B-Instruct-v0.1")
|
44 |
|
45 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
|
47 |
demo = gr.Interface(fn=chat_completion,
|
48 |
inputs=[gr.Textbox(label="Query", lines=2)],
|