初始化提交
This commit is contained in:
88
zhipu_api.ipynb
Normal file
88
zhipu_api.ipynb
Normal file
@@ -0,0 +1,88 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"end_time": "2025-02-09T14:07:16.031829Z",
|
||||
"start_time": "2025-02-09T14:07:14.303357Z"
|
||||
}
|
||||
},
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"from zhipuai import ZhipuAI\n",
|
||||
"\n",
|
||||
"client = ZhipuAI(api_key=\"d1e97306540d12bb2f834be961fcacb1.SNBShlCxWYJCx0qZ\")\n",
|
||||
"\n",
|
||||
"completion = client.chat.completions.create(\n",
|
||||
" model=\"glm-4-flash\",\n",
|
||||
" messages=[\n",
|
||||
" {\"role\": \"user\", \"content\": \"你好,世界!\"},\n",
|
||||
" ],\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"print(completion.choices[0].message.content)"
|
||||
],
|
||||
"id": "5c31cf5e65b29021",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"你好🌍!很高兴见到你,有什么可以帮助你的吗?\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"execution_count": 1
|
||||
},
|
||||
{
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"end_time": "2025-02-09T14:09:26.966550Z",
|
||||
"start_time": "2025-02-09T14:09:19.468942Z"
|
||||
}
|
||||
},
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"# 图片生成\n",
|
||||
"response = client.images.generations(\n",
|
||||
" model=\"cogview-3-flash\", #填写需要调用的模型编码\n",
|
||||
" prompt=\"正在高考的高考考场\",\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"print(response.data[0].url)"
|
||||
],
|
||||
"id": "51c384f791c2befb",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"https://aigc-files.bigmodel.cn/api/cogview/20250209220928a7b73b91d06a4206_0.png\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"execution_count": 4
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 2
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython2",
|
||||
"version": "2.7.6"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
||||
Reference in New Issue
Block a user