You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Azure OpenAI在GitHub Codespace报错:RetryError[APIRemovedInV1]

Azure OpenAI在GitHub Codespace Jupyter Notebook报错排查

问题概述

相同代码在Google Colab运行正常,但在GitHub Codespace的Jupyter Notebook中执行时触发错误,报错信息显示RetryError[<Future at 0x7efc140416f0 state=finished raised APIRemovedInV1>]。

代码详情

访问凭据

import os
from dotenv import load_dotenv, find_dotenv

load_dotenv(find_dotenv())

api_key = os.environ.get("OPENAI_API_KEY")
api_base = os.environ.get("OPENAI_API_BASE")
api_version = os.environ.get("OPENAI_API_VERSION")
api_type = os.environ.get("OPENAI_API_BASE")  # 此处存在错误

print(f'API_KEY: {api_key}')
print(f'API BASE: {api_base}')
print(f'API VERSION: {api_version}')
print(f'API TYPE: {api_type}')

定义LLM模型

from promptify import Prompter, OpenAI, Pipeline, Azure

model = Azure(api_key=api_key, api_base=api_base, api_version=api_version, api_type=api_type, engine='gpt-35-turbo')
prompter = Prompter('multilabel_classification.jinja')
pipe = Pipeline(prompter , model)

# 示例文本
sent = "The patient is a 93-year-old female with a medical history of chronic right hip pain, \
    osteoporosis, hypertension, depression, and chronic atrial fibrillation admitted for evaluation \
        and management of severe nausea and vomiting and urinary tract infection"
print(sent)

多标签分类执行代码

result = pipe.fit(n_output_labels = 5,
                  domain          = 'clinical',
                  text_input      = sent,
                  labels          = None)

# 输出结果
result

报错信息

0%| | 0/1 [00:13<?, ?it/s]
Error in model execution: RetryError[<Future at 0x7efc140416f0 state=finished raised APIRemovedInV1>]

解决方案

  • 修正API类型赋值错误:代码中api_type错误地获取了OPENAI_API_BASE变量的值,应改为获取OPENAI_API_TYPE:

    api_type = os.environ.get("OPENAI_API_TYPE")
    

    确保.env文件中OPENAI_API_TYPE设置为azure(Azure OpenAI对应的类型值)。

  • 同步环境变量配置:检查GitHub Codespace中的.env文件,确保所有Azure OpenAI相关变量(OPENAI_API_KEY、OPENAI_API_BASE、OPENAI_API_VERSION、OPENAI_API_TYPE)和Colab中的配置完全一致。

  • 升级promptify库:旧版本库可能存在API兼容问题,执行以下命令更新到最新版本:

    pip install --upgrade promptify
    
  • 验证API版本兼容性:确认使用的api_version是Azure OpenAI当前支持的版本(如2023-05-15或更新),避免使用已被移除的旧版API。

内容的提问来源于stack exchange,提问作者林抿均

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.05 16:07:49