# 使用Python调用coze
coze官方只提供了curl调用范例,未提供python调用接口。
一个有毅力的吃货花了些时间利用requests库进行了实现,封装成了coze这个python库。
支持流式输出,支持多轮对话。
## 一,安装coze库
```python
pip install coze
```
## 二,使用范例
```python
import os
from coze import Coze
os.environ['COZE_API_TOKEN'] = 'pat_xxx'
os.environ['COZE_BOT_ID'] = "7362845197946257419"
```
```python
chat = Coze(api_token= os.environ['COZE_API_TOKEN'],
bot_id = os.environ['COZE_BOT_ID'],
max_chat_rounds=20,
stream=True)
```
你好!有什么可以帮助你的?
register magic %%chat sucessed ...
可以使用__call__方法调用
```python
response = chat('北京最新的高级产品经理岗位有推荐吗')
```
```raw
call function: liepin-job_recommendation; args ={'address': '北京', 'jobName': '高级产品经理'}
北京近期推荐的高级产品经理岗位有以下几个,提供给对这一职业领域感兴趣的求职者:
1. 获客多 Hokdo公司提供产品经理和高级产品经理岗位,位于北京万泉河地区,产业属于计算机软件并且公司处于A轮融资阶段。提供的薪资为20-30k或25-35k,15个月薪资。招聘负责人是许先生。
2. 北京微云众网络科技有限公司招募的Futures Operations Director 职位涉及Web3 分布式产品运营,位于北京东四地区,公司规模100-499人,被标记具有较大的发展空间和国际化优势。
3. 美团是一个大规模的互联网生活服务公司,已上市,招聘的岗位是“企平-产品专家(工单平台方向)”和“财务科技-税务产品经理(海外税务方向)”,位于北京南法信,提出的薪资在30-60k和25-35k之间,均为15个月薪资。
以上职位都可以通过相应的跳转链接获取更详细的职位描述和申请方式。
```
在notebook中推荐使用jupyter魔法命令进行调用。
![](./data/coze_jupyter.png)
## 三,详细教程
参考 本项目下的 coze_tutorial.ipynb 文件
Raw data
{
"_id": null,
"home_page": "https://github.com/lyhue1991/coze",
"name": "coze",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.0",
"maintainer_email": null,
"keywords": "coze",
"author": "lyhue1991",
"author_email": "lyhue1991@163.com",
"download_url": "https://files.pythonhosted.org/packages/7f/e2/12e353a50e6450c56b0f5ebfd458de10ed94a0115612a53c81d7d0282c35/coze-0.0.1.tar.gz",
"platform": null,
"description": "# \u4f7f\u7528Python\u8c03\u7528coze\n\ncoze\u5b98\u65b9\u53ea\u63d0\u4f9b\u4e86curl\u8c03\u7528\u8303\u4f8b\uff0c\u672a\u63d0\u4f9bpython\u8c03\u7528\u63a5\u53e3\u3002\n\n\u4e00\u4e2a\u6709\u6bc5\u529b\u7684\u5403\u8d27\u82b1\u4e86\u4e9b\u65f6\u95f4\u5229\u7528requests\u5e93\u8fdb\u884c\u4e86\u5b9e\u73b0\uff0c\u5c01\u88c5\u6210\u4e86coze\u8fd9\u4e2apython\u5e93\u3002\n\n\u652f\u6301\u6d41\u5f0f\u8f93\u51fa\uff0c\u652f\u6301\u591a\u8f6e\u5bf9\u8bdd\u3002\n\n\n## \u4e00\uff0c\u5b89\u88c5coze\u5e93\n\n```python\npip install coze \n```\n\n## \u4e8c\uff0c\u4f7f\u7528\u8303\u4f8b\n\n\n```python\nimport os \nfrom coze import Coze \nos.environ['COZE_API_TOKEN'] = 'pat_xxx'\nos.environ['COZE_BOT_ID'] = \"7362845197946257419\"\n\n```\n\n\n```python\nchat = Coze(api_token= os.environ['COZE_API_TOKEN'],\n bot_id = os.environ['COZE_BOT_ID'],\n max_chat_rounds=20,\n stream=True)\n\n```\n\n\n\u4f60\u597d\uff01\u6709\u4ec0\u4e48\u53ef\u4ee5\u5e2e\u52a9\u4f60\u7684\uff1f\n\n\n register magic %%chat sucessed ...\n\n\n\u53ef\u4ee5\u4f7f\u7528__call__\u65b9\u6cd5\u8c03\u7528\n\n\n```python\nresponse = chat('\u5317\u4eac\u6700\u65b0\u7684\u9ad8\u7ea7\u4ea7\u54c1\u7ecf\u7406\u5c97\u4f4d\u6709\u63a8\u8350\u5417')\n```\n\n```raw\ncall function: liepin-job_recommendation; args ={'address': '\u5317\u4eac', 'jobName': '\u9ad8\u7ea7\u4ea7\u54c1\u7ecf\u7406'}\n\n\u5317\u4eac\u8fd1\u671f\u63a8\u8350\u7684\u9ad8\u7ea7\u4ea7\u54c1\u7ecf\u7406\u5c97\u4f4d\u6709\u4ee5\u4e0b\u51e0\u4e2a\uff0c\u63d0\u4f9b\u7ed9\u5bf9\u8fd9\u4e00\u804c\u4e1a\u9886\u57df\u611f\u5174\u8da3\u7684\u6c42\u804c\u8005\uff1a\n\n1. \u83b7\u5ba2\u591a Hokdo\u516c\u53f8\u63d0\u4f9b\u4ea7\u54c1\u7ecf\u7406\u548c\u9ad8\u7ea7\u4ea7\u54c1\u7ecf\u7406\u5c97\u4f4d\uff0c\u4f4d\u4e8e\u5317\u4eac\u4e07\u6cc9\u6cb3\u5730\u533a\uff0c\u4ea7\u4e1a\u5c5e\u4e8e\u8ba1\u7b97\u673a\u8f6f\u4ef6\u5e76\u4e14\u516c\u53f8\u5904\u4e8eA\u8f6e\u878d\u8d44\u9636\u6bb5\u3002\u63d0\u4f9b\u7684\u85aa\u8d44\u4e3a20-30k\u621625-35k\uff0c15\u4e2a\u6708\u85aa\u8d44\u3002\u62db\u8058\u8d1f\u8d23\u4eba\u662f\u8bb8\u5148\u751f\u3002\n\n2. \u5317\u4eac\u5fae\u4e91\u4f17\u7f51\u7edc\u79d1\u6280\u6709\u9650\u516c\u53f8\u62db\u52df\u7684Futures Operations Director \u804c\u4f4d\u6d89\u53caWeb3 \u5206\u5e03\u5f0f\u4ea7\u54c1\u8fd0\u8425\uff0c\u4f4d\u4e8e\u5317\u4eac\u4e1c\u56db\u5730\u533a\uff0c\u516c\u53f8\u89c4\u6a21100-499\u4eba\uff0c\u88ab\u6807\u8bb0\u5177\u6709\u8f83\u5927\u7684\u53d1\u5c55\u7a7a\u95f4\u548c\u56fd\u9645\u5316\u4f18\u52bf\u3002\n\n3. \u7f8e\u56e2\u662f\u4e00\u4e2a\u5927\u89c4\u6a21\u7684\u4e92\u8054\u7f51\u751f\u6d3b\u670d\u52a1\u516c\u53f8\uff0c\u5df2\u4e0a\u5e02\uff0c\u62db\u8058\u7684\u5c97\u4f4d\u662f\u201c\u4f01\u5e73-\u4ea7\u54c1\u4e13\u5bb6\uff08\u5de5\u5355\u5e73\u53f0\u65b9\u5411\uff09\u201d\u548c\u201c\u8d22\u52a1\u79d1\u6280-\u7a0e\u52a1\u4ea7\u54c1\u7ecf\u7406\uff08\u6d77\u5916\u7a0e\u52a1\u65b9\u5411\uff09\u201d\uff0c\u4f4d\u4e8e\u5317\u4eac\u5357\u6cd5\u4fe1\uff0c\u63d0\u51fa\u7684\u85aa\u8d44\u572830-60k\u548c25-35k\u4e4b\u95f4\uff0c\u5747\u4e3a15\u4e2a\u6708\u85aa\u8d44\u3002\n\n\u4ee5\u4e0a\u804c\u4f4d\u90fd\u53ef\u4ee5\u901a\u8fc7\u76f8\u5e94\u7684\u8df3\u8f6c\u94fe\u63a5\u83b7\u53d6\u66f4\u8be6\u7ec6\u7684\u804c\u4f4d\u63cf\u8ff0\u548c\u7533\u8bf7\u65b9\u5f0f\u3002\n```\n\n\u5728notebook\u4e2d\u63a8\u8350\u4f7f\u7528jupyter\u9b54\u6cd5\u547d\u4ee4\u8fdb\u884c\u8c03\u7528\u3002\n\n![](./data/coze_jupyter.png)\n\n\n## \u4e09\uff0c\u8be6\u7ec6\u6559\u7a0b\n\n\u53c2\u8003 \u672c\u9879\u76ee\u4e0b\u7684 coze_tutorial.ipynb \u6587\u4ef6\n",
"bugtrack_url": null,
"license": null,
"summary": "use coze api in python",
"version": "0.0.1",
"project_urls": {
"Homepage": "https://github.com/lyhue1991/coze"
},
"split_keywords": [
"coze"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "162dc879118ff8c4020d398f04d3ad997d11b8de37fa805e982f3b763c888564",
"md5": "2db46c9f9fc377d472e0edfa2c945bd0",
"sha256": "e8878d0881b0191535867e3cc3e99fe1b193cf1308c5e3790552525b8e116bd2"
},
"downloads": -1,
"filename": "coze-0.0.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "2db46c9f9fc377d472e0edfa2c945bd0",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.0",
"size": 4454,
"upload_time": "2024-06-30T14:00:38",
"upload_time_iso_8601": "2024-06-30T14:00:38.401175Z",
"url": "https://files.pythonhosted.org/packages/16/2d/c879118ff8c4020d398f04d3ad997d11b8de37fa805e982f3b763c888564/coze-0.0.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "7fe212e353a50e6450c56b0f5ebfd458de10ed94a0115612a53c81d7d0282c35",
"md5": "6521df5763588a2962fee8f47ee21e0b",
"sha256": "e8f00d761797902341c900ca0d6ef76323f56ce4f721cddb99b5993d10725629"
},
"downloads": -1,
"filename": "coze-0.0.1.tar.gz",
"has_sig": false,
"md5_digest": "6521df5763588a2962fee8f47ee21e0b",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.0",
"size": 4377,
"upload_time": "2024-06-30T14:00:40",
"upload_time_iso_8601": "2024-06-30T14:00:40.317028Z",
"url": "https://files.pythonhosted.org/packages/7f/e2/12e353a50e6450c56b0f5ebfd458de10ed94a0115612a53c81d7d0282c35/coze-0.0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-06-30 14:00:40",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "lyhue1991",
"github_project": "coze",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "coze"
}