阅读量:1
豆包python大语言模型库安装指令:
pip install volcengine-python-sdk
报错:
note: This error originates from a subprocess, and is likely not a problem with pip. ERROR: Failed building wheel for volcengine-python-sdk Running setup.py clean for volcengine-python-sdk Failed to build volcengine-python-sdk ERROR: ERROR: Failed to build installable wheels for some pyproject.toml based projects (volcengine-python-sdk)
联系官方,官方说自己那边可以正常安装 。
这不就奇怪了吗?!
然后想了一下,直接手动下载安装吧!
打开pypi.org,搜索:volcengine-python-sd
下载到本地,解压缩,放到pycharm的虚拟环境下面,路径:venv/Lib/site-packages
当我们去调用官方给的示例的时候会出错,提示有些库没有安装,这个时候,我们再在pycharm中执行一下下面的安装库方法。
pip install volcengine-python-sdk
豆包SDK依赖的库会自动安装上。
上面解决了依赖库的问题,下面我们还需要在头条大模型后台设置几个内容。
先设置一下api访问密钥,访问下面网址:
https://console.volcengine.com/iam/keymanage/
获取到
Access_Key_ID, Secret_Access_Key
访问下面网址,获取apikey:
https://console.volcengine.com/ark/region:ark+cn-beijing/apiKey
获取到apikey 。
访问下面网址获取model:
https://console.volcengine.com/ark/region:ark+cn-beijing/endpoint?current=1&pageSize=10
新建推理模型,获取到调用模型,model
我们还需要开通一下,我们调用的模型:
访问下面网址:
https://console.volcengine.com/ark/region:ark+cn-beijing/openManagement
python 调用示例代码方法:
from volcenginesdkarkruntime import Ark def get_doubao_api(api_key, Access_Key_ID, Secret_Access_Key, prompt): try: client = Ark(api_key=api_key, ak=Access_Key_ID, sk=Secret_Access_Key) completion = client.chat.completions.create( model="ep-20240624053151-fj4hp", messages=[ {"role": "system", "content": "你是豆包,是由字节跳动开发的 AI 人工智能助手"}, {"role": "user", "content": prompt}, ], ) return completion.choices[0].message.content except Exception as e: return e
官方的python api文档入口: