Update app.py
Browse files346 unmodified lines34734834935035135235349 unmodified lines4034044054064074084095 unmodified lines41541641741841942042142 unmodified lines4644654664674684694702 unmodified lines473474475476477478479346 unmodified linesmax_attempts = 5context_reduction_factor = 0.7max_estimated_tokens = 30000 # Leave some room for the model's responseif web_search:contextualized_question, topics, entity_tracker, instructions = chatbot.process_question(question)49 unmodified lines# Estimate token countestimated_tokens = estimate_tokens(formatted_prompt)if estimated_tokens <= max_estimated_tokens:break# Reduce context if estimated token count is too high5 unmodified linesif 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)answer = extract_answer(full_response, instructions)all_answers.append(answer)break42 unmodified linesestimated_tokens = estimate_tokens(formatted_prompt)if estimated_tokens <= max_estimated_tokens:break# Reduce context if estimated token count is too high2 unmodified linesif len(context_str) < 100:raise ValueError("Context reduced too much. Unable to process the query.")full_response = generate_chunked_response(model, formatted_prompt)answer = extract_answer(full_response)return answer346 unmodified lines34734834935035135235349 unmodified lines4034044054064074084095 unmodified lines41541641741841942042142 unmodified lines4644654664674684694702 unmodified lines473474475476477478479346 unmodified linesmax_attempts = 5context_reduction_factor = 0.7max_tokens = 32000 # Maximum tokens allowed by the modelif web_search:contextualized_question, topics, entity_tracker, instructions = chatbot.process_question(question)49 unmodified lines# Estimate token countestimated_tokens = estimate_tokens(formatted_prompt)if estimated_tokens <= max_tokens - 1000: # Leave 1000 tokens for the model's responsebreak# Reduce context if estimated token count is too high5 unmodified linesif 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, max_tokens=1000)answer = extract_answer(full_response, instructions)all_answers.append(answer)break42 unmodified linesestimated_tokens = estimate_tokens(formatted_prompt)if estimated_tokens <= max_tokens - 1000: # Leave 1000 tokens for the model's responsebreak# Reduce context if estimated token count is too high2 unmodified linesif len(context_str) < 100:raise ValueError("Context reduced too much. Unable to process the query.")full_response = generate_chunked_response(model, formatted_prompt, max_tokens=1000)answer = extract_answer(full_response)return answer
app.py+5-5