阿里云百炼有http调用的示例吗?java或者python或者 js都可以。
import requests
url = 'https://dashscope.aliyuncs.com/compatible-mode/v1/files'
api_key = ''
file_path = './test.txt'
headers = {
'Authorization': f'Bearer {api_key}',
}
with open(file_path, 'rb') as file:
files = {
'file': ('test.txt', file),
'purpose': ('', 'file-extract'),
}
response = requests.post(url, headers=headers, files=files)
from pathlib import Path
from openai import OpenAI
client = OpenAI(
api_key="$your-dashscope-api-key",
base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
)
# data.pdf 是一个示例文件
file_object = client.files.create(file=Path("data.pdf"), purpose="file-extract")
参考来源https://help.aliyun.com/zh/dashscope/developer-reference/compatibility-of-openai-with-dashscope/
import requests
url = 'https://dashscope.aliyuncs.com/compatible-mode/v1/files'
api_key = '<your-dashscope-api-key>'
file_path = './test.txt'
headers = {
'Authorization': f'Bearer {api_key}',
}
with open(file_path, 'rb') as file:
files = {
'file': ('test.txt', file),
'purpose': ('', 'file-extract'),
}
response = requests.post(url, headers=headers, files=files)
# 打印响应内容
print(response.text)
此回答整理自钉群“阿里云百炼使用体验”
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。