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**------一款旨在通过自然语言交互帮助用户解答问题、生成代码、创建可视化图表等的智能助手。'}]

参考:

相关推荐
西安老张(AIGC&ComfyUI)17 小时前
第030章:ComfyUI视频制作LTX-2.3模型文生视频工作流详解(三)
人工智能·aigc·comfyui
深蓝AI1 天前
NVIDIA 发布 Nemotron 3 Embed:开源嵌入模型登顶 RTEB,RAG 检索精度全面提升
aigc
TrisighT1 天前
Skill 写成 2000 字说明书?Claude 根本不读——路由器思维与渐进式披露
aigc·ai编程·claude
食尘者1 天前
MacBook Pro M5Max 本地大模型推理实践
macos·aigc
倾颜1 天前
AI 聊天刷新后记录全丢?用浏览器本地存储给 AI Chat 加一层"离线记忆"
前端·aigc
刘棕霆1 天前
企业测试造数为什么这么难?我把熟手经验做成了一个可交付的造数 Skill
aigc·agent·测试
武子康1 天前
HunyuanVideo 全家族选型:原版 13B / I2V / Avatar / Foley / 1.5 8.3B 怎么分工
人工智能·llm·aigc
一孤程1 天前
AI辅助测试用例生成实战——用大模型把测试设计效率提升300%
人工智能·测试工具·ai·aigc·测试用例·测试·测试覆盖率
怕浪猫1 天前
AI Agent 应用开发实战封面大集合
aigc·openai·ai编程