refactor: 将共用代码迁入 lib/ 模块化目录
统一 strategy、key_monitor、trade、hub 等共用库到 lib/ 子包,并补充 lib-structure 文档,便于四所与中控维护。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,42 +1,42 @@
|
||||
"""中控 AI 模型调用(共用 ai_client 配置,逻辑独立)。"""
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from typing import Optional, Sequence
|
||||
|
||||
_REPO_ROOT = Path(__file__).resolve().parents[2]
|
||||
if str(_REPO_ROOT) not in sys.path:
|
||||
sys.path.insert(0, str(_REPO_ROOT))
|
||||
|
||||
from ai_client import ai_generate, ai_generate_chat, ai_provider_label # noqa: E402
|
||||
|
||||
|
||||
def model_label() -> str:
|
||||
return ai_provider_label()
|
||||
|
||||
|
||||
def generate_text(
|
||||
*,
|
||||
system: str,
|
||||
user: str,
|
||||
temperature: float,
|
||||
images_b64: Optional[Sequence[str]] = None,
|
||||
max_tokens: int | None = None,
|
||||
max_continuations: int = 3,
|
||||
) -> str:
|
||||
if max_tokens is not None and max_tokens > 0:
|
||||
return ai_generate_chat(
|
||||
system=system,
|
||||
user=user,
|
||||
temperature=temperature,
|
||||
images_b64=images_b64,
|
||||
max_tokens=int(max_tokens),
|
||||
max_continuations=max_continuations,
|
||||
)
|
||||
prompt = f"{system.strip()}\n\n---\n\n{user.strip()}"
|
||||
return ai_generate(
|
||||
prompt,
|
||||
temperature=temperature,
|
||||
images_b64=images_b64,
|
||||
)
|
||||
"""中控 AI 模型调用(共用 ai_client 配置,逻辑独立)。"""
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from typing import Optional, Sequence
|
||||
|
||||
_REPO_ROOT = Path(__file__).resolve().parents[2]
|
||||
if str(_REPO_ROOT) not in sys.path:
|
||||
sys.path.insert(0, str(_REPO_ROOT))
|
||||
|
||||
from lib.ai.ai_client import ai_generate, ai_generate_chat, ai_provider_label # noqa: E402
|
||||
|
||||
|
||||
def model_label() -> str:
|
||||
return ai_provider_label()
|
||||
|
||||
|
||||
def generate_text(
|
||||
*,
|
||||
system: str,
|
||||
user: str,
|
||||
temperature: float,
|
||||
images_b64: Optional[Sequence[str]] = None,
|
||||
max_tokens: int | None = None,
|
||||
max_continuations: int = 3,
|
||||
) -> str:
|
||||
if max_tokens is not None and max_tokens > 0:
|
||||
return ai_generate_chat(
|
||||
system=system,
|
||||
user=user,
|
||||
temperature=temperature,
|
||||
images_b64=images_b64,
|
||||
max_tokens=int(max_tokens),
|
||||
max_continuations=max_continuations,
|
||||
)
|
||||
prompt = f"{system.strip()}\n\n---\n\n{user.strip()}"
|
||||
return ai_generate(
|
||||
prompt,
|
||||
temperature=temperature,
|
||||
images_b64=images_b64,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user