-
Notifications
You must be signed in to change notification settings - Fork 13
OpenAI codex oauth integration #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
addd836
feat(auth): add provider-scoped api_key_resolver in LLM core
niyue 2d55a83
feat(auth): add openai codex oauth token store and resolver, and rout…
niyue e4a83c9
feat(codex): add tool calling support for chatgpt codex backend
niyue 31559e7
feat(codex): add streaming compatibility for chatgpt codex backend
niyue e7729b8
fix(codex): include assistant tool_calls in request replay
niyue 8fe5a73
feat(codex): migrate transport to httpx and refine oauth login flow
niyue eaf116d
fix(codex): stream SSE chunks incrementally
niyue 761d4a3
refactor(tests): reduce duplication in codex oauth tests
niyue ef70473
Fix Codex transport CI checks
niyue File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import argparse | ||
| import os | ||
|
|
||
| from republic import LLM, login_openai_codex_oauth, openai_codex_oauth_resolver | ||
|
|
||
|
|
||
| def parse_args() -> argparse.Namespace: | ||
| parser = argparse.ArgumentParser( | ||
| description="Authenticate with OpenAI Codex OAuth and run a simple Republic chat.", | ||
| ) | ||
| parser.add_argument( | ||
| "--login-only", | ||
| action="store_true", | ||
| help="Run OAuth login and persist tokens without sending a chat request.", | ||
| ) | ||
| parser.add_argument( | ||
| "--model", | ||
| default=os.getenv("REPUBLIC_CODEX_MODEL", "openai:gpt-5-codex"), | ||
| help="Model to use after login.", | ||
| ) | ||
| parser.add_argument( | ||
| "--prompt", | ||
| default="Explain tape-first workflows in one sentence.", | ||
| help="Prompt to send after login.", | ||
| ) | ||
| return parser.parse_args() | ||
|
|
||
|
|
||
| def prompt_for_redirect(authorize_url: str) -> str: | ||
| print("Open this URL in your browser and complete the sign-in flow:\n") | ||
| print(authorize_url) | ||
| print("\nPaste the full callback URL (or the authorization code) here.") | ||
| return input("> ").strip() | ||
|
|
||
|
|
||
| def main() -> None: | ||
| args = parse_args() | ||
|
|
||
| tokens = login_openai_codex_oauth( | ||
| prompt_for_redirect=None, | ||
| ) | ||
| print("login: ok") | ||
| print("account_id:", tokens.account_id or "-") | ||
|
|
||
| if args.login_only: | ||
| return | ||
|
|
||
| llm = LLM( | ||
| model=args.model, | ||
| api_key_resolver=openai_codex_oauth_resolver(), | ||
| ) | ||
| out = llm.chat(args.prompt) | ||
|
|
||
| if out.error: | ||
| print("error:", out.error.kind, out.error.message) | ||
| return | ||
| print("text:", out.value) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| """Authentication helpers.""" | ||
|
|
||
| from republic.auth.openai_codex import * # noqa: F403 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this PR is merged, I’ll follow up with a separate PR in
bubthat uses these two APIs to:I’ve already done an initial local validation of this flow in
bubusing these two APIs.