mirror of
https://github.com/oobabooga/text-generation-webui.git
synced 2024-10-01 01:26:03 -04:00
Openai embedding fix to support jina-embeddings-v2 (#4642)
This commit is contained in:
parent
baab894759
commit
af76fbedb8
@ -1,6 +1,7 @@
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
from transformers import AutoModel
|
||||||
|
|
||||||
from extensions.openai.errors import ServiceUnavailableError
|
from extensions.openai.errors import ServiceUnavailableError
|
||||||
from extensions.openai.utils import debug_msg, float_list_to_base64
|
from extensions.openai.utils import debug_msg, float_list_to_base64
|
||||||
@ -41,7 +42,12 @@ def load_embedding_model(model: str):
|
|||||||
global embeddings_device, embeddings_model
|
global embeddings_device, embeddings_model
|
||||||
try:
|
try:
|
||||||
print(f"Try embedding model: {model} on {embeddings_device}")
|
print(f"Try embedding model: {model} on {embeddings_device}")
|
||||||
embeddings_model = SentenceTransformer(model, device=embeddings_device)
|
if 'jina-embeddings' in model:
|
||||||
|
embeddings_model = AutoModel.from_pretrained(model, trust_remote_code=True) # trust_remote_code is needed to use the encode method
|
||||||
|
embeddings_model = embeddings_model.to(embeddings_device)
|
||||||
|
else:
|
||||||
|
embeddings_model = SentenceTransformer(model, device=embeddings_device)
|
||||||
|
|
||||||
print(f"Loaded embedding model: {model}")
|
print(f"Loaded embedding model: {model}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
embeddings_model = None
|
embeddings_model = None
|
||||||
|
Loading…
Reference in New Issue
Block a user