import requestsimport jsonimport concurrentfuturesfrom bs4 import BeautifulSoupOPENAI_API_KEY = sk-123456def chatprompt headers = Content-Type applicationjson Authorization fBearer O
The error is occurring because the replace_results_with_original_text function is trying to split the result string using the dot separator and then converting the first part to an integer, but the result string does not always contain a dot-separated number at the beginning.
To fix this, we can check if the result string starts with a number followed by a dot before trying to split it. If it does not, we can assume that it is a chat response and leave it unchanged.
Here's the modified code for the replace_results_with_original_text function:
def replace_results_with_original_text(results, paragraphs): for i, p in enumerate(paragraphs): text = p.get_text().strip() result = results[i] if result.startswith(tuple(map(str, range(10))) + ('.')): number = int(result.split(".")[0]) updated_result = f"{number}. {text}" results[i] = updated_result else: results[i] = result
This code checks if the result string starts with a number followed by a dot or not, using the startswith method with a tuple of strings representing the digits 0-9 and the dot symbol. If it does, it splits the string and replaces the number with the original paragraph number. If it does not, it assumes that the string is a chat response and leaves it unchanged.
原文地址: https://www.cveoy.top/t/topic/OM5 著作权归作者所有。请勿转载和采集!