mirror of
https://github.com/hansjone/oclaw.git
synced 2026-10-10 13:00:45 +08:00
重构仓库目录为统一的 runtime 分层并清理历史 openclaw 残留。
本次迁移将网关/通道/工具/技能/脚本与协议资源集中到新结构,统一路径常量与脚本转发机制,减少顶层噪音并保证运行与测试行为一致。 Made-with: Cursor
This commit is contained in:
parent
ba3836f00f
commit
4a23b715a2
498 changed files with 2760 additions and 2200 deletions
37
runtime/extensions/openai/__init__.py
Normal file
37
runtime/extensions/openai/__init__.py
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
from .api import (
|
||||
OPENAI_CODEX_DEFAULT_MODEL,
|
||||
OPENAI_DEFAULT_AUDIO_TRANSCRIPTION_MODEL,
|
||||
OPENAI_DEFAULT_EMBEDDING_MODEL,
|
||||
OPENAI_DEFAULT_IMAGE_MODEL,
|
||||
OPENAI_DEFAULT_MODEL,
|
||||
OPENAI_DEFAULT_TTS_MODEL,
|
||||
OPENAI_DEFAULT_TTS_VOICE,
|
||||
apply_openai_config,
|
||||
apply_openai_provider_config,
|
||||
build_openai_codex_provider,
|
||||
build_openai_image_generation_provider,
|
||||
build_openai_provider,
|
||||
is_openai_api_base_url,
|
||||
is_openai_codex_base_url,
|
||||
)
|
||||
from .index import build_openai_plugin_entry, plugin_entry, register_openai_plugin
|
||||
|
||||
__all__ = [
|
||||
"OPENAI_CODEX_DEFAULT_MODEL",
|
||||
"OPENAI_DEFAULT_AUDIO_TRANSCRIPTION_MODEL",
|
||||
"OPENAI_DEFAULT_EMBEDDING_MODEL",
|
||||
"OPENAI_DEFAULT_IMAGE_MODEL",
|
||||
"OPENAI_DEFAULT_MODEL",
|
||||
"OPENAI_DEFAULT_TTS_MODEL",
|
||||
"OPENAI_DEFAULT_TTS_VOICE",
|
||||
"apply_openai_config",
|
||||
"apply_openai_provider_config",
|
||||
"build_openai_codex_provider",
|
||||
"build_openai_image_generation_provider",
|
||||
"build_openai_plugin_entry",
|
||||
"build_openai_provider",
|
||||
"is_openai_api_base_url",
|
||||
"is_openai_codex_base_url",
|
||||
"plugin_entry",
|
||||
"register_openai_plugin",
|
||||
]
|
||||
69
runtime/extensions/openai/api.py
Normal file
69
runtime/extensions/openai/api.py
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
from __future__ import annotations
|
||||
import re
|
||||
|
||||
OPENAI_DEFAULT_MODEL = "openai/gpt-4.1"
|
||||
OPENAI_CODEX_DEFAULT_MODEL = "openai/codex-mini-latest"
|
||||
OPENAI_DEFAULT_IMAGE_MODEL = "gpt-image-1"
|
||||
OPENAI_DEFAULT_EMBEDDING_MODEL = "text-embedding-3-large"
|
||||
OPENAI_DEFAULT_AUDIO_TRANSCRIPTION_MODEL = "gpt-4o-mini-transcribe"
|
||||
OPENAI_DEFAULT_TTS_MODEL = "gpt-4o-mini-tts"
|
||||
OPENAI_DEFAULT_TTS_VOICE = "alloy"
|
||||
|
||||
|
||||
def apply_openai_config(cfg: dict) -> dict:
|
||||
return dict(cfg or {})
|
||||
|
||||
|
||||
def apply_openai_provider_config(cfg: dict) -> dict:
|
||||
return dict(cfg or {})
|
||||
|
||||
|
||||
def build_openai_provider() -> dict:
|
||||
return {
|
||||
"id": "openai",
|
||||
"label": "OpenAI",
|
||||
"api": "openai-responses",
|
||||
"base_url": "https://api.openai.com/v1",
|
||||
"default_model": OPENAI_DEFAULT_MODEL,
|
||||
}
|
||||
|
||||
|
||||
def build_openai_codex_provider() -> dict:
|
||||
return {
|
||||
"id": "openai-codex",
|
||||
"label": "OpenAI Codex",
|
||||
"api": "openai-responses",
|
||||
"base_url": "https://chatgpt.com/backend-api",
|
||||
"default_model": OPENAI_CODEX_DEFAULT_MODEL,
|
||||
}
|
||||
|
||||
|
||||
def build_openai_image_generation_provider() -> dict:
|
||||
def _generate(*, prompt: str, size: str | None = None, quality: str | None = None, **_kwargs):
|
||||
return {
|
||||
"model": OPENAI_DEFAULT_IMAGE_MODEL,
|
||||
"prompt": prompt,
|
||||
**({"size": size} if size else {}),
|
||||
**({"quality": quality} if quality else {}),
|
||||
}
|
||||
|
||||
return {
|
||||
"id": "openai",
|
||||
"label": "OpenAI Images",
|
||||
"model": OPENAI_DEFAULT_IMAGE_MODEL,
|
||||
"generate": _generate,
|
||||
}
|
||||
|
||||
|
||||
def is_openai_api_base_url(base_url: str | None = None) -> bool:
|
||||
trimmed = str(base_url or "").strip()
|
||||
if not trimmed:
|
||||
return False
|
||||
return bool(re.fullmatch(r"https?://api\.openai\.com(?:/v1)?/?", trimmed, re.I))
|
||||
|
||||
|
||||
def is_openai_codex_base_url(base_url: str | None = None) -> bool:
|
||||
trimmed = str(base_url or "").strip()
|
||||
if not trimmed:
|
||||
return False
|
||||
return bool(re.fullmatch(r"https?://chatgpt\.com/backend-api(?:/v1)?/?", trimmed, re.I))
|
||||
28
runtime/extensions/openai/index.py
Normal file
28
runtime/extensions/openai/index.py
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from .api import (
|
||||
build_openai_codex_provider,
|
||||
build_openai_image_generation_provider,
|
||||
build_openai_provider,
|
||||
)
|
||||
from oclaw.runtime.extensions.plugin_api import PluginEntry, define_plugin_entry
|
||||
|
||||
|
||||
def register_openai_plugin(api) -> None:
|
||||
if hasattr(api, "register_provider"):
|
||||
api.register_provider(build_openai_provider())
|
||||
api.register_provider(build_openai_codex_provider())
|
||||
if hasattr(api, "register_image_generation_provider"):
|
||||
api.register_image_generation_provider(build_openai_image_generation_provider())
|
||||
|
||||
|
||||
def build_openai_plugin_entry() -> PluginEntry:
|
||||
return define_plugin_entry(
|
||||
id="openai",
|
||||
name="OpenAI Provider",
|
||||
description="Bundled OpenAI provider plugins",
|
||||
register=register_openai_plugin,
|
||||
)
|
||||
|
||||
|
||||
plugin_entry = build_openai_plugin_entry()
|
||||
Loading…
Add table
Add a link
Reference in a new issue