Skip to content

Commit

Permalink
feat(llm): single function to request and receive topic prompts from …
Browse files Browse the repository at this point in the history
…LLM server
  • Loading branch information
nsantacruz committed Feb 6, 2024
1 parent b554a62 commit 6ba6100
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions sefaria/helper/llm/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@
Celery tasks for the LLM server
"""
from typing import List
from celery import shared_task
from celery import shared_task, signature
from sefaria.model.text import Ref
from sefaria.model.topic import Topic
from sefaria.helper.llm.topic_prompt import make_topic_prompt_input, save_topic_prompt_output
from sefaria.helper.llm.llm_interface import TopicPromptGenerationOutput


@shared_task
def generate_topic_prompts(lang: str, sefaria_topic: Topic, orefs: List[Ref], contexts: List[str]):
return make_topic_prompt_input(lang, sefaria_topic, orefs, contexts)


@shared_task
def save_topic_prompts(raw_output: TopicPromptGenerationOutput):
output = TopicPromptGenerationOutput.create(raw_output)
save_topic_prompt_output(output)


def generate_and_save_topic_prompts(lang: str, sefaria_topic: Topic, orefs: List[Ref], contexts: List[str]):
topic_prompt_input = make_topic_prompt_input(lang, sefaria_topic, orefs, contexts)
# TODO rename task in LLM repo!!
generate_signature = signature('llm.generate_topic_prompts', args=(topic_prompt_input,))
chain = generate_signature | save_topic_prompts.s()
return chain()

0 comments on commit 6ba6100

Please sign in to comment.