Spaces:
Sleeping
Sleeping
File size: 1,618 Bytes
42cbd9d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
import json
from app.models import client
from datetime import datetime
# 🔹 Extract Actionable Tasks
def extract_tasks(text):
today_date = datetime.today().strftime("%Y-%m-%d")
response = client.chat.completions.create(
model="accounts/fireworks/models/llama-v3p1-8b-instruct",
messages=[
{
"role": "system",
"content": (
f"You are a task extraction assistant. Today's date is **{today_date}**.\n"
"Your goal is to extract **exactly 2** actionable tasks from the given text.\n"
"Each task must have:\n"
"- A **title** (short summary of the task)\n"
"- A **dueDate** in `YYYY-MM-DD` format (Convert words like 'tomorrow', 'next week' into actual dates based on today's date)\n\n"
"Return **ONLY valid JSON** with this format:\n"
"{\n"
' "tasks": [\n'
' {\n'
' "title": "Task description",\n'
' "dueDate": "YYYY-MM-DD" # Always absolute date\n'
" }\n"
" ]\n"
"}"
),
},
{"role": "user", "content": text},
],
max_tokens=200,
)
# Ensure response is valid JSON
try:
model_output = response.choices[0].message.content.strip()
parsed_response = json.loads(model_output)
return parsed_response.get("tasks", [])
except json.JSONDecodeError:
return []
|