mirror of
https://github.com/tiennm99/serena.git
synced 2026-06-18 00:48:15 +00:00
61f7c15b15
* Add LLM prompt factory (yaml-based)
* Add list_dir tool
* Add onboarding tool (which returns prompt only, as registered MCP prompts
do not appear to be usable by Claude Desktop)
44 lines
1.4 KiB
Python
44 lines
1.4 KiB
Python
from sensai.util import logging
|
|
|
|
from serena.llm.multilang_prompt import MultiLangPromptTemplateCollection
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
def main():
|
|
coll = MultiLangPromptTemplateCollection()
|
|
|
|
package = "src/serena"
|
|
|
|
# collect methods to generate
|
|
indent = " "
|
|
methods = []
|
|
for mpt in coll.prompt_templates.values():
|
|
prompt_name = mpt.name
|
|
params = mpt.get_parameters()
|
|
if len(params) == 0:
|
|
params_str = ""
|
|
else:
|
|
params_str = ", *, " + ", ".join(params)
|
|
methods.append(
|
|
f"def create_{prompt_name}(self{params_str}) -> str:"
|
|
+ f"\n{indent}{indent}return self._format_prompt('{prompt_name}', locals())\n\n{indent}"
|
|
)
|
|
for mpl in coll.prompt_lists.values():
|
|
prompt_name = mpl.name
|
|
methods.append(
|
|
f"def get_list_{prompt_name}(self) -> PromptList:" + f"\n{indent}{indent}return self._get_list('{prompt_name}')\n\n{indent}"
|
|
)
|
|
|
|
# write prompt factory with added methods
|
|
with open("code_templates/prompt_factory_template.py") as f:
|
|
code = f.read()
|
|
methods_str = "".join(methods)
|
|
code = code.replace("# methods", methods_str)
|
|
with open(f"{package}/llm/prompt_factory.py", "w") as f:
|
|
f.write(code)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
logging.run_main(main)
|