Update app.py
Browse files
app.py
CHANGED
@@ -143,24 +143,30 @@ def create_web_search_vectors(search_results):
|
|
143 |
|
144 |
return FAISS.from_documents(documents, embed)
|
145 |
|
146 |
-
def summarize_article(article, content,
|
147 |
-
prompt = f"""
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
154 |
|
155 |
-
|
156 |
-
|
157 |
-
2. Key findings from both the article and search context
|
158 |
-
3. A conclusion that directly answers the user's request: '{query}'."""
|
159 |
|
160 |
-
# Calculate
|
161 |
-
|
162 |
-
model_token_limit = MODEL_TOKEN_LIMITS.get(model, 8192) # Default limit is 8192 if model is not found
|
163 |
-
max_new_tokens = min(model_token_limit - input_tokens, 6500) # Cap output tokens to avoid exceeding limits
|
164 |
|
165 |
try:
|
166 |
response = client.chat_completion(
|
|
|
143 |
|
144 |
return FAISS.from_documents(documents, embed)
|
145 |
|
146 |
+
def summarize_article(article, content, model, system_prompt, user_query, client, temperature=0.2):
|
147 |
+
prompt = f"""Summarize the following article in the context of broader web search results:
|
148 |
+
|
149 |
+
Article:
|
150 |
+
Title: {article['title']}
|
151 |
+
URL: {article['href']}
|
152 |
+
Content: {article['body'][:500]}... # Truncate to avoid extremely long prompts
|
153 |
+
|
154 |
+
Additional Context:
|
155 |
+
{content[:1000]}... # Truncate additional context as well
|
156 |
+
|
157 |
+
User Query: {user_query}
|
158 |
+
|
159 |
+
Write a detailed and complete research document which addresses the User Query, incorporating both the specific article and the broader context. Focus on the most relevant information.
|
160 |
+
"""
|
161 |
+
|
162 |
+
# Calculate input tokens (this is an approximation, you might need a more accurate method)
|
163 |
+
input_tokens = len(prompt.split()) // 4
|
164 |
|
165 |
+
# Get the token limit for the current model
|
166 |
+
model_token_limit = MODEL_TOKEN_LIMITS.get(model, 8192) # Default to 8192 if model not found
|
|
|
|
|
167 |
|
168 |
+
# Calculate max_new_tokens
|
169 |
+
max_new_tokens = min(model_token_limit - input_tokens, 6500) # Cap at 6500 to be safe
|
|
|
|
|
170 |
|
171 |
try:
|
172 |
response = client.chat_completion(
|