AI知识分享AI知识分享
✿导航
  • 人工智能
  • 神经网络
  • 机器学习
  • 深度学习
  • 强化学习
  • 自然语言处理
  • 计算机视觉
  • 数学基础
  • 大模型基础
  • 动手学深度学习
  • 理论理解
  • 工程实践
  • 应用开发
  • AI For Everyone
  • AIGC_2024大会
  • AIGC_2025大会
  • Agentic AI
  • Transformer
  • PyTorch
  • HuggingFace
  • LangChain
  • 蒸馏
  • RAG
  • 目标检测
  • MCP
  • Cursor
  • 概念
  • 意图识别
  • 工具
  • 学习路线
  • PyTorch 资料
  • 公式学习
  • PyTorch 基础练习
✿导航
  • 人工智能
  • 神经网络
  • 机器学习
  • 深度学习
  • 强化学习
  • 自然语言处理
  • 计算机视觉
  • 数学基础
  • 大模型基础
  • 动手学深度学习
  • 理论理解
  • 工程实践
  • 应用开发
  • AI For Everyone
  • AIGC_2024大会
  • AIGC_2025大会
  • Agentic AI
  • Transformer
  • PyTorch
  • HuggingFace
  • LangChain
  • 蒸馏
  • RAG
  • 目标检测
  • MCP
  • Cursor
  • 概念
  • 意图识别
  • 工具
  • 学习路线
  • PyTorch 资料
  • 公式学习
  • PyTorch 基础练习
  • 蒸馏

    • 蒸馏 - 概述
    • 蒸馏 - 模型蒸馏
    • 蒸馏 - 模型压缩的常用方法
    • 蒸馏 - 总结
  • RAG

    • RAG - 基础
    • RAG - 进阶
    • RAG - 应用
    • RAG - 检索组件优化
  • 目标检测

    • 目标检测 - 概述
    • 目标检测 - VOC数据集
    • 目标检测 - COCO数据集
    • 目标检测 - 标注自己的数据集
    • 目标检测 - yolov5
  • MCP

    • MCP - 基础
    • MCP - 架构
    • MCP - 内容
    • MCP - 应用
    • MCP - 案例 weather
    • MCP - 案例 agent
    • MCP - 案例 bilibili
    • MCP - 案例 电影推荐
  • Cursor

    • Cursor - 使用指南
    • Cursor - 三大核心AI功能
    • Cursor - Chat三种模式
    • Cursor - Chat模式配置
    • Cursor - 精准上下文指定
    • Cursor - Rules
    • Cursor - 符号
    • Cursor - 智能插件开发实战

Cline与模型交互过程

Cline上配置API Provider为 OpenAI Compatible

大模型log代码

详情
import httpx
from fastapi import FastAPI, Request
from starlette.responses import StreamingResponse


class AppLogger:
    def __init__(self, log_file="llm.log"):
        """Initialize the logger with a file that will be cleared on startup."""
        self.log_file = log_file
        # Clear the log file on startup
        with open(self.log_file, 'w', encoding='utf-8') as f:
            f.write("")

    def log(self, message):
        """Log a message to both file and console."""

        # Log to file
        with open(self.log_file, 'a', encoding='utf-8') as f:
            f.write(message + "\n")

        # Log to console
        print(message)


app = FastAPI(title="LLM API Logger")
logger = AppLogger("llm.log")


@app.post("/chat/completions")
async def proxy_request(request: Request):
    body_bytes = await request.body()
    body_str = body_bytes.decode('utf-8')
    logger.log(f"模型请求:{body_str}")
    body = await request.json()

    logger.log("模型返回:\n")

    async def event_stream():
        async with httpx.AsyncClient(timeout=None) as client:
            async with client.stream(
                    "POST",
                    "https://api.deepseek.com/chat/completions",
                    json=body,
                    headers={
                        "Content-Type": "application/json",
                        "Accept": "text/event-stream",
                        "Authorization": request.headers.get("Authorization"),
                    },
            ) as response:
                async for line in response.aiter_lines():
                    logger.log(line)
                    yield f"{line}\n"

    return StreamingResponse(event_stream(), media_type="text/event-stream")


if __name__ == "__main__":
    import uvicorn

    uvicorn.run(app, host="0.0.0.0", port=8000)

cline请求大模型全过程

问答内容:

最近更新: 2026/5/5 15:03
Contributors: klc407073648
Prev
MCP - 案例 weather
Next
MCP - 案例 bilibili