目标:借助 Dify 使用 deepseek-chat 模型的 Function Calling 能力,使 agent 获得调用留言板信息 API 的能力。Function Calling 详见 | DeepSeek API Docs
配置模型供应商

新建工具 Tool
导入 OpenAPI Schema
OpenAPI 是用来定义 HTTP APIs 的一套“语言”,它可以描述一个 HTTP 服务暴露了什么“模样”的接口,这里使用我的留言板服务的 OpenAPI Schema,如此配置之后,模型就能理解应该以什么样的数据结构去请求我们 HTTP 服务,也能正确解析接口返回的响应数据。
openapi: 3.0.3
info:
title: 留言板服务
version: 1.0.0
servers:
- url: "http://{hostname}/api"
variables:
hostname:
default: 127.0.0.1
paths:
/message-board:
get:
description: 获取留言板上的所有留言
responses:
"200":
description: todo
content:
application/json:
schema:
type: array
items:
$ref: "#/components/schemas/Message"
default:
description: todo
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
post:
description: 发布一条留言
requestBody:
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/Message"
responses:
"200":
description: todo
default:
description: todo
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
components:
schemas:
Message:
type: object
properties:
id:
type: string
content:
type: string
datetime:
type: string
Error:
type: object
properties:
message:
type: string
配置 Function Description
description 是关系到模型调用工具的时机,详见文档对话补全 | DeepSeek API Docs:

在 Agent 中添加工具进行对话测试
对话中使用“留言板情况如何?”、“今天留言板有没有什么值得注意的留言?”、“最近留言都在讲什么事情?”来测试
