Spaces:
Runtime error
Runtime error
File size: 2,294 Bytes
cdddf91 550b1f1 f2ae05b 643c943 a9638ab 643c943 a9638ab 643c943 7a3aac9 643c943 c1e4174 7a3aac9 643c943 7a3aac9 643c943 7cf2fb1 643c943 a9638ab 643c943 7a3aac9 643c943 a9638ab a90c92b d7810f3 643c943 a9638ab aa8f766 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
import os
import subprocess
def run_command(command):
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
stdout, stderr = process.communicate()
if process.returncode != 0:
raise Exception(f"Command failed with error: {stderr}")
return stdout
def main():
# Clone the repository
print("Cloning the repository...")
run_command("git clone https://github.com/ggerganov/llama.cpp.git")
# Change directory to the cloned repository
os.chdir("llama.cpp")
# Download the file
print("Downloading the GGUF file...")
run_command("wget -O ZhongJing1_5-1_8b-q4_0.gguf https://huggingface.co/CMLL/ZhongJing-2-1_8b-GGUF/resolve/main/ZhongJing1_5-1_8b-q4_0.gguf?download=true")
# Compile the project
print("Compiling the project...")
run_command("make")
# Modify the prompts/chat-with-bob.txt file
print("Modifying the chat-with-bob.txt file...")
dialog_content = """
Transcript of a dialog, where the User interacts with an Assistant named Bob. Bob is a helpful TCM medical assistant, also named 仲景中医大语言模型, and never fails to answer the User's requests immediately and with precision.
User: Hello, Bob.
Bob: Hello. How may I help you today?不断地从书中获取知识,以获得更全面的知识结构。
"""
with open("prompts/chat-with-bob.txt", "w") as f:
f.write(dialog_content)
# Run the llama-cli command
print("Running the llama-cli command...")
process = subprocess.Popen(
['./llama-cli', '-m', 'ZhongJing1_5-1_8b-q4_0.gguf', '-n', '256', '--repeat_penalty', '1.0', '--color', '-i', '-r', 'User:', '-f', 'prompts/chat-with-bob.txt'],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True
)
# Capture the output and filter it
while True:
output = process.stdout.readline()
if 'Transcript of a dialog' in output:
print(output, end='')
break
while True:
output = process.stdout.readline()
if output.startswith('User:') or output.startswith('Bob:'):
print(output, end='')
elif process.poll() is not None:
break
if __name__ == "__main__":
main()
|