Skip to content

Commit

Permalink
fix: fixed the Tree Summarization Strategies in case of empty retriev…
Browse files Browse the repository at this point in the history
…ed contents
  • Loading branch information
umbertogriffo committed Jun 28, 2024
1 parent 190380b commit a320cde
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
17 changes: 17 additions & 0 deletions chatbot/bot/conversation/ctx_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,13 @@ def generate_response(
"""
fmt_prompts = []
node_responses = []

if not retrieved_contents:
qa_prompt = self.llm.generate_qa_prompt(question=question)
logger.info("--- Generating a single response ... ---")
response = self.llm.start_answer_iterator_streamer(qa_prompt, max_new_tokens=max_new_tokens)
return response, qa_prompt

for idx, content in enumerate(retrieved_contents, start=1):
context = content.page_content
logger.info(f"--- Generating a response for the chunk {idx} ... ---")
Expand Down Expand Up @@ -238,6 +245,15 @@ async def generate_response(
Any: A response generator.
"""
fmt_prompts = []

if not retrieved_contents:
qa_prompt = self.llm.generate_qa_prompt(question=question)
logger.info("--- Generating a single response ... ---")
response = await asyncio.gather(
self.llm.async_start_answer_iterator_streamer(qa_prompt, max_new_tokens=max_new_tokens)
)
return response[0], qa_prompt

for idx, content in enumerate(retrieved_contents, start=1):
context = content.page_content
logger.info(f"--- Generating a response for the chunk {idx} ... ---")
Expand Down Expand Up @@ -280,6 +296,7 @@ async def combine_results(
"""
fmt_prompts = []
for idx in range(0, len(texts), num_children):
logger.info(f"--- Creating prompts in batches of size {num_children} ... ---")
text_batch = texts[idx : idx + num_children]
context = "\n\n".join([t for t in text_batch])
fmt_qa_prompt = self.llm.generate_ctx_prompt(question=question, context=context)
Expand Down
3 changes: 0 additions & 3 deletions todo.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# Todo
- Test `openchat-3.6-8b-20240522`:
- https://huggingface.co/openchat/openchat-3.6-8b-20240522
- https://huggingface.co/bartowski/openchat-3.6-8b-20240522-GGUF
- Try Chat Templates https://medium.com/@ahmet_celebi/demystifying-chat-templates-of-llm-using-llama-cpp-and-ctransformers-f17871569cd6
- Make docker container

0 comments on commit a320cde

Please sign in to comment.