market-assistant/backend/pipeline/demos/try_openai_official_llm.py
hub-gif 33bf73e3ba feat(pipeline/llm): OpenAI 官方 ChatGPT 适配器并整理 providers 目录
新增 providers/adapters/openai_official_chatgpt、shared 抽离归一化与 token 启发式;MA_LLM_TEXT_PROVIDER 支持 openai_official/openai_chatgpt/chatgpt。补充单测与 try_openai_official_llm 试跑脚本、.env.example 说明。

Made-with: Cursor
2026-04-27 10:09:26 +08:00

28 lines
967 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""
试跑 OpenAI 官方「ChatGPT」文本适配器不经过完整报告管线
准备:在 .env 中设置 MA_LLM_TEXT_PROVIDER=chatgpt 与 OPENAI_OFFICIAL_API_KEY见 .env.example
用法(在 backend 目录下):
.venv\\Scripts\\python.exe -m pipeline.demos.try_openai_official_llm
"""
from __future__ import annotations
import os
import sys
if __name__ == "__main__":
if not (os.environ.get("OPENAI_OFFICIAL_API_KEY") or "").strip():
print("未设置 OPENAI_OFFICIAL_API_KEY退出。", file=sys.stderr)
sys.exit(1)
# 与生产一致时可在 .env 中设 MA_LLM_TEXT_PROVIDER=chatgpt本脚本也强制用官方适配器
from pipeline.llm.providers.adapters.openai_official_chatgpt import OpenAiOfficialChatGptTextLlm
out = OpenAiOfficialChatGptTextLlm().complete_text(
"You reply in one short English sentence only.",
"What is 2+2?",
temperature=0.0,
)
print(out)