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
70992609
Unverified
Commit
70992609
authored
Feb 05, 2024
by
Jialei
Committed by
GitHub
Feb 05, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: add moonshot support (#2398)
parent
bf736bc5
Changes
11
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
176 additions
and
0 deletions
+176
-0
__init__.py
api/core/model_runtime/model_providers/moonshot/__init__.py
+0
-0
icon_l_en.png
...el_runtime/model_providers/moonshot/_assets/icon_l_en.png
+0
-0
icon_s_en.png
...el_runtime/model_providers/moonshot/_assets/icon_s_en.png
+0
-0
__init__.py
...re/model_runtime/model_providers/moonshot/llm/__init__.py
+0
-0
_position.yaml
...model_runtime/model_providers/moonshot/llm/_position.yaml
+3
-0
llm.py
api/core/model_runtime/model_providers/moonshot/llm/llm.py
+24
-0
moonshot-v1-128k.yaml
...untime/model_providers/moonshot/llm/moonshot-v1-128k.yaml
+29
-0
moonshot-v1-32k.yaml
...runtime/model_providers/moonshot/llm/moonshot-v1-32k.yaml
+29
-0
moonshot-v1-8k.yaml
..._runtime/model_providers/moonshot/llm/moonshot-v1-8k.yaml
+29
-0
moonshot.py
api/core/model_runtime/model_providers/moonshot/moonshot.py
+30
-0
moonshot.yaml
...core/model_runtime/model_providers/moonshot/moonshot.yaml
+32
-0
No files found.
api/core/model_runtime/model_providers/moonshot/__init__.py
0 → 100644
View file @
70992609
api/core/model_runtime/model_providers/moonshot/_assets/icon_l_en.png
0 → 100644
View file @
70992609
13.3 KB
api/core/model_runtime/model_providers/moonshot/_assets/icon_s_en.png
0 → 100644
View file @
70992609
7.25 KB
api/core/model_runtime/model_providers/moonshot/llm/__init__.py
0 → 100644
View file @
70992609
api/core/model_runtime/model_providers/moonshot/llm/_position.yaml
0 → 100644
View file @
70992609
-
moonshot-v1-8k
-
moonshot-v1-32k
-
moonshot-v1-128k
api/core/model_runtime/model_providers/moonshot/llm/llm.py
0 → 100644
View file @
70992609
from
typing
import
List
,
Optional
,
Union
,
Generator
from
core.model_runtime.entities.llm_entities
import
LLMResult
from
core.model_runtime.entities.message_entities
import
(
PromptMessage
,
PromptMessageTool
)
from
core.model_runtime.model_providers.openai_api_compatible.llm.llm
import
OAIAPICompatLargeLanguageModel
class
MoonshotLargeLanguageModel
(
OAIAPICompatLargeLanguageModel
):
def
_invoke
(
self
,
model
:
str
,
credentials
:
dict
,
prompt_messages
:
list
[
PromptMessage
],
model_parameters
:
dict
,
tools
:
Optional
[
list
[
PromptMessageTool
]]
=
None
,
stop
:
Optional
[
List
[
str
]]
=
None
,
stream
:
bool
=
True
,
user
:
Optional
[
str
]
=
None
)
\
->
Union
[
LLMResult
,
Generator
]:
self
.
_add_custom_parameters
(
credentials
)
return
super
()
.
_invoke
(
model
,
credentials
,
prompt_messages
,
model_parameters
,
tools
,
stop
,
stream
,
user
)
def
validate_credentials
(
self
,
model
:
str
,
credentials
:
dict
)
->
None
:
self
.
_add_custom_parameters
(
credentials
)
super
()
.
validate_credentials
(
model
,
credentials
)
@
staticmethod
def
_add_custom_parameters
(
credentials
:
dict
)
->
None
:
credentials
[
'mode'
]
=
'chat'
credentials
[
'endpoint_url'
]
=
'https://api.moonshot.cn/v1'
api/core/model_runtime/model_providers/moonshot/llm/moonshot-v1-128k.yaml
0 → 100644
View file @
70992609
model
:
moonshot-v1-128k
label
:
zh_Hans
:
moonshot-v1-128k
en_US
:
moonshot-v1-128k
model_type
:
llm
features
:
-
agent-thought
model_properties
:
mode
:
chat
context_size
:
4096
parameter_rules
:
-
name
:
temperature
use_template
:
temperature
-
name
:
top_p
use_template
:
top_p
-
name
:
presence_penalty
use_template
:
presence_penalty
-
name
:
frequency_penalty
use_template
:
frequency_penalty
-
name
:
max_tokens
use_template
:
max_tokens
default
:
512
min
:
1
max
:
4096
pricing
:
input
:
'
0.06'
output
:
'
0.06'
unit
:
'
0.001'
currency
:
RMB
api/core/model_runtime/model_providers/moonshot/llm/moonshot-v1-32k.yaml
0 → 100644
View file @
70992609
model
:
moonshot-v1-32k
label
:
zh_Hans
:
moonshot-v1-32k
en_US
:
moonshot-v1-32k
model_type
:
llm
features
:
-
agent-thought
model_properties
:
mode
:
chat
context_size
:
4096
parameter_rules
:
-
name
:
temperature
use_template
:
temperature
-
name
:
top_p
use_template
:
top_p
-
name
:
presence_penalty
use_template
:
presence_penalty
-
name
:
frequency_penalty
use_template
:
frequency_penalty
-
name
:
max_tokens
use_template
:
max_tokens
default
:
512
min
:
1
max
:
4096
pricing
:
input
:
'
0.024'
output
:
'
0.024'
unit
:
'
0.001'
currency
:
RMB
api/core/model_runtime/model_providers/moonshot/llm/moonshot-v1-8k.yaml
0 → 100644
View file @
70992609
model
:
moonshot-v1-8k
label
:
zh_Hans
:
moonshot-v1-8k
en_US
:
moonshot-v1-8k
model_type
:
llm
features
:
-
agent-thought
model_properties
:
mode
:
chat
context_size
:
4096
parameter_rules
:
-
name
:
temperature
use_template
:
temperature
-
name
:
top_p
use_template
:
top_p
-
name
:
presence_penalty
use_template
:
presence_penalty
-
name
:
frequency_penalty
use_template
:
frequency_penalty
-
name
:
max_tokens
use_template
:
max_tokens
default
:
512
min
:
1
max
:
4096
pricing
:
input
:
'
0.012'
output
:
'
0.012'
unit
:
'
0.001'
currency
:
RMB
api/core/model_runtime/model_providers/moonshot/moonshot.py
0 → 100644
View file @
70992609
import
logging
from
core.model_runtime.entities.model_entities
import
AIModelEntity
,
ModelType
from
core.model_runtime.errors.validate
import
CredentialsValidateFailedError
from
core.model_runtime.model_providers.__base.model_provider
import
ModelProvider
logger
=
logging
.
getLogger
(
__name__
)
class
MoonshotProvider
(
ModelProvider
):
def
validate_provider_credentials
(
self
,
credentials
:
dict
)
->
None
:
"""
Validate provider credentials
if validate failed, raise exception
:param credentials: provider credentials, credentials form defined in `provider_credential_schema`.
"""
try
:
model_instance
=
self
.
get_model_instance
(
ModelType
.
LLM
)
model_instance
.
validate_credentials
(
model
=
'moonshot-v1-8k'
,
credentials
=
credentials
)
except
CredentialsValidateFailedError
as
ex
:
raise
ex
except
Exception
as
ex
:
logger
.
exception
(
f
'{self.get_provider_schema().provider} credentials validate failed'
)
raise
ex
api/core/model_runtime/model_providers/moonshot/moonshot.yaml
0 → 100644
View file @
70992609
provider
:
moonshot
label
:
zh_Hans
:
月之暗面
en_US
:
Moonshot
description
:
en_US
:
Models provided by Moonshot, such as moonshot-v1-8k, moonshot-v1-32k, and moonshot-v1-128k.
zh_Hans
:
Moonshot 提供的模型,例如 moonshot-v1-8k、moonshot-v1-32k 和 moonshot-v1-128k。
icon_small
:
en_US
:
icon_s_en.png
icon_large
:
en_US
:
icon_l_en.png
background
:
"
#FFFFFF"
help
:
title
:
en_US
:
Get your API Key from Moonshot
zh_Hans
:
从 Moonshot 获取 API Key
url
:
en_US
:
https://platform.moonshot.cn/console/api-keys
supported_model_types
:
-
llm
configurate_methods
:
-
predefined-model
provider_credential_schema
:
credential_form_schemas
:
-
variable
:
api_key
label
:
en_US
:
API Key
type
:
secret-input
required
:
true
placeholder
:
zh_Hans
:
在此输入您的 API Key
en_US
:
Enter your API Key
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