Update app.py
Browse files142 unmodified lines143144145146147148149150151152153154155156157158159160161162163164165166142 unmodified linesreturn FAISS.from_documents(documents, embed)def summarize_article(article, content, query, model, system_prompt, client, temperature=0.2):prompt = f"""Using the following article:Title: {article.get('title', 'No Title Available')}Content (excerpt): {article.get('body', '')[:2000]} # Truncate if too longURL: {article.get('href', 'No URL Available')}And based on the following web search context (excerpt):{content[:2000]} # Truncate if too longWrite a detailed and complete research document. The document should include:1. An introduction2. Key findings from both the article and search context3. A conclusion that directly answers the user's request: '{query}'."""# Calculate token usage and model limitsinput_tokens = len(prompt.split()) // 4 # Approximate token countmodel_token_limit = MODEL_TOKEN_LIMITS.get(model, 8192) # Default limit is 8192 if model is not foundmax_new_tokens = min(model_token_limit - input_tokens, 6500) # Cap output tokens to avoid exceeding limitstry:response = client.chat_completion(142 unmodified lines143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172142 unmodified linesreturn FAISS.from_documents(documents, embed)def summarize_article(article, content, model, system_prompt, user_query, client, temperature=0.2):prompt = f"""Summarize the following article in the context of broader web search results:Article:Title: {article['title']}URL: {article['href']}Content: {article['body'][:500]}... # Truncate to avoid extremely long promptsAdditional Context:{content[:1000]}... # Truncate additional context as wellUser Query: {user_query}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."""# Calculate input tokens (this is an approximation, you might need a more accurate method)input_tokens = len(prompt.split()) // 4# Get the token limit for the current modelmodel_token_limit = MODEL_TOKEN_LIMITS.get(model, 8192) # Default to 8192 if model not found# Calculate max_new_tokensmax_new_tokens = min(model_token_limit - input_tokens, 6500) # Cap at 6500 to be safetry:response = client.chat_completion(
app.py+22-16