跳转到内容

OpenLIT 集成

OpenLIT 是一个开源工具,只需 一行 代码,就能轻松监控 AI 代理、LLM、向量数据库和 GPU 的性能。

它提供原生 OpenTelemetry 的追踪和指标,用于跟踪成本、延迟、交互和任务序列等重要参数。 这种设置使你能够跟踪超参数并监控性能问题,帮助你随着时间推移不断改进和微调代理。

代理使用情况概览,包括成本和 token代理 otel 追踪和指标概览代理追踪详情概览
OpenLIT 仪表盘
  • 分析仪表盘:通过详细仪表盘监控代理的健康状况和性能,跟踪指标、成本和用户交互。
  • OpenTelemetry 原生可观测性 SDK:供应商中立的 SDK,可将追踪和指标发送到你现有的可观测性工具,如 Grafana、DataDog 等。
  • 自定义和微调模型的成本追踪:使用自定义定价文件,为特定模型定制成本估算,实现精确预算。
  • 异常监控仪表盘:通过监控仪表盘快速发现并解决常见异常和错误。
  • 合规与安全:检测潜在威胁,例如不当内容和 PII 泄露。
  • 提示注入检测:识别潜在的代码注入和机密泄露。
  • API Keys 与机密管理:集中、安全地处理你的 LLM API keys 和机密,避免不安全做法。
  • 提示词管理:使用 PromptHub 管理并为代理提示词建立版本,便于在各个代理间保持一致和轻松访问。
  • 模型 Playground:在部署前测试并比较不同模型在 CrewAI 代理中的表现。
  1. 部署 OpenLIT
    1. 克隆 OpenLIT 仓库
      Terminal window
      git clone [email protected]:openlit/openlit.git
    2. 启动 Docker Compose

      OpenLIT 仓库 的根目录下运行以下命令:

      Terminal window
      docker compose up -d
  2. 安装 OpenLIT SDK
    Terminal window
    pip install openlit
  3. 在应用中初始化 OpenLIT

    将以下两行添加到你的应用代码中:

    使用函数参数设置
    import openlit
    openlit.init(otlp_endpoint="http://127.0.0.1:4318")

    监控 CrewAI 代理的示例用法:

    from crewai import Agent, Task, Crew, Process
    import openlit
    openlit.init(disable_metrics=True)
    # 定义你的代理
    researcher = Agent(
    role="Researcher",
    goal="Conduct thorough research and analysis on AI and AI agents",
    backstory="You're an expert researcher, specialized in technology, software engineering, AI, and startups. You work as a freelancer and are currently researching for a new client.",
    allow_delegation=False,
    llm='command-r'
    )
    # 定义你的任务
    task = Task(
    description="Generate a list of 5 interesting ideas for an article, then write one captivating paragraph for each idea that showcases the potential of a full article on this topic. Return the list of ideas with their paragraphs and your notes.",
    expected_output="5 bullet points, each with a paragraph and accompanying notes.",
    )
    # 定义经理代理
    manager = Agent(
    role="Project Manager",
    goal="Efficiently manage the crew and ensure high-quality task completion",
    backstory="You're an experienced project manager, skilled in overseeing complex projects and guiding teams to success. Your role is to coordinate the efforts of the crew members, ensuring that each task is completed on time and to the highest standard.",
    allow_delegation=True,
    llm='command-r'
    )
    # 使用自定义经理实例化你的 crew
    crew = Crew(
    agents=[researcher],
    tasks=[task],
    manager_agent=manager,
    process=Process.hierarchical,
    )
    # 启动 crew 的工作
    result = crew.kickoff()
    print(result)
    使用环境变量设置

    将以下两行添加到你的应用代码中:

    import openlit
    openlit.init()

    运行以下命令来配置 OTEL 导出端点:

    Terminal window
    export OTEL_EXPORTER_OTLP_ENDPOINT = "http://127.0.0.1:4318"

    监控 CrewAI 异步代理的示例用法:

    import asyncio
    from crewai import Crew, Agent, Task
    import openlit
    openlit.init(otlp_endpoint="http://127.0.0.1:4318")
    # 创建一个启用代码执行的代理
    coding_agent = Agent(
    role="Python Data Analyst",
    goal="Analyze data and provide insights using Python",
    backstory="You are an experienced data analyst with strong Python skills.",
    allow_code_execution=True,
    llm="command-r"
    )
    # 创建一个需要代码执行的任务
    data_analysis_task = Task(
    description="Analyze the given dataset and calculate the average age of participants. Ages: {ages}",
    agent=coding_agent,
    expected_output="5 bullet points, each with a paragraph and accompanying notes.",
    )
    # 创建 crew 并添加任务
    analysis_crew = Crew(
    agents=[coding_agent],
    tasks=[data_analysis_task]
    )
    # 用于异步启动 crew 的异步函数
    async def async_crew_execution():
    result = await analysis_crew.kickoff_async(inputs={"ages": [25, 30, 35, 40, 45]})
    print("Crew Result:", result)
    # 运行异步函数
    asyncio.run(async_crew_execution())

    需要更多高级配置和使用场景,请参阅 OpenLIT Python SDK 仓库

  4. 可视化与分析

    现在,代理可观测性数据已经被收集并发送到 OpenLIT,下一步就是对这些数据进行可视化和分析,以获取代理性能、行为方面的洞察,并识别可改进的领域。

    只需在浏览器中打开 127.0.0.1:3000 即可开始探索。你可以使用默认凭据登录:

    代理使用情况概览,包括成本和 token代理 otel 追踪和指标概览
    OpenLIT 仪表盘