-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
139 lines (121 loc) · 4.31 KB
/
Copy pathsetup.py
File metadata and controls
139 lines (121 loc) · 4.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
"""claudegpt first-run setup wizard.
Triggered automatically by the launcher when .env is missing.
Stdlib only — runs before uv sync has installed our deps.
"""
import shutil
import subprocess
import sys
from pathlib import Path
ROOT = Path(__file__).parent
ENV_PATH = ROOT / ".env"
def ask(prompt: str, default: str = "", *, secret: bool = False) -> str:
suffix = f" [{default}]" if default else ""
while True:
try:
if secret:
import getpass
val = getpass.getpass(f"{prompt}{suffix}: ").strip()
else:
val = input(f"{prompt}{suffix}: ").strip()
except (EOFError, KeyboardInterrupt):
print()
sys.exit(1)
if val:
return val
if default:
return default
print(" (required)")
def choose(prompt: str, options: list[tuple[str, str]]) -> str:
print(prompt)
for i, (_, label) in enumerate(options, 1):
print(f" [{i}] {label}")
while True:
try:
sel = input("> ").strip()
except (EOFError, KeyboardInterrupt):
print()
sys.exit(1)
if sel.isdigit() and 1 <= int(sel) <= len(options):
return options[int(sel) - 1][0]
print(" (pick a number)")
def setup_azure() -> dict[str, str]:
print("\n— Azure OpenAI —")
endpoint = ask("Resource endpoint (https://YOUR.cognitiveservices.azure.com/)")
if not endpoint.startswith(("http://", "https://")):
endpoint = "https://" + endpoint
api_key = ask("API key", secret=True)
print("\nDeployment names (must already exist in your Azure resource):")
opus = ask(" opus tier deployment", "gpt-5-5")
sonnet = ask(" sonnet tier deployment", "gpt-54-mini")
haiku = ask(" haiku tier deployment", "gpt-54-nano")
return {
"CLAUDEGPT_PROVIDER": "azure",
"AZURE_OPENAI_ENDPOINT": endpoint,
"AZURE_OPENAI_API_KEY": api_key,
"AZURE_OPENAI_CHAT_DEPLOYMENT_FULL": opus,
"AZURE_OPENAI_CHAT_DEPLOYMENT": sonnet,
"AZURE_OPENAI_CHAT_DEPLOYMENT_NANO": haiku,
}
def setup_openai() -> dict[str, str]:
print("\n— OpenAI direct —")
key = ask("OPENAI_API_KEY (sk-...)", secret=True)
return {"CLAUDEGPT_PROVIDER": "openai", "OPENAI_API_KEY": key}
def setup_codex() -> dict[str, str]:
print("\n— Codex (ChatGPT subscription) —")
if not shutil.which("codex"):
print("✗ codex CLI not found in PATH.")
print(" Install with: npm install -g @openai/codex")
print(" Then run claudegpt again.")
sys.exit(1)
auth_path = Path.home() / ".codex" / "auth.json"
if not auth_path.exists():
print("No saved Codex login at ~/.codex/auth.json.")
print("Launching `codex login` — sign in with your ChatGPT account in the browser.")
try:
subprocess.run(["codex", "login"], check=True)
except subprocess.CalledProcessError:
print("✗ codex login failed. Aborting.")
sys.exit(1)
if not auth_path.exists():
print("✗ login completed but ~/.codex/auth.json was not created.")
sys.exit(1)
print(f"✓ using {auth_path}")
return {"CLAUDEGPT_PROVIDER": "codex"}
def write_env(env: dict[str, str]) -> None:
body = (
"# Generated by claudegpt setup wizard.\n"
"# Re-run by deleting this file and launching claudegpt again.\n\n"
+ "\n".join(f"{k}={v}" for k, v in env.items())
+ "\n"
)
ENV_PATH.write_text(body)
try:
ENV_PATH.chmod(0o600)
except OSError:
pass
print(f"\n✓ wrote {ENV_PATH}")
def main() -> None:
if ENV_PATH.exists():
print(f"{ENV_PATH} already exists — nothing to do.")
return
print("=" * 56)
print(" claudegpt — first-run setup")
print("=" * 56)
provider = choose(
"\nWhich backend?",
[
("azure", "Azure OpenAI"),
("openai", "OpenAI direct (api.openai.com)"),
("codex", "Codex CLI session (ChatGPT Pro / Plus)"),
],
)
if provider == "azure":
env = setup_azure()
elif provider == "openai":
env = setup_openai()
else:
env = setup_codex()
write_env(env)
print("\nLaunching Claude Code…\n")
if __name__ == "__main__":
main()