Spaces:
Building
Building
Create prompt_builder.py
Browse files- prompt_builder.py +34 -0
prompt_builder.py
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
Flare – Prompt Builder
|
3 |
+
~~~~~~~~~~~~~~~~~~~~~~
|
4 |
+
Merkezi noktadan, şablon + placeholder birleştirir.
|
5 |
+
"""
|
6 |
+
|
7 |
+
from typing import List, Dict
|
8 |
+
|
9 |
+
from config_provider import IntentConfig, ParameterConfig
|
10 |
+
|
11 |
+
# ========= Helper ===========================================================
|
12 |
+
def _join(*parts: List[str]) -> str:
|
13 |
+
"""Boş stringleri atarak satır satır birleştir."""
|
14 |
+
return "\n\n".join(p for p in parts if p)
|
15 |
+
|
16 |
+
|
17 |
+
# ========= Public Builders ==================================================
|
18 |
+
def build_intent_prompt(general_prompt: str,
|
19 |
+
intent: IntentConfig) -> str:
|
20 |
+
return _join(general_prompt, intent.detection_prompt)
|
21 |
+
|
22 |
+
|
23 |
+
def build_param_prompt(intent_prompt_base: str,
|
24 |
+
missing_params: List[ParameterConfig]) -> str:
|
25 |
+
pieces = [intent_prompt_base]
|
26 |
+
pieces += [p.extraction_prompt for p in missing_params]
|
27 |
+
return _join(*pieces)
|
28 |
+
|
29 |
+
|
30 |
+
def build_api_humanize_prompt(intent_prompt_base: str,
|
31 |
+
api_response_prompt: str,
|
32 |
+
api_json: str) -> str:
|
33 |
+
return _join(intent_prompt_base,
|
34 |
+
api_response_prompt.replace("{{api_response}}", api_json))
|