Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Inconsistent base_url behavior with module client and OpenAIClient

未关闭
#1,373 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@SmartManoj 已经在做这个了。

开始于 2025年3月2日。

  • #2157 来自 @SmartManoj —— 未关闭
  • #2990 来自 @LittleChenLiya —— 已关闭,未合并

评估

难度
3/5
预计耗时
1-2 天
新手友好度
48/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
python
领域
api

调研方向

首先追踪 module client 和 OpenAI client 如何处理 base_url,并使用两个复现代码片段进行行为对比。让两个客户端在 base URL 缺少末尾斜杠时构造出相同的有效 completion URL,然后验证两条调用路径生成一致的请求。

由索引模型根据 Issue 内容生成。

描述

bug sdk
Confirm this is an issue with the Python library and not an underlying OpenAI API
  • This is an issue with the Python library
Describe the bug

The issue is that the base_url in the OpenAI client enforces a trailing slash whereas setting the module openai.base_url does not enforce.

This is 100% reproducible and while it can be worked around, the inconsistency in clients causes issues in scripts that use both clients.

To Reproduce
  1. Create a module client and use a base_url without a trailing slash. See error with URL for completions
  2. Create an OpenAIClient and use a base_url without a trailing slash. See no erros.
Code snippets

This works

    client = openai.OpenAI(
        api_key=my_key,
        base_url="https://myllmserver.com/api/v1"
    )
    print(client.completions.create(
       model="mistralai/Mistral-7B-Instruct-v0.2",
       prompt="test" 
    ))

This does not:

    openai.base_url="https://myllmserver.com/api/v1"
    openai.api_key=my_key
    print(openai.completions.create(
       model="mistralai/Mistral-7B-Instruct-v0.2",
       prompt="test"
    ))

Error:

https://myllmserver.com/api/v1completions "HTTP/1.1 404 Not Found"
OS

macOS

Python version

Python v3.12

Library version

openai v1.23.6

主要语言
Python
星标
31.8k
派生
7.3k
平均合并
1 天 3 小时
30 天内合并 PR
131

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

openai/openai-python 的其他 Issue

查看 openai/openai-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。