Skip to content

Commit

Permalink
fix: properly handle Env from global and run options
Browse files Browse the repository at this point in the history
Signed-off-by: Donnie Adams <[email protected]>
  • Loading branch information
thedadams committed Sep 27, 2024
1 parent c965088 commit ac27732
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions gptscript/opts.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
from typing import Mapping, Self
from typing import Self


class GlobalOptions:
Expand All @@ -12,7 +12,7 @@ def __init__(
defaultModelProvider: str = "",
defaultModel: str = "",
cacheDir: str = "",
env: Mapping[str, str] = None,
env: list[str] = None,
):
self.URL = url
self.Token = token
Expand All @@ -22,9 +22,10 @@ def __init__(
self.DefaultModelProvider = defaultModelProvider
self.CacheDir = cacheDir
if env is None:
env = os.environ
env_list = [f"{k}={v}" for k, v in env.items()]
self.Env = env_list
env = [f"{k}={v}" for k, v in os.environ.items()]
elif isinstance(env, dict):
env = [f"{k}={v}" for k, v in env.items()]
self.Env = env

def merge(self, other: Self) -> Self:
cp = self.__class__()
Expand All @@ -37,7 +38,8 @@ def merge(self, other: Self) -> Self:
cp.DefaultModel = other.DefaultModel if other.DefaultModel != "" else self.DefaultModel
cp.DefaultModelProvider = other.DefaultModelProvider if other.DefaultModelProvider != "" else self.DefaultModelProvider
cp.CacheDir = other.CacheDir if other.CacheDir != "" else self.CacheDir
cp.Env = (other.Env or []).extend(self.Env or [])
cp.Env = (other.Env or [])
cp.Env.extend(self.Env or [])
return cp

def toEnv(self):
Expand Down Expand Up @@ -76,7 +78,7 @@ def __init__(self,
defaultModel: str = "",
cacheDir: str = "",
):
super().__init__(url, token, apiKey, baseURL, defaultModelProvider, defaultModel, cacheDir)
super().__init__(url, token, apiKey, baseURL, defaultModelProvider, defaultModel, cacheDir, env)
self.input = input
self.disableCache = disableCache
self.subTool = subTool
Expand All @@ -87,7 +89,6 @@ def __init__(self,
self.credentialOverrides = credentialOverrides
self.credentialContexts = credentialContexts
self.location = location
self.env = env
self.forceSequential = forceSequential

def merge_global_opts(self, other: GlobalOptions) -> Self:
Expand All @@ -104,6 +105,5 @@ def merge_global_opts(self, other: GlobalOptions) -> Self:
cp.credentialOverrides = self.credentialOverrides
cp.credentialContexts = self.credentialContexts
cp.location = self.location
cp.env = self.env
cp.forceSequential = self.forceSequential
return cp

0 comments on commit ac27732

Please sign in to comment.