Skip to main content

LiveKit Agent Plugins for Dify

Project description

livekit-plugins-dify

PyPI version Python 3.9+ License

Dify.ai服务专用的 LiveKit Agents 插件,提供AI应用集成解决方案。

✨ 特性

  • 🤖 大语言模型 (LLM) - 支持Dify.ai平台的应用集成
  • 🔧 灵活配置 - 支持自定义API端点和密钥
  • 📦 开箱即用 - 完整的 Python 包支持

📋 支持的服务

服务 描述 文档链接
LLM 大语言模型 Dify.ai文档

🛠️ 安装

使用 pip 安装

pip install livekit-plugins-dify

从源码安装

git clone https://github.com/your-repo/livekit-plugins-volcengine.git
cd livekit-plugins-volcengine
pip install -e ./livekit-plugins/livekit-plugins-dify

系统要求

  • Python >= 3.9
  • LiveKit Agents >= 1.2.9

⚙️ 配置

环境变量

在使用插件前,请配置以下环境变量:

环境变量 描述 默认值
DIFY_API_KEY Dify API密钥 必需
DIFY_API_BASE Dify API基础URL https://api.dify.ai/v1

.env 文件示例

# .env
DIFY_API_KEY=your_api_key_here
DIFY_API_BASE=https://api.dify.ai/v1

📖 使用指南

基础使用

from livekit.agents import Agent, AgentSession, JobContext, cli, WorkerOptions
from livekit.plugins import dify
from dotenv import load_dotenv

async def entry_point(ctx: JobContext):
    agent = Agent(instructions="You are a helpful assistant.")

    # 创建Dify LLM实例
    llm = dify.LLM(user="your_user_id")

    session = AgentSession(llm=llm)

    await session.start(agent=agent, room=ctx.room)
    await ctx.connect()

    # 支持Dify开场词
    opening_words = await llm.get_opening_words()
    if opening_words:
        await session.say(opening_words)

if __name__ == "__main__":
    load_dotenv()
    cli.run_app(WorkerOptions(entrypoint_fnc=entry_point))

完整配置示例

from livekit.agents import Agent, AgentSession, JobContext, cli, WorkerOptions
from livekit.plugins import dify, volcengine
from dotenv import load_dotenv

async def entry_point(ctx: JobContext):
    agent = Agent(instructions="You are a helpful assistant.")

    # Dify LLM配置
    llm = dify.LLM(
        user="your_user_id",
        api_key="your_api_key",      # 可选,从环境变量获取
        api_base="your_api_base"     # 可选,从环境变量获取
    )

    session = AgentSession(
        stt=volcengine.STT(app_id="your_stt_app_id", cluster="your_cluster"),
        llm=llm,
        tts=volcengine.TTS(app_id="your_tts_app_id", cluster="your_cluster")
    )

    await session.start(agent=agent, room=ctx.room)
    await ctx.connect()

if __name__ == "__main__":
    load_dotenv()
    cli.run_app(WorkerOptions(entrypoint_fnc=entry_point))

🔧 API 参考

LLM (大语言模型)

dify.LLM(
    user: str,                     # 用户ID
    api_key: str = None,           # API密钥 (从环境变量获取)
    api_base: str = None,          # API基础URL (从环境变量获取)
    conversation_id: str = None    # 会话ID (可选)
)

特殊方法

  • get_opening_words() - 获取开场词
  • say(text) - 发送语音消息

❓ 常见问题

Q: 如何获取Dify API密钥?

A: 请访问Dify.ai平台,创建应用并获取API密钥。

Q: 如何配置自定义API端点?

A: 可以通过环境变量 DIFY_API_BASE 或参数 api_base 配置自定义API端点。

Q: 如何使用开场词功能?

A: Dify插件支持自动获取和播放开场词:

opening_words = await llm.get_opening_words()
if opening_words:
    await session.say(opening_words)

📝 更新日志

v1.2.9

  • 支持Dify.ai平台的应用集成
  • 支持开场词功能
  • 支持自定义API端点配置
  • 完善的API文档和使用示例

🤝 贡献

欢迎提交 Issue 和 Pull Request!

📄 许可证

本项目采用 Apache 2.0 许可证。

🙏 致谢

  • LiveKit - 优秀的实时通信框架
  • Dify.ai - 强大的AI应用平台

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

livekit_plugins_difyai-1.2.9.post0.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

livekit_plugins_difyai-1.2.9.post0-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file livekit_plugins_difyai-1.2.9.post0.tar.gz.

File metadata

File hashes

Hashes for livekit_plugins_difyai-1.2.9.post0.tar.gz
Algorithm Hash digest
SHA256 56c9188f4b4d0aaf4e169caf5550db83ad3fd3a35fa480783cbf131324d5e262
MD5 8d3551243e743040770be007648d8ba7
BLAKE2b-256 1eeee6923d0667e23bc549169d7815dce2f54bf7551a0481fe1d083c2157fe7b

See more details on using hashes here.

File details

Details for the file livekit_plugins_difyai-1.2.9.post0-py3-none-any.whl.

File metadata

File hashes

Hashes for livekit_plugins_difyai-1.2.9.post0-py3-none-any.whl
Algorithm Hash digest
SHA256 8cc5b18233738bd44e2409e304d4c9ec860683e734744fc4ef2704b9195672ae
MD5 cdb8147783d0359e560e5ada6a706bb7
BLAKE2b-256 7068e37a3914b63c310f48f1fd93defe7a628c7edea1e05c47c91c01b2a39fa8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page