开发者社区 > 百炼大模型 > 正文

阿里云百炼有http调用的示例吗?java或者python或者 js都可以。

阿里云百炼有http调用的示例吗?java或者python或者 js都可以。

展开
收起
三分钟热度的鱼 2024-07-11 08:55:32 46 0
3 条回答
写回答
取消 提交回答
  • 乘风破浪

    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)

    2024-07-22 10:05:56
    赞同 展开评论 打赏
  • 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/

    2024-07-11 11:02:32
    赞同 4 展开评论 打赏
  • 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)
    

    打印响应内容
    print(response.text) 此回答整理自钉群“阿里云百炼使用体验”

    2024-07-11 09:18:11
    赞同 3 展开评论 打赏

基于通义系列大模型和开源大模型的一站式大模型服务平台,提供「生成式大模型的全流程应用工具」和「企业大模型的全链路训练工具」。为大模型,也为小应用。

相关电子书

更多
JavaScript异步编程 立即下载
Delivering Javascript to World 立即下载
编程语言如何演化-以JS的private为例 立即下载