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

2024-06-16 17:12

本文主要是介绍ChatGPT 网页会话过程数据传输分析以及横向对比,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

新建一个会话

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}

在这里插入图片描述

这篇关于ChatGPT 网页会话过程数据传输分析以及横向对比的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1067046

相关文章

SpringBoot 整合 Grizzly的过程

《SpringBoot整合Grizzly的过程》Grizzly是一个高性能的、异步的、非阻塞的HTTP服务器框架,它可以与SpringBoot一起提供比传统的Tomcat或Jet... 目录为什么选择 Grizzly?Spring Boot + Grizzly 整合的优势添加依赖自定义 Grizzly 作为

Redis主从/哨兵机制原理分析

《Redis主从/哨兵机制原理分析》本文介绍了Redis的主从复制和哨兵机制,主从复制实现了数据的热备份和负载均衡,而哨兵机制可以监控Redis集群,实现自动故障转移,哨兵机制通过监控、下线、选举和故... 目录一、主从复制1.1 什么是主从复制1.2 主从复制的作用1.3 主从复制原理1.3.1 全量复制

Ubuntu系统怎么安装Warp? 新一代AI 终端神器安装使用方法

《Ubuntu系统怎么安装Warp?新一代AI终端神器安装使用方法》Warp是一款使用Rust开发的现代化AI终端工具,该怎么再Ubuntu系统中安装使用呢?下面我们就来看看详细教程... Warp Terminal 是一款使用 Rust 开发的现代化「AI 终端」工具。最初它只支持 MACOS,但在 20

mysql-8.0.30压缩包版安装和配置MySQL环境过程

《mysql-8.0.30压缩包版安装和配置MySQL环境过程》该文章介绍了如何在Windows系统中下载、安装和配置MySQL数据库,包括下载地址、解压文件、创建和配置my.ini文件、设置环境变量... 目录压缩包安装配置下载配置环境变量下载和初始化总结压缩包安装配置下载下载地址:https://d

Redis主从复制的原理分析

《Redis主从复制的原理分析》Redis主从复制通过将数据镜像到多个从节点,实现高可用性和扩展性,主从复制包括初次全量同步和增量同步两个阶段,为优化复制性能,可以采用AOF持久化、调整复制超时时间、... 目录Redis主从复制的原理主从复制概述配置主从复制数据同步过程复制一致性与延迟故障转移机制监控与维

springboot整合gateway的详细过程

《springboot整合gateway的详细过程》本文介绍了如何配置和使用SpringCloudGateway构建一个API网关,通过实例代码介绍了springboot整合gateway的过程,需要... 目录1. 添加依赖2. 配置网关路由3. 启用Eureka客户端(可选)4. 创建主应用类5. 自定

Redis连接失败:客户端IP不在白名单中的问题分析与解决方案

《Redis连接失败:客户端IP不在白名单中的问题分析与解决方案》在现代分布式系统中,Redis作为一种高性能的内存数据库,被广泛应用于缓存、消息队列、会话存储等场景,然而,在实际使用过程中,我们可能... 目录一、问题背景二、错误分析1. 错误信息解读2. 根本原因三、解决方案1. 将客户端IP添加到Re

最新版IDEA配置 Tomcat的详细过程

《最新版IDEA配置Tomcat的详细过程》本文介绍如何在IDEA中配置Tomcat服务器,并创建Web项目,首先检查Tomcat是否安装完成,然后在IDEA中创建Web项目并添加Web结构,接着,... 目录配置tomcat第一步,先给项目添加Web结构查看端口号配置tomcat    先检查自己的to

Redis主从复制实现原理分析

《Redis主从复制实现原理分析》Redis主从复制通过Sync和CommandPropagate阶段实现数据同步,2.8版本后引入Psync指令,根据复制偏移量进行全量或部分同步,优化了数据传输效率... 目录Redis主DodMIK从复制实现原理实现原理Psync: 2.8版本后总结Redis主从复制实

锐捷和腾达哪个好? 两个品牌路由器对比分析

《锐捷和腾达哪个好?两个品牌路由器对比分析》在选择路由器时,Tenda和锐捷都是备受关注的品牌,各自有独特的产品特点和市场定位,选择哪个品牌的路由器更合适,实际上取决于你的具体需求和使用场景,我们从... 在选购路由器时,锐捷和腾达都是市场上备受关注的品牌,但它们的定位和特点却有所不同。锐捷更偏向企业级和专