跳到主要内容

oai.mistral

使用Mistral.AI的API创建一个与OpenAI兼容的客户端。

示例:

llm_config={

  • "config_list" - [{

  • "api_type" - "mistral",

  • "model" - "open-mixtral-8x22b",

  • "api_key" - os.environ.get("MISTRAL_API_KEY") } ]}

    agent = autogen.AssistantAgent("my_agent", llm_config=llm_config)

    使用以下命令安装Mistral.AI Python库:pip install --upgrade mistralai

    资源:

  • 注意 - 需要 mistralai 包版本 >= 1.0.1

MistralAIClient

class MistralAIClient()

Mistral.AI的API客户端。

__init__

def __init__(**kwargs)

需要设置api_key或环境变量

参数:

  • api_key str - 用于使用Mistral.AI的API密钥(或需要设置环境变量MISTRAL_API_KEY)

消息检索

def message_retrieval(
response: ChatCompletion
) -> Union[List[str], List[ChatCompletionMessage]]

从响应中检索消息。

parse_params

def parse_params(params: Dict[str, Any]) -> Dict[str, Any]

从传入的参数中加载Mistral.AI API的参数,并返回经过验证的参数集。检查类型、范围,并设置默认值。

tool_def_to_mistral

def tool_def_to_mistral(
tool_definitions: List[Dict[str, Any]]) -> List[Dict[str, Any]]

将AutoGen工具定义转换为mistral工具格式

calculate_mistral_cost

def calculate_mistral_cost(input_tokens: int, output_tokens: int,
model_name: str) -> float

计算mistral响应的成本。