()
| 62 | |
| 63 | |
| 64 | def main(): |
| 65 | parser = argparse.ArgumentParser( |
| 66 | description=( |
| 67 | "A smart assistant that can execute Python code to help or hurt you." |
| 68 | ) |
| 69 | ) |
| 70 | parser.add_argument( |
| 71 | "prompt", |
| 72 | nargs="*", |
| 73 | help="Prompt for direct execution. If empty, enter conversation mode", |
| 74 | ) |
| 75 | add_config_flags_to_argparser(parser) |
| 76 | args = parser.parse_args() |
| 77 | config = get_config(args) |
| 78 | llm_client = LLMClient(config) |
| 79 | |
| 80 | if history_file.exists(): |
| 81 | readline.read_history_file(history_file) |
| 82 | readline.set_history_length(1000) |
| 83 | |
| 84 | if len(args.prompt) > 0: |
| 85 | rawdog(" ".join(args.prompt), config, llm_client) |
| 86 | else: |
| 87 | banner() |
| 88 | while True: |
| 89 | try: |
| 90 | print("") |
| 91 | if llm_client.session_cost > 0: |
| 92 | print(f"Session cost: ${llm_client.session_cost:.4f}") |
| 93 | print("What can I do for you? (Ctrl-C to exit)") |
| 94 | prompt = input("> ") |
| 95 | # Save history after each command to avoid losing it in case of crash |
| 96 | readline.write_history_file(history_file) |
| 97 | print("") |
| 98 | rawdog(prompt, config, llm_client) |
| 99 | except KeyboardInterrupt: |
| 100 | print("Exiting...") |
| 101 | break |
| 102 | |
| 103 | |
| 104 | if __name__ == "__main__": |
no test coverage detected