Skip to content

Commit

Permalink
refactor small portion of summarizer
Browse files Browse the repository at this point in the history
  • Loading branch information
latekvo committed Jul 15, 2024
1 parent c2c0d21 commit 6574008
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions workers/summarizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,11 @@ def summarize(channel):
prompt_core=current_task.prompt, query_type=current_task.mode.lower()
)

# fixme: there is no context building here, it's just the first result!
context = db_search_for_similar_queries(task_query)

if context is None:
if context is None or len(context) == 0:
print('received context is none')
return

def interpret_prompt_mode():
Expand All @@ -94,26 +96,22 @@ def interpret_prompt_mode():
elif current_task.mode == "wiki":
return web_wiki_lookup_prompt()

def get_user_prompt(_: dict):
return current_task.prompt

def get_context(_: dict):
return context[0].page_content

web_interpret_prompt_mode = interpret_prompt_mode()

print("Summarizing task with uuid: ", current_task.uuid)

chain = (
{
"search_data": RunnableLambda(get_context),
# this has to be a RunnableLambda, it cannot be a string
"user_request": RunnableLambda(get_user_prompt),
}
| web_interpret_prompt_mode
web_interpret_prompt_mode
| llm
| output_parser
)
summary = chain.invoke(current_task)

chain_input = {
"search_data": context[0].page_content,
"user_request": current_task.prompt,
}

summary = chain.invoke(chain_input)
db_update_completion_task_after_summarizing(summary, current_task.uuid)

print(f"{Fore.CYAN}Completed task with uuid: {Fore.RESET}", current_task.uuid)
Expand Down

0 comments on commit 6574008

Please sign in to comment.