()
| 52 | |
| 53 | |
| 54 | def main(): |
| 55 | model = "claude-opus-4-7" |
| 56 | history = [] |
| 57 | print(f"connected to {BASE_URL}") |
| 58 | print(f"current model: {model}") |
| 59 | print("type /exit to quit, /model <id> to switch, /image <prompt> to generate") |
| 60 | print() |
| 61 | |
| 62 | while True: |
| 63 | try: |
| 64 | user = input("> ").strip() |
| 65 | except (EOFError, KeyboardInterrupt): |
| 66 | print() |
| 67 | break |
| 68 | if not user: |
| 69 | continue |
| 70 | if user == "/exit": |
| 71 | break |
| 72 | if user == "/clear": |
| 73 | history = [] |
| 74 | print("(history cleared)") |
| 75 | continue |
| 76 | if user.startswith("/model "): |
| 77 | model = user[len("/model "):].strip() |
| 78 | print(f"(switched to {model})") |
| 79 | continue |
| 80 | if user.startswith("/image "): |
| 81 | prompt = user[len("/image "):].strip() |
| 82 | try: |
| 83 | url = generate_image(prompt) |
| 84 | print(f"image: {url}") |
| 85 | except Exception as e: |
| 86 | print(f"error: {e}") |
| 87 | continue |
| 88 | |
| 89 | history.append({"role": "user", "content": user}) |
| 90 | try: |
| 91 | reply = chat(history, model) |
| 92 | history.append({"role": "assistant", "content": reply}) |
| 93 | except Exception as e: |
| 94 | history.pop() |
| 95 | print(f"error: {e}") |
| 96 | |
| 97 | |
| 98 | if __name__ == "__main__": |
no test coverage detected