langfuse本地安装
目录
- 安装命令
- 项目准备
- 用openai测试
安装命令
-
本地(docker compose):使用 Docker Compose 在你的机器上于 5 分钟内运行 Langfuse。
# 获取最新的 Langfuse 仓库副本 git clone https://github.com/langfuse/langfuse.git cd langfuse# 运行 Langfuse 的 docker compose docker compose up
项目准备
打开 http://localhost:3000
首次登录需要注册
注册完成后,出现下面页面
创建项目,并获取key
用openai测试
用阿里云的账号测试
from langfuse.decorators import observe
from langfuse.openai import openai # OpenAI integrationimport osos.environ["OPENAI_API_KEY"] = "your api key"
os.environ["OPENAI_BASE_URL"] = "https://dashscope.aliyuncs.com/compatible-mode/v1"
os.environ["LANGFUSE_HOST"] = "http://localhost:3000"os.environ["LANGFUSE_PUBLIC_KEY"] = "pk-lf-e1634618-1810-4f05-8d31-e87dc9da548e"
os.environ["LANGFUSE_SECRET_KEY"] = "sk-lf-335af17a-ab0d-4ffe-943f-6cc62a09068e"@observe()
def story():return openai.chat.completions.create(model="qwen-turbo",messages=[{"role": "system", "content": "You are a good assistant."},{"role": "user", "content": "tell me a joke about a cat"},],).choices[0].message.content@observe()
def main():res = story()print(res)return resmain()