From 30e3f01e7fa547dc94dd11328e3b74d2ff6e6a6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Bj=C3=A4reholt?= Date: Wed, 16 Oct 2024 14:19:10 +0200 Subject: [PATCH] fix: change OPENAI_API_BASE to OPENAI_BASE_URL --- docs/providers.md | 2 +- gptme/llm_openai.py | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/docs/providers.md b/docs/providers.md index 84706d17..4a35576a 100644 --- a/docs/providers.md +++ b/docs/providers.md @@ -49,5 +49,5 @@ You first need to install `ollama`, then you can run it with: ```sh ollama pull llama3.2:1b ollama serve -OPENAI_API_BASE="http://127.0.0.1:11434/v1" gptme 'hello' -m local/llama3.2:1b +OPENAI_BASE_URL="http://127.0.0.1:11434/v1" gptme 'hello' -m local/llama3.2:1b ``` diff --git a/gptme/llm_openai.py b/gptme/llm_openai.py index b4ed082c..8c354be9 100644 --- a/gptme/llm_openai.py +++ b/gptme/llm_openai.py @@ -2,6 +2,7 @@ from collections.abc import Generator from typing import TYPE_CHECKING +from .config import Config from .constants import TEMPERATURE, TOP_P from .message import Message, msgs2dicts @@ -20,7 +21,7 @@ } -def init(llm: str, config): +def init(llm: str, config: Config): global openai from openai import AzureOpenAI, OpenAI # fmt: skip @@ -39,7 +40,11 @@ def init(llm: str, config): api_key = config.get_env_required("OPENROUTER_API_KEY") openai = OpenAI(api_key=api_key, base_url="https://openrouter.ai/api/v1") elif llm == "local": - api_base = config.get_env_required("OPENAI_API_BASE") + # OPENAI_API_BASE renamed to OPENAI_BASE_URL: https://github.com/openai/openai-python/issues/745 + api_base = config.get_env("OPENAI_API_BASE") + api_base = api_base or config.get_env("OPENAI_BASE_URL") + if not api_base: + raise KeyError("Missing environment variable OPENAI_BASE_URL") api_key = config.get_env("OPENAI_API_KEY") or "ollama" openai = OpenAI(api_key=api_key, base_url=api_base) else: