init
This commit is contained in:
26
phase0/baue-prompt.py
Normal file
26
phase0/baue-prompt.py
Normal file
@@ -0,0 +1,26 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Setzt ein Prompt-Template zusammen: <DATEI>, <QUELLE> und optional weitere
|
||||
Platzhalter ersetzen.
|
||||
|
||||
Aufruf: baue-prompt.py <template> <projekt-wurzel> <datei-relpfad> <ausgabe> [k=v-datei ...]
|
||||
Zusätzliche Platzhalter: k=pfad ersetzt <k> durch den Inhalt der Datei pfad.
|
||||
"""
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def main():
|
||||
template, wurzel, datei, ausgabe = sys.argv[1:5]
|
||||
text = Path(template).read_text(encoding="utf-8")
|
||||
quelle = (Path(wurzel) / datei).read_text(encoding="utf-8")
|
||||
text = text.replace("<DATEI>", datei)
|
||||
text = text.replace("<QUELLE>", "```python\n" + quelle + "```\n")
|
||||
for extra in sys.argv[5:]:
|
||||
k, pfad = extra.split("=", 1)
|
||||
text = text.replace(f"<{k}>", Path(pfad).read_text(encoding="utf-8"))
|
||||
Path(ausgabe).write_text(text, encoding="utf-8")
|
||||
print(f"{ausgabe}: {len(text)} Zeichen")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user