Skip to main content

A tool to export AI chat history to HTML with syntax highlighting

Project description

中文 | English

License: MIT

AI Chat HTML 导出器

一个专业的 AI 对话历史导出工具,将您与 AI 的对话智能转换为精美 HTML 文件,助力开发调试与 Prompt 观察。

版本 构建状态 许可证 Python

✨ 核心亮点

  • 🚀 极简集成 - 仅需一行代码,轻松收集 AI 对话日志
  • 🔍 透明调试 - 直观了解 AI Agent 的行为过程,无需繁琐的 langsmith 配置
  • 💎 精美展示 - 响应式界面设计,代码语法高亮,JSON 数据格式化
  • 🌐 即时预览 - 支持浏览器中实时查看对话历史
  • 🎨 图片支持 - 自动识别对话中的 base64 和 URL 图片,展示图像内容
  • 🛠 多框架支持 - 完美兼容 LangChain 和 OpenAI API

📋 应用场景

  • AI 应用开发调试过程中快速记录对话历史
  • 收集和展示 AI 交互示例
  • 保存重要的 AI 对话以供日后参考
  • 分享 AI 对话成果给团队成员

🔧 安装方法

从 PyPI 安装

pip install ai-chat-html-exporter

本地开发安装

git clone https://github.com/yourusername/ai-chat-html-exporter.git
cd ai-chat-html-exporter
pip install -e .

🚀 快速上手

LangChain 集成示例

from ai_chat_html_exporter import HtmlExportCallbackHandler
from langchain_openai import AzureChatOpenAI

# 创建导出器实例
llm = AzureChatOpenAI(
    model="gpt-4",
    callbacks=[HtmlExportCallbackHandler()]  # 只需添加这一行
)

# 对话内容会自动保存到 logs 目录下的精美 HTML 文件中
<script src="https://cdn.jsdelivr.net/gh/fishisnow/ai_chat_html_exporter@main/frontend/openai-chat-html-exporter.js"></script>

// 你的 script
import OpenAI from 'openai';

// 配置 OpenAI 客户端
const openaiConfig = {
  apiKey: 'your-api-key',
  baseUrl: 'https://api.openai.com/v1',
};

// 创建带拦截器的 OpenAI 客户端, nodejs 环境测试的时候会自动生成 html 文件
const openaiClient = createChatExporterOpenAI(OpenAI, openaiConfig);

OpenAI API 集成示例

from ai_chat_html_exporter.openai_chat_html_exporter import with_html_logger
from openai import AsyncOpenAI

@with_html_logger  # 只需添加这个装饰器
def get_openai_client(self):
    return AsyncOpenAI(api_key=self.api_key, base_url=self.base_url)

⚙️ 自定义配置

# 自定义输出目录
from ai_chat_html_exporter import HtmlExportCallbackHandler
exporter = HtmlExportCallbackHandler(output_dir="my_chat_logs")

# 更多配置选项即将推出...

📊 输出效果展示

对话历史展示

📦 系统要求

  • Python >= 3.10
  • langchain-core >= 0.1.0
  • python-dotenv >= 1.0.0
  • openai >= 1.6.1

🔜 未来规划

  • 支持更多的 AI 框架集成

🤝 参与贡献

我们欢迎各种形式的贡献!

  1. Fork 本仓库
  2. 创建您的特性分支 (git checkout -b feature/amazing-feature)
  3. 提交您的更改 (git commit -m 'Add some amazing feature')
  4. 推送到分支 (git push origin feature/amazing-feature)
  5. 打开一个 Pull Request

也欢迎提交 Issue 反馈问题或建议!

📄 许可证

本项目采用 MIT 许可证 - 详情请参阅 LICENSE 文件

🔗 相关链接


如果这个项目对您有帮助,请给它一个⭐️!

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

ai_chat_html_exporter-1.0.2.post1.tar.gz (13.5 kB view details)

Uploaded Source

Built Distribution

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

ai_chat_html_exporter-1.0.2.post1-py3-none-any.whl (13.3 kB view details)

Uploaded Python 3

File details

Details for the file ai_chat_html_exporter-1.0.2.post1.tar.gz.

File metadata

File hashes

Hashes for ai_chat_html_exporter-1.0.2.post1.tar.gz
Algorithm Hash digest
SHA256 1e62aed24cd64b7eb5c49cdabc363b8dbebd0b386371bc977e355fc68c5e98ed
MD5 91524b9271030402398c0f8015376819
BLAKE2b-256 db4beeae86a8ea3d645128e03c7014f1626d38db975ab5cf6e0ad960e0f4bfa7

See more details on using hashes here.

Provenance

The following attestation bundles were made for ai_chat_html_exporter-1.0.2.post1.tar.gz:

Publisher: python-publish.yml on fishisnow/ai_chat_html_exporter

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ai_chat_html_exporter-1.0.2.post1-py3-none-any.whl.

File metadata

File hashes

Hashes for ai_chat_html_exporter-1.0.2.post1-py3-none-any.whl
Algorithm Hash digest
SHA256 89abeff26bfcbad80b8e66471acb6f2a147b2ccfbe11802bc389cb893843b990
MD5 10ba95a4006daaa6b25170068b01024c
BLAKE2b-256 a8671d7436d9c3bce01171bf0e0ccbeca39372594ccf64ea7f7665f53494a4ae

See more details on using hashes here.

Provenance

The following attestation bundles were made for ai_chat_html_exporter-1.0.2.post1-py3-none-any.whl:

Publisher: python-publish.yml on fishisnow/ai_chat_html_exporter

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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