config.py 968 B

123456789101112131415161718192021222324252627282930
  1. import os
  2. from openai import OpenAI
  3. # ==================================================================================================
  4. # OPENAI
  5. # TODO: Move this to EventStream Actions when EventStreamRuntime is fully implemented
  6. # NOTE: we need to get env vars inside functions because they will be set in IPython
  7. # AFTER the agentskills is imported (the case for EventStreamRuntime)
  8. # ==================================================================================================
  9. def _get_openai_api_key():
  10. return os.getenv('OPENAI_API_KEY', os.getenv('SANDBOX_ENV_OPENAI_API_KEY', ''))
  11. def _get_openai_base_url():
  12. return os.getenv('OPENAI_BASE_URL', 'https://api.openai.com/v1')
  13. def _get_openai_model():
  14. return os.getenv('OPENAI_MODEL', 'gpt-4o')
  15. def _get_max_token():
  16. return os.getenv('MAX_TOKEN', 500)
  17. def _get_openai_client():
  18. client = OpenAI(api_key=_get_openai_api_key(), base_url=_get_openai_base_url())
  19. return client