Skip to content

Commit

Permalink
Added openai client to config
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Panchenko committed May 22, 2024
1 parent f9d4bfa commit ee6b018
Show file tree
Hide file tree
Showing 5 changed files with 168 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
### Development:

- Initial setup by python-library-template
asds

3 changes: 2 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
"visualizations": "./data/visualizations",
"artifacts": "./data/artifacts",
"temp": "./temp",
"data": "./data"
"data": "./data",
"openai_api_key": "env:OPENAI_API_KEY"
}
157 changes: 156 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ exclude = ["test/*", "examples/*", "docs/*"]
[tool.poetry.dependencies]
python = "^3.11"
accsr = "^0.4.6"
openai = "^1.30.1"
pandas = "^2.2.1"
plotly = "^5.19.0"

Expand Down
9 changes: 8 additions & 1 deletion src/penai/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,23 @@
"""

import os
from typing import cast

from accsr.config import ConfigProviderBase, DefaultDataConfiguration
from openai import OpenAI

file_dir = os.path.dirname(__file__) if "__file__" in locals() else os.getcwd()

top_level_directory: str = os.path.abspath(os.path.join(file_dir, os.pardir, os.pardir))


class __Configuration(DefaultDataConfiguration):
pass
@property
def openai_api_key(self) -> str:
return cast(str, self._get_non_empty_entry("openai_api_key"))

def get_openai_client(self, timeout: int = 100):
return OpenAI(api_key=self.openai_api_key, timeout=timeout)


class ConfigProvider(ConfigProviderBase[__Configuration]):
Expand Down

0 comments on commit ee6b018

Please sign in to comment.