Skip to content

Commit e9db918

Browse files
fix: Fixing the issue with the capturing of env variables (#13)
* fix: Fixing the issue with the capturing of env variables * chore: changelog update
1 parent 9f9f12d commit e9db918

File tree

5 files changed

+29
-4
lines changed

5 files changed

+29
-4
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. Dates are d
44

55
Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
66

7+
#### [v0.1.48](https://github.com/Portkey-AI/portkey-python-sdk/compare/v0.1.45...v0.1.48)
8+
9+
> 14 September 2023
10+
11+
- fix: cache age type fix [`#11`](https://github.com/Portkey-AI/portkey-python-sdk/pull/11)
12+
713
#### [v0.1.45](https://github.com/Portkey-AI/portkey-python-sdk/compare/v0.1.44...v0.1.45)
814

915
> 12 September 2023

portkey/__init__.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,14 @@
2121
TextCompletionChunk,
2222
)
2323
from portkey.version import VERSION
24+
from portkey.api_resources.global_constants import (
25+
PORTKEY_BASE_URL,
26+
PORTKEY_API_KEY_ENV,
27+
PORTKEY_PROXY_ENV,
28+
)
2429

25-
api_key = os.environ.get("PORTKEY_API_KEY", "")
26-
base_url = os.environ.get("PORTKEY_PROXY", "https://api.portkey.ai")
30+
api_key = os.environ.get(PORTKEY_API_KEY_ENV)
31+
base_url = os.environ.get(PORTKEY_PROXY_ENV, PORTKEY_BASE_URL)
2732
config: Optional[Config] = None
2833
mode: Optional[Union[Modes, ModesLiteral]] = None
2934
__version__ = VERSION

portkey/api_resources/global_constants.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,7 @@
2929
VERSION = "0.1.0"
3030
DEFAULT_TIMEOUT = 60
3131
PORTKEY_HEADER_PREFIX = "x-portkey-"
32+
PORTKEY_BASE_URL = "https://api.portkey.ai"
33+
34+
PORTKEY_API_KEY_ENV = "PORTKEY_API_KEY"
35+
PORTKEY_PROXY_ENV = "PORTKEY_PROXY"

portkey/api_resources/utils.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
MISSING_BASE_URL,
2424
MISSING_CONFIG_MESSAGE,
2525
MISSING_MODE_MESSAGE,
26+
PORTKEY_BASE_URL,
27+
PORTKEY_API_KEY_ENV,
28+
PORTKEY_PROXY_ENV,
2629
)
2730

2831

@@ -212,7 +215,7 @@ def parse_api_key(cls, api_key, values):
212215

213216
class ProviderOptions(Constructs):
214217
override_params: Optional[OverrideParams] = None
215-
218+
216219
@validator("cache_age", always=True)
217220
@classmethod
218221
def parse_cache_age(cls, cache_age):
@@ -473,12 +476,19 @@ def parse_llms(cls, llms):
473476
def default_api_key() -> str:
474477
if portkey.api_key:
475478
return portkey.api_key
479+
env_api_key = os.environ.get(PORTKEY_API_KEY_ENV, "")
480+
if env_api_key:
481+
return env_api_key
476482
raise ValueError(MISSING_API_KEY_ERROR_MESSAGE)
477483

478484

479485
def default_base_url() -> str:
480486
if portkey.base_url:
481487
return portkey.base_url
488+
489+
env_base_url = os.environ.get(PORTKEY_PROXY_ENV, PORTKEY_BASE_URL)
490+
if env_base_url:
491+
return env_base_url
482492
raise ValueError(MISSING_BASE_URL)
483493

484494

portkey/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
VERSION = "0.1.48"
1+
VERSION = "0.1.49"

0 commit comments

Comments
 (0)