-
Notifications
You must be signed in to change notification settings - Fork 49
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
3439c12
commit 4125e3d
Showing
6 changed files
with
182 additions
and
71 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
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
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 |
---|---|---|
@@ -1,5 +1,94 @@ | ||
import inquirer | ||
from langchain.embeddings import (HuggingFaceEmbeddings, | ||
HuggingFaceInstructEmbeddings) | ||
from langchain.embeddings.openai import OpenAIEmbeddings | ||
|
||
from codeqai import utils | ||
from codeqai.constants import EmbeddingsModel | ||
|
||
def get_embeddings(): | ||
pass | ||
|
||
class Embeddings: | ||
def __init__( | ||
self, local=False, model=EmbeddingsModel.OPENAI_TEXT_EMBEDDING_ADA_002 | ||
): | ||
self.model = model | ||
|
||
if not local: | ||
if model == EmbeddingsModel.OPENAI_TEXT_EMBEDDING_ADA_002: | ||
self.embeddings = OpenAIEmbeddings( | ||
client=None, model="text_embedding_ada_002" | ||
) | ||
else: | ||
if model == EmbeddingsModel.OLLAMA: | ||
pass | ||
else: | ||
try: | ||
import sentence_transformers # noqa: F401 | ||
except ImportError: | ||
self._install_sentence_transformers() | ||
|
||
if model == EmbeddingsModel.SENTENCETRANSFORMERS_ALL_MPNET_BASE_V2: | ||
self.embeddings = HuggingFaceEmbeddings() | ||
elif model == EmbeddingsModel.INSTRUCTOR_LARGE: | ||
try: | ||
from InstructorEmbedding import \ | ||
INSTRUCTOR # noqa: F401 | ||
except ImportError: | ||
self._install_instructor_embedding() | ||
self.embeddings = HuggingFaceInstructEmbeddings() | ||
|
||
def _install_sentence_transformers(self): | ||
question = [ | ||
inquirer.Confirm( | ||
"confirm", | ||
message=f"{utils.get_bold_text('SentenceTransformers')} not found in this python environment. Do you want to install it now?", | ||
default=True, | ||
), | ||
] | ||
|
||
answers = inquirer.prompt(question) | ||
if answers and answers["confirm"]: | ||
import subprocess | ||
import sys | ||
|
||
try: | ||
subprocess.run( | ||
[ | ||
sys.executable, | ||
"-m", | ||
"pip", | ||
"install", | ||
"sentence_transformers", | ||
], | ||
check=True, | ||
) | ||
except subprocess.CalledProcessError as e: | ||
print(f"Error during sentence_transformers installation: {e}") | ||
|
||
def _install_instructor_embedding(self): | ||
question = [ | ||
inquirer.Confirm( | ||
"confirm", | ||
message=f"{utils.get_bold_text('InstructorEmbedding')} not found in this python environment. Do you want to install it now?", | ||
default=True, | ||
), | ||
] | ||
|
||
answers = inquirer.prompt(question) | ||
if answers and answers["confirm"]: | ||
import subprocess | ||
import sys | ||
|
||
try: | ||
subprocess.run( | ||
[ | ||
sys.executable, | ||
"-m", | ||
"pip", | ||
"install", | ||
"InstructorEmbedding", | ||
], | ||
check=True, | ||
) | ||
except subprocess.CalledProcessError as e: | ||
print(f"Error during sentence_transformers installation: {e}") |
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