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 文件中

OpenAI API 集成示例

支持 AsyncOpenAI, OpenAI, AsyncAzureOpenAI, AzureOpenAI 客户端

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)
<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);
// copy openai-chat-html-exporter.ts to your project
import { createChatExporterOpenAI } from 'openai-chat-html-exporter';
const openaiConfig = {
  apiKey: 'your-api-key',
  baseUrl: 'https://api.openai.com/v1',
};
const openaiClient = createChatExporterOpenAI(OpenAI, openaiConfig);

⚙️ 自定义配置

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

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

📊 输出效果展示

对话历史展示

📦 系统要求

  • Python >= 3.12
  • 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.3.post1.tar.gz (18.7 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.3.post1-py3-none-any.whl (18.5 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for ai_chat_html_exporter-1.0.3.post1.tar.gz
Algorithm Hash digest
SHA256 1dab81636f6745f9616d98403b379e43df6e32d151b8ffaaf4bbe283cfa06dea
MD5 f061fad180f49d8c8005b03f54791a18
BLAKE2b-256 ec1b093d08fd7e9d9da5046f8bd5a68425890a9ccc162f565f15ca7143a4380c

See more details on using hashes here.

Provenance

The following attestation bundles were made for ai_chat_html_exporter-1.0.3.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.3.post1-py3-none-any.whl.

File metadata

File hashes

Hashes for ai_chat_html_exporter-1.0.3.post1-py3-none-any.whl
Algorithm Hash digest
SHA256 d8a7283d45709cbc875d70be7790d547a978de85ea5b6f00f377a9592cbd4de7
MD5 afb66d2589001b620da04dc3b2b1c809
BLAKE2b-256 0295ddc4e1ebcefc83e7368df6d47306b4519105681390ae9ae0615e1880a7d7

See more details on using hashes here.

Provenance

The following attestation bundles were made for ai_chat_html_exporter-1.0.3.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