def themes_post(data: M.SIThemes, background_tasks: BackgroundTasks, as_user: str = None, viewer: M.User = Depends(fastapi_users.get_current_user)): background_tasks.add_task(ga, viewer.id, 'feature', 'themes') user, snooping = getuser(viewer, as_user) entries = M.Entry.snoop(viewer.email, user.id, snooping=snooping, days=data.days, tags=data.tags, for_ai=True) eids = [str(e.id) for e in entries.all()] # For dreams, special handle: process every sentence. TODO make note in UI # tags = request.get_json().get('tags', None) # if tags and len(tags) == 1: # tag_name = Tag.query.get(tags[0]).name # if re.match('dream(s|ing)?', tag_name, re.IGNORECASE): # entries = [s.text for e in entries for s in e.sents] if len(eids) < 2: return send_error("Not enough entries to work with, come back later") return ml.submit_job('themes', dict(args=[eids], kwargs={'algo': data.algo}))
def summarize_post(data: M.SISummarize, as_user: str = None, viewer: M.User = Depends(fastapi_users.get_current_user)): user, snooping = getuser(viewer, as_user) entries = M.Entry.snoop(viewer.email, user.id, snooping=snooping, days=data.days, tags=data.tags, for_ai=True) entries = M.CacheEntry.get_paras(entries) min_ = int(data.words / 2) kwargs = dict(min_length=min_, max_length=data.words) return ml.submit_job('summarization', dict(args=[entries], kwargs=kwargs))
def question_post(data: M.SIQuestion, as_user: str = None, viewer: M.User = Depends(fastapi_users.get_current_user)): user, snooping = getuser(viewer, as_user) question = data.question context = M.Entry.snoop(viewer.email, user.id, snooping=snooping, days=data.days, tags=data.tags, for_ai=True) w_profile = (not snooping) or user.share_data.profile profile_id = user.id if w_profile else None context = M.CacheEntry.get_paras(context, profile_id=profile_id) return ml.submit_job('question-answering', dict(args=[question, context]))