佛洛依德冰山理论

“本我” 代表欲望,受意识遏抑, (完全潜意识)
“自我” 负责处理现实世界的事情; (大部分有意识)
“超我” 是良知或内在的道德判断。 (部分有意识)

豆包代写的代码

import requests
import json
import sys

url = 'http://x.x.x.x/v1/chat-messages'
headers = {
  'Authorization': 'Bearer app-KT4yNocX6Bzey6mZ5Jxxxx',
    'Content-Type': 'application/json'
}
conversation_id = ""

while True:
    try:
        # 获取系统默认编码
        encoding = sys.getdefaultencoding()
        query = input("请输入你的问题(输入 '退出' 结束对话):").encode(encoding).decode(encoding)
        if query == "退出":
            break

        data = {
            "inputs": {},
            "query": query,
            "response_mode": "streaming",
            "conversation_id": conversation_id,
            "user": "ts",
            "files": [
                {
                    "type": "image",
                    "transfer_method": "remote_url",
                    "url": "https://cloud.dify.ai/logo/logo-site.png"
                }
            ]
        }

        try:
            response = requests.post(url, headers=headers, json=data, stream=True)
            response.raise_for_status()

            full_response = []
            full_api_response = []
            for chunk in response.iter_lines(decode_unicode=True):
                if chunk.startswith('data:'):
                    chunk_data = chunk[5:].strip()
                    if chunk_data:
                        full_api_response.append(chunk_data)
                        try:
                            event = json.loads(chunk_data)
                            if event.get('event') == 'message':
                                answer = event.get('answer', '')
                                print(answer, end='', flush=True)
                                full_response.append(answer)
                            elif event.get('event') == 'message_end':
                                print()
                                final_answer = ''.join(full_response)
                                print(f"完整回复: {final_answer}")
                                conversation_id = event.get('conversation_id', conversation_id)
                        except json.JSONDecodeError:
                            print(f"解析错误: {chunk_data}")
            print("\nAPI 接口返回的完整信息:")
            for line in full_api_response:
                print(line)

        except requests.exceptions.RequestException as e:
            print(f"请求错误: {e}")
    except UnicodeDecodeError:
        print("输入解码时出现错误,请检查终端编码设置。")