Files

1 line
1.6 KiB
JSON
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
{"repo": "aigclink/aigc-search", "files": {"glm-4-long.py": {"09b5bce1964c33d18493052de3d484d1b2ade3c7": {"t": 1785674168.7260768, "n": 1197, "h": "d1b22d4fdb96bc0f", "c": "import requests\nimport uuid\nfrom zhipuai import ZhipuAI\nimport streamlit as st\n\n\napi_key = \"你的API-key\"\n\ndef run_v4_sync(input):\n msg = [\n {\n \"role\": \"user\",\n \"content\":input\n }\n ]\n tool = \"web-search-pro\"\n url = \"https://open.bigmodel.cn/api/paas/v4/tools\"\n request_id = str(uuid.uuid4())\n data = {\n \"request_id\": request_id,\n \"tool\": tool,\n \"stream\": False,\n \"messages\": msg\n }\n\n resp = requests.post(\n url,\n json=data,\n headers={'Authorization': api_key},\n timeout=300\n )\n return resp.content.decode()\n\n\n\ndef glmlong(m):\n client = ZhipuAI(api_key=api_key) # 填写您自己的APIKey\n x=run_v4_sync(m)\n response = client.chat.completions.create(\n model=\"glm-4-long\", # 填写需要调用的模型编码\n messages=[\n {\"role\": \"system\", \"content\": \"你是一个搜索内容整合专家助手,你的任务是针对用户搜索内容提供1000字的概括总结,并且备注来源网址。\"},\n {\"role\": \"user\", \"content\": x}\n ],\n stream=False,\n )\n return response.choices[0].message.content\n\nif __name__ == '__main__':\n st.title(\"AIGCLINK:glm-4-long+websearch构建AI搜索最小用例\")\n user_input = st.text_input(\"输入一些文本:\")\n st.write(glmlong(user_input))"}}}}