Skip to content

Examples and guides for using the OpenAI API

Add handling for last chunk in split_into_sentences function

Sung Kim3210b38e3589
diff --git a/apps/web-crawl-q-and-a/web-qa.py b/apps/web-crawl-q-and-a/web-qa.py
index 4a2224a3..a5a86dd5 100644
--- a/apps/web-crawl-q-and-a/web-qa.py
+++ b/apps/web-crawl-q-and-a/web-qa.py
@@ -248,6 +248,10 @@ def split_into_many(text, max_tokens = max_tokens):
# Otherwise, add the sentence to the chunk and add the number of tokens to the total
chunk.append(sentence)
tokens_so_far += token + 1
+
+ # Add the last chunk to the list of chunks
+ if chunk:
+ chunks.append(". ".join(chunk) + ".")
return chunks