Skip to content

Commit 5cdc0bf

Browse files
committed
refactor: class CustomConfigs as a singleton and add aws s3 bucket support
1 parent 79744f6 commit 5cdc0bf

File tree

7 files changed

+237
-51
lines changed

7 files changed

+237
-51
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ PIP := $(PYTHON) -m pip
1414
ifneq ("$(wildcard .env)","")
1515
include .env
1616
else
17-
$(shell echo -e "OPENAI_API_ORGANIZATION=PLEASE-ADD-ME\nOPENAI_API_KEY=PLEASE-ADD-ME\nPINECONE_API_KEY=PLEASE-ADD-ME\nPINECONE_ENVIRONMENT=gcp-starter\nGOOGLE_MAPS_API_KEY=PLEASE-ADD-ME\nDEBUG_MODE=True\n" >> .env)
17+
$(shell echo -e "OPENAI_API_ORGANIZATION=PLEASE-ADD-ME\nOPENAI_API_KEY=PLEASE-ADD-ME\nPINECONE_API_KEY=PLEASE-ADD-ME\nPINECONE_ENVIRONMENT=gcp-starter\nGOOGLE_MAPS_API_KEY=PLEASE-ADD-ME\nDEBUG_MODE=True\SETTINGS_AWS_S3_BUCKET=PLEASE-ADD-ME\n" >> .env)
1818
endif
1919

2020
.PHONY: analyze pre-commit api-init api-activate api-lint api-clean api-test client-init client-lint client-update client-run client-build client-release

api/terraform/python/openai_api/common/conf.py

+10
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ class SettingsDefaults:
170170
GOOGLE_MAPS_API_KEY: str = TFVARS.get("google_maps_api_key", None)
171171

172172
LANGCHAIN_MEMORY_KEY = "chat_history"
173+
SETTINGS_AWS_S3_BUCKET: str = None
173174
OPENAI_API_ORGANIZATION: str = None
174175
OPENAI_API_KEY = SecretStr(None)
175176
OPENAI_ENDPOINT_IMAGE_N = 4
@@ -357,6 +358,7 @@ def __init__(self, **data: Any): # noqa: C901
357358
env="GOOGLE_MAPS_API_KEY",
358359
)
359360
langchain_memory_key: Optional[str] = Field(SettingsDefaults.LANGCHAIN_MEMORY_KEY, env="LANGCHAIN_MEMORY_KEY")
361+
settings_aws_bucket: Optional[str] = Field(SettingsDefaults.SETTINGS_AWS_S3_BUCKET, env="SETTINGS_AWS_S3_BUCKET")
360362
openai_api_organization: Optional[str] = Field(
361363
SettingsDefaults.OPENAI_API_ORGANIZATION, env="OPENAI_API_ORGANIZATION"
362364
)
@@ -564,6 +566,7 @@ def get_installed_packages():
564566
"google_maps_api_key": self.google_maps_api_key,
565567
},
566568
"openai_api": {
569+
"settings_aws_bucket": self.settings_aws_bucket,
567570
"langchain_memory_key": self.langchain_memory_key,
568571
"openai_endpoint_image_n": self.openai_endpoint_image_n,
569572
"openai_endpoint_image_size": self.openai_endpoint_image_size,
@@ -688,6 +691,13 @@ def check_langchain_memory_key(cls, v) -> str:
688691
return SettingsDefaults.LANGCHAIN_MEMORY_KEY
689692
return v
690693

694+
@field_validator("settings_aws_bucket")
695+
def check_lambda_openai_function_config_url(cls, v) -> str:
696+
"""Check settings_aws_bucket"""
697+
if v in [None, ""]:
698+
return SettingsDefaults.SETTINGS_AWS_S3_BUCKET
699+
return v
700+
691701
@field_validator("openai_api_organization")
692702
def check_openai_api_organization(cls, v) -> str:
693703
"""Check openai_api_organization"""

api/terraform/python/openai_api/lambda_openai_function/function_refers_to.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from openai_api.common.const import PYTHON_ROOT
99
from openai_api.lambda_openai_function.natural_language_processing import does_refer_to
10-
from openai_api.lambda_openai_function.refers_to import RefersTo
10+
from openai_api.lambda_openai_function.refers_to import CustomConfig
1111
from openai_api.lambda_openai_function.refers_to import config as refers_to_config
1212

1313

@@ -34,7 +34,7 @@ def search_terms_are_in_messages(messages: list, search_terms: list = None, sear
3434
return False
3535

3636

37-
def customized_prompt(config: RefersTo, messages: list) -> list:
37+
def customized_prompt(config: CustomConfig, messages: list) -> list:
3838
"""Modify the system prompt based on the custom configuration object"""
3939

4040
for i, message in enumerate(messages):
@@ -65,7 +65,7 @@ def get_additional_info(inquiry_type: str) -> str:
6565
raise KeyError(f"Invalid inquiry_type: {inquiry_type}")
6666

6767

68-
def info_tool_factory(config: RefersTo):
68+
def info_tool_factory(config: CustomConfig):
6969
"""
7070
Return a dictionary of chat completion tools.
7171
"""

0 commit comments

Comments
 (0)