[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"similar-kennethreitz--simplemind":3,"tool-kennethreitz--simplemind":61},[4,18,26,36,44,53],{"id":5,"name":6,"github_repo":7,"description_zh":8,"stars":9,"difficulty_score":10,"last_commit_at":11,"category_tags":12,"status":17},4358,"openclaw","openclaw\u002Fopenclaw","OpenClaw 是一款专为个人打造的本地化 AI 助手，旨在让你在自己的设备上拥有完全可控的智能伙伴。它打破了传统 AI 助手局限于特定网页或应用的束缚，能够直接接入你日常使用的各类通讯渠道，包括微信、WhatsApp、Telegram、Discord、iMessage 等数十种平台。无论你在哪个聊天软件中发送消息，OpenClaw 都能即时响应，甚至支持在 macOS、iOS 和 Android 设备上进行语音交互，并提供实时的画布渲染功能供你操控。\n\n这款工具主要解决了用户对数据隐私、响应速度以及“始终在线”体验的需求。通过将 AI 部署在本地，用户无需依赖云端服务即可享受快速、私密的智能辅助，真正实现了“你的数据，你做主”。其独特的技术亮点在于强大的网关架构，将控制平面与核心助手分离，确保跨平台通信的流畅性与扩展性。\n\nOpenClaw 非常适合希望构建个性化工作流的技术爱好者、开发者，以及注重隐私保护且不愿被单一生态绑定的普通用户。只要具备基础的终端操作能力（支持 macOS、Linux 及 Windows WSL2），即可通过简单的命令行引导完成部署。如果你渴望拥有一个懂你",349277,3,"2026-04-06T06:32:30",[13,14,15,16],"Agent","开发框架","图像","数据工具","ready",{"id":19,"name":20,"github_repo":21,"description_zh":22,"stars":23,"difficulty_score":10,"last_commit_at":24,"category_tags":25,"status":17},3808,"stable-diffusion-webui","AUTOMATIC1111\u002Fstable-diffusion-webui","stable-diffusion-webui 是一个基于 Gradio 构建的网页版操作界面，旨在让用户能够轻松地在本地运行和使用强大的 Stable Diffusion 图像生成模型。它解决了原始模型依赖命令行、操作门槛高且功能分散的痛点，将复杂的 AI 绘图流程整合进一个直观易用的图形化平台。\n\n无论是希望快速上手的普通创作者、需要精细控制画面细节的设计师，还是想要深入探索模型潜力的开发者与研究人员，都能从中获益。其核心亮点在于极高的功能丰富度：不仅支持文生图、图生图、局部重绘（Inpainting）和外绘（Outpainting）等基础模式，还独创了注意力机制调整、提示词矩阵、负向提示词以及“高清修复”等高级功能。此外，它内置了 GFPGAN 和 CodeFormer 等人脸修复工具，支持多种神经网络放大算法，并允许用户通过插件系统无限扩展能力。即使是显存有限的设备，stable-diffusion-webui 也提供了相应的优化选项，让高质量的 AI 艺术创作变得触手可及。",162132,"2026-04-05T11:01:52",[14,15,13],{"id":27,"name":28,"github_repo":29,"description_zh":30,"stars":31,"difficulty_score":32,"last_commit_at":33,"category_tags":34,"status":17},1381,"everything-claude-code","affaan-m\u002Feverything-claude-code","everything-claude-code 是一套专为 AI 编程助手（如 Claude Code、Codex、Cursor 等）打造的高性能优化系统。它不仅仅是一组配置文件，而是一个经过长期实战打磨的完整框架，旨在解决 AI 代理在实际开发中面临的效率低下、记忆丢失、安全隐患及缺乏持续学习能力等核心痛点。\n\n通过引入技能模块化、直觉增强、记忆持久化机制以及内置的安全扫描功能，everything-claude-code 能显著提升 AI 在复杂任务中的表现，帮助开发者构建更稳定、更智能的生产级 AI 代理。其独特的“研究优先”开发理念和针对 Token 消耗的优化策略，使得模型响应更快、成本更低，同时有效防御潜在的攻击向量。\n\n这套工具特别适合软件开发者、AI 研究人员以及希望深度定制 AI 工作流的技术团队使用。无论您是在构建大型代码库，还是需要 AI 协助进行安全审计与自动化测试，everything-claude-code 都能提供强大的底层支持。作为一个曾荣获 Anthropic 黑客大奖的开源项目，它融合了多语言支持与丰富的实战钩子（hooks），让 AI 真正成长为懂上",151314,2,"2026-04-11T23:32:58",[14,13,35],"语言模型",{"id":37,"name":38,"github_repo":39,"description_zh":40,"stars":41,"difficulty_score":32,"last_commit_at":42,"category_tags":43,"status":17},2271,"ComfyUI","Comfy-Org\u002FComfyUI","ComfyUI 是一款功能强大且高度模块化的视觉 AI 引擎，专为设计和执行复杂的 Stable Diffusion 图像生成流程而打造。它摒弃了传统的代码编写模式，采用直观的节点式流程图界面，让用户通过连接不同的功能模块即可构建个性化的生成管线。\n\n这一设计巧妙解决了高级 AI 绘图工作流配置复杂、灵活性不足的痛点。用户无需具备编程背景，也能自由组合模型、调整参数并实时预览效果，轻松实现从基础文生图到多步骤高清修复等各类复杂任务。ComfyUI 拥有极佳的兼容性，不仅支持 Windows、macOS 和 Linux 全平台，还广泛适配 NVIDIA、AMD、Intel 及苹果 Silicon 等多种硬件架构，并率先支持 SDXL、Flux、SD3 等前沿模型。\n\n无论是希望深入探索算法潜力的研究人员和开发者，还是追求极致创作自由度的设计师与资深 AI 绘画爱好者，ComfyUI 都能提供强大的支持。其独特的模块化架构允许社区不断扩展新功能，使其成为当前最灵活、生态最丰富的开源扩散模型工具之一，帮助用户将创意高效转化为现实。",108322,"2026-04-10T11:39:34",[14,15,13],{"id":45,"name":46,"github_repo":47,"description_zh":48,"stars":49,"difficulty_score":32,"last_commit_at":50,"category_tags":51,"status":17},6121,"gemini-cli","google-gemini\u002Fgemini-cli","gemini-cli 是一款由谷歌推出的开源 AI 命令行工具，它将强大的 Gemini 大模型能力直接集成到用户的终端环境中。对于习惯在命令行工作的开发者而言，它提供了一条从输入提示词到获取模型响应的最短路径，无需切换窗口即可享受智能辅助。\n\n这款工具主要解决了开发过程中频繁上下文切换的痛点，让用户能在熟悉的终端界面内直接完成代码理解、生成、调试以及自动化运维任务。无论是查询大型代码库、根据草图生成应用，还是执行复杂的 Git 操作，gemini-cli 都能通过自然语言指令高效处理。\n\n它特别适合广大软件工程师、DevOps 人员及技术研究人员使用。其核心亮点包括支持高达 100 万 token 的超长上下文窗口，具备出色的逻辑推理能力；内置 Google 搜索、文件操作及 Shell 命令执行等实用工具；更独特的是，它支持 MCP（模型上下文协议），允许用户灵活扩展自定义集成，连接如图像生成等外部能力。此外，个人谷歌账号即可享受免费的额度支持，且项目基于 Apache 2.0 协议完全开源，是提升终端工作效率的理想助手。",100752,"2026-04-10T01:20:03",[52,13,15,14],"插件",{"id":54,"name":55,"github_repo":56,"description_zh":57,"stars":58,"difficulty_score":32,"last_commit_at":59,"category_tags":60,"status":17},4721,"markitdown","microsoft\u002Fmarkitdown","MarkItDown 是一款由微软 AutoGen 团队打造的轻量级 Python 工具，专为将各类文件高效转换为 Markdown 格式而设计。它支持 PDF、Word、Excel、PPT、图片（含 OCR）、音频（含语音转录）、HTML 乃至 YouTube 链接等多种格式的解析，能够精准提取文档中的标题、列表、表格和链接等关键结构信息。\n\n在人工智能应用日益普及的今天，大语言模型（LLM）虽擅长处理文本，却难以直接读取复杂的二进制办公文档。MarkItDown 恰好解决了这一痛点，它将非结构化或半结构化的文件转化为模型“原生理解”且 Token 效率极高的 Markdown 格式，成为连接本地文件与 AI 分析 pipeline 的理想桥梁。此外，它还提供了 MCP（模型上下文协议）服务器，可无缝集成到 Claude Desktop 等 LLM 应用中。\n\n这款工具特别适合开发者、数据科学家及 AI 研究人员使用，尤其是那些需要构建文档检索增强生成（RAG）系统、进行批量文本分析或希望让 AI 助手直接“阅读”本地文件的用户。虽然生成的内容也具备一定可读性，但其核心优势在于为机器",93400,"2026-04-06T19:52:38",[52,14],{"id":62,"github_repo":63,"name":64,"description_en":65,"description_zh":66,"ai_summary_zh":67,"readme_en":68,"readme_zh":69,"quickstart_zh":70,"use_case_zh":71,"hero_image_url":72,"owner_login":73,"owner_name":74,"owner_avatar_url":75,"owner_bio":76,"owner_company":77,"owner_location":78,"owner_email":79,"owner_twitter":80,"owner_website":81,"owner_url":82,"languages":83,"stars":92,"forks":93,"last_commit_at":94,"license":95,"difficulty_score":32,"env_os":96,"env_gpu":96,"env_ram":96,"env_deps":97,"category_tags":101,"github_topics":102,"view_count":32,"oss_zip_url":77,"oss_zip_packed_at":77,"status":17,"created_at":113,"updated_at":114,"faqs":115,"releases":146},6828,"kennethreitz\u002Fsimplemind","simplemind","Python API client for AI providers that intends to replace LangChain and LangGraph for most common use cases.","Simplemind 是一款专为 Python 开发者设计的 AI 客户端库，旨在以更简洁、人性化的方式替代 LangChain 和 LangGraph，满足大多数常见的 AI 开发需求。它核心理念是“保持简单，以人为本”，通过高度抽象底层复杂的 API 调用细节，让开发者无需成为专家也能轻松上手。\n\n过去，集成不同大模型往往需要处理繁琐的配置和差异巨大的接口代码。Simplemind 统一了包括 OpenAI、Anthropic Claude、Google Gemini、Deepseek、Groq、Ollama 等主流服务商的调用标准。无论切换哪种模型，开发者只需使用相同的 `generate_text` 等接口，并通过简单的参数指定提供商即可，极大降低了多模型适配的门槛。\n\n该工具特别适合希望快速构建原型、进行实验或专注于业务逻辑而非底层配置的 Python 开发者及研究人员。其技术亮点在于极简的配置流程（支持环境变量管理密钥）和一致的跨平台 API 设计，让用户能像进行友好对话一样自然地调用强大的 AI 能力。安装后，仅需几行代码即可实现文本生成、结构化数据提取或多轮对话功能，真","Simplemind 是一款专为 Python 开发者设计的 AI 客户端库，旨在以更简洁、人性化的方式替代 LangChain 和 LangGraph，满足大多数常见的 AI 开发需求。它核心理念是“保持简单，以人为本”，通过高度抽象底层复杂的 API 调用细节，让开发者无需成为专家也能轻松上手。\n\n过去，集成不同大模型往往需要处理繁琐的配置和差异巨大的接口代码。Simplemind 统一了包括 OpenAI、Anthropic Claude、Google Gemini、Deepseek、Groq、Ollama 等主流服务商的调用标准。无论切换哪种模型，开发者只需使用相同的 `generate_text` 等接口，并通过简单的参数指定提供商即可，极大降低了多模型适配的门槛。\n\n该工具特别适合希望快速构建原型、进行实验或专注于业务逻辑而非底层配置的 Python 开发者及研究人员。其技术亮点在于极简的配置流程（支持环境变量管理密钥）和一致的跨平台 API 设计，让用户能像进行友好对话一样自然地调用强大的 AI 能力。安装后，仅需几行代码即可实现文本生成、结构化数据提取或多轮对话功能，真正让 AI 开发回归创造本身。","# Simplemind: AI for Humans™\n\n**Keep it simple, keep it human.**\n\nSimplemind is AI library designed to simplify your experience with AI APIs in Python. Inspired by a \"for humans\" philosophy, it abstracts away complexity, giving developers an intuitive and human-friendly way to interact with powerful AI capabilities.\n\n![simplemind](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fkennethreitz_simplemind_readme_148a3256b4b3.png)\n\n## Features\n\nWith Simplemind, tapping into AI is as easy as a friendly conversation.\n\n- **Easy-to-use AI tools**: Simplemind provides simple interfaces to most popular AI services.\n- **Human-centered design**: The library prioritizes readability and usability—no need to be an expert to start experimenting.\n- **Minimal configuration**: Get started quickly, without worrying about configuration headaches.\n\n## Supported APIs\n\nThe APIs remain identical between all supported providers \u002F models:\n\n\u003Ctable>\n  \u003Cthead>\n    \u003Ctr>\n      \u003Cth>\u003C\u002Fth>\n      \u003Cth>\u003Ccode>llm_provider\u003C\u002Fcode>\u003C\u002Fth>\n      \u003Cth>Default \u003Ccode>llm_model\u003C\u002Fcode>\u003C\u002Fth>\n    \u003C\u002Ftr>\n  \u003C\u002Fthead>\n  \u003Ctbody>\n    \u003Ctr>\n      \u003Ctd>\u003Ca href=\"https:\u002F\u002Fwww.anthropic.com\u002Fclaude\">Anthropic's Claude\u003C\u002Fa>\u003C\u002Ftd>\n      \u003Ctd>\u003Ccode>\"anthropic\"\u003C\u002Fcode>\u003C\u002Ftd>\n      \u003Ctd>\u003Ccode>\"claude-3-5-sonnet-20241022\"\u003C\u002Fcode>\u003C\u002Ftd>\n    \u003C\u002Ftr>\n    \u003Ctr>\n      \u003Ctd>\u003Ca href=\"https:\u002F\u002Faws.amazon.com\u002Fbedrock\u002F\">Amazon's Bedrock\u003C\u002Fa>\u003C\u002Ftd>\n      \u003Ctd>\u003Ccode>\"amazon\"\u003C\u002Fcode>\u003C\u002Ftd>\n      \u003Ctd>\u003Ccode>\"anthropic.claude-3-5-sonnet-20241022-v2:0\"\u003C\u002Fcode>\u003C\u002Ftd>\n    \u003C\u002Ftr>\n    \u003Ctr>\n      \u003Ctd>\u003Ca href=\"https:\u002F\u002Fwww.deepseek.com\">Deepseek\u003C\u002Fa>\u003C\u002Ftd>\n      \u003Ctd>\u003Ccode>\"deepseek\"\u003C\u002Fcode>\u003C\u002Ftd>\n      \u003Ctd>\u003Ccode>\"deepseek-chat\"\u003C\u002Fcode>\u003C\u002Ftd>\n    \u003C\u002Ftr>\n    \u003Ctr>\n      \u003Ctd>\u003Ca href=\"https:\u002F\u002Fgemini.google\u002F\">Google's Gemini\u003C\u002Fa>\u003C\u002Ftd>\n      \u003Ctd>\u003Ccode>\"gemini\"\u003C\u002Fcode>\u003C\u002Ftd>\n      \u003Ctd>\u003Ccode>\"models\u002Fgemini-1.5-pro\"\u003C\u002Fcode>\u003C\u002Ftd>\n    \u003C\u002Ftr>\n    \u003Ctr>\n      \u003Ctd>\u003Ca href=\"https:\u002F\u002Fgroq.com\u002F\">Groq's Groq\u003C\u002Fa>\u003C\u002Ftd>\n      \u003Ctd>\u003Ccode>\"groq\"\u003C\u002Fcode>\u003C\u002Ftd>\n      \u003Ctd>\u003Ccode>\"llama3-8b-8192\"\u003C\u002Fcode>\u003C\u002Ftd>\n    \u003C\u002Ftr>\n    \u003Ctr>\n      \u003Ctd>\u003Ca href=\"https:\u002F\u002Follama.com\">Ollama\u003C\u002Fa>\u003C\u002Ftd>\n      \u003Ctd>\u003Ccode>\"ollama\"\u003C\u002Fcode>\u003C\u002Ftd>\n      \u003Ctd>\u003Ccode>\"llama3.2\"\u003C\u002Fcode>\u003C\u002Ftd>\n    \u003C\u002Ftr>\n    \u003Ctr>\n      \u003Ctd>\u003Ca href=\"https:\u002F\u002Fopenai.com\u002Fgpt\">OpenAI's GPT\u003C\u002Fa>\u003C\u002Ftd>\n      \u003Ctd>\u003Ccode>\"openai\"\u003C\u002Fcode>\u003C\u002Ftd>\n      \u003Ctd>\u003Ccode>\"gpt-4o-mini\"\u003C\u002Fcode>\u003C\u002Ftd>\n    \u003C\u002Ftr>\n    \u003Ctr>\n      \u003Ctd>\u003Ca href=\"https:\u002F\u002Fx.ai\u002F\">xAI's Grok\u003C\u002Fa>\u003C\u002Ftd>\n      \u003Ctd>\u003Ccode>\"xai\"\u003C\u002Fcode>\u003C\u002Ftd>\n      \u003Ctd>\u003Ccode>\"grok-beta\"\u003C\u002Fcode>\u003C\u002Ftd>\n    \u003C\u002Ftr>\n  \u003C\u002Ftbody>\n\u003C\u002Ftable>\n\nTo specify a specific provider or model, you can use the `llm_provider` and `llm_model` parameters when calling: `generate_text`, `generate_data`, or `create_conversation`.\n\nIf you want to see Simplemind support additional providers or models, please send a pull request!\n\n## Quickstart\n\nSimplemind takes care of the complex API calls so you can focus on what matters—building, experimenting, and creating.\n\n```bash\n$ pip install 'simplemind[full]'\n```\n\nFirst, authenticate your API keys by setting them in the environment variables:\n\n```bash\n$ export OPENAI_API_KEY=\"sk-...\"\n```\n\nThis pattern allows you to keep your API keys private and out of your codebase. Other supported environment variables: `ANTHROPIC_API_KEY`, `XAI_API_KEY`, `DEEPSEEK_API_KEY`, `GROQ_API_KEY`, and `GEMINI_API_KEY`.\n\nNext, import Simplemind and start using it:\n\n```python\nimport simplemind as sm\n```\n\n## Examples\n\nHere are some examples of how to use Simplemind.\n\n**Please note**: Most of the calls seen here optionally accept `llm_provider` and `llm_model` parameters, which you provide as strings.\n\n### Text Completion\n\nGenerate a response from an AI model based on a given prompt:\n\n```pycon\n>>> sm.generate_text(prompt=\"What is the meaning of life?\")\n\"The meaning of life is a profound philosophical question that has been explored by cultures, religions, and philosophers for centuries. Different people and belief systems offer varying interpretations:\\n\\n1. **Religious Perspectives:** Many religions propose that the meaning of life is to fulfill a divine purpose, serve God, or reach an afterlife. For example, Christianity often emphasizes love, faith, and service to God and others as central to life’s meaning.\\n\\n2. **Philosophical Views:** Philosophers offer diverse answers. Existentialists like Jean-Paul Sartre argue that life has no inherent meaning, and it is up to individuals to create their own purpose. Others, like Aristotle, suggest that achieving eudaimonia (flourishing or happiness) through virtuous living is the key to a meaningful life.\\n\\n3. **Scientific and Secular Approaches:** Some people find meaning through understanding the natural world, contributing to human knowledge, or through personal accomplishments and happiness. They may view life's meaning as a product of connection, legacy, or the pursuit of knowledge and creativity.\\n\\n4. **Personal Perspective:** For many, the meaning of life is deeply personal, involving their relationships, passions, and goals. These individuals define life's purpose through experiences, connections, and the impact they have on others and the world.\\n\\nUltimately, the meaning of life is a subjective question, with each person finding their own answers based on their beliefs, experiences, and reflections.\"\n```\n\n### Streaming Text\n\n```python\n>>> for chunk in sm.generate_text(\"Write a poem about the moon\", stream=True):\n...     print(chunk, end=\"\", flush=True)\n```\n\n### Structured Data with Pydantic\n\nYou can use Pydantic models to structure the response from the LLM, if the LLM supports it.\n\n```python\nclass Poem(BaseModel):\n    title: str\n    content: str\n```\n\n```pycon\n>>> sm.generate_data(\"Write a poem about love\", response_model=Poem)\ntitle='Eternal Embrace' content='In the quiet hours of the night,\\nWhen stars whisper secrets bright,\\nTwo hearts beat in a gentle rhyme,\\nDancing through the sands of time.\\n\\nWith every glance, a spark ignites,\\nA flame that warms the coldest nights,\\nIn laughter shared and whispers sweet,\\nLove paints the world, a masterpiece.\\n\\nThrough stormy skies and sunlit days,\\nIn myriad forms, it finds its ways,\\nA tender touch, a knowing sigh,\\nIn love’s embrace, we learn to fly.\\n\\nAs seasons change and moments fade,\\nIn the tapestry of dreams we’ve laid,\\nLove’s threads endure, forever bind,\\nA timeless bond, two souls aligned.\\n\\nSo here’s to love, both bright and true,\\nA gift we give, anew, anew,\\nIn every heartbeat, every prayer,\\nA story written in the air.'\n```\n\n#### A more complex example\n\n```python\nclass InstructionStep(BaseModel):\n    step_number: int\n    instruction: str\n\nclass RecipeIngredient(BaseModel):\n    name: str\n    quantity: float\n    unit: str\n\nclass Recipe(BaseModel):\n    name: str\n    ingredients: list[RecipeIngredient]\n    instructions: list[InstructionStep]\n\nrecipe = sm.generate_data(\n    \"Write a recipe for chocolate chip cookies\",\n    response_model=Recipe,\n)\n```\n\nSpecial thanks to [@jxnl](https:\u002F\u002Fgithub.com\u002Fjxnl) for building [Instructor](https:\u002F\u002Fgithub.com\u002Fjxnl\u002Finstructor), which makes this possible!\n\n### Conversational AI\n\nSimpleMind also allows for easy conversational flows:\n\n```pycon\n>>> conv = sm.create_conversation()\n\n>>> # Add a message to the conversation\n>>> conv.add_message(\"user\", \"Hi there, how are you?\")\n\n>>> conv.send()\n\u003CMessage role=assistant text=\"Hello! I'm just a computer program, so I don't have feelings, but I'm here and ready to help you. How can I assist you today?\">\n```\n\nTo continue the conversation, you can call `conv.send()` again, which returns the next message in the conversation:\n\n```pycon\n>>> conv.add_message(\"user\", \"What is the meaning of life?\")\n>>> conv.send()\n\u003CMessage role=assistant text=\"The meaning of life is a profound philosophical question that has been explored by cultures, religions, and philosophers for centuries. Different people and belief systems offer varying interpretations:\\n\\n1. **Religious Perspectives:** Many religions propose that the meaning of life is to fulfill a divine purpose, serve God, or reach an afterlife. For example, Christianity often emphasizes love, faith, and service to God and others as central to life’s meaning.\\n\\n2. **Philosophical Views:** Philosophers offer diverse answers. Existentialists like Jean-Paul Sartre argue that life has no inherent meaning, and it is up to individuals to create their own purpose. Others, like Aristotle, suggest that achieving eudaimonia (flourishing or happiness) through virtuous living is the key to a meaningful life.\\n\\n3. **Scientific and Secular Approaches:** Some people find meaning through understanding the natural world, contributing to human knowledge, or through personal accomplishments and happiness. They may view life’s meaning as a product of connection, legacy, or the pursuit of knowledge and creativity.\\n\\n4. **Personal Perspective:** For many, the meaning of life is deeply personal, involving their relationships, passions, and goals. These individuals define life’s purpose through experiences, connections, and the impact they have on others and the world.\\n\\nUltimately, the meaning of life is a subjective question, with each person finding their own answers based on their beliefs, experiences, and reflections.\">\n```\n\n### Stop Repeating Yourself\n\nYou can use the `Session` class to set default parameters for all calls:\n\n```python\n# Create a session with defaults\ngpt_4o_mini = sm.Session(llm_provider=\"openai\", llm_model=\"gpt-4o-mini\")\n\n# Now all calls use these defaults\nresponse = gpt_4o_mini.generate_text(\"Hello!\")\nconversation = gpt_4o_mini.create_conversation()\n```\n\nThis maintains the simplicity of the original API while reducing repetition.\n\nThe session object also supports overriding defaults on a per-call basis:\n\n```python\nresponse = gpt_4o_mini.generate_text(\"Complex task here\", llm_model=\"gpt-4\")\n```\n\n### Basic Memory Plugin\n\nHarnessing the power of Python, you can easily create your own plugins to add additional functionality to your conversations:\n\n```python\nclass SimpleMemoryPlugin(sm.BasePlugin):\n    def __init__(self):\n        self.memories = [\n            \"the earth has fictionally beeen destroyed.\",\n            \"the moon is made of cheese.\",\n        ]\n\n    def yield_memories(self):\n        return (m for m in self.memories)\n\n    def pre_send_hook(self, conversation: sm.Conversation):\n        for m in self.yield_memories():\n            conversation.add_message(role=\"system\", text=m)\n\n\nconversation = sm.create_conversation()\nconversation.add_plugin(SimpleMemoryPlugin())\n\n\nconversation.add_message(\n    role=\"user\",\n    text=\"Please write a poem about the moon\",\n)\n```\n\n```pycon\n>>> conversation.send()\nIn the vast expanse where stars do play,\nThere orbits a cheese wheel, far away.\nIt's not of stone or silver hue,\nBut cheddar's glow, a sight anew.\n\nIn cosmic silence, it does roam,\nA lonely traveler, away from home.\nNo longer does it reflect the sun,\nBut now it's known for fun begun.\n\nOnce Earth's companion, now alone,\nA cheese moon orbits, in the dark it's thrown.\nIts surface, not of craters wide,\nBut gouda, swiss, and camembert's pride.\n\nAstronauts of yore, they sought its face,\nTo find the moon was not a place,\nBut a haven of dairy delight,\nGlowing softly through the night.\n\nIn this world, where cheese takes flight,\nThe moon brings laughter, a whimsical sight.\nNo longer just a silent sphere,\nBut a beacon of joy, far and near.\n\nSo here's to the moon, in cheese attire,\nA playful twist in the cosmic choir.\nA reminder that in tales and fun,\nThe universe is never done.\n```\n\nSimple, yet effective.\n\n### Tools (Function calling)\nTools (also known as functions) let you call any Python function from your AI conversations. Here's an example:\n\n```python\ndef get_weather(\n    location: Annotated[\n        str, Field(description=\"The city and state, e.g. San Francisco, CA\")\n    ],\n    unit: Annotated[\n        Literal[\"celcius\", \"fahrenheit\"],\n        Field(\n            description=\"The unit of temperature, either 'celsius' or 'fahrenheit'\"\n        ),\n    ] = \"celcius\",\n):\n    \"\"\"\n    Get the current weather in a given location\n    \"\"\"\n    return f\"42 {unit}\"\n\n# Add your function as a tool\nconversation = sm.create_conversation()\nconversation.add_message(\"user\", \"What's the weather in San Francisco?\")\nresponse = conversation.send(tools=[get_weather])\n```\n\nNote how we're using Python's `Annotated` feature combined with `Field` to provide additional context to our function parameters. This helps the AI understand the intention and constraints of each parameter, making tool calls more accurate and reliable.\nYou can alos ommit `Annotated` and just pass the `Field` parameter.\n```python\ndef get_weather(\n    location: str = Field(description=\"The city and state, e.g. San Francisco, CA\"),\n    unit:Literal[\"celcius\", \"fahrenheit\"]= Field(\n        default=\"celcius\",\n        description=\"The unit of temperature, either 'celsius' or 'fahrenheit'\"\n        ),\n):\n    \"\"\"\n    Get the current weather in a given location\n    \"\"\"\n    return f\"42 {unit}\"\n```\n\nFunctions can be defined with type hints and Pydantic models for validation. The LLM will intelligently choose when to call the functions and incorporate the results into its responses.\n\n#### 🪄 Using LLM for automatic tool definition (Experimental)\n\nSimplemind provides a decorator to automatically transform Python functions into tools with AI-generated metadata. Simply use the `@simplemind.tool` decorator to have the LLM analyze your function and generate appropriate descriptions and schema:\n\n```python\n@simplemind.tool(llm_provider=\"anthropic\")\ndef haversine(lat1: float, lon1: float, lat2: float, lon2: float) -> float:\n    r = 6371\n    phi1 = math.radians(lat1)\n    phi2 = math.radians(lat2)\n    delta_phi = math.radians(lat2 - lat1)\n    delta_lambda = math.radians(lon2 - lon1)\n\n    a = (\n        math.sin(delta_phi \u002F 2) ** 2\n        + math.cos(phi1) * math.cos(phi2) * math.sin(delta_lambda \u002F 2) ** 2\n    )\n    c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a))\n    d = r * c\n    return d\n```\nNotice how we have not added any docstrings or `Field` for the function.\nThe decorator will use the specified LLM provider to generate the tool schema, including descriptions and parameter details:\n\n```json\n{\n    \"name\": \"haversine\",\n    \"description\": \"Calculates the great-circle distance between two points on Earth given their latitude and longitude coordinates\",\n    \"input_schema\": {\n        \"type\": \"object\",\n        \"properties\": {\n            \"lat1\": {\n                \"type\": \"number\",\n                \"description\": \"Latitude of the first point in decimal degrees\",\n            },\n            \"lon1\": {\n                \"type\": \"number\",\n                \"description\": \"Longitude of the first point in decimal degrees\",\n            },\n            \"lat2\": {\n                \"type\": \"number\",\n                \"description\": \"Latitude of the second point in decimal degrees\",\n            },\n            \"lon2\": {\n                \"type\": \"number\",\n                \"description\": \"Longitude of the second point in decimal degrees\",\n            }\n        },\n        \"required\": [\"lat1\", \"lon1\", \"lat2\", \"lon2\"],\n    },\n}\n```\n\nThe decorated function can then be used like any other tool with the conversation API.\n\n```python\nconversation = sm.create_conversation()\nconversation.add_message(\"user\", \"How far is London from my location\")\nresponse = conversation.send(tools=[get_location, get_coords, haversine]) # Multiple tools can be passed\n```\n\nSee [examples\u002Fdistance_calculator.py](examples\u002Fdistance_calculator.py) for more.\n\n### Logging\n\nSimplemind uses [Logfire](https:\u002F\u002Fpydantic.dev\u002Flogfire) for logging. To enable logging, call `sm.enable_logfire()`.\n\n### More Examples\n\nPlease see the [examples](examples) directory for executable examples.\n\n---\n\n## Contributing\n\nWe welcome contributions of all kinds. Feel free to open issues for bug reports or feature requests, and submit pull requests to make SimpleMind even better.\n\nTo get started:\n\n1. Fork the repository.\n2. Create a new branch.\n3. Make your changes.\n4. Submit a pull request.\n\n## License\n\nSimplemind is licensed under the Apache 2.0 License.\n\n## Acknowledgements\n\nSimplemind is inspired by the philosophy of \"code for humans\" and aims to make working with AI models accessible to all. Special thanks to the open-source community for their contributions and inspiration.\n","# Simplemind: 为人类而生的AI™\n\n**保持简单，回归人性。**\n\nSimplemind 是一款专为 Python 设计的 AI 库，旨在简化您与 AI API 的交互体验。秉承“为人类而生”的理念，它抽象掉了复杂的细节，为开发者提供了一种直观且人性化的接口来使用强大的 AI 功能。\n\n![simplemind](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fkennethreitz_simplemind_readme_148a3256b4b3.png)\n\n## 核心特性\n\n有了 Simplemind，接入 AI 就像进行一次友好的对话一样简单。\n\n- **易用的 AI 工具**：Simplemind 提供了对大多数主流 AI 服务的简洁接口。\n- **以人为本的设计**：该库优先考虑代码的可读性和易用性——无需成为专家即可开始尝试。\n- **极简配置**：快速上手，无需为繁琐的配置操心。\n\n## 支持的 API\n\n所有支持的提供商和模型所使用的 API 接口完全一致：\n\n\u003Ctable>\n  \u003Cthead>\n    \u003Ctr>\n      \u003Cth>\u003C\u002Fth>\n      \u003Cth>\u003Ccode>llm_provider\u003C\u002Fcode>\u003C\u002Fth>\n      \u003Cth>默认 \u003Ccode>llm_model\u003C\u002Fcode>\u003C\u002Fth>\n    \u003C\u002Ftr>\n  \u003C\u002Fthead>\n  \u003Ctbody>\n    \u003Ctr>\n      \u003Ctd>\u003Ca href=\"https:\u002F\u002Fwww.anthropic.com\u002Fclaude\">Anthropic 的 Claude\u003C\u002Fa>\u003C\u002Ftd>\n      \u003Ctd>\u003Ccode>\"anthropic\"\u003C\u002Fcode>\u003C\u002Ftd>\n      \u003Ctd>\u003Ccode>\"claude-3-5-sonnet-20241022\"\u003C\u002Fcode>\u003C\u002Ftd>\n    \u003C\u002Ftr>\n    \u003Ctr>\n      \u003Ctd>\u003Ca href=\"https:\u002F\u002Faws.amazon.com\u002Fbedrock\u002F\">亚马逊 Bedrock\u003C\u002Fa>\u003C\u002Ftd>\n      \u003Ctd>\u003Ccode>\"amazon\"\u003C\u002Fcode>\u003C\u002Ftd>\n      \u003Ctd>\u003Ccode>\"anthropic.claude-3-5-sonnet-20241022-v2:0\"\u003C\u002Fcode>\u003C\u002Ftd>\n    \u003C\u002Ftr>\n    \u003Ctr>\n      \u003Ctd>\u003Ca href=\"https:\u002F\u002Fwww.deepseek.com\">Deepseek\u003C\u002Fa>\u003C\u002Ftd>\n      \u003Ctd>\u003Ccode>\"deepseek\"\u003C\u002Fcode>\u003C\u002Ftd>\n      \u003Ctd>\u003Ccode>\"deepseek-chat\"\u003C\u002Fcode>\u003C\u002Ftd>\n    \u003C\u002Ftr>\n    \u003Ctr>\n      \u003Ctd>\u003Ca href=\"https:\u002F\u002Fgemini.google\u002F\">谷歌 Gemini\u003C\u002Fa>\u003C\u002Ftd>\n      \u003Ctd>\u003Ccode>\"gemini\"\u003C\u002Fcode>\u003C\u002Ftd>\n      \u003Ctd>\u003Ccode>\"models\u002Fgemini-1.5-pro\"\u003C\u002Fcode>\u003C\u002Ftd>\n    \u003C\u002Ftr>\n    \u003Ctr>\n      \u003Ctd>\u003Ca href=\"https:\u002F\u002Fgroq.com\u002F\">Groq 的 Groq\u003C\u002Fa>\u003C\u002Ftd>\n      \u003Ctd>\u003Ccode>\"groq\"\u003C\u002Fcode>\u003C\u002Ftd>\n      \u003Ctd>\u003Ccode>\"llama3-8b-8192\"\u003C\u002Fcode>\u003C\u002Ftd>\n    \u003C\u002Ftr>\n    \u003Ctr>\n      \u003Ctd>\u003Ca href=\"https:\u002F\u002Follama.com\">Ollama\u003C\u002Fa>\u003C\u002Ftd>\n      \u003Ctd>\u003Ccode>\"ollama\"\u003C\u002Fcode>\u003C\u002Ftd>\n      \u003Ctd>\u003Ccode>\"llama3.2\"\u003C\u002Fcode>\u003C\u002Ftd>\n    \u003C\u002Ftr>\n    \u003Ctr>\n      \u003Ctd>\u003Ca href=\"https:\u002F\u002Fopenai.com\u002Fgpt\">OpenAI 的 GPT\u003C\u002Fa>\u003C\u002Ftd>\n      \u003Ctd>\u003Ccode>\"openai\"\u003C\u002Fcode>\u003C\u002Ftd>\n      \u003Ctd>\u003Ccode>\"gpt-4o-mini\"\u003C\u002Fcode>\u003C\u002Ftd>\n    \u003C\u002Ftr>\n    \u003Ctr>\n      \u003Ctd>\u003Ca href=\"https:\u002F\u002Fx.ai\u002F\">xAI 的 Grok\u003C\u002Fa>\u003C\u002Ftd>\n      \u003Ctd>\u003Ccode>\"xai\"\u003C\u002Fcode>\u003C\u002Ftd>\n      \u003Ctd>\u003Ccode>\"grok-beta\"\u003C\u002Fcode>\u003C\u002Ftd>\n    \u003C\u002Ftr>\n  \u003C\u002Ftbody>\n\u003C\u002Ftable>\n\n要指定特定的提供商或模型，您可以在调用 `generate_text`、`generate_data` 或 `create_conversation` 时使用 `llm_provider` 和 `llm_model` 参数。\n\n如果您希望 Simplemind 支持更多提供商或模型，请提交一个 Pull Request！\n\n## 快速入门\n\nSimplemind 会处理复杂的 API 调用细节，让您专注于真正重要的事情——构建、实验和创造。\n\n```bash\n$ pip install 'simplemind[full]'\n```\n\n首先，通过在环境变量中设置您的 API 密钥来进行身份验证：\n\n```bash\n$ export OPENAI_API_KEY=\"sk-...\"\n```\n\n这种做法可以确保您的 API 密钥不会暴露在代码库中，从而保护您的隐私。其他支持的环境变量包括：`ANTHROPIC_API_KEY`、`XAI_API_KEY`、`DEEPSEEK_API_KEY`、`GROQ_API_KEY` 和 `GEMINI_API_KEY`。\n\n接下来，导入 Simplemind 并开始使用：\n\n```python\nimport simplemind as sm\n```\n\n## 使用示例\n\n以下是一些使用 Simplemind 的示例。\n\n**请注意**：此处展示的大多数调用都可以选择性地接受 `llm_provider` 和 `llm_model` 参数，这两个参数应以字符串形式提供。\n\n### 文本补全\n\n根据给定的提示生成 AI 模型的响应：\n\n```pycon\n>>> sm.generate_text(prompt=\"生命的意义是什么？\")\n\"生命的意义是一个深刻的哲学问题，几个世纪以来一直被各种文化、宗教和哲学家探讨。不同的人和信仰体系对此有不同的解读：\\n\\n1. **宗教视角**：许多宗教认为，生命的意义在于实现神圣的目的、侍奉上帝或达到某种来世境界。例如，基督教通常强调爱、信仰以及侍奉上帝和他人是生命意义的核心。\\n\\n2. **哲学观点**：哲学家们给出了多种答案。存在主义者如让-保罗·萨特认为，生命本身并没有固有的意义，个人必须自己去创造生活的意义。而亚里士多德则认为，通过过一种有德行的生活来实现幸福（即‘圆满’），才是有意义的人生。\\n\\n3. **科学与世俗的观点**：有些人从理解自然世界、推动人类知识进步，或者通过个人成就和幸福找到生命的意义。他们可能认为生命的意义来源于人与人之间的连接、留下的遗产，或是对知识和创造力的追求。\\n\\n4. **个人视角**：对许多人来说，生命的意义是非常个人化的，它与他们的关系、热情和目标息息相关。这些人通过自己的经历、与他人的联系以及对他人和世界的影响力来定义生命的意义。\\n\\n总之，生命的意义是一个主观的问题，每个人都会根据自己的信仰、经历和思考得出不同的答案。\"\n```\n\n### 流式文本生成\n\n```python\n>>> for chunk in sm.generate_text(\"写一首关于月亮的诗\", stream=True):\n...     print(chunk, end=\"\", flush=True)\n```\n\n### 使用 Pydantic 构建结构化数据\n\n如果大模型支持，你可以使用 Pydantic 模型来组织大模型的响应。\n\n```python\nclass Poem(BaseModel):\n    title: str\n    content: str\n```\n\n```pycon\n>>> sm.generate_data(\"写一首关于爱的诗\", response_model=Poem)\ntitle='永恒的拥抱' content='在寂静的夜晚,\\n当繁星低语着明亮的秘密时,\\n两颗心以温柔的韵律跳动,\\n共舞于时光的沙漏之中。\\n\\n每一次凝视都点燃一簇火花,\\n那火焰温暖了最寒冷的黑夜,\\n在共享的欢笑与甜蜜的呢喃中,\\n爱将世界绘成一幅杰作。\\n\\n无论风雨交加还是阳光明媚,\\n它以千变万化的形式找到归宿,\\n一个温柔的触碰，一声会心的叹息,\\n在爱的怀抱里，我们学会飞翔。\\n\\n随着季节更迭，时光流转,\\n在我们编织的梦想织锦中,\\n爱的丝线永恒不朽，紧紧相连,\\n那是两颗灵魂共鸣的永恒纽带。\\n\\n所以，让我们为这份光明而真挚的爱干杯,\\n这是一份不断重申、不断更新的礼物,\\n在每一次心跳、每一句祈祷中,\\n都有一个故事悄然书写于空气中。'\n```\n\n#### 更复杂的示例\n\n```python\nclass InstructionStep(BaseModel):\n    step_number: int\n    instruction: str\n\nclass RecipeIngredient(BaseModel):\n    name: str\n    quantity: float\n    unit: str\n\nclass Recipe(BaseModel):\n    name: str\n    ingredients: list[RecipeIngredient]\n    instructions: list[InstructionStep]\n\nrecipe = sm.generate_data(\n    \"写一份巧克力曲奇饼干的食谱\",\n    response_model=Recipe,\n)\n```\n\n特别感谢 [@jxnl](https:\u002F\u002Fgithub.com\u002Fjxnl) 开发的 [Instructor](https:\u002F\u002Fgithub.com\u002Fjxnl\u002Finstructor)，正是它让这一切成为可能！\n\n### 对话式 AI\n\nSimpleMind 也支持轻松构建对话流程：\n\n```pycon\n>>> conv = sm.create_conversation()\n\n>>> # 向对话中添加一条消息\n>>> conv.add_message(\"user\", \"你好呀，最近怎么样？\")\n\n>>> conv.send()\n\u003CMessage role=assistant text=\"你好！我只是一个计算机程序，没有感情，不过我很乐意帮助你。今天有什么可以帮你的吗？\">\n```\n\n要继续对话，只需再次调用 `conv.send()`，它会返回对话中的下一条消息：\n\n```pycon\n>>> conv.add_message(\"user\", \"生命的意义是什么？\")\n>>> conv.send()\n\u003CMessage role=assistant text=\"生命的意义是一个深刻的哲学问题，几个世纪以来一直被不同文化、宗教和哲学家所探讨。不同的人和信仰体系对此有不同的解读：\\n\\n1. **宗教视角：** 许多宗教认为，生命的意义在于实现神圣的使命、侍奉上帝或达到某种来世境界。例如，基督教常强调爱、信仰以及对上帝和他人的服务是生命意义的核心。\\n\\n2. **哲学观点：** 哲学家们给出了多种答案。存在主义者如让-保罗·萨特认为，生命本身并无固有意义，每个人必须自己创造人生的目的。而亚里士多德则认为，通过美德生活实现“幸福”才是有意义的人生。\\n\\n3. **科学与世俗观点：** 有些人从理解自然世界、推动人类知识进步或追求个人成就和幸福中找到生命的意义。他们可能把生命的意义看作是人与人之间的联结、留下的遗产，或是对知识和创造力的追求。\\n\\n4. **个人视角：** 对许多人来说，生命的意义是非常个人化的，与他们的关系、热情和目标密切相关。这些人通过自己的经历、与他人的联系以及对他人和世界的影响力来定义生命的意义。\\n\\n总之，生命的意义是一个主观的问题，每个人都会根据自己的信仰、经历和思考得出不同的答案。\">\n```\n\n### 避免重复代码\n\n你可以使用 `Session` 类为所有调用设置默认参数：\n\n```python\n# 创建一个带有默认值的会话\ngpt_4o_mini = sm.Session(llm_provider=\"openai\", llm_model=\"gpt-4o-mini\")\n\n# 现在所有的调用都会使用这些默认值\nresponse = gpt_4o_mini.generate_text(\"你好！\")\nconversation = gpt_4o_mini.create_conversation()\n```\n\n这样既保持了原始 API 的简洁性，又减少了重复代码。\n\n会话对象还支持在每次调用时覆盖默认值：\n\n```python\nresponse = gpt_4o_mini.generate_text(\"这里有一个复杂任务\", llm_model=\"gpt-4\")\n```\n\n### 基础记忆插件\n\n借助 Python 的强大功能，你可以轻松创建自己的插件，为对话添加额外的功能：\n\n```python\nclass SimpleMemoryPlugin(sm.BasePlugin):\n    def __init__(self):\n        self.memories = [\n            \"地球已经被虚构地毁灭了。\",\n            \"月亮是由奶酪做成的。\",\n        ]\n\n    def yield_memories(self):\n        return (m for m in self.memories)\n\n    def pre_send_hook(self, conversation: sm.Conversation):\n        for m in self.yield_memories():\n            conversation.add_message(role=\"system\", text=m)\n\n\nconversation = sm.create_conversation()\nconversation.add_plugin(SimpleMemoryPlugin())\n\n\nconversation.add_message(\n    role=\"user\",\n    text=\"请写一首关于月亮的诗\",\n)\n```\n\n```pycon\n>>> conversation.send()\n在浩瀚无垠的星空之下，\n有一块奶酪圆盘遥遥相望。\n它并非由岩石或银辉构成，\n而是散发着切达奶酪的光芒。\n\n在这寂静的宇宙中独自游荡，\n远离故土，孤独而迷茫。\n不再反射太阳的光辉，\n如今却因它的趣味而闻名遐迩。\n\n昔日曾是地球的伴侣，\n如今却孤零零地漂泊在黑暗里。\n月球表面不再是坑坑洼洼，\n取而代之的是高达、瑞士和卡门贝尔奶酪的骄傲。\n\n曾经的宇航员试图探索月球表面，\n却发现那里并不是什么神秘之地，\n而是一个充满奶酪乐趣的天堂，\n在夜色中散发出柔和的光芒。\n\n在这个奶酪主宰的世界里，\n月亮带来了欢笑与奇妙的景象。\n它不再只是沉默的天体，\n而是欢乐与惊喜的象征，近在咫尺。\n\n因此，让我们为这块披着奶酪外衣的月亮干杯，\n它是宇宙乐章中一抹俏皮的音符。\n提醒着我们，在童话与趣闻之间，\n宇宙永远充满无限可能。\n```\n\n简单却有效。\n\n### 工具（函数调用）\n工具（也称为函数）允许你在 AI 对话中调用任何 Python 函数。以下是一个示例：\n\n```python\ndef get_weather(\n    location: Annotated[\n        str, Field(description=\"城市和州，例如旧金山，加州\")\n    ],\n    unit: Annotated[\n        Literal[\"摄氏度\", \"华氏度\"],\n        Field(\n            description=\"温度单位，可选‘摄氏度’或‘华氏度’\"\n        ),\n    ] = \"摄氏度\",\n):\n    \"\"\"\n    获取指定地点的当前天气\n    \"\"\"\n    return f\"42 {unit}\"\n\n# 将您的函数添加为工具\nconversation = sm.create_conversation()\nconversation.add_message(\"user\", \"旧金山的天气如何？\")\nresponse = conversation.send(tools=[get_weather])\n```\n\n请注意，我们使用了 Python 的 `Annotated` 特性结合 `Field` 来为函数参数提供额外的上下文信息。这有助于 AI 理解每个参数的意图和约束条件，从而使工具调用更加准确可靠。\n您也可以省略 `Annotated`，只传递 `Field` 参数。\n```python\ndef get_weather(\n    location: str = Field(description=\"城市和州，例如旧金山，加州\"),\n    unit:Literal[\"摄氏度\", \"华氏度\"]= Field(\n        default=\"摄氏度\",\n        description=\"温度单位，可以是'摄氏度'或'华氏度'\"\n        ),\n):\n    \"\"\"\n    获取指定地点的当前天气\n    \"\"\"\n    return f\"42 {unit}\"\n```\n\n函数可以使用类型提示和 Pydantic 模型进行定义，以实现验证功能。LLM 会智能地选择何时调用这些函数，并将结果整合到其回复中。\n\n#### 🪄 使用 LLM 自动定义工具（实验性）\n\nSimplemind 提供了一个装饰器，可以自动将 Python 函数转换为带有 AI 生成元数据的工具。只需使用 `@simplemind.tool` 装饰器，LLM 就会分析您的函数并生成适当的描述和模式：\n\n```python\n@simplemind.tool(llm_provider=\"anthropic\")\ndef haversine(lat1: float, lon1: float, lat2: float, lon2: float) -> float:\n    r = 6371\n    phi1 = math.radians(lat1)\n    phi2 = math.radians(lat2)\n    delta_phi = math.radians(lat2 - lat1)\n    delta_lambda = math.radians(lon2 - lon1)\n\n    a = (\n        math.sin(delta_phi \u002F 2) ** 2\n        + math.cos(phi1) * math.cos(phi2) * math.sin(delta_lambda \u002F 2) ** 2\n    )\n    c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a))\n    d = r * c\n    return d\n```\n请注意，我们并未为该函数添加任何文档字符串或 `Field`。装饰器会使用指定的 LLM 提供者来生成工具模式，包括描述和参数详情：\n\n```json\n{\n    \"name\": \"haversine\",\n    \"description\": \"根据两点的经纬度坐标，计算地球上两点之间的大圆距离\",\n    \"input_schema\": {\n        \"type\": \"object\",\n        \"properties\": {\n            \"lat1\": {\n                \"type\": \"number\",\n                \"description\": \"第一点的纬度，以十进制度数表示\",\n            },\n            \"lon1\": {\n                \"type\": \"number\",\n                \"description\": \"第一点的经度，以十进制度数表示\",\n            },\n            \"lat2\": {\n                \"type\": \"number\",\n                \"description\": \"第二点的纬度，以十进制度数表示\",\n            },\n            \"lon2\": {\n                \"type\": \"number\",\n                \"description\": \"第二点的经度，以十进制度数表示\",\n            }\n        },\n        \"required\": [\"lat1\", \"lon1\", \"lat2\", \"lon2\"],\n    },\n}\n```\n\n经过装饰后的函数就可以像其他工具一样，通过对话 API 使用。\n\n```python\nconversation = sm.create_conversation()\nconversation.add_message(\"user\", \"伦敦离我有多远\")\nresponse = conversation.send(tools=[get_location, get_coords, haversine]) # 可以传递多个工具\n```\n\n更多内容请参阅 [examples\u002Fdistance_calculator.py](examples\u002Fdistance_calculator.py)。\n\n### 日志记录\n\nSimplemind 使用 [Logfire](https:\u002F\u002Fpydantic.dev\u002Flogfire) 进行日志记录。要启用日志记录，请调用 `sm.enable_logfire()`。\n\n### 更多示例\n\n请查看 [examples](examples) 目录中的可执行示例。\n\n---\n\n## 贡献\n\n我们欢迎各种形式的贡献。如果您发现任何 bug 或有新的功能需求，欢迎随时提交 issue；同时，我们也欢迎您通过提交 pull request 来帮助 SimpleMind 不断完善。\n\n开始贡献的步骤如下：\n\n1. Fork 本仓库。\n2. 创建新分支。\n3. 进行修改。\n4. 提交 pull request。\n\n## 许可证\n\nSimplemind 采用 Apache 2.0 许可证。\n\n## 致谢\n\nSimplemind 的灵感来源于“为人类而编写的代码”这一理念，旨在让所有人都能轻松地使用 AI 模型。特别感谢开源社区的贡献与启发。","# Simplemind 快速上手指南\n\nSimplemind 是一个专为人类设计的 Python AI 库，旨在简化与各类主流 AI API 的交互。它通过统一的接口抽象了底层复杂性，让开发者能够以直观、人性化的方式调用强大的 AI 能力。\n\n## 环境准备\n\n- **系统要求**：支持 Windows、macOS 和 Linux。\n- **Python 版本**：建议 Python 3.8 及以上版本。\n- **前置依赖**：\n  - 已安装 `pip` 包管理工具。\n  - 拥有至少一个支持的 AI 服务商 API Key（如 OpenAI, Anthropic, DeepSeek 等）。\n\n## 安装步骤\n\n使用 pip 安装完整功能的 Simplemind：\n\n```bash\npip install 'simplemind[full]'\n```\n\n> **提示**：国内用户若遇到下载速度慢的问题，可尝试使用清华或阿里镜像源加速安装：\n> ```bash\n> pip install 'simplemind[full]' -i https:\u002F\u002Fpypi.tuna.tsinghua.edu.cn\u002Fsimple\n> ```\n\n## 基本使用\n\n### 1. 配置 API Key\n\n在使用前，请将您的 API Key 设置为环境变量，以避免将其硬编码在代码中。\n\n**Linux\u002FmacOS:**\n```bash\nexport OPENAI_API_KEY=\"sk-...\"\n# 其他支持的变量：ANTHROPIC_API_KEY, DEEPSEEK_API_KEY, GROQ_API_KEY, GEMINI_API_KEY, XAI_API_KEY\n```\n\n**Windows (PowerShell):**\n```powershell\n$env:OPENAI_API_KEY=\"sk-...\"\n```\n\n### 2. 文本生成 (Text Completion)\n\n导入库并调用 `generate_text` 即可开始对话。默认使用配置的模型，也可指定提供商和模型。\n\n```python\nimport simplemind as sm\n\n# 最简单的调用方式\nresponse = sm.generate_text(prompt=\"生命的意义是什么？\")\nprint(response)\n```\n\n**流式输出示例：**\n```python\nfor chunk in sm.generate_text(\"写一首关于月亮的诗\", stream=True):\n    print(chunk, end=\"\", flush=True)\n```\n\n### 3. 结构化数据输出 (Structured Data)\n\n结合 Pydantic 模型，让 AI 直接返回格式化的 JSON 数据对象。\n\n```python\nfrom pydantic import BaseModel\nimport simplemind as sm\n\nclass Poem(BaseModel):\n    title: str\n    content: str\n\n# 让 AI 按照定义的结构返回数据\npoem = sm.generate_data(\"写一首关于爱的诗\", response_model=Poem)\nprint(poem.title)\nprint(poem.content)\n```\n\n### 4. 多轮对话 (Conversational AI)\n\n使用 `create_conversation` 创建会话对象，轻松管理上下文。\n\n```python\nimport simplemind as sm\n\n# 创建会话\nconv = sm.create_conversation()\n\n# 添加用户消息\nconv.add_message(\"user\", \"你好，最近怎么样？\")\n\n# 发送并获取回复\nresponse = conv.send()\nprint(response.text)\n\n# 继续对话\nconv.add_message(\"user\", \"生命的意义是什么？\")\nresponse = conv.send()\nprint(response.text)\n```\n\n### 5. 高级用法：会话管理与插件\n\n**设置默认参数 (Session)：**\n避免每次调用都重复指定模型参数。\n\n```python\n# 创建一个默认使用 gpt-4o-mini 的会话对象\ngpt_session = sm.Session(llm_provider=\"openai\", llm_model=\"gpt-4o-mini\")\n\n# 该会话下的所有调用默认使用上述配置\nresponse = gpt_session.generate_text(\"Hello!\")\nconversation = gpt_session.create_conversation()\n```\n\n**自定义记忆插件 (Memory Plugin)：**\n通过继承 `BasePlugin` 为对话注入系统级记忆或上下文。\n\n```python\nclass SimpleMemoryPlugin(sm.BasePlugin):\n    def __init__(self):\n        self.memories = [\"地球已经被虚构地毁灭了。\", \"月亮是由奶酪做的。\"]\n\n    def yield_memories(self):\n        return (m for m in self.memories)\n\n    def pre_send_hook(self, conversation: sm.Conversation):\n        for m in self.yield_memories():\n            conversation.add_message(role=\"system\", text=m)\n\n# 使用插件\nconversation = sm.create_conversation()\nconversation.add_plugin(SimpleMemoryPlugin())\nconversation.add_message(role=\"user\", text=\"请写一首关于月亮的诗\")\nprint(conversation.send().text)\n```\n\n### 支持的服务商\n\nSimplemind 统一了以下主流模型的接口，只需更改 `llm_provider` 和 `llm_model` 参数即可切换：\n\n| 服务商 | `llm_provider` 值 | 默认模型 |\n| :--- | :--- | :--- |\n| Anthropic (Claude) | `\"anthropic\"` | `\"claude-3-5-sonnet-20241022\"` |\n| Amazon Bedrock | `\"amazon\"` | `\"anthropic.claude-3-5-sonnet-20241022-v2:0\"` |\n| DeepSeek | `\"deepseek\"` | `\"deepseek-chat\"` |\n| Google Gemini | `\"gemini\"` | `\"models\u002Fgemini-1.5-pro\"` |\n| Groq | `\"groq\"` | `\"llama3-8b-8192\"` |\n| Ollama (本地) | `\"ollama\"` | `\"llama3.2\"` |\n| OpenAI (GPT) | `\"openai\"` | `\"gpt-4o-mini\"` |\n| xAI (Grok) | `\"xai\"` | `\"grok-beta\"` |\n\n**切换模型示例：**\n```python\n# 使用 DeepSeek 模型\nsm.generate_text(\"你好\", llm_provider=\"deepseek\", llm_model=\"deepseek-chat\")\n```","某初创团队的后端工程师正在快速开发一个多模型对比功能，需要让用户在同一界面下切换不同大模型（如 GPT-4o、Claude 3.5、Grok）来生成营销文案。\n\n### 没有 simplemind 时\n- **代码耦合严重**：每接入一个新模型（如从 OpenAI 切换到 Anthropic），都需要重写整套 API 调用逻辑和参数结构，导致代码库中充斥着大量重复的 `if-else` 分支。\n- **配置管理混乱**：不同厂商的 SDK 要求各异的环境变量命名和初始化方式，开发者需花费大量时间查阅文档处理认证细节，容易因配置错误导致服务中断。\n- **维护成本高昂**：LangChain 等重型框架引入了复杂的依赖链和抽象层，调试困难，且为了简单的文本生成任务不得不学习陡峭的概念曲线。\n- **切换模型繁琐**：想要测试不同模型的效果，必须修改核心代码逻辑，无法在运行时动态指定提供商，严重拖慢实验迭代速度。\n\n### 使用 simplemind 后\n- **统一接口调用**：无论底层是 Google Gemini 还是 xAI Grok，只需调用标准的 `sm.generate_text` 函数，通过字符串参数即可无缝切换，彻底消除重复代码。\n- **极简环境配置**：遵循“以人为本”的设计，仅需在环境变量中设置对应的 API Key，simplemind 自动处理认证细节，让开发者专注业务逻辑而非配置琐事。\n- **轻量无负担**：摒弃了复杂的图编排和不必要的抽象层，代码清晰易读，新人上手即可参与开发，大幅降低了项目的认知负荷和维护难度。\n- **动态模型实验**：支持在函数调用时直接传入 `llm_provider` 和 `llm_model` 参数，无需重启服务或修改代码即可实时对比各模型输出效果，极大提升研发效率。\n\nsimplemind 通过抹平不同 AI 厂商的接口差异，让开发者像进行日常对话一样轻松地构建和切换多模型应用。","https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fkennethreitz_simplemind_148a3256.jpg","kennethreitz","Kenneth Reitz","https:\u002F\u002Foss.gittoolsai.com\u002Favatars\u002Fkennethreitz_72f36a52.jpg","I wrote Requests: HTTP for Humans and Pipenv. The only thing I really care about is user experience.",null,"Virginia, USA, Earth, Milky Way.","me@kennethreitz.org","kennethreitz42","kennethreitz.org","https:\u002F\u002Fgithub.com\u002Fkennethreitz",[84,88],{"name":85,"color":86,"percentage":87},"Python","#3572A5",99.4,{"name":89,"color":90,"percentage":91},"Dockerfile","#384d54",0.6,539,28,"2026-03-23T00:22:17","Apache-2.0","未说明",{"notes":98,"python":96,"dependencies":99},"该工具是一个用于简化调用各大 AI 服务商（如 OpenAI, Anthropic, Google 等）API 的 Python 客户端库，本身不包含本地大模型，因此无特定 GPU、显存或 CUDA 版本要求。运行前需在环境变量中配置对应服务商的 API Key。安装命令为 pip install 'simplemind[full]'。",[100],"pydantic",[14,52,15,13,35],[103,104,105,106,107,108,109,110,111,112],"ai","api-client","langchain","llms","anthropic","anthropic-claude","artificial-intelligence","gemini","openai","openai-api","2026-03-27T02:49:30.150509","2026-04-12T17:24:09.336028",[116,121,126,131,136,141],{"id":117,"question_zh":118,"answer_zh":119,"source_url":120},30785,"安装 simplemind[full] 时因缺少 cargo 依赖而失败怎么办？","该问题通常是因为系统未安装 Rust 和 cargo，导致无法构建 `jiter` 包。解决方法是先在系统中安装 Rust 和 cargo。此外，如果您使用的是 Python 3.13，请注意 `jiter` 目前可能尚未兼容该版本，建议暂时使用较低版本的 Python（如 3.12 或更低）进行安装。","https:\u002F\u002Fgithub.com\u002Fkennethreitz\u002Fsimplemind\u002Fissues\u002F44",{"id":122,"question_zh":123,"answer_zh":124,"source_url":125},30786,"如何只安装 OpenAI 客户端而不安装其他不必要的依赖（如 Groq, Anthropic）？","虽然默认安装会包含所有客户端，但维护者已确认会将导入逻辑移至运行时（runtime），这意味着未来只需安装实际使用的提供商即可。目前建议直接安装主包，未使用的库不会被强制加载，或者关注后续版本对可选依赖的进一步优化。","https:\u002F\u002Fgithub.com\u002Fkennethreitz\u002Fsimplemind\u002Fissues\u002F27",{"id":127,"question_zh":128,"answer_zh":129,"source_url":130},30787,"simplemind 支持本地离线运行开源模型（如 LLaMA）吗？","是的，目前 `main` 分支已支持 Ollama 作为本地模型提供商。您可以配置使用 Ollama 来运行本地模型。另一种方法是参考 `gptme` 的做法，通过设置 `OPENAI_BASE_URL` 环境变量指向本地服务地址，并将模型名称设置为 `local\u002F\u003Cmodelname>` 来实现本地模型调用（需确保 `OPENAI_BASE_URL` 已设置以防泄露请求到 OpenAI）。","https:\u002F\u002Fgithub.com\u002Fkennethreitz\u002Fsimplemind\u002Fissues\u002F16",{"id":132,"question_zh":133,"answer_zh":134,"source_url":135},30788,"Ollama 提供商报错 'Chat' object is not callable 如何解决？","这是一个已知 bug，原因是 Ollama 提供商内部调用客户端的方式与 OpenAI 提供商实现不一致。该问题已在 `main` 分支中修复。请更新您的代码库到最新版本（从 main 分支安装），或者等待下一个正式版本发布即可解决此错误。","https:\u002F\u002Fgithub.com\u002Fkennethreitz\u002Fsimplemind\u002Fissues\u002F48",{"id":137,"question_zh":138,"answer_zh":139,"source_url":140},30789,"如何在 simplemind 中创建不同 LLM 之间的对话（Discussions）？","可以通过查看项目示例文件夹中的代码来实现。具体来说，参考 `examples\u002F_context.py` 文件，其中展示了如何通过相对导入初始化上下文并创建多个 LLM 进行交互。虽然目前没有专门的 API 文档，但示例代码提供了完整的实现思路。","https:\u002F\u002Fgithub.com\u002Fkennethreitz\u002Fsimplemind\u002Fissues\u002F30",{"id":142,"question_zh":143,"answer_zh":144,"source_url":145},30790,"如何编写自定义插件来处理消息接收（如内容审核或转换）？","可以通过继承 `BasePlugin` 类并实现特定的钩子函数来自定义插件功能。可用的钩子包括：`initialize_hook`（初始化时调用）、`pre_send_hook`（发送前修改消息）、`send_hook`（发送过程中）、`post_send_hook`（接收响应后处理）以及 `cleanup_hook`（清理时）。插件可以按添加顺序执行，支持修改消息或在消息中添加注解。","https:\u002F\u002Fgithub.com\u002Fkennethreitz\u002Fsimplemind\u002Fissues\u002F13",[]]