Shreyas094 commited on
Commit
58ed008
1 Parent(s): 6e35de4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -14
app.py CHANGED
@@ -143,23 +143,24 @@ def create_web_search_vectors(search_results):
143
 
144
  return FAISS.from_documents(documents, embed)
145
 
146
- def summarize_article(article, model, system_prompt, user_query, client, temperature=0.2):
147
  prompt = f"""Using the following article:
148
- Title: {article['title']}
149
- Content (excerpt): {article['body'][:2000]} # Truncate if too long
150
- URL: {article['href']}
151
- Using the following context from web search results (excerpt):
152
- {content[:2000]} # Truncate if too long
153
- Write a detailed and complete research document that includes an introduction, key findings, and a conclusion that addresses the following user request: '{query}'."""
154
-
155
- # Calculate input tokens (this is an approximation, you might need a more accurate method)
156
- input_tokens = len(prompt.split()) // 4
157
 
158
- # Get the token limit for the current model
159
- model_token_limit = MODEL_TOKEN_LIMITS.get(model, 8192) # Default to 8192 if model not found
 
 
160
 
161
- # Calculate max_new_tokens
162
- max_new_tokens = min(model_token_limit - input_tokens, 6500) # Cap at 6500 to be safe
 
 
163
 
164
  try:
165
  response = client.chat_completion(
 
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(