Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
dify
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ai-tech
dify
Commits
920fb6d0
Unverified
Commit
920fb6d0
authored
Aug 19, 2023
by
takatost
Committed by
GitHub
Aug 19, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: embedding price config (#918)
parent
fd0fc8f4
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
41 additions
and
16 deletions
+41
-16
base.py
api/core/model_providers/models/embedding/base.py
+4
-6
minimax_embedding.py
...ore/model_providers/models/embedding/minimax_embedding.py
+0
-6
azure_openai.json
api/core/model_providers/rules/azure_openai.json
+2
-2
minimax.json
api/core/model_providers/rules/minimax.json
+20
-1
spark.json
api/core/model_providers/rules/spark.json
+15
-1
No files found.
api/core/model_providers/models/embedding/base.py
View file @
920fb6d0
...
@@ -32,7 +32,6 @@ class BaseEmbedding(BaseProviderModel):
...
@@ -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):
...
@@ -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):
...
@@ -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):
...
@@ -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):
...
@@ -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
...
...
api/core/model_providers/models/embedding/minimax_embedding.py
View file @
920fb6d0
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):
...
@@ -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)}"
)
...
...
api/core/model_providers/rules/azure_openai.json
View file @
920fb6d0
...
@@ -18,8 +18,8 @@
...
@@ -18,8 +18,8 @@
"currency"
:
"USD"
"currency"
:
"USD"
},
},
"gpt-35-turbo"
:
{
"gpt-35-turbo"
:
{
"prompt"
:
"0.00
15
"
,
"prompt"
:
"0.00
2
"
,
"completion"
:
"0.00
2
"
,
"completion"
:
"0.00
15
"
,
"unit"
:
"0.001"
,
"unit"
:
"0.001"
,
"currency"
:
"USD"
"currency"
:
"USD"
},
},
...
...
api/core/model_providers/rules/minimax.json
View file @
920fb6d0
...
@@ -9,5 +9,24 @@
...
@@ -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"
}
}
}
}
\ No newline at end of file
api/core/model_providers/rules/spark.json
View file @
920fb6d0
...
@@ -9,5 +9,19 @@
...
@@ -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"
}
}
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment