yetessam commited on
Commit
8252cd7
·
verified ·
1 Parent(s): 261b1a1

Update prompts/prompts.py

Browse files
Files changed (1) hide show
  1. prompts/prompts.py +57 -0
prompts/prompts.py CHANGED
@@ -25,3 +25,60 @@ def load_prompts():
25
  print(merged_prompts)
26
 
27
  return {str(k): _to_str(v) for k, v in merged.items()}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  print(merged_prompts)
26
 
27
  return {str(k): _to_str(v) for k, v in merged.items()}
28
+
29
+
30
+
31
+ def print_default_prompt_templates(
32
+
33
+ base_url,
34
+ model_id,
35
+ api_key=None,
36
+ ):
37
+ import os, tempfile, pathlib, yaml
38
+ from smolagents import CodeAgent, InferenceClientModel
39
+
40
+ api_key = api_key or os.getenv("HF_TOKEN")
41
+
42
+ model = InferenceClientModel(
43
+ base_url=base_url,
44
+ api_key=api_key, # or token=api_key
45
+ model_id=model_id,
46
+ temperature=0.2,
47
+ max_tokens=1200,
48
+ )
49
+ agent = CodeAgent(tools=[], model=model)
50
+
51
+ # Try to print from the in-memory PromptTemplates object
52
+ try:
53
+ pt = getattr(agent, "prompt_templates", None)
54
+ if pt is not None:
55
+ def pick(obj, fields):
56
+ return {k: getattr(obj, k) for k in fields if getattr(obj, k, None)}
57
+ out = {}
58
+ if getattr(pt, "system_prompt", None):
59
+ out["system_prompt"] = pt.system_prompt
60
+ if getattr(pt, "planning", None):
61
+ out["planning"] = pick(pt.planning, ["plan", "update_plan_pre_messages", "update_plan_post_messages"])
62
+ if getattr(pt, "managed_agent", None):
63
+ out["managed_agent"] = pick(pt.managed_agent, ["task", "report"])
64
+ if getattr(pt, "final_answer", None):
65
+ out["final_answer"] = pick(pt.final_answer, ["pre_messages", "post_messages"])
66
+ print(yaml.safe_dump(out, sort_keys=False, allow_unicode=True))
67
+ return
68
+ except Exception as e:
69
+ print(f"[warn] couldn't access agent.prompt_templates directly: {e}")
70
+
71
+ # Fallback: export prompt.yaml and print it
72
+ try:
73
+ with tempfile.TemporaryDirectory() as td:
74
+ agent.save(td) # should write prompt.yaml
75
+ p = pathlib.Path(td) / "prompt.yaml"
76
+ if p.exists():
77
+ print(p.read_text(encoding="utf-8"))
78
+ else:
79
+ print("[warn] agent.save() produced no prompt.yaml")
80
+ except Exception as e:
81
+ print(f"[error] failed to export defaults: {e}")
82
+
83
+
84
+