Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -51,22 +51,22 @@ llm_classes = {
|
|
51 |
|
52 |
xml_system = """You're a helpful AI assistant. Given a user prompt and some related sources, \
|
53 |
fulfill all the requirements of the prompt and provide citations. If a part of the generated text does \
|
54 |
-
not use any of the sources, don't put a citation for that part. Otherwise, list all sources used for that part of the
|
55 |
At the end of each relevant part, add a citation in square brackets, numbered sequentially starting from [0], regardless of the source's original ID.
|
56 |
|
57 |
|
58 |
Remember, you must return both the requested text and citations. A citation consists of a VERBATIM quote that \
|
59 |
-
justifies the
|
60 |
-
that justify the
|
61 |
|
62 |
-
<
|
63 |
-
<
|
64 |
<citations>
|
65 |
<citation><source_id></source_id><source></source><quote></quote></citation>
|
66 |
<citation><source_id></source_id><source></source><quote></quote></citation>
|
67 |
...
|
68 |
</citations>
|
69 |
-
</
|
70 |
|
71 |
Here are the sources:{context}"""
|
72 |
xml_prompt = ChatPromptTemplate.from_messages(
|
@@ -190,13 +190,13 @@ def generate_rag(
|
|
190 |
result = rag_chain.invoke({"input": prompt})
|
191 |
from pprint import pprint
|
192 |
pprint(result)
|
193 |
-
return result['
|
194 |
|
195 |
|
196 |
def process_input(topic, length, tone, format_, pdfs):
|
197 |
# Construct the prompt
|
198 |
prompt = f"Write a {format_} about {topic} in about {length} words and a {tone} tone."
|
199 |
-
|
200 |
# Generate the text and citations using RAG
|
201 |
rag_output = generate_rag(
|
202 |
prompt=prompt,
|
|
|
51 |
|
52 |
xml_system = """You're a helpful AI assistant. Given a user prompt and some related sources, \
|
53 |
fulfill all the requirements of the prompt and provide citations. If a part of the generated text does \
|
54 |
+
not use any of the sources, don't put a citation for that part. Otherwise, list all sources used for that part of the text.
|
55 |
At the end of each relevant part, add a citation in square brackets, numbered sequentially starting from [0], regardless of the source's original ID.
|
56 |
|
57 |
|
58 |
Remember, you must return both the requested text and citations. A citation consists of a VERBATIM quote that \
|
59 |
+
justifies the text and a sequential number (starting from 0) for the quote's article. Return a citation for every quote across all articles \
|
60 |
+
that justify the text. Use the following format for your final output:
|
61 |
|
62 |
+
<cited_text>
|
63 |
+
<text></text>
|
64 |
<citations>
|
65 |
<citation><source_id></source_id><source></source><quote></quote></citation>
|
66 |
<citation><source_id></source_id><source></source><quote></quote></citation>
|
67 |
...
|
68 |
</citations>
|
69 |
+
</cited_text>
|
70 |
|
71 |
Here are the sources:{context}"""
|
72 |
xml_prompt = ChatPromptTemplate.from_messages(
|
|
|
190 |
result = rag_chain.invoke({"input": prompt})
|
191 |
from pprint import pprint
|
192 |
pprint(result)
|
193 |
+
return result['cited_text'][0]['text'], result['cited_text'][1]['citations']
|
194 |
|
195 |
|
196 |
def process_input(topic, length, tone, format_, pdfs):
|
197 |
# Construct the prompt
|
198 |
prompt = f"Write a {format_} about {topic} in about {length} words and a {tone} tone."
|
199 |
+
print(prompt)
|
200 |
# Generate the text and citations using RAG
|
201 |
rag_output = generate_rag(
|
202 |
prompt=prompt,
|