From 4e06e12ab60f4d856e6106dedab09526ae020a74 Mon Sep 17 00:00:00 2001 From: lang07123 Date: Tue, 31 Mar 2026 11:51:57 +0800 Subject: [PATCH] =?UTF-8?q?feat(provider):=20=E6=B7=BB=E5=8A=A0=20Langfuse?= =?UTF-8?q?=20=E8=A7=82=E6=B5=8B=E5=B9=B3=E5=8F=B0=E7=9A=84=E9=9B=86?= =?UTF-8?q?=E6=88=90=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit feat(provider): 添加 Langfuse 观测平台的集成支持 --- nanobot/providers/openai_compat_provider.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/nanobot/providers/openai_compat_provider.py b/nanobot/providers/openai_compat_provider.py index a216e9046..a06bfa237 100644 --- a/nanobot/providers/openai_compat_provider.py +++ b/nanobot/providers/openai_compat_provider.py @@ -4,6 +4,7 @@ from __future__ import annotations import asyncio import hashlib +import importlib import os import secrets import string @@ -12,7 +13,15 @@ from collections.abc import Awaitable, Callable from typing import TYPE_CHECKING, Any import json_repair -from openai import AsyncOpenAI + +if os.environ.get("LANGFUSE_SECRET_KEY"): + LANGFUSE_AVAILABLE = importlib.util.find_spec("langfuse") is not None + if not LANGFUSE_AVAILABLE: + raise ImportError("Langfuse is not available; please install it with `pip install langfuse`") + + from langfuse.openai import AsyncOpenAI +else: + from openai import AsyncOpenAI from nanobot.providers.base import LLMProvider, LLMResponse, ToolCallRequest