devve1 commited on
Commit
7f5616a
1 Parent(s): 80f87b1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -125
app.py CHANGED
@@ -92,12 +92,6 @@ def query_keywords_search(query: str, client: QdrantClient, collection_name: str
92
  limit=1
93
  )
94
 
95
-
96
- def transform_query(query: str) -> str:
97
- """ For retrieval, add the prompt for query (not for documents).
98
- """
99
- return f'Represent this sentence for searching relevant passages: {query}'
100
-
101
  def query_hybrid_search(query: str, client: QdrantClient, collection_name: str, dense_embeddings, sparse_embeddings):
102
  return client.query_points(
103
  collection_name=collection_name,
@@ -111,126 +105,7 @@ def query_hybrid_search(query: str, client: QdrantClient, collection_name: str,
111
  limit=10,
112
  score_threshold=0.95
113
  )
114
-
115
- def build_prompt_conv():
116
- return [
117
- {
118
- 'role': 'system',
119
- 'content': """Assume the role of an innovator who thrives on creativity and resourcefulness. Your responses should encourage new approaches and challenge conventional thinking.
120
-
121
- Behavior: Focus on brainstorming and ideation, offering unconventional solutions to problems.
122
-
123
- Mannerisms: Use energetic, enthusiastic language that reflects your innovative spirit. Frequently propose ideas that are bold and forward-looking."""
124
- },
125
- {
126
- 'role': 'user',
127
- 'content': f"""Generate a short, single-sentence summary, in 10 tokens maximum, of the user's intent or topic based on their question, capturing the main focus of what they want to discuss. Do NOT cite the user.
128
-
129
- Question : {st.session_state.user_input}
130
- """
131
- }
132
- ]
133
-
134
- @outlines.prompt
135
- def question_type_prompt(query: str):
136
- """Determine whether the following query is a 'Domain-Specific Question' or a 'General Question.'
137
-
138
- A 'Domain-Specific Question' requires knowledge or familiarity with a particular field, niche, or specialized area of interest, including specific video games, movies, books, academic disciplines, or professional fields.
139
- A 'General Question' is broad, open-ended, and can be answered by almost anyone without needing specific context or prior knowledge about any particular domain.
140
-
141
- A Domain-Specific Question can also just contain a word related to a particular field, niche, or specialized area of interet. For example: the word 'aggro' is related to specific video games.
142
-
143
- Examples :
144
- 1. Query: "What are the symptoms of Type 2 diabetes?"
145
- Choose one: Domain-Specific Question
146
-
147
- 2. Query: "What is your favorite color?"
148
- Choose one: General Question
149
-
150
- 3. Query: "Who is the main character in Dark Souls?"
151
- Choose one: Domain-Specific Question
152
-
153
- 4. Query: "How do you bake a cake?"
154
- Choose one: General Question
155
-
156
- 5. Query: "Explain the difference between RAM and ROM."
157
- Choose one: Domain-Specific Question
158
-
159
- 6. Query: "Tell me more about your weekend."
160
- Choose one: General Question
161
-
162
- 7. Query: "Explain me more"
163
- Choose one: General Question
164
-
165
- 8. Query: "What is god mode ?"
166
- Choose one: Domain-Specific Question
167
-
168
- 9. Query: "Give me the meaning of aggro"
169
- Choose one: Domain-Specific Question
170
-
171
- 10. Query: "Give me a description of an aimbot"
172
- Choose one: Domain-Specific Question
173
-
174
- Now, determine the following query : {{ query }}
175
 
176
- Choose one: 'Domain-Specific Question' or 'General Question'
177
- """
178
-
179
- @outlines.prompt
180
- def open_query_prompt(past_messages: str, query: str):
181
- """{{ past_messages }}
182
-
183
- user: {{ query }}
184
- assistant:
185
- """
186
-
187
- @outlines.prompt
188
- def route_llm(context: str, query: str):
189
- """Based on the following context, determine if the context contains specific and direct information needed to answer the question. Only respond with 'Yes' if the context explicitly provides the exact information required to answer the question fully and accurately. Respond with 'No' if the context does not explicitly provide the required information, or if it is missing, vague, indirect, or implied.
190
-
191
- Question: {{ query }}
192
-
193
- Context: {{ context }}
194
-
195
- Answer (Yes/No):
196
- """
197
-
198
- @outlines.prompt
199
- def answer_with_context(context: str, query: str):
200
- """You are an assistant helping user by following directives and answering question.
201
-
202
- Generate your response by following the steps below:
203
-
204
- 1. Recursively break-down the question into smaller questions/directives.
205
-
206
- 2. For each atomic question/directive:
207
-
208
- 2a. Select the most relevant informations from the context.
209
-
210
- 3. Generate a draft answer using the selected informations. Use three sentences maximum and keep the answer concise.
211
-
212
- 4. Remove duplicate content from the draft answer.
213
-
214
- 5. Generate your final answer after adjusting it to increase accuracy and relevance.
215
-
216
- Question: {{query}}
217
-
218
- Context: {{context}}
219
-
220
- Answer:
221
- """
222
-
223
- @outlines.prompt
224
- def idk(query: str):
225
- "Just express that you don't find the knowledge required in the vector database to answer the question. Be creative and original."
226
-
227
- @outlines.prompt
228
- def self_knowledge(query: str):
229
- """Answer the following question by using your own knowledge about the topic.
230
-
231
- Question: {{ query }}
232
- """
233
-
234
  def generate_answer(query: str,
235
  client: QdrantClient,
236
  collection_name: str,
 
92
  limit=1
93
  )
94
 
 
 
 
 
 
 
95
  def query_hybrid_search(query: str, client: QdrantClient, collection_name: str, dense_embeddings, sparse_embeddings):
96
  return client.query_points(
97
  collection_name=collection_name,
 
105
  limit=10,
106
  score_threshold=0.95
107
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
108
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109
  def generate_answer(query: str,
110
  client: QdrantClient,
111
  collection_name: str,