|
| 1 | +# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. ========= |
| 2 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 3 | +# you may not use this file except in compliance with the License. |
| 4 | +# You may obtain a copy of the License at |
| 5 | +# |
| 6 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | +# |
| 8 | +# Unless required by applicable law or agreed to in writing, software |
| 9 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 10 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 | +# See the License for the specific language governing permissions and |
| 12 | +# limitations under the License. |
| 13 | +# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. ========= |
| 14 | +from __future__ import annotations |
| 15 | + |
| 16 | +from typing import Optional, Sequence, Union |
| 17 | + |
| 18 | +from camel.configs.base_config import BaseConfig |
| 19 | + |
| 20 | + |
| 21 | +class MinimaxConfig(BaseConfig): |
| 22 | + r"""Defines the parameters for generating chat completions using OpenAI |
| 23 | + compatibility with Minimax. |
| 24 | +
|
| 25 | + Reference: https://api.minimax.chat/document/guides/chat-model |
| 26 | +
|
| 27 | + Args: |
| 28 | + temperature (float, optional): Sampling temperature to use, between |
| 29 | + :obj:`0.0` and :obj:`1.0`. Higher values make the output more |
| 30 | + random, while lower values make it more focused and deterministic. |
| 31 | + Recommended to use :obj:`1.0`. Values outside this range will |
| 32 | + return an error. (default: :obj:`None`) |
| 33 | + top_p (float, optional): An alternative to sampling with temperature, |
| 34 | + called nucleus sampling, where the model considers the results of |
| 35 | + the tokens with top_p probability mass. So :obj:`0.1` means only |
| 36 | + the tokens comprising the top 10% probability mass are considered. |
| 37 | + (default: :obj:`None`) |
| 38 | + n (int, optional): How many chat completion choices to generate for |
| 39 | + each input message. Only supports value :obj:`1`. |
| 40 | + (default: :obj:`None`) |
| 41 | + response_format (object, optional): An object specifying the format |
| 42 | + that the model must output. Setting to |
| 43 | + {"type": "json_object"} enables JSON mode, which guarantees the |
| 44 | + message the model generates is valid JSON. Important: when using |
| 45 | + JSON mode, you must also instruct the model to produce JSON |
| 46 | + yourself via a system or user message. Without this, the model |
| 47 | + may generate an unending stream of whitespace until the generation |
| 48 | + reaches the token limit, resulting in a long-running and seemingly |
| 49 | + "stuck" request. Also note that the message content may be |
| 50 | + partially cut off if finish_reason="length", which indicates the |
| 51 | + generation exceeded max_tokens or the conversation exceeded the |
| 52 | + max context length. (default: :obj:`None`) |
| 53 | + stream (bool, optional): If set, partial message deltas will be sent, |
| 54 | + like in ChatGPT. Tokens will be sent as data-only server-sent |
| 55 | + events as they become available, with the stream terminated by |
| 56 | + a data: [DONE] message. (default: :obj:`None`) |
| 57 | + stop (str or list, optional): Up to :obj:`4` sequences where the API |
| 58 | + will stop generating further tokens. (default: :obj:`None`) |
| 59 | + max_tokens (int, optional): The maximum number of tokens to generate |
| 60 | + in the chat completion. The total length of input tokens and |
| 61 | + generated tokens is limited by the model's context length. |
| 62 | + (default: :obj:`None`) |
| 63 | + user (str, optional): A unique identifier representing your end-user, |
| 64 | + which can help to monitor and detect abuse. |
| 65 | + (default: :obj:`None`) |
| 66 | + tool_choice (Union[dict[str, str], str], optional): Controls which (if |
| 67 | + any) tool is called by the model. :obj:`"none"` means the model |
| 68 | + will not call any tool and instead generates a message. |
| 69 | + :obj:`"auto"` means the model can pick between generating a |
| 70 | + message or calling one or more tools. :obj:`"required"` means the |
| 71 | + model must call one or more tools. Specifying a particular tool |
| 72 | + via {"type": "function", "function": {"name": "my_function"}} |
| 73 | + forces the model to call that tool. :obj:`"none"` is the default |
| 74 | + when no tools are present. :obj:`"auto"` is the default if tools |
| 75 | + are present. |
| 76 | +
|
| 77 | + Note: |
| 78 | + Some OpenAI parameters such as presence_penalty, frequency_penalty, |
| 79 | + and logit_bias will be ignored by Minimax. |
| 80 | + """ |
| 81 | + |
| 82 | + temperature: Optional[float] = None |
| 83 | + top_p: Optional[float] = None |
| 84 | + n: Optional[int] = None |
| 85 | + stream: Optional[bool] = None |
| 86 | + stop: Optional[Union[str, Sequence[str]]] = None |
| 87 | + max_tokens: Optional[int] = None |
| 88 | + response_format: Optional[dict] = None |
| 89 | + user: Optional[str] = None |
| 90 | + tool_choice: Optional[Union[dict[str, str], str]] = None |
| 91 | + |
| 92 | + |
| 93 | +MINIMAX_API_PARAMS = {param for param in MinimaxConfig.model_fields.keys()} |
0 commit comments