Spaces:
Runtime error
Runtime error
leandrocarneiro
commited on
Upload rag.py
Browse files
rag.py
CHANGED
@@ -61,22 +61,20 @@ class Rag:
|
|
61 |
self.vectorstore = vectorstore
|
62 |
self.memory = ConversationBufferMemory(memory_key="chat_history", return_messages=True, output_key="answer")
|
63 |
|
64 |
-
#
|
65 |
-
#Do not use only your knowledge to make the news.
|
66 |
-
prompt_template = """Your task is to create news for a newspaper based on pieces of text delimited by <> and a question delimited by <>.
|
67 |
-
Do not use only your knowledge to make the news. Make the news based on the question, but using the pieces of text.
|
68 |
-
If the pieces of text don't enough information about the question to create the news, just say that you need more sources of information, nothing more.
|
69 |
-
The news should have a title.
|
70 |
-
The news should be written in a formal language.
|
71 |
-
The news should have between {min_words} and {max_words} words and it should be in Portuguese language.
|
72 |
-
The news should be about the following context: <{context}>
|
73 |
-
Question: <{question}>
|
74 |
-
Answer here:"""
|
75 |
-
self.prompt = PromptTemplate(template=prompt_template,
|
76 |
-
input_variables=["context", "question"],
|
77 |
-
partial_variables={"min_words": min_words, "max_words": max_words})
|
78 |
-
|
79 |
if model == 'openai':
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
self.qa = ConversationalRetrievalChain.from_llm(
|
81 |
llm=ChatOpenAI(model_name="gpt-3.5-turbo-0125", #0125 #1106
|
82 |
temperature=0,
|
@@ -91,6 +89,20 @@ class Rag:
|
|
91 |
return_source_documents=True,
|
92 |
)
|
93 |
else:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
self.qa = ConversationalRetrievalChain.from_llm(
|
95 |
llm=Together(model="mistralai/Mixtral-8x7B-Instruct-v0.1", #0125 #1106
|
96 |
temperature=0,
|
|
|
61 |
self.vectorstore = vectorstore
|
62 |
self.memory = ConversationBufferMemory(memory_key="chat_history", return_messages=True, output_key="answer")
|
63 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
if model == 'openai':
|
65 |
+
prompt_template = """Your task is to create news for a newspaper based on pieces of text delimited by <> and a question delimited by <>.
|
66 |
+
Do not use only your knowledge to make the news. Make the news based on the question, but using the pieces of text.
|
67 |
+
If the pieces of text don't enough information about the question to create the news, just say that you need more sources of information, nothing more.
|
68 |
+
The news should have a title.
|
69 |
+
The news should be written in a formal language.
|
70 |
+
The news should have between {min_words} and {max_words} words and it should be in Portuguese language.
|
71 |
+
The news should be about the following context: <{context}>
|
72 |
+
Question: <{question}>
|
73 |
+
Answer here:"""
|
74 |
+
self.prompt = PromptTemplate(template=prompt_template,
|
75 |
+
input_variables=["context", "question"],
|
76 |
+
partial_variables={"min_words": min_words, "max_words": max_words})
|
77 |
+
|
78 |
self.qa = ConversationalRetrievalChain.from_llm(
|
79 |
llm=ChatOpenAI(model_name="gpt-3.5-turbo-0125", #0125 #1106
|
80 |
temperature=0,
|
|
|
89 |
return_source_documents=True,
|
90 |
)
|
91 |
else:
|
92 |
+
prompt_template = """Your task is to create news for a newspaper based on pieces of text delimited by <> and a question delimited by <>.
|
93 |
+
Do not use only your knowledge to make the news. Make the news based on the question, but using the pieces of text.
|
94 |
+
If the pieces of text don't enough information about the question to create the news, just say that you need more sources of information, nothing more.
|
95 |
+
The news should have a title.
|
96 |
+
The news should be written in a formal language.
|
97 |
+
The source should not be in the news.
|
98 |
+
The news should have between {min_words} and {max_words} words and it should be in Portuguese language.
|
99 |
+
The news should be about the following context: <{context}>
|
100 |
+
Question: <{question}>
|
101 |
+
Answer here:"""
|
102 |
+
self.prompt = PromptTemplate(template=prompt_template,
|
103 |
+
input_variables=["context", "question"],
|
104 |
+
partial_variables={"min_words": min_words, "max_words": max_words})
|
105 |
+
|
106 |
self.qa = ConversationalRetrievalChain.from_llm(
|
107 |
llm=Together(model="mistralai/Mixtral-8x7B-Instruct-v0.1", #0125 #1106
|
108 |
temperature=0,
|