mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-13 17:58:59 +08:00
feat: support jina-clip-v1 embedding model (#5146)
This commit is contained in:
parent
790543131a
commit
8210637bc5
@ -0,0 +1,9 @@
|
|||||||
|
model: jina-clip-v1
|
||||||
|
model_type: text-embedding
|
||||||
|
model_properties:
|
||||||
|
context_size: 8192
|
||||||
|
max_chunks: 2048
|
||||||
|
pricing:
|
||||||
|
input: '0.001'
|
||||||
|
unit: '0.001'
|
||||||
|
currency: USD
|
@ -52,9 +52,14 @@ class JinaTextEmbeddingModel(TextEmbeddingModel):
|
|||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def transform_jina_input_text(model, text):
|
||||||
|
if model == 'jina-clip-v1':
|
||||||
|
return {"text": text}
|
||||||
|
return text
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
'model': model,
|
'model': model,
|
||||||
'input': texts
|
'input': [transform_jina_input_text(model, text) for text in texts]
|
||||||
}
|
}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -75,16 +80,19 @@ class JinaTextEmbeddingModel(TextEmbeddingModel):
|
|||||||
else:
|
else:
|
||||||
raise InvokeBadRequestError(msg)
|
raise InvokeBadRequestError(msg)
|
||||||
except JSONDecodeError as e:
|
except JSONDecodeError as e:
|
||||||
raise InvokeServerUnavailableError(f"Failed to convert response to json: {e} with text: {response.text}")
|
raise InvokeServerUnavailableError(
|
||||||
|
f"Failed to convert response to json: {e} with text: {response.text}")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
resp = response.json()
|
resp = response.json()
|
||||||
embeddings = resp['data']
|
embeddings = resp['data']
|
||||||
usage = resp['usage']
|
usage = resp['usage']
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise InvokeServerUnavailableError(f"Failed to convert response to json: {e} with text: {response.text}")
|
raise InvokeServerUnavailableError(
|
||||||
|
f"Failed to convert response to json: {e} with text: {response.text}")
|
||||||
|
|
||||||
usage = self._calc_response_usage(model=model, credentials=credentials, tokens=usage['total_tokens'])
|
usage = self._calc_response_usage(
|
||||||
|
model=model, credentials=credentials, tokens=usage['total_tokens'])
|
||||||
|
|
||||||
result = TextEmbeddingResult(
|
result = TextEmbeddingResult(
|
||||||
model=model,
|
model=model,
|
||||||
@ -122,7 +130,8 @@ class JinaTextEmbeddingModel(TextEmbeddingModel):
|
|||||||
try:
|
try:
|
||||||
self._invoke(model=model, credentials=credentials, texts=['ping'])
|
self._invoke(model=model, credentials=credentials, texts=['ping'])
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise CredentialsValidateFailedError(f'Credentials validation failed: {e}')
|
raise CredentialsValidateFailedError(
|
||||||
|
f'Credentials validation failed: {e}')
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def _invoke_error_mapping(self) -> dict[type[InvokeError], list[type[Exception]]]:
|
def _invoke_error_mapping(self) -> dict[type[InvokeError], list[type[Exception]]]:
|
||||||
@ -185,7 +194,8 @@ class JinaTextEmbeddingModel(TextEmbeddingModel):
|
|||||||
model_type=ModelType.TEXT_EMBEDDING,
|
model_type=ModelType.TEXT_EMBEDDING,
|
||||||
fetch_from=FetchFrom.CUSTOMIZABLE_MODEL,
|
fetch_from=FetchFrom.CUSTOMIZABLE_MODEL,
|
||||||
model_properties={
|
model_properties={
|
||||||
ModelPropertyKey.CONTEXT_SIZE: int(credentials.get('context_size'))
|
ModelPropertyKey.CONTEXT_SIZE: int(
|
||||||
|
credentials.get('context_size'))
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user