|
| 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 CometAPIConfig(BaseConfig): |
| 22 | + r"""Defines the parameters for generating chat completions using CometAPI's |
| 23 | + OpenAI-compatible interface. |
| 24 | +
|
| 25 | + Reference: https://api.cometapi.com/v1/ |
| 26 | +
|
| 27 | + Args: |
| 28 | + temperature (float, optional): Sampling temperature to use, between |
| 29 | + :obj:`0` and :obj:`2`. Higher values make the output more random, |
| 30 | + while lower values make it more focused and deterministic. |
| 31 | + (default: :obj:`None`) |
| 32 | + top_p (float, optional): An alternative to sampling with temperature, |
| 33 | + called nucleus sampling, where the model considers the results of |
| 34 | + the tokens with top_p probability mass. So :obj:`0.1` means only |
| 35 | + the tokens comprising the top 10% probability mass are considered. |
| 36 | + (default: :obj:`None`) |
| 37 | + n (int, optional): How many chat completion choices to generate for |
| 38 | + each input message. (default: :obj:`None`) |
| 39 | + response_format (object, optional): An object specifying the format |
| 40 | + that the model must output. Compatible with GPT-4 Turbo and all |
| 41 | + GPT-3.5 Turbo models newer than gpt-3.5-turbo-1106. Setting to |
| 42 | + {"type": "json_object"} enables JSON mode, which guarantees the |
| 43 | + message the model generates is valid JSON. Important: when using |
| 44 | + JSON mode, you must also instruct the model to produce JSON |
| 45 | + yourself via a system or user message. Without this, the model |
| 46 | + may generate an unending stream of whitespace until the generation |
| 47 | + reaches the token limit, resulting in a long-running and seemingly |
| 48 | + "stuck" request. Also note that the message content may be |
| 49 | + partially cut off if finish_reason="length", which indicates the |
| 50 | + generation exceeded max_tokens or the conversation exceeded the |
| 51 | + max context length. |
| 52 | + stream (bool, optional): If True, partial message deltas will be sent |
| 53 | + as data-only server-sent events as they become available. |
| 54 | + (default: :obj:`None`) |
| 55 | + stop (str or list, optional): Up to :obj:`4` sequences where the API |
| 56 | + will stop generating further tokens. (default: :obj:`None`) |
| 57 | + max_tokens (int, optional): The maximum number of tokens to generate |
| 58 | + in the chat completion. The total length of input tokens and |
| 59 | + generated tokens is limited by the model's context length. |
| 60 | + (default: :obj:`None`) |
| 61 | + presence_penalty (float, optional): Number between :obj:`-2.0` and |
| 62 | + :obj:`2.0`. Positive values penalize new tokens based on whether |
| 63 | + they appear in the text so far, increasing the model's likelihood |
| 64 | + to talk about new topics. See more information about frequency and |
| 65 | + presence penalties. (default: :obj:`None`) |
| 66 | + frequency_penalty (float, optional): Number between :obj:`-2.0` and |
| 67 | + :obj:`2.0`. Positive values penalize new tokens based on their |
| 68 | + existing frequency in the text so far, decreasing the model's |
| 69 | + likelihood to repeat the same line verbatim. See more information |
| 70 | + about frequency and presence penalties. (default: :obj:`None`) |
| 71 | + user (str, optional): A unique identifier representing your end-user, |
| 72 | + which can help CometAPI to monitor and detect abuse. |
| 73 | + (default: :obj:`None`) |
| 74 | + tools (list[FunctionTool], optional): A list of tools the model may |
| 75 | + call. Currently, only functions are supported as a tool. Use this |
| 76 | + to provide a list of functions the model may generate JSON inputs |
| 77 | + for. A max of 128 functions are supported. |
| 78 | + tool_choice (Union[dict[str, str], str], optional): Controls which (if |
| 79 | + any) tool is called by the model. :obj:`"none"` means the model |
| 80 | + will not call any tool and instead generates a message. |
| 81 | + :obj:`"auto"` means the model can pick between generating a |
| 82 | + message or calling one or more tools. :obj:`"required"` means the |
| 83 | + model must call one or more tools. Specifying a particular tool |
| 84 | + via {"type": "function", "function": {"name": "my_function"}} |
| 85 | + forces the model to call that tool. :obj:`"none"` is the default |
| 86 | + when no tools are present. :obj:`"auto"` is the default if tools |
| 87 | + are present. |
| 88 | + """ |
| 89 | + |
| 90 | + temperature: Optional[float] = None |
| 91 | + top_p: Optional[float] = None |
| 92 | + n: Optional[int] = None |
| 93 | + stream: Optional[bool] = None |
| 94 | + stop: Optional[Union[str, Sequence[str]]] = None |
| 95 | + max_tokens: Optional[int] = None |
| 96 | + presence_penalty: Optional[float] = None |
| 97 | + response_format: Optional[dict] = None |
| 98 | + frequency_penalty: Optional[float] = None |
| 99 | + user: Optional[str] = None |
| 100 | + tools: Optional[list] = None |
| 101 | + tool_choice: Optional[Union[dict[str, str], str]] = None |
| 102 | + |
| 103 | + |
| 104 | +COMETAPI_API_PARAMS = {param for param in CometAPIConfig.model_fields.keys()} |
0 commit comments