mistral-api

Mistral API:Mistral AI 的 API,欧洲领先的 LLM 提供商,擅长代码生成与推理模型。适用于需要 GDPR 合规的 AI 推理、使用 Codestral 进行代码生成、多语言任务处理、高性价比推理或要求欧洲数据驻留的场景。

仓库最近推送
GitHub Stars
219
Forks
38
Issues / PRs
7

安装方式

先用 Prompt 核对来源与依赖。也可下载安装包。

用 AI 助手安装

复制提示词,让助手先核对固定版本和依赖。

查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "mistral-api":https://skillpi.com/zh/skills/deepskill-3e394cab6b5e3362ba69750724092415ecb5ee3f06aa66c162abcd7543e74425。安装前核对上游来源和版本:https://github.com/TerminalSkills/skills。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。

来源与配置

github.com

配置方式待核实

请查看原始来源中的适用工具、依赖和权限要求。

安装实测待补充

Mistral API:Mistral AI 的 API,欧洲领先的 LLM 提供商,擅长代码生成与推理模型。适用于需要 GDPR 合规的 AI 推理、使用 Codestral 进行代码生成、多语言任务处理、高性价比推理或要求欧洲数据驻留的场景。

0 下载

介绍来源: third_party · TerminalSkills · 1.0.0 参考来源

SkillPi 解读

软件、账号及付费要求
贝什
实测状态
未测试

文件浏览

在原站浏览文件 ↗

原始 SKILL.md

打开原文 ↗
Frontmatter
name: mistral-api
description: >-
  Mistral AI API — European LLM provider with strong code and reasoning models.
  Use when you need GDPR-compliant AI inference, code generation with Codestral,
  multilingual tasks, cost-efficient inference, or a European data-residency option.
license: Apache-2.0
compatibility: "Python 3.9+ or Node.js 18+ with mistralai SDK"
metadata:
  author: terminal-skills
  version: "1.0.0"
  category: data-ai
  tags: ["mistral", "llm", "european-ai", "gdpr", "code-generation"]
  use-cases:
    - "Generate code completions and fill-in-the-middle with Codestral"
    - "Run GDPR-compliant AI workloads with EU data residency"
    - "Build multilingual NLP pipelines with strong French/European language support"
  agents: [claude-code, openai-codex, gemini-cli, cursor]

Mistral AI API

Overview

Mistral AI is a French AI company providing high-quality, cost-efficient language models with EU data residency and GDPR compliance. Their models excel at code generation (Codestral), multilingual tasks, and reasoning. Mistral's API follows OpenAI conventions closely, making integration straightforward.

Setup

# Python
pip install mistralai

# TypeScript/Node
npm install @mistralai/mistralai
export MISTRAL_API_KEY=...

Available Models

Model Context Best For
mistral-large-latest 128k Most capable, complex reasoning
mistral-small-latest 128k Cost-efficient, everyday tasks
codestral-latest 256k Code generation & completion
mistral-embed 8k Text embeddings
open-mistral-nemo 128k Open-weight, edge deployment

Instructions

Basic Chat Completion (Python)

from mistralai import Mistral

client = Mistral(api_key="your_api_key")  # or reads MISTRAL_API_KEY

response = client.chat.complete(
    model="mistral-large-latest",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Explain the difference between async and sync programming."},
    ],
)

print(response.choices[0].message.content)
print(f"Prompt tokens: {response.usage.prompt_tokens}")
print(f"Completion tokens: {response.usage.completion_tokens}")

TypeScript/Node.js

import Mistral from "@mistralai/mistralai";

const client = new Mistral({ apiKey: process.env.MISTRAL_API_KEY });

const response = await client.chat.complete({
  model: "mistral-large-latest",
  messages: [{ role: "user", content: "Hello from TypeScript!" }],
});

console.log(response.choices[0].message.content);

Streaming

from mistralai import Mistral

client = Mistral()

stream = client.chat.stream(
    model="mistral-small-latest",
    messages=[{"role": "user", "content": "Write a haiku about programming."}],
)

for event in stream:
    chunk = event.data.choices[0].delta.content
    if chunk:
        print(chunk, end="", flush=True)
print()

Function Calling

import json
from mistralai import Mistral

client = Mistral()

tools = [
    {
        "type": "function",
        "function": {
            "name": "search_products",
            "description": "Search for products in a catalog",
            "parameters": {
                "type": "object",
                "properties": {
                    "query": {"type": "string"},
                    "max_price": {"type": "number"},
                    "category": {"type": "string"},
                },
                "required": ["query"],
            },
        },
    }
]

messages = [{"role": "user", "content": "Find laptops under $1000"}]

response = client.chat.complete(
    model="mistral-large-latest",
    messages=messages,
    tools=tools,
    tool_choice="auto",
)

if response.choices[0].finish_reason == "tool_calls":
    tool_call = response.choices[0].message.tool_calls[0]
    args = json.loads(tool_call.function.arguments)
    print(f"Function: {tool_call.function.name}, Args: {args}")

    # Add tool result and continue
    messages.append(response.choices[0].message)
    messages.append({
        "role": "tool",
        "tool_call_id": tool_call.id,
        "content": json.dumps([{"name": "ThinkPad X1", "price": 899}]),
    })

    final = client.chat.complete(model="mistral-large-latest", messages=messages)
    print(final.choices[0].message.content)

JSON Mode

from mistralai import Mistral
import json

client = Mistral()

response = client.chat.complete(
    model="mistral-small-latest",
    messages=[
        {
            "role": "user",
            "content": "Return a JSON object with fields: title, author, year for the book '1984'",
        }
    ],
    response_format={"type": "json_object"},
)

data = json.loads(response.choices[0].message.content)
print(data)  # {"title": "1984", "author": "George Orwell", "year": 1949}

Text Embeddings

from mistralai import Mistral

client = Mistral()

response = client.embeddings.create(
    model="mistral-embed",
    inputs=["Machine learning is transforming industries.", "AI is the future of technology."],
)

embeddings = [item.embedding for item in response.data]
print(f"Embedding dimension: {len(embeddings[0])}")  # 1024

# Compute cosine similarity
import numpy as np

def cosine_similarity(a, b):
    return np.dot(a, b) / (np.linalg.norm(a) * np.linalg.norm(b))

similarity = cosine_similarity(embeddings[0], embeddings[1])
print(f"Similarity: {similarity:.3f}")

Codestral for Code Completion

from mistralai import Mistral

client = Mistral()

# Fill-in-the-middle (FIM) — Codestral's signature feature
response = client.fim.complete(
    model="codestral-latest",
    prompt="def fibonacci(n):\n    if n <= 1:\n        return n\n    ",
    suffix="\n\nresult = fibonacci(10)\nprint(result)",
)

print(response.choices[0].message.content)
# Returns the middle code that connects prompt to suffix
# Standard code generation
response = client.chat.complete(
    model="codestral-latest",
    messages=[
        {
            "role": "user",
            "content": "Write a Python class for a rate limiter using token bucket algorithm.",
        }
    ],
)
print(response.choices[0].message.content)

GDPR Compliance Notes

  • All API data processed in EU data centers by default.
  • Mistral AI is headquartered in Paris, France — subject to EU/GDPR jurisdiction.
  • For enterprise data residency guarantees, use Mistral's Azure or GCP deployments.
  • No training on user data by default — check your plan's DPA for details.

Guidelines

  • Use mistral-large-latest for complex tasks, mistral-small-latest for cost savings.
  • Codestral is specialized for code and significantly outperforms general models on FIM tasks.
  • The mistral-embed model produces 1024-dimensional vectors.
  • Mistral models have strong multilingual performance, especially in French, Spanish, Italian, German, and Portuguese.
  • Function calling requires tool_choice to be set — use "auto" for model-driven decisions.
  • JSON mode requires the system or user prompt to explicitly mention JSON output.

当前收录版本

1.0.0

核对来源版本 ↗

质量评测

满分100 · 来自 SkillPi LAB 实验室的评测报告。

场景价值92/100

亮点

  • 提供 GDPR 合规与欧洲数据驻留的差异化 AI 推理能力
  • 完整覆盖 Codestral 代码生成、多语言处理、函数调用等高价值场景
触发精准95/100

亮点

  • 触发描述精准覆盖 GDPR、代码生成、多语言等核心使用场景
  • frontmatter 与 body 内 description 一致且完整
结构规范93/100

亮点

  • 结构清晰,分 Setup、Models、Instructions 等逻辑章节
  • 提供 Python/TypeScript/Streaming/Function Calling/JSON/Embeddings/Codestral 全场景端到端示例
执行可靠91/100

亮点

  • SDK 来源明确,参数使用规范
  • 覆盖 tool_calls 处理、JSON 解析等关键异常路径
证据可验 (前四项均值)93/100

取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。

正文静态检测

100 / 100 · skillpi-20261123-no-r3-v1

正文未命中当前规则。

分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。

权限与使用前检查

根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。

  • 安装或获取外部依赖

    使用官方来源并锁定版本,在隔离环境检查安装脚本。当前文档检查不覆盖后续下载的代码。

    主文档提及 · 第 31, 34 行
  • 账号、密钥或授权

    使用专用、最小权限账号,不把密钥粘贴到公开内容或命令日志;核对接收数据的服务与租户。

    主文档提及 · 第 58, 78 行

本站展示提示不会授予权限。涉及文件改动、密钥、外部发送或费用时,仍由你使用的工具按需确认。

安全评级与访问范围

safe · 静态证据核验,不代表运行安全保证。

贝什

使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。