Skip to content

Commit

Permalink
support load_env
Browse files Browse the repository at this point in the history
  • Loading branch information
kennymckormick committed Mar 19, 2024
1 parent db460d1 commit 39037dd
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 1 deletion.
7 changes: 7 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Development Setting
INTERNAL=
ALLES=
DASHSCOPE_API_KEY=
GOOGLE_API_KEY=
OPENAI_API_KEY=
OPENAI_API_BASE=
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ celerybeat.pid
*.sage.py

# Environments
.env
# .env
.venv
env/
venv/
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pandas>=1.5.3
pillow
portalocker
pycocoevalcap
python-dotenv
requests
rich
seaborn
Expand Down
1 change: 1 addition & 0 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,5 @@ def main():


if __name__ == '__main__':
load_env()
main()
2 changes: 2 additions & 0 deletions vlmeval/evaluate/misc.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import os
from vlmeval.api import OpenAIWrapper, OpenAIWrapperInternal
from vlmeval.smp import load_env

INTERNAL = os.environ.get('INTERNAL', 0)


def build_judge(version, **kwargs):
load_env()
model_map = {
'gpt-4-turbo': 'gpt-4-1106-preview',
'gpt-4-0613': 'gpt-4-0613',
Expand Down
21 changes: 21 additions & 0 deletions vlmeval/smp/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,24 @@ def run_command(cmd):
if isinstance(cmd, str):
cmd = cmd.split()
return subprocess.check_output(cmd)

def load_env():
try:
import vlmeval
except ImportError:
warnings.warn('VLMEval is not installed. Failed to import environment variables from .env file. ')
return
pth = osp.realpath(vlmeval.__path__)
pth = osp.join('../.env')
pth = osp.realpath(pth)
if not osp.exists(pth):
warnings.warn(f'Did not detect the .env file at {pth}, failed to load. ')
return

from dotenv import dotenv_values
values = dotenv_values(pth)
for k, v in values.items():
if v is not None and len(v):
os.environ[k] = v
print(f'API Keys successfully loaded from {pth}')
return

0 comments on commit 39037dd

Please sign in to comment.