mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-14 04:25:59 +08:00
fix: embedding price config (#918)
This commit is contained in:
parent
fd0fc8f4fe
commit
920fb6d0e1
@ -32,7 +32,6 @@ class BaseEmbedding(BaseProviderModel):
|
|||||||
def price_config(self) -> dict:
|
def price_config(self) -> dict:
|
||||||
def get_or_default():
|
def get_or_default():
|
||||||
default_price_config = {
|
default_price_config = {
|
||||||
'prompt': decimal.Decimal('0'),
|
|
||||||
'completion': decimal.Decimal('0'),
|
'completion': decimal.Decimal('0'),
|
||||||
'unit': decimal.Decimal('0'),
|
'unit': decimal.Decimal('0'),
|
||||||
'currency': 'USD'
|
'currency': 'USD'
|
||||||
@ -40,7 +39,6 @@ class BaseEmbedding(BaseProviderModel):
|
|||||||
rules = self.model_provider.get_rules()
|
rules = self.model_provider.get_rules()
|
||||||
price_config = rules['price_config'][self.base_model_name] if 'price_config' in rules else default_price_config
|
price_config = rules['price_config'][self.base_model_name] if 'price_config' in rules else default_price_config
|
||||||
price_config = {
|
price_config = {
|
||||||
'prompt': decimal.Decimal(price_config['prompt']),
|
|
||||||
'completion': decimal.Decimal(price_config['completion']),
|
'completion': decimal.Decimal(price_config['completion']),
|
||||||
'unit': decimal.Decimal(price_config['unit']),
|
'unit': decimal.Decimal(price_config['unit']),
|
||||||
'currency': price_config['currency']
|
'currency': price_config['currency']
|
||||||
@ -59,8 +57,8 @@ class BaseEmbedding(BaseProviderModel):
|
|||||||
:param tokens:
|
:param tokens:
|
||||||
:return: decimal.Decimal('0.0000001')
|
:return: decimal.Decimal('0.0000001')
|
||||||
"""
|
"""
|
||||||
unit_price = self._price_config['completion']
|
unit_price = self.price_config['completion']
|
||||||
unit = self._price_config['unit']
|
unit = self.price_config['unit']
|
||||||
total_price = tokens * unit_price * unit
|
total_price = tokens * unit_price * unit
|
||||||
total_price = total_price.quantize(decimal.Decimal('0.0000001'), rounding=decimal.ROUND_HALF_UP)
|
total_price = total_price.quantize(decimal.Decimal('0.0000001'), rounding=decimal.ROUND_HALF_UP)
|
||||||
logging.debug(f"tokens={tokens}, unit_price={unit_price}, unit={unit}, total_price:{total_price}")
|
logging.debug(f"tokens={tokens}, unit_price={unit_price}, unit={unit}, total_price:{total_price}")
|
||||||
@ -73,7 +71,7 @@ class BaseEmbedding(BaseProviderModel):
|
|||||||
:return: decimal.Decimal('0.0001')
|
:return: decimal.Decimal('0.0001')
|
||||||
|
|
||||||
"""
|
"""
|
||||||
unit_price = self._price_config['completion']
|
unit_price = self.price_config['completion']
|
||||||
unit_price = unit_price.quantize(decimal.Decimal('0.0001'), rounding=decimal.ROUND_HALF_UP)
|
unit_price = unit_price.quantize(decimal.Decimal('0.0001'), rounding=decimal.ROUND_HALF_UP)
|
||||||
logger.debug(f'unit_price:{unit_price}')
|
logger.debug(f'unit_price:{unit_price}')
|
||||||
return unit_price
|
return unit_price
|
||||||
@ -96,7 +94,7 @@ class BaseEmbedding(BaseProviderModel):
|
|||||||
|
|
||||||
:return: get from price config, default 'USD'
|
:return: get from price config, default 'USD'
|
||||||
"""
|
"""
|
||||||
currency = self._price_config['currency']
|
currency = self.price_config['currency']
|
||||||
return currency
|
return currency
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
|
@ -1,6 +1,3 @@
|
|||||||
import decimal
|
|
||||||
import logging
|
|
||||||
|
|
||||||
from langchain.embeddings import MiniMaxEmbeddings
|
from langchain.embeddings import MiniMaxEmbeddings
|
||||||
|
|
||||||
from core.model_providers.error import LLMBadRequestError
|
from core.model_providers.error import LLMBadRequestError
|
||||||
@ -22,9 +19,6 @@ class MinimaxEmbedding(BaseEmbedding):
|
|||||||
|
|
||||||
super().__init__(model_provider, client, name)
|
super().__init__(model_provider, client, name)
|
||||||
|
|
||||||
def get_currency(self):
|
|
||||||
return 'RMB'
|
|
||||||
|
|
||||||
def handle_exceptions(self, ex: Exception) -> Exception:
|
def handle_exceptions(self, ex: Exception) -> Exception:
|
||||||
if isinstance(ex, ValueError):
|
if isinstance(ex, ValueError):
|
||||||
return LLMBadRequestError(f"Minimax: {str(ex)}")
|
return LLMBadRequestError(f"Minimax: {str(ex)}")
|
||||||
|
@ -18,8 +18,8 @@
|
|||||||
"currency": "USD"
|
"currency": "USD"
|
||||||
},
|
},
|
||||||
"gpt-35-turbo": {
|
"gpt-35-turbo": {
|
||||||
"prompt": "0.0015",
|
"prompt": "0.002",
|
||||||
"completion": "0.002",
|
"completion": "0.0015",
|
||||||
"unit": "0.001",
|
"unit": "0.001",
|
||||||
"currency": "USD"
|
"currency": "USD"
|
||||||
},
|
},
|
||||||
|
@ -9,5 +9,24 @@
|
|||||||
],
|
],
|
||||||
"quota_unit": "tokens"
|
"quota_unit": "tokens"
|
||||||
},
|
},
|
||||||
"model_flexibility": "fixed"
|
"model_flexibility": "fixed",
|
||||||
|
"price_config": {
|
||||||
|
"abab5.5-chat": {
|
||||||
|
"prompt": "0.015",
|
||||||
|
"completion": "0.015",
|
||||||
|
"unit": "0.001",
|
||||||
|
"currency": "RMB"
|
||||||
|
},
|
||||||
|
"abab5-chat": {
|
||||||
|
"prompt": "0.015",
|
||||||
|
"completion": "0.015",
|
||||||
|
"unit": "0.001",
|
||||||
|
"currency": "RMB"
|
||||||
|
},
|
||||||
|
"embo-01": {
|
||||||
|
"completion": "0",
|
||||||
|
"unit": "0.0001",
|
||||||
|
"currency": "RMB"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -9,5 +9,19 @@
|
|||||||
],
|
],
|
||||||
"quota_unit": "tokens"
|
"quota_unit": "tokens"
|
||||||
},
|
},
|
||||||
"model_flexibility": "fixed"
|
"model_flexibility": "fixed",
|
||||||
|
"price_config": {
|
||||||
|
"spark": {
|
||||||
|
"prompt": "0.18",
|
||||||
|
"completion": "0.18",
|
||||||
|
"unit": "0.0001",
|
||||||
|
"currency": "RMB"
|
||||||
|
},
|
||||||
|
"spark-v2": {
|
||||||
|
"prompt": "0.36",
|
||||||
|
"completion": "0.36",
|
||||||
|
"unit": "0.0001",
|
||||||
|
"currency": "RMB"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user