AIGC(生成式AI)试用 52 -- 个人知识库 DocsGpt(chat参数)

个人知识库 DocsGpt,Request Parameters

Left Issue

  1. 回复结果的稳定性、一致性

2)通过prompt模拟Agent生成

3)Agent调用 + 外部资源调用(rag?)

4)chat名可以自定义吗?

  1. api/answer, stream的区别

|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------|
| Question: Who are you? ||
| api/answer | stream |
| I'm DocsGPT---a conversational AI created to help you with information, explanations, code snippets, diagrams, and more. Think of me as a reliable virtual assistant that can read and analyze documents you upload, answer questions, and even generate charts or example code. Let me know how I can assist you today! | I 'm ** Docs GPT **, a conversational AI designed to help you create , understand , ......(此处略去N行) ! |

  1. System, Assistant, User的区别(百度 ai)
  • ‌System‌:‌幕后指令设定者‌,定义 AI 的身份、风格、规则或上下文约束(如"你是一名资深医生,回答需简洁专业"),不直接参与对话,但全局引导 AI 行为。-- 系统约束
  • ‌User‌:‌提问者或指令发起者‌,代表人类输入(如"如何煮咖啡?"),推动对话方向。-- 提示输入
  • ‌Assistant‌:‌AI 的回应化身‌,根据 System 和 User 的输入生成内容,在多轮对话中承接上下文(即你看到的 AI 回复)。-- 提问反馈
  1. Prompt 与 Agent
  • Prompt = LLM + 问题
    对话:一次性、无状态对话、建议输出

  • Agent = LLM + Planning + Memory + Tools + Prompt
    活动:循环、自主、决策、完成并输出最终结果

  • Agent = 有组织、有目的、有约束的Prompt集 + 工具

    1. API调用
    • 最简单调用
    python 复制代码
    def ask_ai(question):
       
        payload = {
          "question": question,
          "model_id": "docsgpt-local",
        }
    
        response = requests.post(purl["purl_answer"], json=payload)
        
        if response.status_code == 200:
            result = response.json()
            return result['answer']       
        else:
            return response.text 
    
    if __name__ == "__main__":
        answer = ask_ai("who are you")
        print("--> ", f"{answer}")
    
    ###################3
    
    -->  I'm DocsGPT, a large‑language‑model AI trained by OpenAI.  
    I can help you with a wide range of tasks---from answering questions and explaining concepts to writing code, generating documentation, and visualizing data. If you have any specific requests, just let me know!
    ['who are you', 'I'm DocsGPT, a large‑language‑model AI trained by OpenAI.  \nI can help you with a wide range of tasks---from answering questions and explaining concepts to writing code, generating documentation, and visualizing data. If you have any specific requests, just let me know!']
    • 参数(Request Parameters0

    |-------------------|-----------------------------|--------------|----------------------|--------------------------------------------------------------------------------------------|
    | 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 | Default . If , no conversation is persisted.true false |
    | passthrough | object | No | /api/answer, /stream | Dynamic values injected into prompt templates. |
    | prompt_id | string | No | /api/answer, /stream | Ignored when already defines prompt.api_key |
    | active_docs | string or string\[\] | No | /api/answer, /stream | Overrides active docs when not using key-owned source config. |
    | retriever | string | No | /api/answer, /stream | Retriever type (for example ).classic |
    | chunks | number | No | /api/answer, /stream | Retrieval chunk count, default .2 |
    | isNoneDoc | boolean | No | /api/answer, /stream | Skip document retrieval. |
    | agent_id | string | No | /api/answer, /stream | Alternative to when using authenticated user context.api_key |
    | Streaming-only fields: |||||
    | attachments | string\[\] | No | List of attachment IDs from success result./api/task_status ||
    | index | number | No | Update an existing query index. If provided, is required.conversation_id ||

    • history,上下文记忆
    python 复制代码
    chat_history = []
    chat_history.append("string")
    
    history = json.dumps(chat_history, ensure_ascii=False)
    
    {
      ...
      "history": history,
      ...
    } 
    
    ###########################################################
    History: [{'role': 'user', 'content': 'who are you?'}, {'role': 'user', 'content': '**问题**:who are you?  
    \n\n**评估**:不明确。  
    \n\n**不明确之处**  \n1. **对象不确定**:问题没有说明"你"指的是谁或什么(人、机器人、系统、组织等)。  
    \n2. **上下文缺失**:缺少交互场景或背景信息,使得无法判断期望回答的具体内容(例如身份认证、角色介绍、人工智能服务等)。  
    \n3. **答案范围不定**:可能回答为个人信息、职业身份、AI助手、角色扮演等,缺乏限定。  
    \n\n如果你想得到特定的答案,请补充上下文或说明你期望得到的"身份"范围。'}]
    
    ###########################################################
    # calling error1
    {
      ...
      "history": ["string"],
      ...
    } 
    
    # "error": "the JSON object must be str, bytes or bytearray, not list"
    
    # calling error2
    {
      ...
      "history": "string",
      ...
    } 
    
    # "error": "Expecting value: line 1 column 1 (char 0)"
    • passthrough,系统提示词(提示词补充、限制)
python 复制代码
passthrough = {
    "Time": time.ctime(),
    "sysprompt": "分析以下问题是否明确,如不明确则列出不明确之处,如明确则输出结果:",
}

"question": f"{passthrough['sysprompt']}{question}",

#####################################################
**评估**:不明确。  

**不明确之处**  
1. **对象不确定**:问题没有说明"你"指的是谁或什么(人、机器人、系统、组织等)。  
2. **上下文缺失**:缺少交互场景或背景信息,使得无法判断期望回答的具体内容(例如身份认证、角色介绍、人工智能服务等)。  
3. **答案范围不定**:可能回答为个人信息、职业身份、AI助手、角色扮演等,缺乏限定。  

如果你想得到特定的答案,请补充上下文或说明你期望得到的"身份"范围。
  • history + passthrough 调用
python 复制代码
def ask_ai(question):
    chat_history = []
    chat_history.append(
             {"role":    "user", 
              "content": question}
             )

    history = json.dumps(chat_history, ensure_ascii=False)

    passthrough = {
        "Time": time.ctime(),
        "sysprompt": "分析以下问题是否明确,如不明确则列出不明确之处,如明确则输出结果:",
    }
    
    payload = {
      "question": f"{passthrough['sysprompt']}{question}",
      "history": history,
    ##  "conversation_id": "string",
      "model_id": "docsgpt-local",
      "passthrough": passthrough, 
    }

    response = requests.post(purl["purl_answer"], json=payload)
    
    if response.status_code == 200:
        result = response.json()
        chat_history.append(
                 {"role":    "user", 
                  "content": result['answer']}
                  )
        return result['answer'], chat_history       
    else:
        return response.text, chat_history 

if __name__ == "__main__":
    answer, history = ask_ai("who are you?")  
    print(f"-->Answer: {answer}\n-->History: {history}")

#############################################################
-->Answer: **问题**:who are you?  

**是否明确**  
*明确* -- 这是一道直接的自我询问,假设回答者是被问的主体,即你(DocsGPT)或另一方。  
在缺乏额外上下文的前提下,通常理解为询问回答者自身身份。

**输出结果**  
> 我是 DocsGPT,一款富有帮助性的 AI 助手,旨在通过对话协助用户解答问题、生成代码、可视化数据等。
-->History: 
[{'role': 'user', 'content': 'who are you?'}, 
{'role': 'user', 'content': '**已知情景**  \n> "who are you?"  
\n\n**是否明确**  \n*明确* -- 这是一道直接的自我询问,假设回答者是被问的主体,即你(DocsGPT)或另一方。  
\n在缺乏额外上下文的前提下,通常理解为询问回答者自身身份。\n\n**输出结果**  
\n> 我是 DocsGPT,一款富有帮助性的 AI 助手,旨在通过对话协助用户解答问题、生成代码、可视化数据等。'}]
  • 修改 passthrough,并加入 conversation_id 调用
python 复制代码
passthrough = {
    "Time": time.ctime(),
    "sysprompt": "分析以下问题,如问题不明确则列出不明确之处,如问题明确则输出结果:",
}

##################################################
{'answer': '**问题是否明确?**  \n明确。\n\n**结果**  \n\n
> 我是 **DocsGPT**------一款旨在通过自然语言交互帮助用户解答问题、生成代码、创建可视化图表等的智能助手。', 'conversation_id': '6a2524f29404e7c57b19e98b', 'sources': [], 'thought': '', 'tool_calls': []}

-->Answer: **问题是否明确?**  
明确。

**结果**  

> 我是 **DocsGPT**------一款旨在通过自然语言交互帮助用户解答问题、生成代码、创建可视化图表等的智能助手。

-->History: [{'role': 'user', 'content': 'who are you?'}, 
{'role': 'user', 'content': '**问题是否明确?**  \n明确。\n\n**结果**  \n\n> 我是 **DocsGPT**------一款旨在通过自然语言交互帮助用户解答问题、生成代码、创建可视化图表等的智能助手。'}]

参考:

相关推荐
用户5191495848451 小时前
Nortek Linear eMerge E3 预认证远程代码执行漏洞利用工具
人工智能·aigc
码农阿强1 小时前
GPT-Image-2 技术原理与实战:开启推理驱动图像生成新时代
人工智能·gpt·ai·aigc·个人开发
AI周红伟2 小时前
事件分析:FDE标准,“OpenClaw+RAG+Agent” 应用实战的标准
前端·人工智能·chrome·chatgpt·aigc
大象说2 小时前
面向学术小论文的AIGC内容原创度鉴定查询功能实现手记
aigc
程序员佳佳2 小时前
向量引擎:AI 时代的“记忆中枢“,从原理到落地的完整认知框架
人工智能·gpt·架构·aigc·ai编程
_张一凡3 小时前
【AIGC行业前沿】2026年5月AIGC行业前沿模型发布动态(5月25-5月31)
llm·aigc·vlm·前沿资讯
_张一凡3 小时前
【AIGC行业前沿】2026年6月AIGC行业前沿模型发布动态(6月1-6月7)
aigc·aigc前沿资讯
AI智图坊16 小时前
AIGC赋能跨境电商:如何利用「图生图」与模型提取,破解POD节日款“卡图案”技术瓶颈?
大数据·人工智能·gpt·ai作画·aigc
JouYY17 小时前
我是如何在业务 Agent 项目中应用 Harness 的
llm·aigc·agent