Commit f7a00c05 by nzy

Load content & remove duplicate exports statement

parent 2eb5805a
......@@ -5,6 +5,10 @@ import argparse
import os
import tempfile
import asyncio
from pathlib import Path
dest_lib = Path("./descriptions")
fun_lib = Path("./js")
def doc_template(fun_name):
return f"""\
......@@ -34,7 +38,12 @@ def input_content(content):
return content
def sketch(fun_name):
code = input_content(sketch_template(fun_name))
if (path := fun_lib / f"{fun_name}.js").exists():
with open(path, "r") as f:
content = f.read()
else:
content = sketch_template(fun_name)
code = input_content(content)
create_sketch(fun_name, code)
def hole(fun_name):
......
......@@ -40,6 +40,7 @@ def create_sketch(fun_name, code):
for hole in holes:
final_code.append(f"const {{ {hole} }} = require('./{hole}.js');")
final_code.append(code)
if not code.split("\n")[-1].startswith("exports"):
final_code.append(f"exports.{fun_name} = {fun_name};")
final_code = "\n".join(final_code)
......
......@@ -50,10 +50,17 @@ function test() {
### Import
生成的代码都在js文件夹中,可以使用一个repl bot调用,如目录下run.js所示。
### Debug
目前包含代码的合并。
对于`sketch A`,A依赖于`hole [B, C]`,如果想修改`A`的实现,可以直接`python anplc.py sketch A`。此时`hole [B, C]`已有的实现不会变化。
如果A中添加了新的`hole D`,则会创建`hole D`
如果A中不再依赖一个`hole C`,目前需要手动删除A中的import语句,与js和description文件夹下的`C.js C.json`文件。
## Others
非windows系统下,请注释掉`anplc.py`第85行`asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())`
此行为windows系统特有问题。
对于openai库的配置,请修改`llm.py`的开头,修改api_key与代理。
\ No newline at end of file
对于openai库的配置,请修改`llm.py`的开头,修改api_key与代理,更改模型在llm.py第51行的config中。
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment