You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.3 KiB
46 lines
1.3 KiB
import os
|
|
|
|
|
|
def check_append_file(prompt: str) -> str:
|
|
if "@" in prompt:
|
|
parts = prompt.split(" ")
|
|
content = []
|
|
for part in parts:
|
|
if part.startswith("@"):
|
|
filename = part[1:]
|
|
try:
|
|
if os.path.exists(filename):
|
|
with open(filename, "r", encoding="utf-8") as f:
|
|
content.append("%s:'''\n%s'''" % (filename, f.read()))
|
|
except FileNotFoundError:
|
|
print(f"File '{filename}' not found.")
|
|
except Exception as e:
|
|
print("exception encountered %s", e)
|
|
content.append(prompt)
|
|
return "\n".join(content)
|
|
return prompt
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
exit() # not accidentally trigger it
|
|
|
|
# Create some sample files
|
|
with open("fmain.py", "w") as f:
|
|
f.write("# This is main.py\n")
|
|
with open("finference.py", "w") as f:
|
|
f.write("# This is inference.py\n")
|
|
|
|
# Test cases
|
|
test_prompts = [
|
|
"@fmain.py",
|
|
"@fmain.py @finference.py",
|
|
"@fnonexistent.py",
|
|
"@fmain.py @fnonexistent.py"
|
|
]
|
|
|
|
for prompt in test_prompts:
|
|
print(f"Testing prompt: {prompt}")
|
|
result = check_append_file(prompt)
|
|
print(f"Result: {result}")
|
|
print("-" * 20)
|