Inconsistent base_url behavior with module client and OpenAIClient

Offen
#1,373 4 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

@SmartManoj arbeitet bereits daran.

Seit 02.3.2025.

  • #2157 von @SmartManoj — offen
  • #2990 von @LittleChenLiya — ohne Merge geschlossen

Bewertung

Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Anfängerfreundlichkeit
48/100
Issue-Typ
Bug
Klarheit
Größtenteils klar
Aktivitätsstatus
Veraltet
Tech-Stack
python
Bereich
api

Rechercherichtung

Beginne damit, nachzuverfolgen, wie base_url für module client und OpenAI client verarbeitet wird, und verwende die beiden Reproduktions-Snippets als Verhaltensvergleich. Lass beide Clients dieselbe gültige completion URL erzeugen, wenn die base URL keinen abschließenden Schrägstrich enthält, und überprüfe anschließend, dass die beiden Aufrufpfade konsistente Requests erzeugen.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

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

Vorherrschende Sprache
Python
Sterne
32k
Forks
7.3k
Ø Merge
16 Std. 38 Min.
Gemergte PRs (30 T.)
170

Entwicklungsumgebung

In Codespaces öffnen

Startet den Dev-Container des Projekts im Browser, mit Ihrem eigenen GitHub-Konto.

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus openai/openai-python

Alle Issues in openai/openai-python

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.