Shreyas094 commited on
Commit
1dd8b2c
·
verified ·
1 Parent(s): 58ed008

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -16
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, query, model, system_prompt, client, temperature=0.2):
147
- prompt = f"""Using the following article:
148
- Title: {article.get('title', 'No Title Available')}
149
- Content (excerpt): {article.get('body', '')[:2000]} # Truncate if too long
150
- URL: {article.get('href', 'No URL Available')}
151
-
152
- And based on the following web search context (excerpt):
153
- {content[:2000]} # Truncate if too long
 
 
 
 
 
 
 
 
 
 
154
 
155
- Write a detailed and complete research document. The document should include:
156
- 1. An introduction
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 token usage and model limits
161
- input_tokens = len(prompt.split()) // 4 # Approximate token count
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(