algocean-codex-oauth 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- algocean_codex_oauth-0.1.0/.gitignore +12 -0
- algocean_codex_oauth-0.1.0/LICENSE +21 -0
- algocean_codex_oauth-0.1.0/PKG-INFO +310 -0
- algocean_codex_oauth-0.1.0/README.md +280 -0
- algocean_codex_oauth-0.1.0/pyproject.toml +51 -0
- algocean_codex_oauth-0.1.0/src/algocean_codex_oauth/__init__.py +15 -0
- algocean_codex_oauth-0.1.0/src/algocean_codex_oauth/auth.py +65 -0
- algocean_codex_oauth-0.1.0/src/algocean_codex_oauth/chat_model.py +311 -0
- algocean_codex_oauth-0.1.0/src/algocean_codex_oauth/client.py +327 -0
- algocean_codex_oauth-0.1.0/src/algocean_codex_oauth/config.py +72 -0
- algocean_codex_oauth-0.1.0/src/algocean_codex_oauth/errors.py +5 -0
- algocean_codex_oauth-0.1.0/src/algocean_codex_oauth/messages.py +71 -0
- algocean_codex_oauth-0.1.0/src/algocean_codex_oauth/session.py +45 -0
- algocean_codex_oauth-0.1.0/src/algocean_codex_oauth/types.py +14 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 algocean1204
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: algocean-codex-oauth
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Drop-in ChatOpenAI replacement for LangChain/LangGraph using Codex ChatGPT OAuth subscription.
|
|
5
|
+
Project-URL: Homepage, https://github.com/algocean1204/AlgoceanCodexOAuth
|
|
6
|
+
Project-URL: Documentation, https://github.com/algocean1204/AlgoceanCodexOAuth#readme
|
|
7
|
+
Project-URL: Repository, https://github.com/algocean1204/AlgoceanCodexOAuth
|
|
8
|
+
Project-URL: Issues, https://github.com/algocean1204/AlgoceanCodexOAuth/issues
|
|
9
|
+
Project-URL: Changelog, https://github.com/algocean1204/AlgoceanCodexOAuth/releases
|
|
10
|
+
Author: algocean1204
|
|
11
|
+
License-Expression: MIT
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Keywords: algocean,chatgpt,codex,langchain,langgraph,oauth,openai
|
|
14
|
+
Classifier: Development Status :: 4 - Beta
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
23
|
+
Requires-Python: >=3.10
|
|
24
|
+
Requires-Dist: langchain-core>=0.3.0
|
|
25
|
+
Provides-Extra: dev
|
|
26
|
+
Requires-Dist: pydantic>=2.0; extra == 'dev'
|
|
27
|
+
Requires-Dist: pytest-asyncio>=0.24; extra == 'dev'
|
|
28
|
+
Requires-Dist: pytest>=8.0; extra == 'dev'
|
|
29
|
+
Description-Content-Type: text/markdown
|
|
30
|
+
|
|
31
|
+
# AlgoceanCodexOAuth
|
|
32
|
+
|
|
33
|
+
LangChain / LangGraph에서 **`ChatOpenAI` 자리에 그대로 꽂는** Codex ChatGPT OAuth LLM 래퍼입니다.
|
|
34
|
+
|
|
35
|
+
API key 과금 경로는 코드에서 차단하고, 로컬 `codex login`으로 저장된 **ChatGPT OAuth 구독 한도**만 사용합니다.
|
|
36
|
+
|
|
37
|
+
```text
|
|
38
|
+
LangGraph / LangChain
|
|
39
|
+
→ AlgoceanCodexOAuth
|
|
40
|
+
→ codex exec
|
|
41
|
+
→ 로컬 ChatGPT OAuth 세션
|
|
42
|
+
→ Codex 구독 한도 / 크레딧
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## 설치
|
|
46
|
+
|
|
47
|
+
### 1. Codex CLI + ChatGPT OAuth (1회)
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
npm install -g @openai/codex
|
|
51
|
+
|
|
52
|
+
unset OPENAI_API_KEY
|
|
53
|
+
unset CODEX_API_KEY
|
|
54
|
+
codex logout
|
|
55
|
+
codex login
|
|
56
|
+
codex login status
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
공식 인증 문서: [Codex Authentication](https://developers.openai.com/codex/auth)
|
|
60
|
+
|
|
61
|
+
### 2. Python 패키지
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
pip install algocean-codex-oauth
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
LangGraph 프로젝트:
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
pip install algocean-codex-oauth langgraph langchain-core
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Quick Start
|
|
74
|
+
|
|
75
|
+
### ChatOpenAI → AlgoceanCodexOAuth (1:1 교체)
|
|
76
|
+
|
|
77
|
+
**Before (API key)**
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
from langchain_openai import ChatOpenAI
|
|
81
|
+
from langchain_core.messages import HumanMessage
|
|
82
|
+
|
|
83
|
+
llm = ChatOpenAI(model="gpt-4o")
|
|
84
|
+
response = llm.invoke([HumanMessage(content="FastAPI Depends를 짧게 설명해줘.")])
|
|
85
|
+
print(response.content)
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
**After (Codex OAuth)**
|
|
89
|
+
|
|
90
|
+
```python
|
|
91
|
+
from algocean_codex_oauth import AlgoceanCodexOAuth
|
|
92
|
+
from langchain_core.messages import HumanMessage
|
|
93
|
+
|
|
94
|
+
llm = AlgoceanCodexOAuth(model="gpt-5.5")
|
|
95
|
+
response = llm.invoke([HumanMessage(content="FastAPI Depends를 짧게 설명해줘.")])
|
|
96
|
+
print(response.content)
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## LangGraph
|
|
100
|
+
|
|
101
|
+
### 단일 노드
|
|
102
|
+
|
|
103
|
+
```python
|
|
104
|
+
from langchain_core.messages import HumanMessage, SystemMessage
|
|
105
|
+
from langgraph.graph import StateGraph, END
|
|
106
|
+
from typing_extensions import TypedDict
|
|
107
|
+
|
|
108
|
+
from algocean_codex_oauth import AlgoceanCodexOAuth
|
|
109
|
+
|
|
110
|
+
class State(TypedDict):
|
|
111
|
+
user_input: str
|
|
112
|
+
answer: str
|
|
113
|
+
|
|
114
|
+
llm = AlgoceanCodexOAuth(model="gpt-5.5")
|
|
115
|
+
|
|
116
|
+
async def assistant_node(state: State) -> State:
|
|
117
|
+
messages = [
|
|
118
|
+
SystemMessage(content="간결한 개인 비서."),
|
|
119
|
+
HumanMessage(content=state["user_input"]),
|
|
120
|
+
]
|
|
121
|
+
ai = await llm.ainvoke(messages)
|
|
122
|
+
return {"answer": ai.content}
|
|
123
|
+
|
|
124
|
+
graph = StateGraph(State)
|
|
125
|
+
graph.add_node("assistant", assistant_node)
|
|
126
|
+
graph.set_entry_point("assistant")
|
|
127
|
+
graph.add_edge("assistant", END)
|
|
128
|
+
app = graph.compile()
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### ReAct Agent
|
|
132
|
+
|
|
133
|
+
```python
|
|
134
|
+
from langgraph.prebuilt import create_react_agent
|
|
135
|
+
from langchain_core.messages import HumanMessage
|
|
136
|
+
from algocean_codex_oauth import AlgoceanCodexOAuth
|
|
137
|
+
|
|
138
|
+
llm = AlgoceanCodexOAuth(model="gpt-5.5")
|
|
139
|
+
agent = create_react_agent(llm, tools=[])
|
|
140
|
+
result = agent.invoke({"messages": [HumanMessage(content="hello")]})
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### Structured Output (LangGraph state merge)
|
|
144
|
+
|
|
145
|
+
```python
|
|
146
|
+
from pydantic import BaseModel, Field
|
|
147
|
+
from langchain_core.messages import HumanMessage
|
|
148
|
+
from algocean_codex_oauth import AlgoceanCodexOAuth
|
|
149
|
+
|
|
150
|
+
class Analysis(BaseModel):
|
|
151
|
+
summary: str = Field(description="요약")
|
|
152
|
+
risk_level: str = Field(description="low | medium | high")
|
|
153
|
+
|
|
154
|
+
llm = AlgoceanCodexOAuth(model="gpt-5.5")
|
|
155
|
+
structured = llm.with_structured_output(Analysis)
|
|
156
|
+
result = structured.invoke([HumanMessage(content="위험도를 평가해줘.")])
|
|
157
|
+
print(result.summary, result.risk_level)
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
내부적으로 Codex CLI `--output-schema`를 사용합니다.
|
|
161
|
+
문서: [Codex non-interactive mode](https://developers.openai.com/codex/noninteractive)
|
|
162
|
+
|
|
163
|
+
## ChatOpenAI 기능 대응
|
|
164
|
+
|
|
165
|
+
| ChatOpenAI (API key) | AlgoceanCodexOAuth |
|
|
166
|
+
| --- | --- |
|
|
167
|
+
| `llm.invoke(messages)` | 동일 |
|
|
168
|
+
| `await llm.ainvoke(messages)` | 동일 |
|
|
169
|
+
| `llm.astream(messages)` | 동일 |
|
|
170
|
+
| `llm.with_structured_output(schema)` | 동일 |
|
|
171
|
+
| LangGraph `state["messages"]` 멀티턴 | `thread_mode="messages"` (기본) |
|
|
172
|
+
| 대화 세션 유지 | `thread_mode="codex_resume"` + `ephemeral=False` |
|
|
173
|
+
| 새 대화 시작 | `llm.reset_thread()` |
|
|
174
|
+
| `response.response_metadata["usage"]` | 동일 |
|
|
175
|
+
|
|
176
|
+
## 생성자
|
|
177
|
+
|
|
178
|
+
```python
|
|
179
|
+
AlgoceanCodexOAuth(
|
|
180
|
+
model: str = "gpt-5.5",
|
|
181
|
+
*,
|
|
182
|
+
timeout: int = 180,
|
|
183
|
+
sandbox: str = "read-only",
|
|
184
|
+
workdir: str | None = None,
|
|
185
|
+
ephemeral: bool = True,
|
|
186
|
+
thread_mode: str = "messages", # messages | codex_resume
|
|
187
|
+
codex_bin: str = "codex",
|
|
188
|
+
require_chatgpt_login: bool = True,
|
|
189
|
+
)
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
### Preset
|
|
193
|
+
|
|
194
|
+
```python
|
|
195
|
+
llm = AlgoceanCodexOAuth.chat(model="gpt-5.5") # messages 멀티턴
|
|
196
|
+
llm = AlgoceanCodexOAuth.repo_read(workdir="/path/to/repo")
|
|
197
|
+
llm = AlgoceanCodexOAuth.repo_write(workdir="/path/to/repo") # codex_resume
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
| Preset | thread_mode | 멀티턴 방식 |
|
|
201
|
+
| --- | --- | --- |
|
|
202
|
+
| `chat()` | `messages` | ChatOpenAI처럼 messages 히스토리 전달 |
|
|
203
|
+
| `repo_read(path)` | `messages` | messages 히스토리 |
|
|
204
|
+
| `repo_write(path)` | `codex_resume` | Codex exec resume (에이전트) |
|
|
205
|
+
|
|
206
|
+
## 멀티턴 — ChatOpenAI와 동일하게
|
|
207
|
+
|
|
208
|
+
### 방식 1: messages (기본, LangGraph 표준)
|
|
209
|
+
|
|
210
|
+
```python
|
|
211
|
+
messages = [HumanMessage(content="코드네임은 ALPHA7")]
|
|
212
|
+
ai1 = await llm.ainvoke(messages)
|
|
213
|
+
messages += [ai1, HumanMessage(content="코드네임이 뭐야?")]
|
|
214
|
+
ai2 = await llm.ainvoke(messages)
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
LangGraph `state["messages"]` 패턴과 1:1 동일합니다.
|
|
218
|
+
|
|
219
|
+
### 방식 2: codex_resume (Codex thread 유지)
|
|
220
|
+
|
|
221
|
+
```python
|
|
222
|
+
llm = AlgoceanCodexOAuth(
|
|
223
|
+
model="gpt-5.5",
|
|
224
|
+
workdir="/path/to/repo",
|
|
225
|
+
sandbox="read-only",
|
|
226
|
+
ephemeral=False,
|
|
227
|
+
thread_mode="codex_resume",
|
|
228
|
+
)
|
|
229
|
+
|
|
230
|
+
await llm.ainvoke([HumanMessage(content="첫 질문")])
|
|
231
|
+
await llm.ainvoke([HumanMessage(content="이어서")]) # exec resume
|
|
232
|
+
llm.reset_thread() # 새 대화
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
### Streaming
|
|
236
|
+
|
|
237
|
+
```python
|
|
238
|
+
async for chunk in llm.astream([HumanMessage(content="hello")]):
|
|
239
|
+
print(chunk.content, end="", flush=True)
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
## Provider 스위치 (미니 Codex)
|
|
243
|
+
|
|
244
|
+
```python
|
|
245
|
+
def get_llm(use_codex_oauth: bool):
|
|
246
|
+
if use_codex_oauth:
|
|
247
|
+
from algocean_codex_oauth import AlgoceanCodexOAuth
|
|
248
|
+
return AlgoceanCodexOAuth(model="gpt-5.5")
|
|
249
|
+
from langchain_openai import ChatOpenAI
|
|
250
|
+
return ChatOpenAI(model="gpt-4o")
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
그래프 코드는 동일하고 import / 클래스만 바꾸면 됩니다.
|
|
254
|
+
|
|
255
|
+
## OAuth 정책
|
|
256
|
+
|
|
257
|
+
라이브러리는 호출마다 아래를 강제합니다.
|
|
258
|
+
|
|
259
|
+
- `OPENAI_API_KEY`, `CODEX_API_KEY` 환경 변수 제거
|
|
260
|
+
- `require_chatgpt_login=True` 시 `codex login status`로 ChatGPT OAuth 확인
|
|
261
|
+
- API key 인증 감지 시 `AlgoceanCodexOAuthError` 발생
|
|
262
|
+
|
|
263
|
+
## 아키텍처
|
|
264
|
+
|
|
265
|
+
```text
|
|
266
|
+
algocean_codex_oauth/
|
|
267
|
+
├── chat_model.py # AlgoceanCodexOAuth (BaseChatModel) — public API
|
|
268
|
+
├── client.py # codex exec / exec resume
|
|
269
|
+
├── auth.py # OAuth 검증, API key 차단
|
|
270
|
+
├── config.py # AlgoceanCodexConfig
|
|
271
|
+
├── messages.py # LangChain messages → prompt
|
|
272
|
+
├── session.py # 멀티턴 thread resume (고급)
|
|
273
|
+
└── errors.py
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
## 멀티턴 (Session 래퍼)
|
|
277
|
+
|
|
278
|
+
`AlgoceanCodexSession`은 `thread_mode="codex_resume"` 편의 래퍼입니다.
|
|
279
|
+
직접 `AlgoceanCodexOAuth(..., thread_mode="codex_resume")` 를 써도 동일합니다.
|
|
280
|
+
|
|
281
|
+
## 제한
|
|
282
|
+
|
|
283
|
+
- **개인 로컬 / 개인 구독** 용도입니다. SaaS 서버에서 외부 사용자에게 AI를 제공하는 용도에는 맞지 않습니다.
|
|
284
|
+
- Codex CLI(`codex`)가 PATH에 있어야 합니다.
|
|
285
|
+
- `danger-full-access` sandbox는 격리 환경에서만 사용하세요.
|
|
286
|
+
|
|
287
|
+
## 개발
|
|
288
|
+
|
|
289
|
+
```bash
|
|
290
|
+
git clone https://github.com/algocean1204/AlgoceanCodexOAuth.git
|
|
291
|
+
cd AlgoceanCodexOAuth
|
|
292
|
+
pip install -e ".[dev]"
|
|
293
|
+
pytest
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
## PyPI
|
|
297
|
+
|
|
298
|
+
```bash
|
|
299
|
+
pip install algocean-codex-oauth
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
## License
|
|
303
|
+
|
|
304
|
+
MIT
|
|
305
|
+
|
|
306
|
+
## Links
|
|
307
|
+
|
|
308
|
+
- GitHub: https://github.com/algocean1204/AlgoceanCodexOAuth
|
|
309
|
+
- Codex CLI: https://developers.openai.com/codex/cli/reference
|
|
310
|
+
- Codex Auth: https://developers.openai.com/codex/auth
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
# AlgoceanCodexOAuth
|
|
2
|
+
|
|
3
|
+
LangChain / LangGraph에서 **`ChatOpenAI` 자리에 그대로 꽂는** Codex ChatGPT OAuth LLM 래퍼입니다.
|
|
4
|
+
|
|
5
|
+
API key 과금 경로는 코드에서 차단하고, 로컬 `codex login`으로 저장된 **ChatGPT OAuth 구독 한도**만 사용합니다.
|
|
6
|
+
|
|
7
|
+
```text
|
|
8
|
+
LangGraph / LangChain
|
|
9
|
+
→ AlgoceanCodexOAuth
|
|
10
|
+
→ codex exec
|
|
11
|
+
→ 로컬 ChatGPT OAuth 세션
|
|
12
|
+
→ Codex 구독 한도 / 크레딧
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## 설치
|
|
16
|
+
|
|
17
|
+
### 1. Codex CLI + ChatGPT OAuth (1회)
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install -g @openai/codex
|
|
21
|
+
|
|
22
|
+
unset OPENAI_API_KEY
|
|
23
|
+
unset CODEX_API_KEY
|
|
24
|
+
codex logout
|
|
25
|
+
codex login
|
|
26
|
+
codex login status
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
공식 인증 문서: [Codex Authentication](https://developers.openai.com/codex/auth)
|
|
30
|
+
|
|
31
|
+
### 2. Python 패키지
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
pip install algocean-codex-oauth
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
LangGraph 프로젝트:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
pip install algocean-codex-oauth langgraph langchain-core
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Quick Start
|
|
44
|
+
|
|
45
|
+
### ChatOpenAI → AlgoceanCodexOAuth (1:1 교체)
|
|
46
|
+
|
|
47
|
+
**Before (API key)**
|
|
48
|
+
|
|
49
|
+
```python
|
|
50
|
+
from langchain_openai import ChatOpenAI
|
|
51
|
+
from langchain_core.messages import HumanMessage
|
|
52
|
+
|
|
53
|
+
llm = ChatOpenAI(model="gpt-4o")
|
|
54
|
+
response = llm.invoke([HumanMessage(content="FastAPI Depends를 짧게 설명해줘.")])
|
|
55
|
+
print(response.content)
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
**After (Codex OAuth)**
|
|
59
|
+
|
|
60
|
+
```python
|
|
61
|
+
from algocean_codex_oauth import AlgoceanCodexOAuth
|
|
62
|
+
from langchain_core.messages import HumanMessage
|
|
63
|
+
|
|
64
|
+
llm = AlgoceanCodexOAuth(model="gpt-5.5")
|
|
65
|
+
response = llm.invoke([HumanMessage(content="FastAPI Depends를 짧게 설명해줘.")])
|
|
66
|
+
print(response.content)
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## LangGraph
|
|
70
|
+
|
|
71
|
+
### 단일 노드
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
from langchain_core.messages import HumanMessage, SystemMessage
|
|
75
|
+
from langgraph.graph import StateGraph, END
|
|
76
|
+
from typing_extensions import TypedDict
|
|
77
|
+
|
|
78
|
+
from algocean_codex_oauth import AlgoceanCodexOAuth
|
|
79
|
+
|
|
80
|
+
class State(TypedDict):
|
|
81
|
+
user_input: str
|
|
82
|
+
answer: str
|
|
83
|
+
|
|
84
|
+
llm = AlgoceanCodexOAuth(model="gpt-5.5")
|
|
85
|
+
|
|
86
|
+
async def assistant_node(state: State) -> State:
|
|
87
|
+
messages = [
|
|
88
|
+
SystemMessage(content="간결한 개인 비서."),
|
|
89
|
+
HumanMessage(content=state["user_input"]),
|
|
90
|
+
]
|
|
91
|
+
ai = await llm.ainvoke(messages)
|
|
92
|
+
return {"answer": ai.content}
|
|
93
|
+
|
|
94
|
+
graph = StateGraph(State)
|
|
95
|
+
graph.add_node("assistant", assistant_node)
|
|
96
|
+
graph.set_entry_point("assistant")
|
|
97
|
+
graph.add_edge("assistant", END)
|
|
98
|
+
app = graph.compile()
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### ReAct Agent
|
|
102
|
+
|
|
103
|
+
```python
|
|
104
|
+
from langgraph.prebuilt import create_react_agent
|
|
105
|
+
from langchain_core.messages import HumanMessage
|
|
106
|
+
from algocean_codex_oauth import AlgoceanCodexOAuth
|
|
107
|
+
|
|
108
|
+
llm = AlgoceanCodexOAuth(model="gpt-5.5")
|
|
109
|
+
agent = create_react_agent(llm, tools=[])
|
|
110
|
+
result = agent.invoke({"messages": [HumanMessage(content="hello")]})
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### Structured Output (LangGraph state merge)
|
|
114
|
+
|
|
115
|
+
```python
|
|
116
|
+
from pydantic import BaseModel, Field
|
|
117
|
+
from langchain_core.messages import HumanMessage
|
|
118
|
+
from algocean_codex_oauth import AlgoceanCodexOAuth
|
|
119
|
+
|
|
120
|
+
class Analysis(BaseModel):
|
|
121
|
+
summary: str = Field(description="요약")
|
|
122
|
+
risk_level: str = Field(description="low | medium | high")
|
|
123
|
+
|
|
124
|
+
llm = AlgoceanCodexOAuth(model="gpt-5.5")
|
|
125
|
+
structured = llm.with_structured_output(Analysis)
|
|
126
|
+
result = structured.invoke([HumanMessage(content="위험도를 평가해줘.")])
|
|
127
|
+
print(result.summary, result.risk_level)
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
내부적으로 Codex CLI `--output-schema`를 사용합니다.
|
|
131
|
+
문서: [Codex non-interactive mode](https://developers.openai.com/codex/noninteractive)
|
|
132
|
+
|
|
133
|
+
## ChatOpenAI 기능 대응
|
|
134
|
+
|
|
135
|
+
| ChatOpenAI (API key) | AlgoceanCodexOAuth |
|
|
136
|
+
| --- | --- |
|
|
137
|
+
| `llm.invoke(messages)` | 동일 |
|
|
138
|
+
| `await llm.ainvoke(messages)` | 동일 |
|
|
139
|
+
| `llm.astream(messages)` | 동일 |
|
|
140
|
+
| `llm.with_structured_output(schema)` | 동일 |
|
|
141
|
+
| LangGraph `state["messages"]` 멀티턴 | `thread_mode="messages"` (기본) |
|
|
142
|
+
| 대화 세션 유지 | `thread_mode="codex_resume"` + `ephemeral=False` |
|
|
143
|
+
| 새 대화 시작 | `llm.reset_thread()` |
|
|
144
|
+
| `response.response_metadata["usage"]` | 동일 |
|
|
145
|
+
|
|
146
|
+
## 생성자
|
|
147
|
+
|
|
148
|
+
```python
|
|
149
|
+
AlgoceanCodexOAuth(
|
|
150
|
+
model: str = "gpt-5.5",
|
|
151
|
+
*,
|
|
152
|
+
timeout: int = 180,
|
|
153
|
+
sandbox: str = "read-only",
|
|
154
|
+
workdir: str | None = None,
|
|
155
|
+
ephemeral: bool = True,
|
|
156
|
+
thread_mode: str = "messages", # messages | codex_resume
|
|
157
|
+
codex_bin: str = "codex",
|
|
158
|
+
require_chatgpt_login: bool = True,
|
|
159
|
+
)
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### Preset
|
|
163
|
+
|
|
164
|
+
```python
|
|
165
|
+
llm = AlgoceanCodexOAuth.chat(model="gpt-5.5") # messages 멀티턴
|
|
166
|
+
llm = AlgoceanCodexOAuth.repo_read(workdir="/path/to/repo")
|
|
167
|
+
llm = AlgoceanCodexOAuth.repo_write(workdir="/path/to/repo") # codex_resume
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
| Preset | thread_mode | 멀티턴 방식 |
|
|
171
|
+
| --- | --- | --- |
|
|
172
|
+
| `chat()` | `messages` | ChatOpenAI처럼 messages 히스토리 전달 |
|
|
173
|
+
| `repo_read(path)` | `messages` | messages 히스토리 |
|
|
174
|
+
| `repo_write(path)` | `codex_resume` | Codex exec resume (에이전트) |
|
|
175
|
+
|
|
176
|
+
## 멀티턴 — ChatOpenAI와 동일하게
|
|
177
|
+
|
|
178
|
+
### 방식 1: messages (기본, LangGraph 표준)
|
|
179
|
+
|
|
180
|
+
```python
|
|
181
|
+
messages = [HumanMessage(content="코드네임은 ALPHA7")]
|
|
182
|
+
ai1 = await llm.ainvoke(messages)
|
|
183
|
+
messages += [ai1, HumanMessage(content="코드네임이 뭐야?")]
|
|
184
|
+
ai2 = await llm.ainvoke(messages)
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
LangGraph `state["messages"]` 패턴과 1:1 동일합니다.
|
|
188
|
+
|
|
189
|
+
### 방식 2: codex_resume (Codex thread 유지)
|
|
190
|
+
|
|
191
|
+
```python
|
|
192
|
+
llm = AlgoceanCodexOAuth(
|
|
193
|
+
model="gpt-5.5",
|
|
194
|
+
workdir="/path/to/repo",
|
|
195
|
+
sandbox="read-only",
|
|
196
|
+
ephemeral=False,
|
|
197
|
+
thread_mode="codex_resume",
|
|
198
|
+
)
|
|
199
|
+
|
|
200
|
+
await llm.ainvoke([HumanMessage(content="첫 질문")])
|
|
201
|
+
await llm.ainvoke([HumanMessage(content="이어서")]) # exec resume
|
|
202
|
+
llm.reset_thread() # 새 대화
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
### Streaming
|
|
206
|
+
|
|
207
|
+
```python
|
|
208
|
+
async for chunk in llm.astream([HumanMessage(content="hello")]):
|
|
209
|
+
print(chunk.content, end="", flush=True)
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
## Provider 스위치 (미니 Codex)
|
|
213
|
+
|
|
214
|
+
```python
|
|
215
|
+
def get_llm(use_codex_oauth: bool):
|
|
216
|
+
if use_codex_oauth:
|
|
217
|
+
from algocean_codex_oauth import AlgoceanCodexOAuth
|
|
218
|
+
return AlgoceanCodexOAuth(model="gpt-5.5")
|
|
219
|
+
from langchain_openai import ChatOpenAI
|
|
220
|
+
return ChatOpenAI(model="gpt-4o")
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
그래프 코드는 동일하고 import / 클래스만 바꾸면 됩니다.
|
|
224
|
+
|
|
225
|
+
## OAuth 정책
|
|
226
|
+
|
|
227
|
+
라이브러리는 호출마다 아래를 강제합니다.
|
|
228
|
+
|
|
229
|
+
- `OPENAI_API_KEY`, `CODEX_API_KEY` 환경 변수 제거
|
|
230
|
+
- `require_chatgpt_login=True` 시 `codex login status`로 ChatGPT OAuth 확인
|
|
231
|
+
- API key 인증 감지 시 `AlgoceanCodexOAuthError` 발생
|
|
232
|
+
|
|
233
|
+
## 아키텍처
|
|
234
|
+
|
|
235
|
+
```text
|
|
236
|
+
algocean_codex_oauth/
|
|
237
|
+
├── chat_model.py # AlgoceanCodexOAuth (BaseChatModel) — public API
|
|
238
|
+
├── client.py # codex exec / exec resume
|
|
239
|
+
├── auth.py # OAuth 검증, API key 차단
|
|
240
|
+
├── config.py # AlgoceanCodexConfig
|
|
241
|
+
├── messages.py # LangChain messages → prompt
|
|
242
|
+
├── session.py # 멀티턴 thread resume (고급)
|
|
243
|
+
└── errors.py
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
## 멀티턴 (Session 래퍼)
|
|
247
|
+
|
|
248
|
+
`AlgoceanCodexSession`은 `thread_mode="codex_resume"` 편의 래퍼입니다.
|
|
249
|
+
직접 `AlgoceanCodexOAuth(..., thread_mode="codex_resume")` 를 써도 동일합니다.
|
|
250
|
+
|
|
251
|
+
## 제한
|
|
252
|
+
|
|
253
|
+
- **개인 로컬 / 개인 구독** 용도입니다. SaaS 서버에서 외부 사용자에게 AI를 제공하는 용도에는 맞지 않습니다.
|
|
254
|
+
- Codex CLI(`codex`)가 PATH에 있어야 합니다.
|
|
255
|
+
- `danger-full-access` sandbox는 격리 환경에서만 사용하세요.
|
|
256
|
+
|
|
257
|
+
## 개발
|
|
258
|
+
|
|
259
|
+
```bash
|
|
260
|
+
git clone https://github.com/algocean1204/AlgoceanCodexOAuth.git
|
|
261
|
+
cd AlgoceanCodexOAuth
|
|
262
|
+
pip install -e ".[dev]"
|
|
263
|
+
pytest
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
## PyPI
|
|
267
|
+
|
|
268
|
+
```bash
|
|
269
|
+
pip install algocean-codex-oauth
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
## License
|
|
273
|
+
|
|
274
|
+
MIT
|
|
275
|
+
|
|
276
|
+
## Links
|
|
277
|
+
|
|
278
|
+
- GitHub: https://github.com/algocean1204/AlgoceanCodexOAuth
|
|
279
|
+
- Codex CLI: https://developers.openai.com/codex/cli/reference
|
|
280
|
+
- Codex Auth: https://developers.openai.com/codex/auth
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "algocean-codex-oauth"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Drop-in ChatOpenAI replacement for LangChain/LangGraph using Codex ChatGPT OAuth subscription."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
requires-python = ">=3.10"
|
|
12
|
+
authors = [{ name = "algocean1204" }]
|
|
13
|
+
keywords = ["codex", "openai", "oauth", "langgraph", "langchain", "chatgpt", "algocean"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 4 - Beta",
|
|
16
|
+
"Intended Audience :: Developers",
|
|
17
|
+
"License :: OSI Approved :: MIT License",
|
|
18
|
+
"Programming Language :: Python :: 3",
|
|
19
|
+
"Programming Language :: Python :: 3.10",
|
|
20
|
+
"Programming Language :: Python :: 3.11",
|
|
21
|
+
"Programming Language :: Python :: 3.12",
|
|
22
|
+
"Programming Language :: Python :: 3.13",
|
|
23
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
24
|
+
]
|
|
25
|
+
dependencies = [
|
|
26
|
+
"langchain-core>=0.3.0",
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
[project.optional-dependencies]
|
|
30
|
+
dev = [
|
|
31
|
+
"pytest>=8.0",
|
|
32
|
+
"pytest-asyncio>=0.24",
|
|
33
|
+
"pydantic>=2.0",
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
[project.urls]
|
|
37
|
+
Homepage = "https://github.com/algocean1204/AlgoceanCodexOAuth"
|
|
38
|
+
Documentation = "https://github.com/algocean1204/AlgoceanCodexOAuth#readme"
|
|
39
|
+
Repository = "https://github.com/algocean1204/AlgoceanCodexOAuth"
|
|
40
|
+
Issues = "https://github.com/algocean1204/AlgoceanCodexOAuth/issues"
|
|
41
|
+
Changelog = "https://github.com/algocean1204/AlgoceanCodexOAuth/releases"
|
|
42
|
+
|
|
43
|
+
[tool.hatch.build.targets.wheel]
|
|
44
|
+
packages = ["src/algocean_codex_oauth"]
|
|
45
|
+
|
|
46
|
+
[tool.hatch.build.targets.sdist]
|
|
47
|
+
include = ["src/algocean_codex_oauth", "README.md", "LICENSE"]
|
|
48
|
+
|
|
49
|
+
[tool.pytest.ini_options]
|
|
50
|
+
asyncio_mode = "auto"
|
|
51
|
+
testpaths = ["tests"]
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"""AlgoceanCodexOAuth — LangChain/LangGraph Codex OAuth LLM."""
|
|
2
|
+
|
|
3
|
+
from .chat_model import AlgoceanCodexOAuth
|
|
4
|
+
from .config import AlgoceanCodexConfig
|
|
5
|
+
from .errors import AlgoceanCodexOAuthError
|
|
6
|
+
from .session import AlgoceanCodexSession
|
|
7
|
+
|
|
8
|
+
__all__ = [
|
|
9
|
+
"AlgoceanCodexOAuth",
|
|
10
|
+
"AlgoceanCodexConfig",
|
|
11
|
+
"AlgoceanCodexOAuthError",
|
|
12
|
+
"AlgoceanCodexSession",
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
__version__ = "0.1.0"
|