Skip to content

Commit

Permalink
feat(llm): add url for topic generating
Browse files Browse the repository at this point in the history
  • Loading branch information
nsantacruz committed Feb 11, 2024
1 parent 6ba6100 commit a285346
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
14 changes: 14 additions & 0 deletions reader/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3089,6 +3089,20 @@ def topics_list_api(request):
return response


@staff_member_required
def generate_topic_prompts_api(request, slug: str):
if request.method == "POST":
from sefaria.helper.llm.tasks import generate_and_save_topic_prompts
post_body = json.loads(request.body)
lang = post_body.get('lang')
topic = Topic.init(slug)
orefs = [Ref(tref) for tref in post_body.get('refs')]
context_hints = post_body.get('context_hints')
generate_and_save_topic_prompts(lang, topic, orefs, context_hints)
return jsonResponse({"acknowledged": True}, status=202)
return jsonResponse({"error": "This API only accepts POST requests."})


@staff_member_required
def add_new_topic_api(request):
if request.method == "POST":
Expand Down
1 change: 1 addition & 0 deletions sefaria/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@
# Topics API
urlpatterns += [
url(r'^api/topics$', reader_views.topics_list_api),
url(r'^api/topics/generate-prompts/(?P<slug>.+)$', reader_views.generate_topic_prompts_api),
url(r'^api/topics-graph/(?P<topic>.+)$', reader_views.topic_graph_api),
url(r'^api/ref-topic-links/(?P<tref>.+)$', reader_views.topic_ref_api),
url(r'^api/v2/topics/(?P<topic>.+)$', reader_views.topics_api, {'v2': True}),
Expand Down

0 comments on commit a285346

Please sign in to comment.