This is code generates and prints an ollama response. While it is printing I would like…
- User
This is code generates and prints an ollama response. While it is printing I would like to listen whether the shortcuts ctrl-s or ctrl-l was pressed. Is this possible? If possible I would like this to be done with prompt_toolkit, since this is already a dependency.
codeimport ollama response = ollama.chat( messages=[{'role':'user','content':'hey'}], model = 'hf.co/bartowski/Mistral-Large-Instruct-2411-GGUF:IQ2_M', keep_alive=-1, stream=True, ) for comp in response: delta = comp['message']['content'] print(delta, end='',flush=True)Other requiremenets:
- It should not consume other keyboard shortcuts, so e.g. ctrl-c should still be able to abort generation.
- I also don't want the terminal text input to be messed up if the program exits unexpectantly
- The code should be as short as possible
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.