-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e895a98
commit 9872a18
Showing
9 changed files
with
117 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,8 @@ | |
export PYTHONPATH="/Users/sarah.lauzeral/Library/CloudStorage/[email protected]/Mon Drive/internal_projects/skaff-rag-accelerator/" | ||
``` | ||
|
||
```bash | ||
python "/Users/sarah.lauzeral/Library/CloudStorage/[email protected]/Mon Drive/internal_projects/skaff-rag-accelerator/backend/main.py" | ||
``` | ||
|
||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import os | ||
from pathlib import Path | ||
|
||
import yaml | ||
from dotenv import load_dotenv | ||
from jinja2 import Environment, FileSystemLoader | ||
|
||
|
||
def get_config() -> dict: | ||
load_dotenv() | ||
env = Environment(loader=FileSystemLoader(Path(__file__).parent)) | ||
template = env.get_template("models_config.yaml") | ||
config = template.render(os.environ) | ||
return yaml.safe_load(config) | ||
|
||
|
||
def load_models_config(): | ||
with open(Path(__file__).parent / "models_config.yaml", "r") as file: | ||
return yaml.safe_load(file) | ||
|
||
|
||
if __name__ == "__main__": | ||
print(get_config()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from langchain import embeddings | ||
|
||
|
||
def get_embedding_model_instance(config): | ||
embedding_spec = getattr(embeddings, config["embedding_model_config"]["model_source"]) | ||
all_config_field = {**config["embedding_model_config"], **config["embedding_provider_config"]} | ||
kwargs = { | ||
key: value | ||
for key, value in all_config_field.items() | ||
if key in embedding_spec.__fields__.keys() | ||
} | ||
return embedding_spec(**kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,10 @@ | ||
from langchain import chat_models | ||
from pathlib import Path | ||
import yaml | ||
|
||
def get_model_instance(): | ||
config = load_models_config() | ||
|
||
def get_llm_model_instance(config): | ||
llm_spec = getattr(chat_models, config["llm_model_config"]["model_source"]) | ||
all_config_field = {**config["llm_model_config"], **config["llm_provider_config"]} | ||
kwargs = {key: value for key, value in all_config_field.items() if key in llm_spec.__fields__.keys()} | ||
kwargs = { | ||
key: value for key, value in all_config_field.items() if key in llm_spec.__fields__.keys() | ||
} | ||
return llm_spec(**kwargs) | ||
|
||
|
||
def load_models_config(): | ||
with open(Path(__file__).parent / "models_config.yaml", "r") as file: | ||
return yaml.safe_load(file) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import inspect | ||
|
||
from config_renderer import get_config | ||
from langchain import vectorstores | ||
|
||
|
||
def get_vector_store(embedding_model): | ||
config = get_config() | ||
vector_store_spec = getattr(vectorstores, config["vector_store_provider"]["model_source"]) | ||
all_config_field = config["vector_store_provider"] | ||
|
||
# the vector store class in langchain doesn't have a uniform interface to pass the embedding model | ||
# we extract the propertiy of the class that matches the 'Embeddings' type | ||
# and instanciate the vector store with our embedding model | ||
signature = inspect.signature(vector_store_spec.__init__) | ||
parameters = signature.parameters | ||
params_dict = dict(parameters) | ||
embedding_param = next( | ||
(param for param in params_dict.values() if "Embeddings" in str(param.annotation)), None | ||
) | ||
|
||
kwargs = {key: value for key, value in all_config_field.items() if key in parameters.keys()} | ||
kwargs[embedding_param.name] = embedding_model | ||
vector_store = vector_store_spec(**kwargs) | ||
return vector_store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters