当前位置: 首页 > news >正文

AIGC(生成式AI)试用 45 -- 个人知识库 DocsGpt

一切从DocsGPT的API调用开始。

0. 启动DocsGpt
1) 启动 Docker Desktop
2) 启动 DocsGPT
# Launch DocsGPT with Docker Compose
docker compose -f deployment/docker-compose.yaml up -d

# Launch DocsGPT with Ollama, CPU
docker compose --env-file .env -f deployment/docker-compose.yaml -f deployment/optional/docker-compose.optional.ollama-cpu.yaml up -d

1. Python API调用
(千问) 提问:python调用API方法
Python 中调用 API(通常指 HTTP 接口,如 RESTful API)最常用的方式是使用requests库。

场景方法
获取数据requests.get(url, params=...)
提交 JSONrequests.post(url, json=...)
上传文件requests.post(url, files=...)
带 Tokenheaders={"Authorization": "Bearer xxx"}
安全健壮timeout+try-except+raise_for_status()
import requests # GET方法 Parameters = {} response = requests.get(GET_URL, Parameters) # return: response.status_code, response.text # POST方法 Data = {} # headers, json response = requests.post(post_URL, Data, headers)

2. 调用DocsGPT --

answerAnswer related operations
analyticsAnalytics and reporting operations
attachmentsFile attachments and media operations
conversationsConversation management operations
modelsAvailable models
agentsAgent management operations
promptsPrompt management operations
sharingConversation sharing operations
sourcesSource document management operations
toolsTool management operations
connectorsConnector operations

- payload Parameters -- 待确认、实际验证

question用户提问或输入
api_keyagent API key
chunk上下文数量,指定从向量数据库中检索多少个相关文本片段(chunks)作为上下文
retriever检索器类型(即如何从文档中查找相关信息):default;parent_document, 先子块再父文档;multi_query
temperature控制大语言模型(LLM)生成文本的随机性/创造性,0.0~2.0,确定~随机,注意幻觉的产生
passthrough是否启用 “直通模式”:True,不查RAG文档直接提问;执行RAG流程(检索+提问)
history对话历史, JSON
model_id指定LLM模型类型
prompt_idlocal 或 prompt_id,本地无需验证
isNoneDocFalse,查看RAG文档
save_conversationTrue: 保留对话历史
toolsLLM 可调用的外部函数/插件
attachments上传附件,知识库补充
json_schemaLLM 输出必须符合的 JSON 结构,用于强制格式化响应

- POST: api/answer

import requests purl = "http://localhost:7091/api/answer" payload = { "question": "who are you?", ## "history": [string], ## "conversation_id": "string", "prompt_id": "default", "chunks": 2, "retriever": "", ## "api_key": "string", "active_docs": "", "isNoneDoc": True, "save_conversation": True, "model_id": "docsgpt-local", "passthrough": {}, "temperature": 0.0, "top_k": 5 } response = requests.post(purl, json=payload) if response.status_code == 200: result = response.json() print(f">> Answer: {result.get('answer')}, \n>> StatusCode: {response.status_code}, \n>> Text: {response.text}") else: print(f"Fail: {response.status_code}, {response.text}") ############### >> Answer: I am your DocsGPT. I am an AI assistant designed to provide helpful and accurate responses, assist with documentation, and engage in meaningful conversations. I aim to be proactive and helpful in answering your questions based on both your input and any additional context provided., >> StatusCode: 200, >> Text: { "answer": "I am your DocsGPT. I am an AI assistant designed to provide helpful and accurate responses, assist with documentation, and engage in meaningful conversations. I aim to be proactive and helpful in answering your questions based on both your input and any additional context provided.", "conversation_id": "6967afe8066b58e22408544f", "sources": [], "thought": "", "tool_calls": [] } ################ Error List --> "model_id": "deepseek-r1:1.5b", Fail: 500, { "error": "Invalid model_id 'deepseek-r1:1.5b'. Available models: docsgpt-local, gpt-5.1, gpt-5-mini" } --> not set "model_id" >> Answer: None, >> StatusCode: 200, >> Text: { "answer": null, "conversation_id": null, "sources": null, "thought": "Please try again later. We apologize for any inconvenience.", "tool_calls": null } --> "history": [], Fail: 500, { "error": "the JSON object must be str, bytes or bytearray, not list" } --> "conversation_id": "string", Fail: 500, { "error": "Conversation not found or unauthorized" }

- POST: stream

import requests, json purl = "http://localhost:7091/stream" payload = { "question": "who are you?", ## "history": ["string"], ## "conversation_id": "", ## "prompt_id": "default", ## "chunks": 2, ## "retriever": "string", #### "api_key": "string", ## "active_docs": "string", ## "isNoneDoc": True, ## "index": 0, ## "save_conversation": True, "model_id": "docsgpt-local", ## "attachments": ["string"], ## "passthrough": {} } response = requests.post(purl, json=payload) if response.status_code == 200: result = response.iter_lines() answer= "" jid = "" for line in result: if line: text = line.decode('utf-8', errors='ignore') data = text.split("data:")[1].strip() jdata = json.loads(data) if jdata.get("answer"): answer = answer + jdata["answer"] if jdata.get("id"): jid = jdata["id"] print(f">> Answer: {answer}, \n>> StatusCode: {response.status_code}, \n>> ID: {jid}") else: print(f"Fail: {response.status_code}, {jid}") ########################## >> Answer: I am DocsGPT, an AI assistant designed to help you with documents and answer questions. I analyze uploaded documents (PDF, DOCX, TXT, etc.) to provide contextualized answers. I can also use available tools, like APIs, to fetch real-time data when needed. My goal is to deliver accurate, relevant, and actionable responses., >> StatusCode: 200, >> ID: 696a382be304c4e05c085443 ########################## Error List --> <Response [200]> <class 'requests.models.Response'> result = response.iter_lines() --> json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0) line: b'data: {"type": "id", "id": "696a3ab5e304c4e05c085453"}' text = line.decode('utf-8', errors='ignore') text: data: {"type": "id", "id": "696a3ab5e304c4e05c085453"}

- POST: api/create_prompt

import requests, json curl = "http://localhost:7091/api/create_prompt" gsurl = "http://localhost:7091/api/get_prompts" gurl = "http://localhost:7091/api/get_single_prompt" purl = "http://localhost:7091/stream" payload = { "content": "", "name": "who are you?", } response = requests.post(curl, json=payload) result = response.json() payload = { "question": "你是谁?来自哪里?能做什么?", ## "history": ["string"], ## "conversation_id": "", "prompt_id": f"{result.get("id")}", ## "chunks": 2, ## "retriever": "string", #### "api_key": "string", ## "active_docs": "string", ## "isNoneDoc": True, ## "index": 0, ## "save_conversation": True, "model_id": "docsgpt-local", ## "attachments": ["string"], ## "passthrough": {} } response = requests.post(purl, json=payload) if response.status_code == 200: result = response.iter_lines() answer= "" jid = "" for line in result: if line: text = line.decode('utf-8', errors='ignore') data = text.split("data:")[1].strip() jdata = json.loads(data) if jdata.get("answer"): answer = answer + jdata["answer"] if jdata.get("id"): jid = jdata["id"] print(f">> Answer: {answer}, \n>> StatusCode: {response.status_code}, \n>> ID: {jid}") else: print(f"Fail: {response.status_code}") ############################################# >> Answer: 我是 **Kimi**,由 **月之暗面科技有限公司**(Moonshot AI)训练的大语言模型。我出生于 **2023 年 10 月**,知识截止于 **2025 年 4 月**。 我擅长用自然流畅的语言和你交流,能做的事情包括但不限于: - 回答各类知识和信息咨询 - 帮你阅读、总结长文档或网页内容 - 协助写作、翻译、润色文本 - 帮你写代码、解释代码、调试程序 - 制定计划、提供建议、模拟对话等 你可以随时向我提问,我会尽力帮你解决。, >> StatusCode: 200, >> ID: 696cf48bbb06b2fb690853c9

- POST:api/create_agent

import requests, json purl = "http://localhost:7091/api/create_agent" payload = { "name": "NewAgent", "description": "This is new angent", ## "image": {}, "source": "Default", ## "sources": [ ## "string" ## ], "chunks": 2, "retriever": "string", "prompt_id": "default", ## "tools": [ ## "string" ## ], "agent_type": "Classic", "status": "published", ## "json_schema": {}, ## "limited_token_mode": true, ## "token_limit": 0, ## "limited_request_mode": true, ## "request_limit": 0, ## "models": [ ## "string" ## ], "default_model_id": "docsgpt-local", } response = requests.post(purl, json=payload, stream=True) if response.status_code == 200: result = response.json() print("result: ", result) print(result) print(f">> Answer: {result.get('answer')}, \n>> StatusCode: {response.status_code}, \n>> Text: {response.text}") else: print(f"Fail: {response.status_code}, {response.text}") ##################################### Fail: 201, { "id": "696cdd93e304c4e05c0854eb", "key": "7524f0b4-e4ec-4cc6-9cd5-faa2869274ca" ########################## Error List --> Fail: 400, { "message": "Status must be either 'draft' or 'published'", "success": false } --> Fail: 400, { "message": "Either 'source' or 'sources' field is required for published agents", "success": false } --> Fail: 400, { "message": "Missing required fields: description, chunks, retriever, prompt_id, agent_type", "success": false }

- Get:api/get_agent(s)

import requests, json purl = "http://localhost:7091/api/delete_agent" gurl = "http://localhost:7091/api/get_agent" gsurl = "http://localhost:7091/api/get_agents" response = requests.get(gsurl) result = response.json() for gid in result: response = requests.get(gurl+"?id="+gid.get("id")) result = response.json() print("---------->Agent: ") for agent in result: print(agent,": ",result[agent]) ################################### ---------->Agent: agent_type : classic chunks : 2 created_at : Wed, 31 Dec 2025 14:09:38 GMT default_model_id : description : pic word recognize id : 69552ea240d00b40db5f1543 image : json_schema : None key : 8d64...4b85 last_used_at : Wed, 31 Dec 2025 15:50:50 GMT limited_request_mode : False limited_token_mode : False models : [] name : PicWordReg pinned : False prompt_id : 69552e8040d00b40db5f1542 request_limit : 0 retriever : shared : True shared_metadata : {'shared_at': 'Wed, 31 Dec 2025 14:09:46 GMT', 'shared_by': ''} shared_token : ml7EmEkaTFYeHh_QAkWOnhvqsN5wEpkpKEwbdeSM3Qk source : sources : [] status : published token_limit : 0 tool_details : [] tools : [] updated_at : Wed, 31 Dec 2025 14:09:38 GMT

3. Issues
- api/answer, stream的区别

特性非流式(如/api/answer流式(stream=true
响应方式一次性返回完整答案逐字/逐 token 返回
等待时间需等待模型生成完整内容后才返回(延迟高)首字几乎立即返回(延迟低)
网络传输单次 HTTP 响应持续的 HTTP 流(如 SSE、Chunked Transfer)
用户体验“转圈 → 突然全部出现”“打字机效果”,边生成边显示
资源占用服务端需缓存完整结果服务端边生成边发送,内存更省
适用场景后台处理、批量任务聊天界面、实时交互
效果对比

用户点击“发送”

等待 5 秒(模型思考 + 生成)

屏幕突然显示完整回答
感觉卡顿,但代码简单

用户点击“发送”

0.5 秒后第一个字出现

后续文字像打字机一样逐字输出
体验流畅,有“正在思考”的反馈

场景后台自动化任务(如生成报告)
API 被其他程序调用(非人交互)
Web 聊天界面(如微信、网页助手)
移动 App 聊天
简单、适合机器调用,但用户体验差复杂一点,但提供实时反馈,是聊天类应用的标准做法

4. DocsGPT Port

  • Port: 5173, DocsGPT running
    setup.ps1: Write-ColorText "DocsGPT is running at http://localhost:5173"
    DocsGPT-main\application\app.py: redirect("http://localhost:5173")
  • Port: 11434, AI Model
    .env: OPENAI_BASE_URL=http://host.docker.internal:11434
    deployment\optional\docker-compose.optional.ollama-cpu.yaml: ports: - "11434:11434"
  • Port: 7091, API access
    deployment\docker-compose-local.yaml: VITE_API_HOST=http://localhost:7091

4. DocsGPT environment

  • ollama
    ollama list ########################################################## NAME ID SIZE MODIFIED deepseek-r1:1.5b a42b25d8c10a 1.1 GB 11 months ago
  • Docker
    docker --version docker-compose --version docker system info ########################################################## Docker version 29.1.3, build f52814d Docker Compose version v2.40.3-desktop.1 Client: Version: 29.1.3 Context: desktop-linux ...... Server: Containers: 9 Running: 6 wsl --list --verbose ########################################################## NAME STATE VERSION * docker-desktop Running 2 docker images ########################################################## i Info → U In Use IMAGE ID DISK USAGE CONTENT SIZE EXTRA arc53/docsgpt-fe:develop 89a336ecda3a 973MB 236MB U arc53/docsgpt:develop f49f4d12dd3c 12GB 4.28GB U docsgpt-oss-backend:latest 61116975e170 15.2GB 5.45GB U docsgpt-oss-frontend:latest 7bdb0c8f98ed 973MB 236MB U docsgpt-oss-worker:latest 9c3988fdb2f3 15.2GB 5.45GB U mongo:6 03cda579c8ca 1.06GB 273MB U ollama/ollama:latest 2c9595c555fd 6.14GB 2.17GB U redis:6-alpine 37e002448575 45.1MB 12.9MB U

Field

Type

Required

Applies to

Notes

question

string

Yes

/api/answer,/stream

User query.

api_key

string

Usually

/api/answer,/stream

Recommended for agent API use. Loads agent config from key.

conversation_id

string

No

/api/answer,/stream

Continue an existing conversation.

history

string(JSON-encoded array)

No

/api/answer,/stream

Used for new conversations. Format:[{\"prompt\":\"...\",\"response\":\"...\"}].

model_id

string

No

/api/answer,/stream

Override model for this request.

save_conversation

boolean

No

/api/answer,/stream

Defaulttrue. Iffalse, no conversation is persisted.

passthrough

object

No

/api/answer,/stream

Dynamic values injected into prompt templates.

prompt_id

string

No

/api/answer,/stream

Ignored whenapi_keyalready defines prompt.

active_docs

stringorstring[]

No

/api/answer,/stream

Overrides active docs when not using key-owned source config.

retriever

string

No

/api/answer,/stream

Retriever type (for exampleclassic).

chunks

number

No

/api/answer,/stream

Retrieval chunk count, default2.

isNoneDoc

boolean

No

/api/answer,/stream

Skip document retrieval.

agent_id

string

No

/api/answer,/stream

Alternative toapi_keywhen using authenticated user context.

参考:

  • AIGC(生成式AI)试用 43 -- 个人知识库-CSDN博客
http://www.jsqmd.com/news/1176561/

相关文章:

  • reflow社区贡献指南:从使用到参与开发的完整路径
  • 5分钟实战指南:掌握EmulatorJS浏览器游戏模拟器的高效用法
  • 德州诺图空调设备有限公司|武城鲁权屯全品类消防通风设备源头厂家 - 品牌优选官
  • 3分钟网页打包终极指南:零代码经验将任何网站变桌面应用
  • Erjang架构解密:如何将Erlang Beam文件编译为JVM Class文件的实现原理
  • PUBG地图黑客Web界面开发:JavaScript与Firebase集成完整指南
  • Codex技能目录:AI助手能力扩展的标准化技术方案
  • 3个实战场景:深度掌握Evidently AI的数据质量检测与异常值筛查
  • 如何测试GeocoderLaravel:使用Http::fake()进行地理编码测试
  • 高级用法:OAS-Kit自定义规则与插件开发指南
  • 如何扩展Samsungctl:自定义按键映射与插件开发完整指南
  • 3个TED演讲技巧:用AI赋能实现英语听力口语双突破
  • 萧邦官方售后服务中心地址与电话实地考察报告_多信源验证(2026年7月最新) - 萧邦中国官方服务中心
  • 2026合扬黄金回收7天报价留存有效,苏州旧金残缺无票据正常回收 - 合扬
  • 30分钟构建专属智能问答系统:Langchain-Chatchat本地知识库实战指南
  • 5分钟上手Pyvis:打造惊艳交互式网络图的Python利器
  • 15个实战项目深度解析:从零构建完整技术作品集
  • 如何在5分钟内上手Try Puppeteer?新手必备的云端自动化工具
  • 3个简单步骤:让旧电视盒变身专业Linux服务器
  • 终极指南:3步快速搭建AzerothCore-WoTLK魔兽世界服务器
  • 降 AIGC 工具处理完还要自己改吗?怎么配合才最省心 - 我要发一区
  • 天梭官方售后服务中心服务电话及全部地址实地考察报告+多信源验证(2026年7月更新) - 天梭服务中心
  • Hackers中的Swift 6.2新特性应用:如何构建现代化的iOS应用
  • 深度解析Automat:Python状态机编程的高效实战指南
  • hot-lib-reloader-rs高级配置:多库管理与自定义加载策略
  • telegram-purple插件打包指南:从源代码到Debian、RPM和Windows安装包
  • Deepseek广告公司推荐:2026年五家GEO服务商实力排名与分析 - GEO优化
  • 拼多多新店快速起流量完整实操
  • MogoChat用户指南:玩转通知设置与/me状态消息的终极教程
  • 3步打造个性终端:electerm主题定制从入门到精通