Drop-in ChatOpenAI replacement for LangChain/LangGraph — local Codex OAuth or deployed OpenAI API key.
Project description
AlgoceanCodexOAuth
LangChain / LangGraph에서 ChatOpenAI 자리에 그대로 꽂는 LLM 래퍼입니다.
auth=oauth(기본) — 로컬 Codex CLI + ChatGPT OAuth 구독 한도auth=api_key— OpenAI API key 과금 (langchain_openai.ChatOpenAI위임)
PyPI: algocean-codex-oauth · GitHub: algocean1204/AlgoceanCodexOAuth
1분 시작
pip install -U algocean-codex-oauth langgraph langchain-core
codex login # oauth 사용 시 1회 (ChatGPT 로그인)
from algocean_codex_oauth import AlgoceanCodexOAuth
from langchain_core.messages import HumanMessage
llm = AlgoceanCodexOAuth.chat(model="gpt-5.5")
print(llm.invoke([HumanMessage(content="Hello")]).content)
LangGraph 노드에도 동일한 llm 객체를 넣으면 됩니다.
어떤 auth를 쓸까?
auth=oauth (기본) |
auth=api_key |
|
|---|---|---|
| 언제 | 로컬 개발 PC | 배포 서버, CI |
| 인증 | codex login |
환경 변수 ALGOCEANCODEXOAUTH_API |
| 과금 | Codex / ChatGPT 구독 | OpenAI API |
| 설치 | pip install algocean-codex-oauth (동일) |
pip install algocean-codex-oauth (동일) |
repo 에이전트 (repo_read / repo_write) |
✅ | ❌ |
| Codex thread resume | ✅ | ❌ |
그래프 코드는 그대로 — llm을 만드는 줄만 auth와 model을 바꾸면 됩니다.
설치
pip install -U algocean-codex-oauth
oauth / api_key 모두 동일한 패키지입니다. auth는 코드 또는 환경 변수로 선택합니다.
oauth — 로컬 개발 (추가 1회)
npm install -g @openai/codex
codex login
codex login status
Codex 인증: Codex Authentication
oauth 모드에서는 ChatGPT OAuth만 사용합니다. OpenAI API key 환경 변수가 설정되어 있으면 oauth 호출이 차단될 수 있습니다.
api_key — 배포 / 서버 (추가 설정)
export ALGOCEANCODEXOAUTH_API=<your-openai-api-key>
# 선택: export ALGOCEANCODEXOAUTH_AUTH=api_key
LangGraph 프로젝트 의존성 예:
pip install -U algocean-codex-oauth langgraph langchain-core
기본 사용
동기 / 비동기
from algocean_codex_oauth import AlgoceanCodexOAuth, oauth, api_key
from langchain_core.messages import HumanMessage
# oauth (기본) — auth 생략 가능
llm = AlgoceanCodexOAuth(model="gpt-5.5")
# api_key
llm = AlgoceanCodexOAuth(auth=api_key, model="gpt-4o")
response = llm.invoke([HumanMessage(content="FastAPI Depends를 짧게 설명해줘.")])
await llm.ainvoke([HumanMessage(content="...")])
환경 변수로 모드 선택
from algocean_codex_oauth import AlgoceanCodexOAuth
llm = AlgoceanCodexOAuth.from_env(model="gpt-4o")
ALGOCEANCODEXOAUTH_AUTH=api_key일 때 ALGOCEANCODEXOAUTH_API가 필요합니다.
터미널 가이드 — help()
from algocean_codex_oauth import AlgoceanCodexOAuth
AlgoceanCodexOAuth.help() # 개요
AlgoceanCodexOAuth.help("langgraph") # LangGraph 예제
AlgoceanCodexOAuth.help("auth") # oauth vs api_key
AlgoceanCodexOAuth.help("all") # 전체
토픽: install, quickstart, langgraph, auth, multiturn, presets, all
LangGraph
단일 노드 그래프
from langchain_core.messages import HumanMessage, SystemMessage
from langgraph.graph import StateGraph, END
from typing_extensions import TypedDict
from algocean_codex_oauth import AlgoceanCodexOAuth
class State(TypedDict):
user_input: str
answer: str
llm = AlgoceanCodexOAuth(model="gpt-5.5")
async def assistant_node(state: State) -> State:
messages = [
SystemMessage(content="간결한 개인 비서."),
HumanMessage(content=state["user_input"]),
]
ai = await llm.ainvoke(messages)
return {"answer": ai.content}
graph = StateGraph(State)
graph.add_node("assistant", assistant_node)
graph.set_entry_point("assistant")
graph.add_edge("assistant", END)
app = graph.compile()
배포 시 — api_key로 동일 그래프
from algocean_codex_oauth import AlgoceanCodexOAuth, api_key
llm = AlgoceanCodexOAuth(auth=api_key, model="gpt-4o")
# 그래프·노드 코드는 동일
ReAct Agent
from langgraph.prebuilt import create_react_agent
from langchain_core.messages import HumanMessage
from algocean_codex_oauth import AlgoceanCodexOAuth
llm = AlgoceanCodexOAuth(model="gpt-5.5")
agent = create_react_agent(llm, tools=[])
result = agent.invoke({"messages": [HumanMessage(content="hello")]})
Structured Output
from pydantic import BaseModel, Field
from langchain_core.messages import HumanMessage
from algocean_codex_oauth import AlgoceanCodexOAuth
class Analysis(BaseModel):
summary: str = Field(description="요약")
risk_level: str = Field(description="low | medium | high")
llm = AlgoceanCodexOAuth(model="gpt-5.5")
structured = llm.with_structured_output(Analysis)
result = structured.invoke([HumanMessage(content="위험도를 평가해줘.")])
ChatOpenAI와 동일한 API
| ChatOpenAI | AlgoceanCodexOAuth |
|---|---|
llm.invoke(messages) |
동일 |
await llm.ainvoke(messages) |
동일 |
llm.astream(messages) |
동일 |
llm.with_structured_output(schema) |
동일 |
LangGraph state["messages"] 멀티턴 |
thread_mode="messages" (기본) |
| Codex thread resume | thread_mode="codex_resume" (oauth 전용) |
| 새 대화 | llm.reset_thread() (oauth) |
Preset — 용도별 바로 쓰기
from algocean_codex_oauth import AlgoceanCodexOAuth
# LangGraph Q&A — 순수 LLM (AGENTS.md/rules 무시, 기본)
llm = AlgoceanCodexOAuth.chat(model="gpt-5.5")
# repo 읽기 전용 에이전트 (oauth 전용)
llm = AlgoceanCodexOAuth.repo_read(workdir="/path/to/repo")
# repo 쓰기 에이전트 (oauth 전용)
llm = AlgoceanCodexOAuth.repo_write(workdir="/path/to/repo")
| Preset | 용도 | auth |
|---|---|---|
chat() |
LangGraph Q&A, 일반 대화 | oauth / api_key |
repo_read(path) |
코드베이스 탐색 | oauth |
repo_write(path) |
코드 수정 에이전트 | oauth |
LLM-only (chat(), oauth)
LangGraph Q&A처럼 일반 LLM에 가깝게 동작합니다.
- 프로젝트
AGENTS.md/ Codex rules 적용 안 함 - read-only sandbox, 단발성 대화에 적합
- repo 에이전트가 필요하면
repo_read()/repo_write()사용
멀티턴
messages 모드 (기본, ChatOpenAI와 동일)
messages = [HumanMessage(content="코드네임은 ALPHA7")]
ai1 = await llm.ainvoke(messages)
messages += [ai1, HumanMessage(content="코드네임이 뭐야?")]
ai2 = await llm.ainvoke(messages)
LangGraph state["messages"] 패턴과 1:1 동일합니다.
codex_resume (oauth, repo 작업)
llm = AlgoceanCodexOAuth(
model="gpt-5.5",
workdir="/path/to/repo",
sandbox="read-only",
ephemeral=False,
thread_mode="codex_resume",
)
await llm.ainvoke([HumanMessage(content="첫 질문")])
await llm.ainvoke([HumanMessage(content="이어서")])
llm.reset_thread()
Streaming
async for chunk in llm.astream([HumanMessage(content="hello")]):
print(chunk.content, end="", flush=True)
로컬 ↔ 배포 전환
import os
from algocean_codex_oauth import AlgoceanCodexOAuth, oauth, api_key
def get_llm():
if os.getenv("ALGOCEANCODEXOAUTH_API"):
return AlgoceanCodexOAuth(auth=api_key, model="gpt-4o")
return AlgoceanCodexOAuth(auth=oauth, model="gpt-5.5")
생성자 옵션
AlgoceanCodexOAuth(
model="gpt-5.5",
auth=oauth, # oauth | api_key
timeout=180,
sandbox="read-only", # oauth 전용
workdir=None, # oauth 전용
ephemeral=True, # oauth 전용
thread_mode="messages", # messages | codex_resume (oauth)
codex_bin="codex",
require_chatgpt_login=True,
)
환경 변수
| 변수 | 설명 |
|---|---|
ALGOCEANCODEXOAUTH_API |
api_key 모드 OpenAI API key |
ALGOCEANCODEXOAUTH_AUTH |
oauth 또는 api_key (기본 oauth) |
제한 사항
- oauth — 개인 로컬 / 개인 구독 용도. SaaS 서버 배포에는 부적합.
- api_key — OpenAI API 과금. repo sandbox / codex resume 미지원.
- oauth — Codex CLI(
codex)가 PATH에 있어야 합니다.
License
MIT
Links
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file algocean_codex_oauth-0.2.6.tar.gz.
File metadata
- Download URL: algocean_codex_oauth-0.2.6.tar.gz
- Upload date:
- Size: 15.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7d8be534cbad5acfde7105bf4faf1093429ec9ca624e031b007c21600fbda0ad
|
|
| MD5 |
f5ed870dacb31ef504b2e746927f452d
|
|
| BLAKE2b-256 |
b0939ff3cc8bbefea454bf6269d0fe420bf807a8dd91c23223d1c516845d5319
|
Provenance
The following attestation bundles were made for algocean_codex_oauth-0.2.6.tar.gz:
Publisher:
publish.yml on algocean1204/AlgoceanCodexOAuth
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
algocean_codex_oauth-0.2.6.tar.gz -
Subject digest:
7d8be534cbad5acfde7105bf4faf1093429ec9ca624e031b007c21600fbda0ad - Sigstore transparency entry: 2020521041
- Sigstore integration time:
-
Permalink:
algocean1204/AlgoceanCodexOAuth@4761c9ab5f03185ba15f23a03a50c6a69adda28b -
Branch / Tag:
refs/tags/v0.2.6 - Owner: https://github.com/algocean1204
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@4761c9ab5f03185ba15f23a03a50c6a69adda28b -
Trigger Event:
push
-
Statement type:
File details
Details for the file algocean_codex_oauth-0.2.6-py3-none-any.whl.
File metadata
- Download URL: algocean_codex_oauth-0.2.6-py3-none-any.whl
- Upload date:
- Size: 20.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
066837bc7dd788fbff2ca649d34f4ccad251b235d92f9074b919c2b15542b4be
|
|
| MD5 |
e05fbee1e23884c21c7a34625c4ca29e
|
|
| BLAKE2b-256 |
56a08ed02172a8c6355e3aa5a861e4221f252ab9bad2231b664f0a0dcb8c6cc9
|
Provenance
The following attestation bundles were made for algocean_codex_oauth-0.2.6-py3-none-any.whl:
Publisher:
publish.yml on algocean1204/AlgoceanCodexOAuth
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
algocean_codex_oauth-0.2.6-py3-none-any.whl -
Subject digest:
066837bc7dd788fbff2ca649d34f4ccad251b235d92f9074b919c2b15542b4be - Sigstore transparency entry: 2020521160
- Sigstore integration time:
-
Permalink:
algocean1204/AlgoceanCodexOAuth@4761c9ab5f03185ba15f23a03a50c6a69adda28b -
Branch / Tag:
refs/tags/v0.2.6 - Owner: https://github.com/algocean1204
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@4761c9ab5f03185ba15f23a03a50c6a69adda28b -
Trigger Event:
push
-
Statement type: