Skip to content

Commit

Permalink
fix: change OPENAI_API_BASE to OPENAI_BASE_URL
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikBjare committed Oct 16, 2024
1 parent f735111 commit 30e3f01
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/providers.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
9 changes: 7 additions & 2 deletions gptme/llm_openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -20,7 +21,7 @@
}


def init(llm: str, config):
def init(llm: str, config: Config):
global openai
from openai import AzureOpenAI, OpenAI # fmt: skip

Expand All @@ -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:
Expand Down

0 comments on commit 30e3f01

Please sign in to comment.