From 73adf37aee87edd02de91652aa34619b161f5bd4 Mon Sep 17 00:00:00 2001 From: Joshua Date: Wed, 28 Feb 2024 11:46:55 +0800 Subject: [PATCH 1/5] feat:add mistral ai --- .../model_providers/mistralai/__init__.py | 0 .../mistralai/_assets/icon_l_en.png | Bin 0 -> 7064 bytes .../mistralai/_assets/icon_s_en.png | Bin 0 -> 2359 bytes .../mistralai/llm/_position.yaml | 5 ++ .../model_providers/mistralai/llm/llm.py | 30 +++++++++++ .../mistralai/llm/mistral-large-latest.yaml | 51 ++++++++++++++++++ .../mistralai/llm/mistral-medium-latest.yaml | 51 ++++++++++++++++++ .../mistralai/llm/mistral-small-latest.yaml | 51 ++++++++++++++++++ .../mistralai/llm/open-mistral-7b.yaml | 50 +++++++++++++++++ .../mistralai/llm/open-mixtral-8x7b.yaml | 51 ++++++++++++++++++ .../model_providers/mistralai/mistralai.py | 30 +++++++++++ .../model_providers/mistralai/mistralai.yaml | 31 +++++++++++ 12 files changed, 350 insertions(+) create mode 100644 api/core/model_runtime/model_providers/mistralai/__init__.py create mode 100644 api/core/model_runtime/model_providers/mistralai/_assets/icon_l_en.png create mode 100644 api/core/model_runtime/model_providers/mistralai/_assets/icon_s_en.png create mode 100644 api/core/model_runtime/model_providers/mistralai/llm/_position.yaml create mode 100644 api/core/model_runtime/model_providers/mistralai/llm/llm.py create mode 100644 api/core/model_runtime/model_providers/mistralai/llm/mistral-large-latest.yaml create mode 100644 api/core/model_runtime/model_providers/mistralai/llm/mistral-medium-latest.yaml create mode 100644 api/core/model_runtime/model_providers/mistralai/llm/mistral-small-latest.yaml create mode 100644 api/core/model_runtime/model_providers/mistralai/llm/open-mistral-7b.yaml create mode 100644 api/core/model_runtime/model_providers/mistralai/llm/open-mixtral-8x7b.yaml create mode 100644 api/core/model_runtime/model_providers/mistralai/mistralai.py create mode 100644 api/core/model_runtime/model_providers/mistralai/mistralai.yaml diff --git a/api/core/model_runtime/model_providers/mistralai/__init__.py b/api/core/model_runtime/model_providers/mistralai/__init__.py new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/api/core/model_runtime/model_providers/mistralai/_assets/icon_l_en.png b/api/core/model_runtime/model_providers/mistralai/_assets/icon_l_en.png new file mode 100644 index 0000000000000000000000000000000000000000..f019b1edceac20bb838c9be16985b4e8767344d8 GIT binary patch literal 7064 zcmV;J8)xKFNk&GH8vp=TMM6+kP&il$0000G00030002<{06|PpNIwk#009|-Y#V^i z-}q;U=zp5>aRdTM`-_hd5vl9Awr!=k7pDpq70?6Yw3}fHavk}NeE$tZOuz(q!~Xx! z9Qpqq&)2)E5hr7;cgLR{+laHaZQHhO+qN;z*lUe4o-~q9U-f>yZdBEUPIvnF+>3|_ zxNU&{OKE9=1QIm=_QP_b*U;oWZ&om`7xVp?@5Q`N{C|JU`!pYryu#-Jxoh4R^S*f^ zNjz-_X0;r(q*?_i^;EUV@Bp(M4QBnQz^se#=pm^Vxtk=wy$cFKKmODt-R&RGk<*>=H|y9 zm92-+*jGG`JT6;J)x-@~U!O&EvHsq!(57$G<-_)fNE^>JZ&~}3PDfm%G+8P9N$Kby z5!&|hI~AZ9{lJ1idHM1z0KeO~ix@7VLE8c%O;mm32~P&N-%rhB_;b4fTXxxE9Q8qZ zUA9>P<{RF6FwNJ0?mZJqokzTY-tXLFn)|<&E^puX8I&O8Xa=66G?&j{u#2fLwSEO-ovNtH6G0rjqC@EB0Je5qpoRd(9l-p}uOkP6 z&|a^<=mlrPSf^6}Y6u|gW?-UI72qMPSh42oKYG%gikjt<7f&nX<>}u@RSmek<6evt zv_3TqHTu(1H;o!${7?4SSPF8iby-uO~ETc;)qh|ysnPXLkb z4C3U5>*#MJ@BI{X(Ii z9Ohnp`W z?egGvEr59JBLc8|^uD37cfHHvF30@V@*LuWC^rA=P)>p4m-4rfyVYRZ4FFRRY~Dn( zv47-bSAP(T@r$2#Lity77{8YK9RSnU(X1K-M0MlGKK`=GblxJdswb89-r0MFc=0#Lj!%NQ%%|m;(|}RAo(Nu0_x+2@3xM z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zko)dhknJF^$vzgwa1)wIJ^r9T0r?v2eTY9m;Rp6U$ViA+K;Z`tNRR{GT?6Vtax~aF zWRo<%3LbuRE$8cLo!wL3E8N}uuUP>SBS5c%V*wsspkM+an4e&ghOP?i9Z+Op(+}4S zjdwh%ppgqo9k^8CmVs#oMI|uGVPS*A@xUM=qzarM@OvHSUNX zC`yL1p>roW$#X}(QeHI0-9K4#y;=3b|5xvQ=G?ohbH}t#ugpHZN&@ClbLsnxad+bD!|BtAoMi%JqtBr5#fS0$|phcA|yLvO>#!y^oA{At`|cUC6L4=!MPAm7NMG_ zz(pcf@4~ZJ3Z%S))6;ngEl!ka7rM!m}^Put` zT#iACMU-;9JR1}=h-wU6Y5`RMMe&&=F&|VQqm=i^^(8zlgKIfZbq8|5-L;@X99+vm mDk+dCib;GlsrW&LI>^cE&+)o@=v8Dri0kR<=d#Wzp$Pz6^0S-( literal 0 HcmV?d00001 diff --git a/api/core/model_runtime/model_providers/mistralai/llm/_position.yaml b/api/core/model_runtime/model_providers/mistralai/llm/_position.yaml new file mode 100644 index 0000000000000..76b4a2ab2de98 --- /dev/null +++ b/api/core/model_runtime/model_providers/mistralai/llm/_position.yaml @@ -0,0 +1,5 @@ +- open-mistral-7b +- open-mixtral-8x7b +- mistral-small-latest +- mistral-medium-latest +- mistral-large-latest \ No newline at end of file diff --git a/api/core/model_runtime/model_providers/mistralai/llm/llm.py b/api/core/model_runtime/model_providers/mistralai/llm/llm.py new file mode 100644 index 0000000000000..266c9d527219d --- /dev/null +++ b/api/core/model_runtime/model_providers/mistralai/llm/llm.py @@ -0,0 +1,30 @@ +from collections.abc import Generator +from typing import Optional, Union + +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 MistralAILargeLanguageModel(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) + + # mistral dose not support user/stop arguments + stop = [] + user = None + + 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.mistral.ai/v1' diff --git a/api/core/model_runtime/model_providers/mistralai/llm/mistral-large-latest.yaml b/api/core/model_runtime/model_providers/mistralai/llm/mistral-large-latest.yaml new file mode 100644 index 0000000000000..c10f2e2030080 --- /dev/null +++ b/api/core/model_runtime/model_providers/mistralai/llm/mistral-large-latest.yaml @@ -0,0 +1,51 @@ +model: mistral-large-latest +label: + zh_Hans: mistral-large-latest + en_US: mistral-large-latest +model_type: llm +features: + - agent-thought +model_properties: + context_size: 32000 +parameter_rules: + - name: temperature + use_template: temperature + default: 0.7 + min: 0 + max: 1 + - name: top_p + use_template: top_p + default: 1 + min: 0 + max: 1 + - name: max_tokens + use_template: max_tokens + default: 1024 + min: 1 + max: 8000 + - name: safe_prompt + defulat: false + type: boolean + help: + en_US: Whether to inject a safety prompt before all conversations. + zh_Hans: 是否开启提示词审查 + label: + en_US: SafePrompt + zh_Hans: 提示词审查 + - name: random_seed + type: int + help: + en_US: The seed to use for random sampling. If set, different calls will generate deterministic results. + zh_Hans: 当开启随机数种子以后,你可以通过指定一个固定的种子来使得回答结果更加稳定 + label: + en_US: RandomSeed + zh_Hans: 随机数种子 + default: 0 + min: 0 + max: 2147483647 +pricing: + input: '0.008' + output: '0.024' + unit: '0.001' + currency: USD + diff --git a/api/core/model_runtime/model_providers/mistralai/llm/mistral-medium-latest.yaml b/api/core/model_runtime/model_providers/mistralai/llm/mistral-medium-latest.yaml new file mode 100644 index 0000000000000..605534216f9c2 --- /dev/null +++ b/api/core/model_runtime/model_providers/mistralai/llm/mistral-medium-latest.yaml @@ -0,0 +1,51 @@ +model: mistral-medium-latest +label: + zh_Hans: mistral-medium-latest + en_US: mistral-medium-latest +model_type: llm +features: + - agent-thought +model_properties: + context_size: 32000 +parameter_rules: + - name: temperature + use_template: temperature + default: 0.7 + min: 0 + max: 1 + - name: top_p + use_template: top_p + default: 1 + min: 0 + max: 1 + - name: max_tokens + use_template: max_tokens + default: 1024 + min: 1 + max: 8000 + - name: safe_prompt + defulat: false + type: boolean + help: + en_US: Whether to inject a safety prompt before all conversations. + zh_Hans: 是否开启提示词审查 + label: + en_US: SafePrompt + zh_Hans: 提示词审查 + - name: random_seed + type: int + help: + en_US: The seed to use for random sampling. If set, different calls will generate deterministic results. + zh_Hans: 当开启随机数种子以后,你可以通过指定一个固定的种子来使得回答结果更加稳定 + label: + en_US: RandomSeed + zh_Hans: 随机数种子 + default: 0 + min: 0 + max: 2147483647 +pricing: + input: '0.0027' + output: '0.0081' + unit: '0.001' + currency: USD + diff --git a/api/core/model_runtime/model_providers/mistralai/llm/mistral-small-latest.yaml b/api/core/model_runtime/model_providers/mistralai/llm/mistral-small-latest.yaml new file mode 100644 index 0000000000000..a9f074abb2818 --- /dev/null +++ b/api/core/model_runtime/model_providers/mistralai/llm/mistral-small-latest.yaml @@ -0,0 +1,51 @@ +model: mistral-small-latest +label: + zh_Hans: mistral-small-latest + en_US: mistral-small-latest +model_type: llm +features: + - agent-thought +model_properties: + context_size: 32000 +parameter_rules: + - name: temperature + use_template: temperature + default: 0.7 + min: 0 + max: 1 + - name: top_p + use_template: top_p + default: 1 + min: 0 + max: 1 + - name: max_tokens + use_template: max_tokens + default: 1024 + min: 1 + max: 8000 + - name: safe_prompt + defulat: false + type: boolean + help: + en_US: Whether to inject a safety prompt before all conversations. + zh_Hans: 是否开启提示词审查 + label: + en_US: SafePrompt + zh_Hans: 提示词审查 + - name: random_seed + type: int + help: + en_US: The seed to use for random sampling. If set, different calls will generate deterministic results. + zh_Hans: 当开启随机数种子以后,你可以通过指定一个固定的种子来使得回答结果更加稳定 + label: + en_US: RandomSeed + zh_Hans: 随机数种子 + default: 0 + min: 0 + max: 2147483647 +pricing: + input: '0.002' + output: '0.006' + unit: '0.001' + currency: USD + diff --git a/api/core/model_runtime/model_providers/mistralai/llm/open-mistral-7b.yaml b/api/core/model_runtime/model_providers/mistralai/llm/open-mistral-7b.yaml new file mode 100644 index 0000000000000..30454f7df22ea --- /dev/null +++ b/api/core/model_runtime/model_providers/mistralai/llm/open-mistral-7b.yaml @@ -0,0 +1,50 @@ +model: open-mistral-7b +label: + zh_Hans: open-mistral-7b + en_US: open-mistral-7b +model_type: llm +features: + - agent-thought +model_properties: + context_size: 8000 +parameter_rules: + - name: temperature + use_template: temperature + default: 0.7 + min: 0 + max: 1 + - name: top_p + use_template: top_p + default: 1 + min: 0 + max: 1 + - name: max_tokens + use_template: max_tokens + default: 1024 + min: 1 + max: 2048 + - name: safe_prompt + defulat: false + type: boolean + help: + en_US: Whether to inject a safety prompt before all conversations. + zh_Hans: 是否开启提示词审查 + label: + en_US: SafePrompt + zh_Hans: 提示词审查 + - name: random_seed + type: int + help: + en_US: The seed to use for random sampling. If set, different calls will generate deterministic results. + zh_Hans: 当开启随机数种子以后,你可以通过指定一个固定的种子来使得回答结果更加稳定 + label: + en_US: RandomSeed + zh_Hans: 随机数种子 + default: 0 + min: 0 + max: 2147483647 +pricing: + input: '0.00025' + output: '0.00025' + unit: '0.001' + currency: USD diff --git a/api/core/model_runtime/model_providers/mistralai/llm/open-mixtral-8x7b.yaml b/api/core/model_runtime/model_providers/mistralai/llm/open-mixtral-8x7b.yaml new file mode 100644 index 0000000000000..6b70ce6fe7221 --- /dev/null +++ b/api/core/model_runtime/model_providers/mistralai/llm/open-mixtral-8x7b.yaml @@ -0,0 +1,51 @@ +model: open-mixtral-8x7b +label: + zh_Hans: open-mixtral-8x7b + en_US: open-mixtral-8x7b +model_type: llm +features: + - agent-thought +model_properties: + context_size: 32000 +parameter_rules: + - name: temperature + use_template: temperature + default: 0.7 + min: 0 + max: 1 + - name: top_p + use_template: top_p + default: 1 + min: 0 + max: 1 + - name: max_tokens + use_template: max_tokens + default: 1024 + min: 1 + max: 8000 + - name: safe_prompt + defulat: false + type: boolean + help: + en_US: Whether to inject a safety prompt before all conversations. + zh_Hans: 是否开启提示词审查 + label: + en_US: SafePrompt + zh_Hans: 提示词审查 + - name: random_seed + type: int + help: + en_US: The seed to use for random sampling. If set, different calls will generate deterministic results. + zh_Hans: 当开启随机数种子以后,你可以通过指定一个固定的种子来使得回答结果更加稳定 + label: + en_US: RandomSeed + zh_Hans: 随机数种子 + default: 0 + min: 0 + max: 2147483647 +pricing: + input: '0.0007' + output: '0.0007' + unit: '0.001' + currency: USD + diff --git a/api/core/model_runtime/model_providers/mistralai/mistralai.py b/api/core/model_runtime/model_providers/mistralai/mistralai.py new file mode 100644 index 0000000000000..f1d825f6c6f04 --- /dev/null +++ b/api/core/model_runtime/model_providers/mistralai/mistralai.py @@ -0,0 +1,30 @@ +import logging + +from core.model_runtime.entities.model_entities import 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 MistralAIProvider(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='open-mistral-7b', + 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 diff --git a/api/core/model_runtime/model_providers/mistralai/mistralai.yaml b/api/core/model_runtime/model_providers/mistralai/mistralai.yaml new file mode 100644 index 0000000000000..c9b4226ea6e57 --- /dev/null +++ b/api/core/model_runtime/model_providers/mistralai/mistralai.yaml @@ -0,0 +1,31 @@ +provider: mistralai +label: + en_US: MistralAI +description: + en_US: Models provided by MistralAI, such as open-mistral-7b and mistral-large-latest. + zh_Hans: MistralAI 提供的模型,例如 open-mistral-7b 和 mistral-large-latest。 +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 MistralAI + zh_Hans: 从 MistralAI 获取 API Key + url: + en_US: https://console.mistral.ai/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 From 7a10992bfc2a6dcdb1c21b112c176207d2f529a5 Mon Sep 17 00:00:00 2001 From: Joshua Date: Wed, 28 Feb 2024 11:51:15 +0800 Subject: [PATCH 2/5] fix: linter --- api/core/model_runtime/model_providers/mistralai/llm/llm.py | 1 + 1 file changed, 1 insertion(+) diff --git a/api/core/model_runtime/model_providers/mistralai/llm/llm.py b/api/core/model_runtime/model_providers/mistralai/llm/llm.py index 266c9d527219d..01ed8010de873 100644 --- a/api/core/model_runtime/model_providers/mistralai/llm/llm.py +++ b/api/core/model_runtime/model_providers/mistralai/llm/llm.py @@ -5,6 +5,7 @@ from core.model_runtime.entities.message_entities import PromptMessage, PromptMessageTool from core.model_runtime.model_providers.openai_api_compatible.llm.llm import OAIAPICompatLargeLanguageModel + class MistralAILargeLanguageModel(OAIAPICompatLargeLanguageModel): def _invoke(self, model: str, credentials: dict, prompt_messages: list[PromptMessage], model_parameters: dict, From e014b238deb22fa7eb62c11834ccf24bb589c9f3 Mon Sep 17 00:00:00 2001 From: Joshua Date: Wed, 28 Feb 2024 12:00:01 +0800 Subject: [PATCH 3/5] fix: linter --- .../model_runtime/model_providers/mistralai/llm/_position.yaml | 2 +- .../model_providers/mistralai/llm/mistral-large-latest.yaml | 1 - .../model_providers/mistralai/llm/mistral-medium-latest.yaml | 1 - .../model_providers/mistralai/llm/mistral-small-latest.yaml | 1 - .../model_providers/mistralai/llm/open-mixtral-8x7b.yaml | 1 - 5 files changed, 1 insertion(+), 5 deletions(-) diff --git a/api/core/model_runtime/model_providers/mistralai/llm/_position.yaml b/api/core/model_runtime/model_providers/mistralai/llm/_position.yaml index 76b4a2ab2de98..5e74dc5dfec4f 100644 --- a/api/core/model_runtime/model_providers/mistralai/llm/_position.yaml +++ b/api/core/model_runtime/model_providers/mistralai/llm/_position.yaml @@ -2,4 +2,4 @@ - open-mixtral-8x7b - mistral-small-latest - mistral-medium-latest -- mistral-large-latest \ No newline at end of file +- mistral-large-latest diff --git a/api/core/model_runtime/model_providers/mistralai/llm/mistral-large-latest.yaml b/api/core/model_runtime/model_providers/mistralai/llm/mistral-large-latest.yaml index c10f2e2030080..0131ced403ce0 100644 --- a/api/core/model_runtime/model_providers/mistralai/llm/mistral-large-latest.yaml +++ b/api/core/model_runtime/model_providers/mistralai/llm/mistral-large-latest.yaml @@ -48,4 +48,3 @@ pricing: output: '0.024' unit: '0.001' currency: USD - diff --git a/api/core/model_runtime/model_providers/mistralai/llm/mistral-medium-latest.yaml b/api/core/model_runtime/model_providers/mistralai/llm/mistral-medium-latest.yaml index 605534216f9c2..f3b022eef222b 100644 --- a/api/core/model_runtime/model_providers/mistralai/llm/mistral-medium-latest.yaml +++ b/api/core/model_runtime/model_providers/mistralai/llm/mistral-medium-latest.yaml @@ -48,4 +48,3 @@ pricing: output: '0.0081' unit: '0.001' currency: USD - diff --git a/api/core/model_runtime/model_providers/mistralai/llm/mistral-small-latest.yaml b/api/core/model_runtime/model_providers/mistralai/llm/mistral-small-latest.yaml index a9f074abb2818..31a7c048237dd 100644 --- a/api/core/model_runtime/model_providers/mistralai/llm/mistral-small-latest.yaml +++ b/api/core/model_runtime/model_providers/mistralai/llm/mistral-small-latest.yaml @@ -48,4 +48,3 @@ pricing: output: '0.006' unit: '0.001' currency: USD - diff --git a/api/core/model_runtime/model_providers/mistralai/llm/open-mixtral-8x7b.yaml b/api/core/model_runtime/model_providers/mistralai/llm/open-mixtral-8x7b.yaml index 6b70ce6fe7221..c1c39b3ff99cd 100644 --- a/api/core/model_runtime/model_providers/mistralai/llm/open-mixtral-8x7b.yaml +++ b/api/core/model_runtime/model_providers/mistralai/llm/open-mixtral-8x7b.yaml @@ -48,4 +48,3 @@ pricing: output: '0.0007' unit: '0.001' currency: USD - From 0f07be12346c8000b10e5f048461adef93018463 Mon Sep 17 00:00:00 2001 From: Joshua Date: Wed, 28 Feb 2024 12:08:56 +0800 Subject: [PATCH 4/5] fix: linter --- .../model_providers/mistralai/llm/mistral-large-latest.yaml | 2 +- .../model_providers/mistralai/llm/mistral-medium-latest.yaml | 2 +- .../model_providers/mistralai/llm/mistral-small-latest.yaml | 2 +- .../model_providers/mistralai/llm/open-mixtral-8x7b.yaml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/api/core/model_runtime/model_providers/mistralai/llm/mistral-large-latest.yaml b/api/core/model_runtime/model_providers/mistralai/llm/mistral-large-latest.yaml index 0131ced403ce0..b729012c40788 100644 --- a/api/core/model_runtime/model_providers/mistralai/llm/mistral-large-latest.yaml +++ b/api/core/model_runtime/model_providers/mistralai/llm/mistral-large-latest.yaml @@ -20,7 +20,7 @@ parameter_rules: max: 1 - name: max_tokens use_template: max_tokens - default: 1024 + default: 1024 min: 1 max: 8000 - name: safe_prompt diff --git a/api/core/model_runtime/model_providers/mistralai/llm/mistral-medium-latest.yaml b/api/core/model_runtime/model_providers/mistralai/llm/mistral-medium-latest.yaml index f3b022eef222b..6e586b48437ba 100644 --- a/api/core/model_runtime/model_providers/mistralai/llm/mistral-medium-latest.yaml +++ b/api/core/model_runtime/model_providers/mistralai/llm/mistral-medium-latest.yaml @@ -20,7 +20,7 @@ parameter_rules: max: 1 - name: max_tokens use_template: max_tokens - default: 1024 + default: 1024 min: 1 max: 8000 - name: safe_prompt diff --git a/api/core/model_runtime/model_providers/mistralai/llm/mistral-small-latest.yaml b/api/core/model_runtime/model_providers/mistralai/llm/mistral-small-latest.yaml index 31a7c048237dd..4e7e6147f5543 100644 --- a/api/core/model_runtime/model_providers/mistralai/llm/mistral-small-latest.yaml +++ b/api/core/model_runtime/model_providers/mistralai/llm/mistral-small-latest.yaml @@ -20,7 +20,7 @@ parameter_rules: max: 1 - name: max_tokens use_template: max_tokens - default: 1024 + default: 1024 min: 1 max: 8000 - name: safe_prompt diff --git a/api/core/model_runtime/model_providers/mistralai/llm/open-mixtral-8x7b.yaml b/api/core/model_runtime/model_providers/mistralai/llm/open-mixtral-8x7b.yaml index c1c39b3ff99cd..a35cf0a9ae4d1 100644 --- a/api/core/model_runtime/model_providers/mistralai/llm/open-mixtral-8x7b.yaml +++ b/api/core/model_runtime/model_providers/mistralai/llm/open-mixtral-8x7b.yaml @@ -20,7 +20,7 @@ parameter_rules: max: 1 - name: max_tokens use_template: max_tokens - default: 1024 + default: 1024 min: 1 max: 8000 - name: safe_prompt From 1a27cce1ab26a33b44c371d5266da419dd8b9459 Mon Sep 17 00:00:00 2001 From: Joshua Date: Wed, 28 Feb 2024 13:00:47 +0800 Subject: [PATCH 5/5] position change --- api/core/model_runtime/model_providers/_position.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/api/core/model_runtime/model_providers/_position.yaml b/api/core/model_runtime/model_providers/_position.yaml index b2c6518395ee3..8c878d67d8114 100644 --- a/api/core/model_runtime/model_providers/_position.yaml +++ b/api/core/model_runtime/model_providers/_position.yaml @@ -6,6 +6,7 @@ - bedrock - togetherai - ollama +- mistralai - replicate - huggingface_hub - zhipuai