-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel_manager.py
45 lines (34 loc) · 1.21 KB
/
model_manager.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
"""
This file contains the implementation of the OpenAIModelManager class, which acts as a manager for OpenAI-based models.
The module provides functionalities for:
- Validating and managing OpenAI API keys.
- Initializing helpers for text-based and document-based interactions.
- Managing integrations with OpenAI and LangChain.
"""
from helpers.openai_helper import OpenAIHelper
from helpers.langchain_helper import LangChainHelper
from langchain_openai import OpenAIEmbeddings
class OpenAIModelManager():
"""
A manager class for handling OpenAI models and associated functionalities.
"""
def __init__(self, api_key):
"""
Initialize the OpenAIModelManager class.
Args:
api_key (str): The OpenAI API key for authentication.
Returns:
None
"""
self.model = OpenAIHelper(api_key)
self.lang_model = LangChainHelper(self.model, OpenAIEmbeddings(api_key=api_key))
self._validate_api_key()
def _validate_api_key(self):
"""
Validate the provided OpenAI API key.
Raises:
Exception: If the API key is invalid.
Returns:
None
"""
self.model.check_api_key()