Update app.py
Browse files346 unmodified lines34734834935035035135235349 unmodified lines4034044054064064074084095 unmodified lines41541641741841841942042142 unmodified lines4644654664674674684694702 unmodified lines473474475476476477478479346 unmodified lines
max_attempts = 5 context_reduction_factor = 0.7 max_estimated_tokens = 30000 # Leave some room for the model's response max_tokens = 32000 # Maximum tokens allowed by the model
if web_search: contextualized_question, topics, entity_tracker, instructions = chatbot.process_question(question)49 unmodified lines # Estimate token count estimated_tokens = estimate_tokens(formatted_prompt) if estimated_tokens <= max_estimated_tokens: if estimated_tokens <= max_tokens - 1000: # Leave 1000 tokens for the model's response break # Reduce context if estimated token count is too high5 unmodified lines if len(current_context) + len(current_conv_context) + len(str(current_topics)) + len(str(current_entities)) < 100: raise ValueError("Context reduced too much. Unable to process the query.")
full_response = generate_chunked_response(model, formatted_prompt) full_response = generate_chunked_response(model, formatted_prompt, max_tokens=1000) answer = extract_answer(full_response, instructions) all_answers.append(answer) break42 unmodified lines
estimated_tokens = estimate_tokens(formatted_prompt) if estimated_tokens <= max_estimated_tokens: if estimated_tokens <= max_tokens - 1000: # Leave 1000 tokens for the model's response break # Reduce context if estimated token count is too high2 unmodified lines if len(context_str) < 100: raise ValueError("Context reduced too much. Unable to process the query.")
full_response = generate_chunked_response(model, formatted_prompt) full_response = generate_chunked_response(model, formatted_prompt, max_tokens=1000) answer = extract_answer(full_response)
return answerapp.py+5-5