Update app.py
Browse files
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,
|
| 147 |
prompt = f"""Using the following article:
|
| 148 |
-
Title: {article
|
| 149 |
-
Content (excerpt): {article
|
| 150 |
-
URL: {article
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 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 |
-
|
| 159 |
-
|
|
|
|
|
|
|
| 160 |
|
| 161 |
-
# Calculate
|
| 162 |
-
|
|
|
|
|
|
|
| 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(
|