mirror of
https://github.com/langgenius/dify.git
synced 2024-11-16 11:42:29 +08:00
feat: add moonshot support (#2398)
This commit is contained in:
parent
bf736bc55d
commit
70992609d4
Binary file not shown.
After Width: | Height: | Size: 13 KiB |
Binary file not shown.
After Width: | Height: | Size: 7.2 KiB |
|
@ -0,0 +1,3 @@
|
||||||
|
- moonshot-v1-8k
|
||||||
|
- moonshot-v1-32k
|
||||||
|
- moonshot-v1-128k
|
24
api/core/model_runtime/model_providers/moonshot/llm/llm.py
Normal file
24
api/core/model_runtime/model_providers/moonshot/llm/llm.py
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
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'
|
|
@ -0,0 +1,29 @@
|
||||||
|
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
|
|
@ -0,0 +1,29 @@
|
||||||
|
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
|
|
@ -0,0 +1,29 @@
|
||||||
|
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
|
30
api/core/model_runtime/model_providers/moonshot/moonshot.py
Normal file
30
api/core/model_runtime/model_providers/moonshot/moonshot.py
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
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
|
|
@ -0,0 +1,32 @@
|
||||||
|
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
|
Loading…
Reference in New Issue
Block a user