尝试创建 API 客户端,注入工具定义。
(model: str)
| 691 | |
| 692 | |
| 693 | def _create_api_client(model: str): |
| 694 | """尝试创建 API 客户端,注入工具定义。""" |
| 695 | try: |
| 696 | from mini_claude_code.api_client import ClaudeApiClient |
| 697 | api_key = os.environ.get("ANTHROPIC_API_KEY", "") |
| 698 | if not api_key: |
| 699 | print( |
| 700 | "error: ANTHROPIC_API_KEY not set. " |
| 701 | "Set it with: export ANTHROPIC_API_KEY=your-key", |
| 702 | file=sys.stderr, |
| 703 | ) |
| 704 | return None |
| 705 | return ClaudeApiClient( |
| 706 | api_key=api_key, |
| 707 | model=model, |
| 708 | tools=DEFAULT_TOOL_DEFINITIONS, |
| 709 | ) |
| 710 | except ImportError: |
| 711 | print( |
| 712 | "error: anthropic package not installed. " |
| 713 | "Install it with: pip install anthropic", |
| 714 | file=sys.stderr, |
| 715 | ) |
| 716 | return None |
| 717 | |
| 718 | |
| 719 | if __name__ == "__main__": |
no test coverage detected