{
  "openapi": "3.0.3",
  "info": {
    "title": "国力化工 AI 助手 API",
    "description": "国力化工产品智能助手API，提供产品查询、价格咨询、化学属性查询等功能。AI助手能够理解用户问题并调用相应的工具函数来查询国力化工产品数据库，为用户提供专业的化工产品咨询服务。",
    "version": "1.0.0",
    "contact": {
      "name": "国力化工技术支持",
      "phone": "0513-88826680",
      "sales_mobile": "15962749399"
    }
  },
  "servers": [
    {
      "url": "https://www.guolichem.com",
      "description": "正式服务器"
    }
  ],
  "paths": {
    "/api/ai_chat/send": {
      "post": {
        "summary": "发送聊天消息",
        "description": "向AI助手发送消息并获取回复。支持产品查询、价格咨询、化学属性查询、产品对比等功能。AI会自动调用相应的工具函数来查询产品数据库。",
        "operationId": "sendMessage",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["message"],
                "properties": {
                  "message": {
                    "type": "string",
                    "description": "用户发送的消息内容",
                    "example": "O-25的价格是多少？"
                  }
                }
              },
              "example": {
                "message": "平平加O-25的价格是多少？"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "成功获取AI回复",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "code": {
                      "type": "integer",
                      "description": "状态码，1表示成功"
                    },
                    "msg": {
                      "type": "string",
                      "description": "响应消息"
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "message": {
                          "type": "string",
                          "description": "AI助手的回复内容"
                        }
                      }
                    }
                  }
                },
                "example": {
                  "code": 1,
                  "msg": "发送成功",
                  "data": {
                    "message": "O-25（平平加O-25）的参考价格约为12元/公斤。具体价格请致电咨询：销售手机 15962749399 或 15962749399，公司固话 0513-88826680。"
                  }
                }
              }
            }
          },
          "500": {
            "description": "服务器错误",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "code": {
                      "type": "integer",
                      "example": 0
                    },
                    "msg": {
                      "type": "string",
                      "description": "错误信息"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/ai_chat/history": {
      "get": {
        "summary": "获取聊天历史",
        "description": "获取当前用户的聊天历史记录，返回最近50条消息。",
        "operationId": "getChatHistory",
        "responses": {
          "200": {
            "description": "成功获取聊天历史",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "code": {
                      "type": "integer",
                      "description": "状态码，1表示成功"
                    },
                    "msg": {
                      "type": "string",
                      "description": "响应消息"
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "list": {
                          "type": "array",
                          "description": "消息列表",
                          "items": {
                            "type": "object",
                            "properties": {
                              "id": {
                                "type": "integer",
                                "description": "消息ID"
                              },
                              "role": {
                                "type": "string",
                                "enum": ["user", "assistant"],
                                "description": "角色：user为用户，assistant为AI助手"
                              },
                              "content": {
                                "type": "string",
                                "description": "消息内容"
                              },
                              "create_time": {
                                "type": "integer",
                                "description": "创建时间戳"
                              }
                            }
                          }
                        }
                      }
                    }
                  }
                },
                "example": {
                  "code": 1,
                  "msg": "获取成功",
                  "data": {
                    "list": [
                      {
                        "id": 1,
                        "role": "user",
                        "content": "O-25的价格是多少？",
                        "create_time": 1717651200
                      },
                      {
                        "id": 2,
                        "role": "assistant",
                        "content": "O-25（平平加O-25）的参考价格...",
                        "create_time": 1717651201
                      }
                    ]
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "SendMessageRequest": {
        "type": "object",
        "required": ["message"],
        "properties": {
          "message": {
            "type": "string",
            "description": "用户消息"
          }
        }
      },
      "SendMessageResponse": {
        "type": "object",
        "properties": {
          "code": {
            "type": "integer"
          },
          "msg": {
            "type": "string"
          },
          "data": {
            "type": "object",
            "properties": {
              "message": {
                "type": "string",
                "description": "AI回复"
              }
            }
          }
        }
      },
      "ChatHistoryResponse": {
        "type": "object",
        "properties": {
          "code": {
            "type": "integer"
          },
          "msg": {
            "type": "string"
          },
          "data": {
            "type": "object",
            "properties": {
              "list": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/ChatMessage"
                }
              }
            }
          }
        }
      },
      "ChatMessage": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "role": {
            "type": "string",
            "enum": ["user", "assistant"]
          },
          "content": {
            "type": "string"
          },
          "create_time": {
            "type": "integer"
          }
        }
      }
    },
    "securitySchemes": {},
    "parameters": {},
    "responses": {},
    "examples": {}
  },
  "x-ai-tools": {
    "description": "AI助手可调用的工具函数",
    "tools": [
      {
        "name": "search_products",
        "description": "根据关键词搜索产品，支持搜索产品名称、别名、CAS号等",
        "parameters": {
          "type": "object",
          "properties": {
            "keyword": {
              "type": "string",
              "description": "搜索关键词"
            },
            "limit": {
              "type": "integer",
              "description": "返回结果数量，默认为10",
              "default": 10
            }
          },
          "required": ["keyword"]
        },
        "returns": {
          "type": "object",
          "properties": {
            "data_source": {
              "type": "string",
              "description": "数据来源：国力化工数据库"
            },
            "keyword": {
              "type": "string"
            },
            "total": {
              "type": "integer"
            },
            "products": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "product_id": {
                    "type": "integer"
                  },
                  "product_name": {
                    "type": "string"
                  },
                  "alias": {
                    "type": "string"
                  },
                  "cas": {
                    "type": "string"
                  },
                  "product_url": {
                    "type": "string"
                  }
                }
              }
            }
          }
        }
      },
      {
        "name": "get_product_detail",
        "description": "根据产品ID或产品名称查询产品的详细信息",
        "parameters": {
          "type": "object",
          "properties": {
            "product_id": {
              "type": "integer",
              "description": "产品ID"
            },
            "product_name": {
              "type": "string",
              "description": "产品名称"
            }
          }
        },
        "returns": {
          "type": "object",
          "properties": {
            "data_source": {
              "type": "string",
              "description": "数据来源：国力化工数据库"
            },
            "product_id": {
              "type": "integer"
            },
            "product_name": {
              "type": "string"
            },
            "fullname": {
              "type": "string",
              "description": "产品全称"
            },
            "alias": {
              "type": "string",
              "description": "别名"
            },
            "cas": {
              "type": "string",
              "description": "CAS号"
            },
            "molecular_formula": {
              "type": "string",
              "description": "分子式"
            },
            "molecular_weight": {
              "type": "string",
              "description": "分子量"
            },
            "appearance": {
              "type": "string",
              "description": "外观"
            },
            "application": {
              "type": "string",
              "description": "应用领域"
            },
            "safety": {
              "type": "string",
              "description": "安全信息"
            }
          }
        }
      },
      {
        "name": "get_product_chemical_properties",
        "description": "查询产品的化学属性信息，包括分子式、分子量、安全信息等",
        "parameters": {
          "type": "object",
          "properties": {
            "product_id": {
              "type": "integer",
              "description": "产品ID"
            },
            "product_name": {
              "type": "string",
              "description": "产品名称"
            }
          }
        },
        "returns": {
          "type": "object",
          "properties": {
            "data_source": {
              "type": "string"
            },
            "product_id": {
              "type": "integer"
            },
            "product_name": {
              "type": "string"
            },
            "fullname": {
              "type": "string"
            },
            "alias": {
              "type": "string"
            },
            "cas": {
              "type": "string"
            },
            "molecular_formula": {
              "type": "string"
            },
            "molecular_weight": {
              "type": "string"
            },
            "appearance": {
              "type": "string"
            },
            "application": {
              "type": "string"
            },
            "safety": {
              "type": "string"
            }
          }
        }
      },
      {
        "name": "compare_products",
        "description": "对比多个产品的参数信息，便于用户进行产品选型",
        "parameters": {
          "type": "object",
          "properties": {
            "product_ids": {
              "type": "array",
              "items": {
                "type": "integer"
              },
              "description": "产品ID数组"
            },
            "product_names": {
              "type": "array",
              "items": {
                "type": "string"
              },
              "description": "产品名称数组"
            }
          }
        },
        "returns": {
          "type": "object",
          "properties": {
            "data_source": {
              "type": "string"
            },
            "products": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "product_id": {
                    "type": "integer"
                  },
                  "product_name": {
                    "type": "string"
                  },
                  "product_url": {
                    "type": "string"
                  }
                }
              }
            },
            "comparison": {
              "type": "object",
              "description": "对比数据，key为参数名称，value为各产品的参数值数组"
            }
          }
        }
      },
      {
        "name": "get_product_price",
        "description": "查询产品价格信息，返回价格和销售联系方式",
        "parameters": {
          "type": "object",
          "properties": {
            "product_id": {
              "type": "integer",
              "description": "产品ID"
            },
            "product_name": {
              "type": "string",
              "description": "产品名称"
            }
          }
        },
        "returns": {
          "type": "object",
          "properties": {
            "data_source": {
              "type": "string",
              "description": "数据来源：国力化工数据库"
            },
            "product_id": {
              "type": "integer"
            },
            "product_name": {
              "type": "string"
            },
            "has_price": {
              "type": "boolean",
              "description": "是否有价格信息"
            },
            "price_text": {
              "type": "string",
              "description": "价格文本"
            },
            "sales_phone_1": {
              "type": "string",
              "description": "销售手机1"
            },
            "sales_phone_2": {
              "type": "string",
              "description": "销售手机2"
            },
            "company_mobile": {
              "type": "string",
              "description": "公司手机"
            },
            "company_phone": {
              "type": "string",
              "description": "公司固话"
            },
            "wechat_qrcode": {
              "type": "string",
              "description": "微信二维码URL"
            }
          }
        }
      }
    ]
  }
}
