コンテンツにスキップ

Craft AI Modules を利用する

Craft AI ModulesはCraft FunctionsからAIモデルを簡単に利用できる機能です。次のような特徴があります。

  • プレイドがフルマネージドでホストしているので、AIモデルの契約や保守/運用が不要です。
  • 入力に使ったデータはモデルの再トレーニングには使用されないなど、エンタープライズ基準のAIモデルを提供しており、安心して利用できます。

概要

Craft AI Modulesでは、Craft Functionsから利用できるAPIクライアントを経由して各種AIモデルにアクセスします。

craft-ai-modules

各プロバイダにおける構成要素は次のとおりです。

Vertex AI Platform

  • Craft Functions向けのクライアント
    • aiModules というクライアントを提供しています。

利用方法

Craft AI Modulesの利用方法を説明します。

Vertex AI Platformのモデルを利用する

Vertex AI Platformのモデルは aiModules クライアント経由で利用できます。利用できるメソッドはリファレンスをご確認ください。

// Main export function
export default async function (data, { MODULES }) {
const { aiModules } = MODULES;
// コンテンツ生成(テキスト生成)を行う
const response = await aiModules.gcpGeminiGenerateContent({
model: "gemini-2.5-flash",
contents: [{ role: 'user', parts: [{ text: "How does AI work?" }] }],
});
// 返却値のフォーマット
// response = {
// usageMetadata: {
// candidatesTokenCount: ...,
// totalTokenCount: ...,
// promptTokenCount: ...,
// thoughtsTokenCount: ...,
// },
// candidates: [
// {
// role: 'user', // 役割
// parts: [
// text: 'answer text...', // 生成結果
// functionCall: { // tool 呼び出しの引数
// name: 'tool',
// args: { ... },
// },
// functionResponse: { // tool 呼び出し結果
// name: 'tool',
// response: { ... },
// },
// ...
// ],
// finishReason: '...' // 回答終了理由
// },
// ...
// ],
// }
...
}