Name 等
Logo:自動生成
Name 介紹
Description 介紹
Instructions 要求或命令等 比如用中文回復,角色。
Knowledge 上傳你的知識庫,如果你有某一垂直行業(yè)的數(shù)據(jù),基于數(shù)據(jù)來回答。比如我有某個芯片的指令集。
Capabilities 都要
Actions:就這個難以理解一點,下面詳說含義用法。
Addtional Settings 目前只有是否允許使用對話數(shù)據(jù)提高模型。
Actions 示例1:json格式
在ChatGPT中,Actions
是用于定義和執(zhí)行特定任務的功能模塊。這些任務通常涉及到與外部系統(tǒng)或服務的交互。你提供的示例是一個開放API(應用程序編程接口)的規(guī)格說明,用于獲取特定地點的當前天氣數(shù)據(jù)。讓我來解釋一下這個示例中各部分的含義:
-
openapi: 指定OpenAPI規(guī)格的版本,這里是3.1.0版本。
-
info: 提供API的基本信息。
- title: API的名稱,這里是“Get weather data”。
- description: API的簡要描述,說明它用于檢索特定位置的當前天氣數(shù)據(jù)。
- version: API的版本,這里是v1.0.0。
-
servers: 定義API的服務器列表。
- 這里只有一個服務器URL:“https://weather.example.com”。
-
paths: 描述API的各種路徑及其操作。
-
/location: 這是一個路徑,用于獲取特定位置的天氣數(shù)據(jù)。
-
get: 表示這是一個GET請求。
- description: 該操作的描述,這里是“獲取特定位置的溫度”。
- operationId: 操作的唯一標識符,這里是“GetCurrentWeather”。
-
parameters: 定義傳遞給API的參數(shù)。
- name: 參數(shù)的名稱,這里是“l(fā)ocation”。
- in: 參數(shù)的位置,這里是在查詢字符串中。
- description: 參數(shù)的描述,這里是“要檢索天氣的城市和州”。
- required: 是否必需,這里是true。
- schema: 參數(shù)的數(shù)據(jù)類型,這里是字符串。
-
get: 表示這是一個GET請求。
-
/location: 這是一個路徑,用于獲取特定位置的天氣數(shù)據(jù)。
-
components: 定義API使用的通用組件,這里的“schemas”是空的,表示沒有定義額外的數(shù)據(jù)結構。
在ChatGPT的上下文中,若要使用這樣的API,你需要根據(jù)這個規(guī)格描述構建相應的請求。例如,如果要獲取某個城市的天氣數(shù)據(jù),你會向"https://weather.example.com/location"發(fā)送一個帶有位置參數(shù)的GET請求。然而,由于ChatGPT當前的運行環(huán)境不支持直接與外部API交互,這類操作通常無法直接執(zhí)行。
//用中文解釋一下chatGPT中Actions的用法
{
"openapi": "3.1.0",
"info": {
"title": "Get weather data",
"description": "Retrieves current weather data for a location.",
"version": "v1.0.0"
},
"servers": [
{
"url": "https://weather.example.com"
}
],
"paths": {
"/location": {
"get": {
"description": "Get temperature for a specific location",
"operationId": "GetCurrentWeather",
"parameters": [
{
"name": "location",
"in": "query",
"description": "The city and state to retrieve the weather for",
"required": true,
"schema": {
"type": "string"
}
}
],
"deprecated": false
}
}
},
"components": {
"schemas": {}
}
}
Actions 示例2:YAML格式
# Taken from https://github.com/OAI/OpenAPI-Specification/blob/main/examples/v3.0/petstore.yaml
openapi: "3.0.0"
info:
version: 1.0.0
title: Swagger Petstore
license:
name: MIT
servers:
- url: https://petstore.swagger.io/v1
paths:
/pets:
get:
summary: List all pets
operationId: listPets
tags:
- pets
parameters:
- name: limit
in: query
description: How many items to return at one time (max 100)
required: false
schema:
type: integer
maximum: 100
format: int32
responses:
'200':
description: A paged array of pets
headers:
x-next:
description: A link to the next page of responses
schema:
type: string
content:
application/json:
schema:
$ref: "#/components/schemas/Pets"
default:
description: unexpected error
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
post:
summary: Create a pet
operationId: createPets
tags:
- pets
responses:
'201':
description: Null response
default:
description: unexpected error
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
/pets/{petId}:
get:
summary: Info for a specific pet
operationId: showPetById
tags:
- pets
parameters:
- name: petId
in: path
required: true
description: The id of the pet to retrieve
schema:
type: string
responses:
'200':
description: Expected response to a valid request
content:
application/json:
schema:
$ref: "#/components/schemas/Pet"
default:
description: unexpected error
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
components:
schemas:
Pet:
type: object
required:
- id
- name
properties:
id:
type: integer
format: int64
name:
type: string
tag:
type: string
Pets:
type: array
maxItems: 100
items:
$ref: "#/components/schemas/Pet"
Error:
type: object
required:
- code
- message
properties:
code:
type: integer
format: int32
message:
type: string
這個YAML文件是一個OpenAPI 3.0規(guī)范的示例,用于定義一個名為“Swagger Petstore”的API。這個API提供了操作寵物商店數(shù)據(jù)的接口。以下是文件的主要部分及其功能:
-
openapi: 指定OpenAPI規(guī)格的版本,這里是3.0.0版本。
-
info: 提供API的基本信息。
- version: API的版本,這里是1.0.0。
- title: API的名稱,這里是“Swagger Petstore”。
- license: 指定API的許可證,這里使用的是MIT許可證。
-
servers: 定義API的服務器列表。
- 這里的URL是"https://petstore.swagger.io/v1",代表API的主機地址。
-
paths: 描述API的各種路徑及其操作。
-
/pets: 這是一個路徑,用于處理與寵物相關的請求。
-
get: 獲取寵物列表的操作。
- summary: 操作的簡要描述,這里是“列出所有寵物”。
- parameters: 請求參數(shù),這里是一個名為“l(fā)imit”的查詢參數(shù),用于指定返回的項目數(shù)(最多100個)。
- responses: 定義了可能的響應。
- post: 創(chuàng)建新寵物的操作。
-
get: 獲取寵物列表的操作。
-
/pets/{petId}: 獲取特定寵物的詳細信息的路徑。
- get: 操作的描述,這里是“獲取特定寵物的信息”。
-
/pets: 這是一個路徑,用于處理與寵物相關的請求。
-
components: 定義API使用的通用組件。
- schemas: 定義了多個模式,包括“Pet”、“Pets”和“Error”,用于描述數(shù)據(jù)結構。
在這個API中,例如,如果想要獲取寵物列表,可以向"/pets"路徑發(fā)送一個GET請求,可能會帶有“l(fā)imit”參數(shù)來限制返回的數(shù)量。如果想要獲取特定寵物的詳細信息,可以向"/pets/{petId}“發(fā)送一個GET請求,其中”{petId}"是寵物的唯一標識符。
由于ChatGPT的運行環(huán)境不支持直接與外部API交互,這些操作無法直接在當前環(huán)境中執(zhí)行。但是,這個文件提供了一個完整的API規(guī)范,可以用于生成API文檔或在服務器上實現(xiàn)相應的功能。
Actions 示例3:json格式空白模板
{
"openapi": "3.1.0",
"info": {
"title": "Untitled",
"description": "Your OpenAPI specification",
"version": "v1.0.0"
},
"servers": [
{
"url": ""
}
],
"paths": {},
"components": {
"schemas": {}
}
}
外部系統(tǒng)示例(提供簡單的API來響應天氣查詢)
以下示例展示了如何設計一個外部系統(tǒng)來處理來自ChatGPT的請求,并返回JSON格式的天氣數(shù)據(jù)。這個示例中,假設外部系統(tǒng)是一個基于HTTP的Web服務,它提供了一個簡單的API來響應天氣查詢。
API設計
-
路徑:
/getWeather
-
方法:
GET
-
請求參數(shù):
-
location
: 要查詢天氣的地點(例如城市名稱)
-
請求示例
假設外部系統(tǒng)的基礎URL是 https://example-weather-api.com
。則一個向該API發(fā)送請求的URL可能是:
https://example-weather-api.com/getWeather?location=Beijing
處理請求
當外部系統(tǒng)收到一個請求時,它會解析查詢參數(shù)中的location
,然后根據(jù)這個地點獲取當前的天氣數(shù)據(jù)。
響應格式
響應將以JSON格式返回,包含地點、溫度、天氣狀況等信息。
響應示例
{
"location": "Beijing",
"temperature": "15°C",
"condition": "Sunny",
"humidity": "40%",
"wind": "10 km/h",
"forecast": [
{ "day": "Monday", "temperature": "16°C", "condition": "Partly Cloudy" },
{ "day": "Tuesday", "temperature": "14°C", "condition": "Rain" },
{ "day": "Wednesday", "temperature": "13°C", "condition": "Thunderstorms" }
]
}
實現(xiàn)注意事項
-
安全性: 確保處理請求時考慮到安全性,例如通過驗證輸入,防止注入攻擊等。
-
性能: 根據(jù)預期的負載選擇合適的服務器規(guī)格和擴展策略。
-
數(shù)據(jù)源: 此API可能依賴于第三方天氣服務提供數(shù)據(jù),因此需要考慮數(shù)據(jù)源的可靠性和更新頻率。
-
錯誤處理: 應妥善處理可能出現(xiàn)的錯誤情況,并返回相應的錯誤信息。
請注意,這個示例是理論上的設計,具體實現(xiàn)會根據(jù)技術棧、應用場景和業(yè)務需求有所不同。文章來源:http://www.zghlxwxcb.cn/news/detail-756772.html
用php寫一個外部系統(tǒng)示例(提供簡單的API來響應天氣查詢)
創(chuàng)建一個簡單的PHP腳本來模擬上述描述的外部系統(tǒng)是完全可行的。這個腳本將接收一個查詢參數(shù)(location
),然后返回硬編碼的天氣數(shù)據(jù)。在實際應用中,你可能會從數(shù)據(jù)庫或第三方API中獲取這些數(shù)據(jù),但為了簡單起見,我們在這里使用靜態(tài)數(shù)據(jù)。文章來源地址http://www.zghlxwxcb.cn/news/detail-756772.html
示例PHP腳本
<?php
// 模擬的天氣數(shù)據(jù)
$weatherData = [
"Beijing" => [
"temperature" => "15°C",
"condition" => "Sunny",
"humidity" => "40%",
"wind" => "10 km/h",
"forecast" => [
["day" => "Monday", "temperature" => "16°C", "condition" => "Partly Cloudy"],
["day" => "Tuesday", "temperature" => "14°C", "condition" => "Rain"],
["day" => "Wednesday", "temperature" => "13°C", "condition" => "Thunderstorms"]
]
],
// 更多地點的數(shù)據(jù)可以在此添加
];
header('Content-Type: application/json');
// 獲取查詢參數(shù)
$location = $_GET['location'] ?? 'Unknown';
// 查找對應地點的天氣數(shù)據(jù)
$response = $weatherData[$location] ?? null;
if ($response) {
// 如果找到了數(shù)據(jù),則返回
echo json_encode(["location" => $location] + $response);
} else {
// 沒有找到數(shù)據(jù),則返回錯誤信息
echo json_encode(["error" => "Weather data not found for location: " . $location]);
}
使用方法
- 將上述代碼保存為一個
.php
文件,例如getWeather.php
。 - 部署這個文件到一個PHP服務器上。你可以使用任何標準的LAMP(Linux, Apache, MySQL, PHP)或WAMP(Windows, Apache, MySQL, PHP)堆棧。
- 通過瀏覽器或任何HTTP客戶端訪問這個腳本,如:
http://yourserver.com/getWeather.php?location=Beijing
。
注意事項
- 這個示例非?;A,只用于演示目的。
- 它不包含任何安全性或錯誤處理功能,這在生產(chǎn)環(huán)境中是必需的。
- 在實際應用中,你可能需要從數(shù)據(jù)庫或第三方API中動態(tài)獲取天氣數(shù)據(jù)。
- 確保你的PHP服務器配置正確,可以處理GET請求并返回JSON數(shù)據(jù)。
到了這里,關于GPTs的創(chuàng)建與使用,自定義GPTs中的Actions示例用法 定義和執(zhí)行特定任務的功能模塊 通過API與外部系統(tǒng)或服務的交互的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!