Chatgpt 网页会话过程数据传输分析以及横向对比

2024/06/16 LLM 共 11468 字,约 33 分钟

新建一个会话

https://chatgpt.com/backend-api/conversation POST

请求

{
    "action": "next",
    "messages": [
        {
            "id": "aaa2d6d4-5a8b-473e-bd21-e3bf2ee4f571",
            "author": {
                "role": "user"
            },
            "content": {
                "content_type": "text",
                "parts": [
                    "为 TikTok 帐户创建一个用于评估房地产楼盘的内容日历。"
                ]
            },
            "metadata": {
                "is_starter_prompt": true
            }
        }
    ],
    "parent_message_id": "aaa10e5b-13c0-4682-8285-23b44800ac47",
    "model": "auto",
    "timezone_offset_min": -480,
    "suggestions": [
        "为 TikTok 帐户创建一个用于评估房地产楼盘的内容日历。",
        "让我们通过世界首都小测试来提高我的地理知识水平。你可以先随便问我一个国家的首都,我会尽我最大的努力提供正确答案。",
        "随便告诉我一个关于罗马帝国的趣事",
        "我刚搬到一个新城市,希望结交些朋友。你能推荐一些有趣的活动来帮助我实现这个目标吗?"
    ],
    "history_and_training_disabled": false,
    "conversation_mode": {
        "kind": "primary_assistant"
    },
    "force_paragen": false,
    "force_paragen_model_slug": "",
    "force_nulligen": false,
    "force_rate_limit": false,
    "reset_rate_limits": false,
    "websocket_request_id": "0352852e-f148-4288-ac1f-a0c452913f88",
    "force_use_sse": false
}

响应

{
    "wss_url": "wss://chatgpt-async-webps-prod-southcentralus-0.chatgpt.com/client/hubs/conversations?access_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJodHRwczovL2NoYXRncHQtYXN5bmMtd2VicHMtcHJvZC1zb3V0aGNlbnRyYWx1cy0wLndlYnB1YnN1Yi5henVyZS5jb20vY2xpZW50L2h1YnMvY29udmVyc2F0aW9ucyIsImlhdCI6MTcxODUyMTc3OSwiZXhwIjoxNzE4NTI1Mzc5LCJzdWIiOiJ1c2VyLVBtQk9aVkROZDNBb2psbExzZ0VpSU9EMCIsInJvbGUiOlsid2VicHVic3ViLmpvaW5MZWF2ZUdyb3VwLnVzZXItUG1CT1pWRE5kM0FvamxsTHNnRWlJT0QwIl0sIndlYnB1YnN1Yi5ncm91cCI6WyJ1c2VyLVBtQk9aVkROZDNBb2psbExzZ0VpSU9EMCJdfQ.FtFv5GNo_okUpcQa84k8B8TL3GfsUD-M-6CFxP-IQeo",
    "fallback_wss_url": "wss://chatgpt-async-webps-prod-eastus-0.chatgpt.com/client/hubs/conversations?access_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJodHRwczovL2NoYXRncHQtYXN5bmMtd2VicHMtcHJvZC1lYXN0dXMtMC53ZWJwdWJzdWIuYXp1cmUuY29tL2NsaWVudC9odWJzL2NvbnZlcnNhdGlvbnMiLCJpYXQiOjE3MTg1MjE3NzksImV4cCI6MTcxODUyNTM3OSwic3ViIjoidXNlci1QbUJPWlZETmQzQW9qbGxMc2dFaUlPRDAiLCJyb2xlIjpbIndlYnB1YnN1Yi5qb2luTGVhdmVHcm91cC51c2VyLVBtQk9aVkROZDNBb2psbExzZ0VpSU9EMCJdLCJ3ZWJwdWJzdWIuZ3JvdXAiOlsidXNlci1QbUJPWlZETmQzQW9qbGxMc2dFaUlPRDAiXX0.ViTMpHrXz4XfZN4zH8nDZTSpl2gMZ4w2kKJ9WVhoHA0",
    "expires_at": "2024-06-16T08:09:39.172404+00:00",
    "conversation_id": "4744527e-da3d-4ae8-ba71-c16904fb36fe",
    "response_id": "8948f9bac9347964-NRT",
    "websocket_request_id": "0352852e-f148-4288-ac1f-a0c452913f88"
}

stop conversation?

https://chatgpt.com/backend-api/stop_conversation

请求

{"websocket_request_id":"0352852e-f148-4288-ac1f-a0c452913f88"} // 这个在上面新建一个会话那里出现过

响应

{"status":"ok"}

继续会话

https://chatgpt.com/backend-api/conversation

看起来 ChatGPT 用的是 eventsteam

建立 WebSocket 连接

  • 使用提供的 wss_url 或者 fallback_wss_url 来建立 WebSocket 连接。
  • 确保在建立连接时使用了正确的访问令牌(access_token)。

发送消息请求

  • 在建立连接后,发送你希望模型继续生成的消息请求。你需要将当前的对话 ID (conversation_id) 和父消息 ID (parent_message_id) 包含在请求中。

接收消息响应

  • 监听 WebSocket 连接,接收服务器发送的响应消息。
  • 响应消息中应该包含实际的输出内容。
{
    "action": "next",
    "messages": [
        {
            "id": "aaa2a4fc-dce4-45be-96c0-91e36b9d6288",
            "author": {
                "role": "user"
            },
            "content": {
                "content_type": "text",
                "parts": [
                    "噢噢好的"
                ]
            },
            "metadata": {}
        }
    ],
    "conversation_id": "4744527e-da3d-4ae8-ba71-c16904fb36fe",
    // 父消息id
    "parent_message_id": "4f2bfcfd-a93b-4b49-bd0a-134883a2a558",
    "model": "auto",
    "timezone_offset_min": -480,
    "suggestions": [],
    "history_and_training_disabled": false,
    "conversation_mode": {
        "kind": "primary_assistant"
    },
    "force_paragen": false,
    "force_paragen_model_slug": "",
    "force_nulligen": false,
    "force_rate_limit": false,
    "reset_rate_limits": false,
    "websocket_request_id": "8353fe2d-9927-451b-bb93-6ac65f28ab12",
    "force_use_sse": false
}

响应

难道响应用的是 websocket?

{
    "wss_url": "wss://chatgpt-async-webps-prod-southcentralus-0.chatgpt.com/client/hubs/conversations?access_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJodHRwczovL2NoYXRncHQtYXN5bmMtd2VicHMtcHJvZC1zb3V0aGNlbnRyYWx1cy0wLndlYnB1YnN1Yi5henVyZS5jb20vY2xpZW50L2h1YnMvY29udmVyc2F0aW9ucyIsImlhdCI6MTcxODUyMjY3MSwiZXhwIjoxNzE4NTI2MjcxLCJzdWIiOiJ1c2VyLVBtQk9aVkROZDNBb2psbExzZ0VpSU9EMCIsInJvbGUiOlsid2VicHVic3ViLmpvaW5MZWF2ZUdyb3VwLnVzZXItUG1CT1pWRE5kM0FvamxsTHNnRWlJT0QwIl0sIndlYnB1YnN1Yi5ncm91cCI6WyJ1c2VyLVBtQk9aVkROZDNBb2psbExzZ0VpSU9EMCJdfQ.QhSJPJ0NSr4wAFgobR5ft8tK5BtMGLHIlX_Vgt6O4mM",
    "fallback_wss_url": "wss://chatgpt-async-webps-prod-eastus-0.chatgpt.com/client/hubs/conversations?access_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJodHRwczovL2NoYXRncHQtYXN5bmMtd2VicHMtcHJvZC1lYXN0dXMtMC53ZWJwdWJzdWIuYXp1cmUuY29tL2NsaWVudC9odWJzL2NvbnZlcnNhdGlvbnMiLCJpYXQiOjE3MTg1MjI2NzEsImV4cCI6MTcxODUyNjI3MSwic3ViIjoidXNlci1QbUJPWlZETmQzQW9qbGxMc2dFaUlPRDAiLCJyb2xlIjpbIndlYnB1YnN1Yi5qb2luTGVhdmVHcm91cC51c2VyLVBtQk9aVkROZDNBb2psbExzZ0VpSU9EMCJdLCJ3ZWJwdWJzdWIuZ3JvdXAiOlsidXNlci1QbUJPWlZETmQzQW9qbGxMc2dFaUlPRDAiXX0.vd-Gu40JVwJxoMkIFBWUEG9mXtQlM2Se-AUE8N-onww",
    "expires_at": "2024-06-16T08:24:31.588490+00:00",
    "conversation_id": "4744527e-da3d-4ae8-ba71-c16904fb36fe",
    "response_id": "89490f8489ec6876-NRT",
    "websocket_request_id": "8353fe2d-9927-451b-bb93-6ac65f28ab12"
}

看看 qwen

这个是历史对话消息。

{
  "limit": 20,
  "has_more": false,
  "data": [
    {
      "id": "f929b595-18a9-4b51-a22b-a7642d189378",
      "conversation_id": "a9de725e-f3c3-4bc6-9803-362ef76d3c49",
      "inputs": {},
      "query": "111",
      "answer": "",
      "message_files": [],
      "feedback": null,
      "retriever_resources": [],
      "created_at": 1716340511,
      "agent_thoughts": [],
      "status": "error",
      "error": "[openai_api_compatible] Server Unavailable Error, HTTPConnectionPool(host='211.71.15.49', port=8000): Max retries exceeded with url: /v1/chat/completions (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f4621ecb2e0>: Failed to establish a new connection: [Errno 111] Connection refused'))"
    },
    {
      "id": "8c035b93-1f01-43f8-b845-8acde26a05bd",
      "conversation_id": "a9de725e-f3c3-4bc6-9803-362ef76d3c49",
      "inputs": {},
      "query": "222",
      "answer": "Hello! It seems you've typed \"222\". How can I assist you with this? Are you looking for mathematical operations or is it related to a code, phone number or something else? Please provide more details so I can assist you better.",
      "message_files": [],
      "feedback": null,
      "retriever_resources": [],
      "created_at": 1718523368,
      "agent_thoughts": [],
      "status": "normal",
      "error": null
    },
    {
      "id": "3f61f0de-f759-4039-9d83-dcd3f4126c65",
      "conversation_id": "a9de725e-f3c3-4bc6-9803-362ef76d3c49",
      "inputs": {},
      "query": "333",
      "answer": "It looks like you've now typed \"333\". Are you perhaps sharing numbers for a specific reason or looking for a particular pattern or information associated with these numbers? Kindly provide more context so I can assist you effectively.",
      "message_files": [],
      "feedback": null,
      "retriever_resources": [],
      "created_at": 1718523378,
      "agent_thoughts": [],
      "status": "normal",
      "error": null
    }
  ]
}

下面这个是 eventstream 返回。

正常的单个item
{"event": "message", "conversation_id": "a9de725e-f3c3-4bc6-9803-362ef76d3c49", "message_id": "3f61f0de-f759-4039-9d83-dcd3f4126c65", "created_at": 1718523378, "task_id": "438214f6-e4a7-4020-84ae-ec5b0c3bd511", "id": "3f61f0de-f759-4039-9d83-dcd3f4126c65", "answer": ""}
eventstream的最后一个
{"event": "message_end", "conversation_id": "a9de725e-f3c3-4bc6-9803-362ef76d3c49", "message_id": "3f61f0de-f759-4039-9d83-dcd3f4126c65", "created_at": 1718523378, "task_id": "438214f6-e4a7-4020-84ae-ec5b0c3bd511", "id": "3f61f0de-f759-4039-9d83-dcd3f4126c65", "metadata": {"usage": {"prompt_tokens": 1, "prompt_unit_price": "0", "prompt_price_unit": "0", "prompt_price": "0.0000000", "completion_tokens": 44, "completion_unit_price": "0", "completion_price_unit": "0", "completion_price": "0.0000000", "total_tokens": 45, "total_price": "0.0000000", "currency": "USD", "latency": 2.9540078879799694}}}

这么奢侈的吗?

看看 coze

用的也是 eventstream。

response 的 type 大概有这几种:

  • ack
  • verbose
  • answer
  • follow_up
{"message":{"role":"user","type":"ack","content":"你知道薛之谦吗?","content_type":"text","message_id":"7381002802132156435","reply_id":"7381002802132156435","section_id":"7366505240650285090","extra_info":{"local_message_id":"Vi2fyFvCENEa2KQn2f7Rx","input_tokens":"","output_tokens":"","token":"","plugin_status":"","time_cost":"","workflow_tokens":"","bot_state":"","plugin_request":"","tool_name":"","plugin":"","mock_hit_info":"","log_id":"20240616154036FE428F3592749279D50E","stream_id":"","message_title":"","stream_plugin_running":"","new_section_id":"","remove_query_id":"","execute_display_name":""},"status":"","sender_id":"7366504662972760100","content_time":1718523636761,"message_index":"1","source":0},"is_finish":true,"index":0,"conversation_id":"7366503630755315712","seq_id":0}

{"message":{"role":"assistant","type":"verbose","content":"{\"msg_type\":\"time_capsule_recall\",\"data\":\"{\\\"wraped_text\\\":\\\"\\\",\\\"origin_search_results\\\":\\\"[]\\\"}\",\"from_module\":null,\"from_unit\":null}","content_type":"text","message_id":"7381002802132172819","reply_id":"7381002802132156435","section_id":"7366505240650285090","extra_info":{"local_message_id":"","input_tokens":"","output_tokens":"","token":"","plugin_status":"","time_cost":"0.3","workflow_tokens":"","bot_state":"","plugin_request":"","tool_name":"","plugin":"","mock_hit_info":"","log_id":"20240616154036FE428F3592749279D50E","stream_id":"","message_title":"","stream_plugin_running":"","new_section_id":"","remove_query_id":"","execute_display_name":""},"status":"","sender_id":"7366504662972760100","content_time":0,"message_index":"0","source":0},"is_finish":true,"index":1,"conversation_id":"7366503630755315712","seq_id":1}


{"message":{"role":"assistant","type":"answer","content":"当然","content_type":"text","message_id":"7381002802132221971","reply_id":"7381002802132156435","section_id":"7366505240650285090","extra_info":{"local_message_id":"","input_tokens":"2618","output_tokens":"0","token":"2618","plugin_status":"","time_cost":"","workflow_tokens":"","bot_state":"{\"bot_id\":\"7366504662972760100\"}","plugin_request":"","tool_name":"","plugin":"","mock_hit_info":"","log_id":"20240616154036FE428F3592749279D50E","stream_id":"267da90686d0484b8751229cf045037c","message_title":"","stream_plugin_running":"","new_section_id":"","remove_query_id":"","execute_display_name":""},"status":"","sender_id":"7366504662972760100","content_time":1718523638670,"message_index":"2","source":0},"is_finish":false,"index":2,"conversation_id":"7366503630755315712","seq_id":2}

最后一个
{"message":{"role":"assistant","type":"verbose","content":"{\"msg_type\":\"generate_answer_finish\",\"data\":\"\",\"from_module\":null,\"from_unit\":null}","content_type":"text","message_id":"7381002802132353043","reply_id":"7381002802132156435","section_id":"7366505240650285090","extra_info":{"local_message_id":"","input_tokens":"","output_tokens":"","token":"","plugin_status":"","time_cost":"4.1","workflow_tokens":"","bot_state":"{\"bot_id\":\"7366504662972760100\"}","plugin_request":"","tool_name":"","plugin":"","mock_hit_info":"","log_id":"20240616154036FE428F3592749279D50E","stream_id":"","message_title":"","stream_plugin_running":"","new_section_id":"","remove_query_id":"","execute_display_name":""},"status":"","sender_id":"7366504662972760100","content_time":0,"message_index":"0","source":0},"is_finish":true,"index":3,"conversation_id":"7366503630755315712","seq_id":76}

建议
{"message":{"role":"assistant","type":"follow_up","content":"薛之谦的代表作有哪些?","content_type":"text","message_id":"7381002802132418579","reply_id":"7381002802132156435","section_id":"7366505240650285090","extra_info":{"local_message_id":"","input_tokens":"","output_tokens":"","token":"","plugin_status":"","time_cost":"","workflow_tokens":"","bot_state":"{\"bot_id\":\"7366504662972760100\"}","plugin_request":"","tool_name":"","plugin":"","mock_hit_info":"","log_id":"20240616154036FE428F3592749279D50E","stream_id":"","message_title":"","stream_plugin_running":"","new_section_id":"","remove_query_id":"","execute_display_name":""},"status":"","sender_id":"7366504662972760100","content_time":0,"message_index":"0","source":0},"is_finish":true,"index":4,"conversation_id":"7366503630755315712","seq_id":77}

文档信息

Search

    Table of Contents