(self)
| 464 | return chat, valid_command, config |
| 465 | |
| 466 | async def _inner_run(self): |
| 467 | interface = RichInterface(model_id=self.model_id, user_id=self.user, base_url=self.base_url) |
| 468 | interface.clear() |
| 469 | chat = new_chat_history(self.system_prompt) |
| 470 | |
| 471 | # Starts the session with a minimal help message at the top, so that a user doesn't get stuck |
| 472 | interface.print_help(minimal=True) |
| 473 | interface.print_model_load(self.model_id) |
| 474 | |
| 475 | config = self.config |
| 476 | |
| 477 | async with AsyncInferenceClient(base_url=self.base_url) as client: |
| 478 | pending_user_input: str | None = None |
| 479 | while True: |
| 480 | try: |
| 481 | if pending_user_input is not None: |
| 482 | user_input = pending_user_input |
| 483 | pending_user_input = None |
| 484 | interface.print_user_message(user_input) |
| 485 | else: |
| 486 | user_input = interface.input() |
| 487 | |
| 488 | # User commands |
| 489 | if user_input == "!exit": |
| 490 | break |
| 491 | |
| 492 | elif user_input == "!clear": |
| 493 | chat = new_chat_history(self.system_prompt) |
| 494 | interface.clear() |
| 495 | continue |
| 496 | |
| 497 | elif user_input == "!help": |
| 498 | interface.print_help() |
| 499 | continue |
| 500 | |
| 501 | elif user_input.startswith("!save") and len(user_input.split()) < 2: |
| 502 | split_input = user_input.split() |
| 503 | filename = ( |
| 504 | split_input[1] |
| 505 | if len(split_input) == 2 |
| 506 | else os.path.join( |
| 507 | self.save_folder, self.model_id, f"chat_{time.strftime('%Y-%m-%d_%H-%M-%S')}.json" |
| 508 | ) |
| 509 | ) |
| 510 | save_chat(filename=filename, chat=chat, settings=self.settings) |
| 511 | interface.print_color(text=f"Chat saved to {filename}!", color="green") |
| 512 | continue |
| 513 | |
| 514 | elif user_input.startswith("!set"): |
| 515 | # splits the new args into a list of strings, each string being a `flag=value` pair (same format as |
| 516 | # `generate_flags`) |
| 517 | new_generate_flags = user_input[4:].strip() |
| 518 | new_generate_flags = new_generate_flags.split() |
| 519 | # sanity check: each member in the list must have an = |
| 520 | for flag in new_generate_flags: |
| 521 | if "=" not in flag: |
| 522 | interface.print_color( |
| 523 | text=( |
no test coverage detected