Skip to content

Commit

Permalink
refactor: class CustomConfigs as a singleton and add aws s3 bucket su…
Browse files Browse the repository at this point in the history
…pport
  • Loading branch information
lpm0073 committed Jan 26, 2024
1 parent 79744f6 commit 5cdc0bf
Show file tree
Hide file tree
Showing 7 changed files with 237 additions and 51 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ PIP := $(PYTHON) -m pip
ifneq ("$(wildcard .env)","")
include .env
else
$(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)
$(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)
endif

.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
Expand Down
10 changes: 10 additions & 0 deletions api/terraform/python/openai_api/common/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ class SettingsDefaults:
GOOGLE_MAPS_API_KEY: str = TFVARS.get("google_maps_api_key", None)

LANGCHAIN_MEMORY_KEY = "chat_history"
SETTINGS_AWS_S3_BUCKET: str = None
OPENAI_API_ORGANIZATION: str = None
OPENAI_API_KEY = SecretStr(None)
OPENAI_ENDPOINT_IMAGE_N = 4
Expand Down Expand Up @@ -357,6 +358,7 @@ def __init__(self, **data: Any): # noqa: C901
env="GOOGLE_MAPS_API_KEY",
)
langchain_memory_key: Optional[str] = Field(SettingsDefaults.LANGCHAIN_MEMORY_KEY, env="LANGCHAIN_MEMORY_KEY")
settings_aws_bucket: Optional[str] = Field(SettingsDefaults.SETTINGS_AWS_S3_BUCKET, env="SETTINGS_AWS_S3_BUCKET")
openai_api_organization: Optional[str] = Field(
SettingsDefaults.OPENAI_API_ORGANIZATION, env="OPENAI_API_ORGANIZATION"
)
Expand Down Expand Up @@ -564,6 +566,7 @@ def get_installed_packages():
"google_maps_api_key": self.google_maps_api_key,
},
"openai_api": {
"settings_aws_bucket": self.settings_aws_bucket,
"langchain_memory_key": self.langchain_memory_key,
"openai_endpoint_image_n": self.openai_endpoint_image_n,
"openai_endpoint_image_size": self.openai_endpoint_image_size,
Expand Down Expand Up @@ -688,6 +691,13 @@ def check_langchain_memory_key(cls, v) -> str:
return SettingsDefaults.LANGCHAIN_MEMORY_KEY
return v

@field_validator("settings_aws_bucket")
def check_lambda_openai_function_config_url(cls, v) -> str:
"""Check settings_aws_bucket"""
if v in [None, ""]:
return SettingsDefaults.SETTINGS_AWS_S3_BUCKET
return v

@field_validator("openai_api_organization")
def check_openai_api_organization(cls, v) -> str:
"""Check openai_api_organization"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from openai_api.common.const import PYTHON_ROOT
from openai_api.lambda_openai_function.natural_language_processing import does_refer_to
from openai_api.lambda_openai_function.refers_to import RefersTo
from openai_api.lambda_openai_function.refers_to import CustomConfig
from openai_api.lambda_openai_function.refers_to import config as refers_to_config


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


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

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


def info_tool_factory(config: RefersTo):
def info_tool_factory(config: CustomConfig):
"""
Return a dictionary of chat completion tools.
"""
Expand Down
Loading

0 comments on commit 5cdc0bf

Please sign in to comment.