Spaces:
Build error
Build error
Update app.py
Browse files78 unmodified lines798081828384854 unmodified lines9091929394959697989910010110210378 unmodified lines"temperature": 0.7,"top_p": 0.95,"top_k": 40,"repetition_penalty": 1.1}}4 unmodified linesresult = response.json()if isinstance(result, list) and len(result) > 0:chunk = result[0].get('generated_text', '')full_response += chunkif chunk.endswith((".", "!", "?")):breakelse:breakelse:breakreturn full_response.strip()def duckduckgo_search(query):with DDGS() as ddgs:78 unmodified lines79808182838485864 unmodified lines91929394959697989910010110210310410510610710810911011111211311411511611711811912012178 unmodified lines"temperature": 0.7,"top_p": 0.95,"top_k": 40,"repetition_penalty": 1.1,"stop": ["</s>", "[/INST]"] # Add stop tokens}}4 unmodified linesresult = response.json()if isinstance(result, list) and len(result) > 0:chunk = result[0].get('generated_text', '')# Remove any part of the chunk that's already in full_responsenew_content = chunk[len(full_response):].strip()if not new_content:break # No new content, so we're donefull_response += new_contentif chunk.endswith((".", "!", "?", "</s>", "[/INST]")):break# Update the prompt for the next iterationpayload["inputs"] = full_responseelse:breakelse:break# Clean up the responseclean_response = re.sub(r'<s>\[INST\].*?\[/INST\]\s*', '', full_response, flags=re.DOTALL)clean_response = clean_response.replace("Using the following context:", "").strip()clean_response = clean_response.replace("Using the following context from the PDF documents:", "").strip()return clean_responsedef duckduckgo_search(query):with DDGS() as ddgs:
app.py+22-4