alpaca.cpp
alpaca.cpp copied to clipboard
Run from command line / as batch process?
Just two quick questions: is it possible to start the bin model also from the command line and e.g. specify a file as input prompt? And would it also be possible to do this several times without loading the bin file again? That would be very helpful, e.g. to work through a whole list of possible prompts.
you can probably do it now with a shell script. which os are you on?
@edmundronald: Thanks a lot for your answer. My OS is the Ubuntu Linux subsystem of Windows 10. The shell script is a good idea. I have tried the command "./chat < input.txt | tee output.txt | head -n 2" now.
With the input.txt "How is it possible to redirect the output of a program in Linux into a file?"
I get the following output, however.
[33m
[1m[32m[0mIn order for you to be able to save your programs' outputs as files, first make sure they are executable by adding an "exec" permission on them. Then use the command 'tee >filename'. This will take all input from standard output and redirect it to filename (the file).[0m
It seems to be correct (except some special characters) but if I don't stop with "head" then more and more lines are "invented". I'm not shure if there is a more elegant way.
I leave a clean answer to the experts here otherwise, look up a reference to shell script programming a thought: ask chatgpt :)
A clean and documented method for calling the script (or an API) would be nevertheless very helpful. Of course it's possible to write such shell scripts and call them e.g. from Python (as I've already done).
How to do that in Python? I tried subprocess, but it could just initialize without any outputs. Can you do some interactive conversations with Python?
@tinaaaaa42: I wrote the following script that works somehow though the result is unfortunately not always complete and needs postprocessing. The input file 'input.txt' contains the prompt. The solution is admittedly not elegant, subprocess seems to have problems with ./chat.
import subprocess
# Open the input and output files
with open('input.txt', 'r') as input_file, open('output.txt', 'w') as output_file:
# Spawn the "chat" process
chat_process = subprocess.Popen(['./chat'], stdin=input_file, stdout=subprocess.PIPE)
# Read the first two lines of output from "chat" and write them to the output file
for i in range(1, 3):
line = chat_process.stdout.readline()
output_file.write(line.decode())
# Terminate the "chat" process
chat_process.terminate()
@rds0001 Thanks, it does work! Using a file is a good idea. As for the "./chat" problem, if you are using Windows, I think "chat" or "chat.exe" would do the work.