File size: 1,744 Bytes
ce67dc2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
44
45
46
47
48
49
50
51
52
53
import json
from vcelldb.params_model import QueryParams
from utils.llm_helper import get_llm_client

SYSTEM_PROMPT = f"""
You are an assistant for a VCell BioModel explorer that responds only in JSON.
Your job is to extract structured API parameters from user questions about VCell models.

Only return the following keys if relevant:
- bmName
- bmId
- category (one of: all, public, shared, tutorials, educational)
- owner
- savedLow (format: YYYY-MM-DD)
- savedHigh (format: YYYY-MM-DD)
- startRow (int)
- maxRows (int)
- orderBy (one of: date_desc, date_asc, name_desc, name_asc)

Here is the JSON Schema for the parameters:
The JSON object must follow this schema:\n{json.dumps(QueryParams.model_json_schema(), indent=2)}

Respond only with a JSON object. Do not explain anything else.
"""


def get_path_params(user_prompt: str):
    """
    This function extracts the path parameters from the user prompt.

    Args:
        user_prompt (str): A Natural Language prompt from the user that will be used to extract path parameters.

    Returns:
        dict: A dictionary containing the extracted path parameters.
    """
    client = get_llm_client()

    try:
        response = client.chat.completions.create(
            model="llama-3.3-70b-versatile",
            messages=[
                {"role": "system", "content": SYSTEM_PROMPT},
                {"role": "user", "content": user_prompt},
            ],
            response_format={"type": "json_object"},
        )
        content = QueryParams.model_validate_json(response.choices[0].message.content)
        params = content.model_dump(exclude_none=True)
        return params
    except Exception as e:
        return {"error": f"Failed to extract parameters: {str(e)}"}