-
Notifications
You must be signed in to change notification settings - Fork 131
Expand file tree
/
Copy path__init__.py
More file actions
41 lines (32 loc) · 1.32 KB
/
Copy path__init__.py
File metadata and controls
41 lines (32 loc) · 1.32 KB
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
from __future__ import annotations
from felderize.constants import PROMPTS_DIR
def _load(name: str) -> str:
"""Load a prompt template by filename from the prompts directory."""
return (PROMPTS_DIR / name).read_text()
def build_user_prompt(schema_sql: str, query_sql: str) -> str:
"""Build the initial translation prompt for the given schema and query."""
return _load("user_prompt.md").format(
schema_sql=schema_sql.strip(),
query_sql=query_sql.strip(),
)
def build_force_query_prompt(
schema_sql: str, query_sql: str, unsupported: list[str]
) -> str:
"""Build a follow-up prompt when the LLM returned an empty feldera_query."""
unsup_text = "\n".join(f"- {u}" for u in unsupported)
return _load("force_query_prompt.md").format(
unsup_text=unsup_text,
schema_sql=schema_sql.strip(),
query_sql=query_sql.strip(),
)
def build_repair_prompt(
schema_sql: str, query_sql: str, feldera_sql: str, errors: list[str]
) -> str:
"""Build a repair prompt containing the compiler errors from the previous attempt."""
error_text = "\n".join(f"- {e}" for e in errors)
return _load("repair_prompt.md").format(
schema_sql=schema_sql.strip(),
query_sql=query_sql.strip(),
feldera_sql=feldera_sql.strip(),
error_text=error_text,
)