スキルプラグイン開発
概要
SERVICEMEでは、スキルプラグインはCopilotのオプション機能を指します。システムに組み込まれているプラグインの他に、開発を通じてスキルプラグインを拡張し、Copilotにさらなる能力を付与することができます。
システム内蔵スキルプラグイン
番号 | プラグイン | プラグインタイプ | 用途 |
---|---|---|---|
SearchKnowledgebase | ナレッジベース検索 | APIプラグイン | プライベートナレッジの検索機能を提供 |
ImageGeneration | 画像生成 | APIプラグイン | テキスト記述に基づいて画像を生成 |
Browsing | ウェブ閲覧 | APIプラグイン | リアルタイム情報を検索するためのウェブ閲覧機能を提供 |
Charts | チャート | APIプラグイン | 提供されたデータに基づいて対応するチャートを生成、棒グラフ、折れ線グラフ、円グラフをサポート |
DocumentReader | 文書リーダー | APIプラグイン | 単一文書または選択された文書の要約情報を提供 |
QuestionContact | 質問連絡先 | APIプラグイン | 質問の分野に基づいて、対応する分野の連絡先を返す |
タイプ説明
タイプ | 説明 |
---|---|
APIプラグイン | スキルプラグインはバックエンドAPIとして機能し、Copilotがコンテキストに基づいてAPIの入力パラメータを埋め、APIの戻り値を解析 |
APIスキルプラグイン
認証方式のサポート
現在、固定ヘッダー認証または認証不要のインターフェース呼び出しのみをサポートしています。
タイプ | 説明 |
---|---|
固定ヘッダー | リクエストヘッダーを通じて固定のキーを指定してインターフェース認証を行う、OpenAI api_keyの形式に類似 |
プラグイン開発
このプロセスを理解しやすくするために、タイムゾーンコードを使用してタイムゾーン情報を取得するAPIプラグインを例にします。
第一歩:タイムゾーンコードに基づいてタイムゾーン情報を返すAPIを提供します。
APIの例
- .NET (Web API)
- Java (Spring Boot)
- Python (Fast API)
- Javascript (Next.js)
using Microsoft.AspNetCore.Mvc;
using System;
namespace WorldTimeApi.Controllers
{
[ApiController]
[Route("api/[controller]")]
public class TimeController : ControllerBase
{
[HttpGet("current/zone")]
public IActionResult GetTimeByZone([FromQuery] string timeZone)
{
if (string.IsNullOrEmpty(timeZone))
{
return BadRequest("Missing required parameter: timeZone");
}
try
{
// タイムゾーン情報を検索
var timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById(timeZone);
// 指定されたタイムゾーンの現在時刻を取得
var currentTime = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, timeZoneInfo);
// 結果を返す
return Ok(new
{
TimeZone = timeZone,
CurrentTime = currentTime.ToString("yyyy-MM-ddTHH:mm:ss")
});
}
catch (TimeZoneNotFoundException)
{
return NotFound("Time zone not found");
}
catch (InvalidTimeZoneException)
{
return BadRequest("Invalid time zone");
}
catch (Exception ex)
{
return StatusCode(500, $"Internal server error: {ex.Message}");
}
}
}
}
package com.example.worldtime;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
@RestController
public class TimeController {
@GetMapping("/api/Time/current/zone")
public Object getTimeByZone(@RequestParam String timeZone) {
try {
ZoneId zoneId = ZoneId.of(timeZone);
ZonedDateTime currentTime = ZonedDateTime.ofInstant(Instant.now(), zoneId);
return new TimeResponse(timeZone, currentTime.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
} catch (Exception e) {
return "Invalid time zone: " + e.getMessage();
}
}
static class TimeResponse {
public String timeZone;
public String currentTime;
public TimeResponse(String timeZone, String currentTime) {
this.timeZone = timeZone;
this.currentTime = currentTime;
}
}
}
from fastapi import FastAPI, HTTPException
from pydantic import BaseModel
from datetime import datetime
import pytz
app = FastAPI()
class TimeResponse(BaseModel):
timeZone: str
currentTime: str
@app.get("/api/Time/current/zone", response_model=TimeResponse)
async def get_time_by_zone(timeZone: str):
if not timeZone:
raise HTTPException(status_code=400, detail="Missing required parameter: timeZone")
try:
tz = pytz.timezone(timeZone)
current_time = datetime.now(tz)
return TimeResponse(
timeZone=timeZone,
currentTime=current_time.strftime('%Y-%m-%dT%H:%M:%S')
)
except pytz.UnknownTimeZoneError:
raise HTTPException(status_code=404, detail="Time zone not found")
except Exception as e:
raise HTTPException(status_code=500, detail=f"Internal server error: {str(e)}")
import moment from 'moment-timezone';
export default function handler(req, res) {
const { timeZone } = req.query;
if (!timeZone) {
return res.status(400).json({ error: 'Missing required parameter: timeZone' });
}
try {
const currentTime = moment().tz(timeZone).format('YYYY-MM-DDTHH:mm:ss');
res.status(200).json({
timeZone: timeZone,
currentTime: currentTime,
});
} catch (e) {
res.status(404).json({ error: 'Time zone not found' });
}
}
第二歩:このプラグインをシステムに登録します
スキルプラグインを追加し、以下の情報を入力します
フィールド説明
- Code、プラグインのコード、システム内でのプラグインの一意の識別子、意味のある記述を使用することを推奨。
- Name、プラグインの表示名、Copilotが思考および実行中に使用するプラグイン名、多言語対応を考慮。
- Description、プラグインの説明、プラグインの役割を説明するために使用され、Copilotのスキルプラグイン追加画面に表示。
- Request Header、プラグイン呼び出しに必要なヘッダーパラメータを入力するためのフィール ド、例:API_KEY
- 【重要】OpenAPI / Swagger Schema ( JSON )、APIの主体の説明、ここでの情報はCopilotがこのスキルをどのような状況で呼び出すべきか、各パラメータをどのように埋めるべきかを理解するために重要。
OpenAPI Schema (JSON) の例
Get time zone
{
"Openapi": "3.0.0",
"Info": {
"Title": "World Time",
"Description": "Getting world time",
"Version": "v1.0.0"
},
"Servers": [
{
"Url": "https://www.timeapi.io"
}
],
"Paths": {
"/api/Time/current/zone": {
"Get": {
"OperationId": "zone",
"Description": "Get world time by timezone name",
"Deprecated": false,
"Parameters": [
{
"Name": "timeZone",
"In": "query",
"Required": true,
"Description": "Full IANA time zone names.",
"Schema": {
"Type": "string"
}
}
]
}
}
}
}
注意
- Info/Title、ここに記載するプラグインのタイトルは、Copilotがこのプラグインの役割を理解するのに役立ちます。
- Paths/[api path]/Get/OperationId、Copilotのプロンプトで特定のシナリオで呼び出すAPIを明示するために、反引号`%OperationId%`を使用できます。詳細は以下の第四歩の例を参照。
- Paths/[api path]/Get/Description、Copilotが理解するのを助け、特定のAPI呼び出しを行う状況に影響を与えます。
- Paths/[api path]/Get/Parameters、実際のAPIと一致させることが重要です。例えば、ここではqueryなので、APIもqueryからパラメータを取得する必要があります。ここが他のタイプ(例:json body)であれば、APIも一致させる必要があります。パラメータ名の説明は、パラメータの埋め込み成功率を向上させるのに役立ちます。
- Servers/Url、APIのBaseURLであり、正しく入力しないと呼び出しに失敗します。
- 【オプション】プラグインの設定が完了したら、DEBUG機能を使用してデバッグできます。
第三歩:Copilotにスキルプラグインを追加します
Copilotの設定画面で、[スキルプラグイン]タブを通じてプラグインを追加します。
設定を保存した後、専門家との対話でテストを行います。
第四歩:【オプション】Copilotのプロンプトに必要な説明を追加し、このスキルをより良く実行するように指示します。
例
特定のサイトで検索を行うためのブラウザプラグインのガイド
### Skill 3: Web Searching
- `Browsering`ツールキットを使用してウェブサイトにアクセスし、以下のサイトからHR情報を検索できます: (site:*.linkedin.com; site:*.zhipin.com)
- 結果を使用してユーザーのリクエストを満たし、応答の最後に参照リンクをリストアップします。
注:ほとんどの場合、CopilotはOpenAPI Schemaの情報に基づいて実行タイミングやパラメータの埋め込みを自動的に判断します。