(model_path, backend, trust_remote_code=False, **kwargs)
| 70 | |
| 71 | |
| 72 | def main(model_path, backend, trust_remote_code=False, **kwargs): |
| 73 | if backend != 'pytorch': |
| 74 | # set auto backend mode |
| 75 | backend = autoget_backend(model_path, trust_remote_code=trust_remote_code) |
| 76 | quit = False |
| 77 | with build_pipe(model_path, backend, trust_remote_code=trust_remote_code, **kwargs) as pipe: |
| 78 | gen_config = build_gen_config(**kwargs) |
| 79 | adapter_name = get_adapter_name(**kwargs) |
| 80 | while not quit: |
| 81 | with closing(pipe.session()) as sess: |
| 82 | while True: |
| 83 | try: |
| 84 | prompt = input_prompt() |
| 85 | except KeyboardInterrupt: |
| 86 | quit = True |
| 87 | break |
| 88 | if prompt == 'end': |
| 89 | sess.close() |
| 90 | break |
| 91 | if prompt == 'exit': |
| 92 | quit = True |
| 93 | break |
| 94 | if prompt.strip() == '': |
| 95 | continue |
| 96 | resps = pipe.chat(prompt, |
| 97 | session=sess, |
| 98 | gen_config=gen_config, |
| 99 | adapter_name=adapter_name, |
| 100 | stream_response=True) |
| 101 | try: |
| 102 | for resp in resps: |
| 103 | print(resp.text, end='', flush=True) |
| 104 | except KeyboardInterrupt: |
| 105 | sess.abort() |
| 106 | else: |
| 107 | print('exiting...') |
| 108 | |
| 109 | |
| 110 | if __name__ == '__main__': |
no test coverage detected