Spaces:
Sleeping
Sleeping
Create mouh/learning/prompts.py
Browse files- mouh/learning/prompts.py +13 -4
mouh/learning/prompts.py
CHANGED
|
@@ -21,9 +21,18 @@ def render_files(files: dict[str, str]) -> str:
|
|
| 21 |
return _block(files)
|
| 22 |
|
| 23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
def user_prompt(instruction: str, tests: dict[str, str], previous_files: dict[str, str] | None = None,
|
| 25 |
-
diagnostics: list[str] | None = None) -> str:
|
| 26 |
-
parts = [
|
|
|
|
| 27 |
if previous_files:
|
| 28 |
parts.append(f"## Code actuel (échoue)\n{_block(previous_files)}")
|
| 29 |
if diagnostics:
|
|
@@ -35,6 +44,6 @@ def user_prompt(instruction: str, tests: dict[str, str], previous_files: dict[st
|
|
| 35 |
|
| 36 |
|
| 37 |
def chat_messages(instruction: str, tests: dict[str, str], previous_files: dict[str, str] | None = None,
|
| 38 |
-
diagnostics: list[str] | None = None) -> list[dict[str, str]]:
|
| 39 |
return [{"role": "system", "content": SYSTEM_PROMPT},
|
| 40 |
-
{"role": "user", "content": user_prompt(instruction, tests, previous_files, diagnostics)}]
|
|
|
|
| 21 |
return _block(files)
|
| 22 |
|
| 23 |
|
| 24 |
+
def _examples(examples: list[dict] | None) -> str:
|
| 25 |
+
if not examples:
|
| 26 |
+
return ""
|
| 27 |
+
parts = [f"### Exemple {i}\n{ex['instruction'].strip()[:1200]}\n{_block(ex['files'])}" for i, ex in
|
| 28 |
+
enumerate(examples, 1)]
|
| 29 |
+
return "## Exemples validés similaires (mémoire)\n" + "\n\n".join(parts)
|
| 30 |
+
|
| 31 |
+
|
| 32 |
def user_prompt(instruction: str, tests: dict[str, str], previous_files: dict[str, str] | None = None,
|
| 33 |
+
diagnostics: list[str] | None = None, examples: list[dict] | None = None) -> str:
|
| 34 |
+
parts = [_examples(examples)] if examples else []
|
| 35 |
+
parts += [f"## Tâche\n{instruction.strip()}", f"## Tests\n{_block(tests)}"]
|
| 36 |
if previous_files:
|
| 37 |
parts.append(f"## Code actuel (échoue)\n{_block(previous_files)}")
|
| 38 |
if diagnostics:
|
|
|
|
| 44 |
|
| 45 |
|
| 46 |
def chat_messages(instruction: str, tests: dict[str, str], previous_files: dict[str, str] | None = None,
|
| 47 |
+
diagnostics: list[str] | None = None, examples: list[dict] | None = None) -> list[dict[str, str]]:
|
| 48 |
return [{"role": "system", "content": SYSTEM_PROMPT},
|
| 49 |
+
{"role": "user", "content": user_prompt(instruction, tests, previous_files, diagnostics, examples)}]
|