Files
notes/resource/ai/大模型安装笔记/结构化输出和工具调用.md
Docker7530 d17550351d 1774673562
2026-03-28 12:52:49 +08:00

3.5 KiB

{
    "model": "deepseek-chat",
    "messages": [
        {
            "role": "user",
            "content": "北京现在的天气怎么样?"
        }
    ],
    "tools": [
        {
            "type": "function",
            "function": {
                "name": "get_weather",
                "description": "获取指定城市的天气信息",
                "parameters": {
                    "type": "object",
                    "properties": {
                        "city": {
                            "type": "string",
                            "description": "城市名称"
                        }
                    },
                    "required": [
                        "city"
                    ]
                }
            }
        }
    ],
    "tool_choice": "auto"
}


{
    "id": "06bcc2b7-602a-474b-bdd3-01cea249b121",
    "object": "chat.completion",
    "created": 1774519072,
    "model": "deepseek-chat",
    "choices": [
        {
            "index": 0,
            "message": {
                "role": "assistant",
                "content": "我来帮您查询北京的天气情况。",
                "tool_calls": [
                    {
                        "index": 0,
                        "id": "call_00_s4Qs5fJiG0yeRTpOgYxnxRyp",
                        "type": "function",
                        "function": {
                            "name": "get_weather",
                            "arguments": "{\"city\": \"北京\"}"
                        }
                    }
                ]
            },
            "logprobs": null,
            "finish_reason": "tool_calls"
        }
    ],
    "usage": {
        "prompt_tokens": 309,
        "completion_tokens": 51,
        "total_tokens": 360,
        "prompt_tokens_details": {
            "cached_tokens": 0
        },
        "prompt_cache_hit_tokens": 0,
        "prompt_cache_miss_tokens": 309
    },
    "system_fingerprint": "fp_eaab8d114b_prod0820_fp8_kvcache_new_kvcache"
}
{
    "model": "deepseek-chat",
    "messages": [
        {
            "role": "user",
            "content": "给我返回一个水果的信息,包含名称和颜色"
        }
    ],
    "response_format": {
        "type": "json_schema",
        "json_schema": {
            "name": "fruit",
            "schema": {
                "type": "object",
                "properties": {
                    "name": {
                        "type": "string",
                        "description": "水果名称"
                    },
                    "color": {
                        "type": "string",
                        "description": "水果颜色"
                    }
                },
                "required": [
                    "name",
                    "color"
                ]
            }
        }
    }
}
{
    "id": "chatcmpl-2b2225c5-02d0-4817-8039-329b3c790128",
    "object": "chat.completion",
    "created": 1774519551,
    "model": "gpt-5.4",
    "choices": [
        {
            "index": 0,
            "message": {
                "role": "assistant",
                "content": "{\"color\":\"红色\",\"name\":\"苹果\"}"
            },
            "finish_reason": "stop"
        }
    ],
    "usage": {
        "prompt_tokens": 80,
        "completion_tokens": 17,
        "total_tokens": 97,
        "prompt_tokens_details": {},
        "completion_tokens_details": {
            "reasoning_tokens": 0,
            "accepted_prediction_tokens": 0,
            "rejected_prediction_tokens": 0
        }
    }
}