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.
 
 
 
 

44 lines
1.2 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") as f:
content.append("%s:'''\n%s'''" % (filename, f.read()))
except FileNotFoundError:
print(f"File '{filename}' not found.")
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)