コンテンツにスキップ

Craft AI Modules Google

const { aiModules } = MODULES;

Table of Contents

aiModules

Standard AI modules for GCP services

gcpGeminiGenerateContent

Geminiにリクエストを送信する

Parameters

Returns Promise<GeminiResultValue>

gcpGeminiGenerateContentStream

Geminiにストリーミングリクエストを送信する

Parameters

Returns Promise<void>

gcpEmbeddingsText

TextEmbeddingsにリクエストを送信する

Parameters

  • param Object
    • param.text string テキストの内容 (deprecated, use instances instead)
    • param.instances Array<TextEmbeddingInstance>? インスタンスの配列
    • param.parameters TextEmbeddingParameters? パラメータ
    • param.model string? モデル名 (optional) - ‘text-multilingual-embedding-002’, ‘text-embedding-004’, ‘gemini-embedding-001’

Returns Promise<EmbeddingsResultValue>

gcpEmbeddingsMulti

MultiModalEmbeddingsにリクエストを送信する

Parameters

  • param Object
    • param.text string? テキストの内容
    • param.dimension number? 次元数
    • param.bytesBase64Encoded string? 画像をBase64エンコードしたバイト列
    • param.model string? モデル名 (optional) - ‘multimodalembedding@001’
  • Throws Error failed. text or bytesBase64Encoded is required

Returns Promise<MultiEmbeddingsResultValue>

gcpRerank

GCP Rerank APIにリクエストを送信する

Parameters

  • param Object
    • param.query string 検索クエリ
    • param.records Array<RerankRecord> ランク付けするレコードの配列
    • param.model string? モデル名(デフォルト: semantic-ranker-512@latest)。利用可能なモデル: semantic-ranker-512@latest, semantic-ranker-default-004, semantic-ranker-fast-004
    • param.ignoreRecordDetailsInResponse boolean? レコードのタイトルとコンテンツも返さないか(デフォルト: true)
    • param.topN number? 返される上位レコードの数(デフォルト: 10)
  • Throws Error failed. query and records are required

Returns Promise<RerankResultValue>

ALLOWED_GEMINI_MODELS

Standard版で利用可能なGeminiモデル

validateGeminiModel

Geminiモデルのバリデーション

Parameters

  • Throws Error モデルが許可されていない場合

GeminiGenerationConfig

Type: Object

Properties

  • maxOutputTokens number? 最大出力トークン数
  • temperature number? 温度パラメータ (0-2)
  • topP number? Top-p サンプリング
  • responseMimeType string? レスポンスのMIMEタイプ
  • responseSchema Object? レスポンススキーマ
  • thinkingConfig Object? Thinking mode設定
    • thinkingConfig.includeThoughts boolean? 思考プロセスを含めるか
    • thinkingConfig.thinkingBudget number? 思考用トークン予算(Gemini 2.5モデル用、0-32768)
    • thinkingConfig.thinkingLevel ("minimal" | "low" | "medium" | "high")? 思考レベル(Gemini 3/3.1モデル用、デフォルト’high’、無効化不可)。* gemini-3-flash-preview: ‘minimal’ | ‘low’ | ‘medium’ | ‘high’ サポート
      • gemini-3.1-pro-preview: ‘low’ | ‘medium’ | ‘high’ サポート
      • gemini-3.1-flash-lite-preview: ‘minimal’ | ‘low’ | ‘medium’ | ‘high’ サポート

GeminiSafetySetting

Type: Object

Properties

  • category ("HARM_CATEGORY_HARASSMENT" | "HARM_CATEGORY_HATE_SPEECH" | "HARM_CATEGORY_SEXUALLY_EXPLICIT" | "HARM_CATEGORY_DANGEROUS_CONTENT") 安全性カテゴリ
  • threshold ("BLOCK_NONE" | "BLOCK_ONLY_HIGH" | "BLOCK_MEDIUM_AND_ABOVE" | "BLOCK_LOW_AND_ABOVE") ブロック閾値

GeminiCandidate

Type: Object

Properties

  • content Object コンテンツ
  • finishReason string? 終了理由
  • groundingMetadata Object? グラウンディングメタデータ

GeminiResponse

Type: Object

Properties

  • candidates Array<GeminiCandidate> 候補リスト

  • usageMetadata Object 使用量メタデータ

    • usageMetadata.promptTokenCount number プロンプトトークン数
    • usageMetadata.candidatesTokenCount number 候補トークン数
    • usageMetadata.totalTokenCount number 合計トークン数
  • groundingMetadata Object? グラウンディングメタデータ

GeminiStreamChunk

Type: Object

Properties

  • delta Object? デルタコンテンツ
  • finishReason string? 終了理由
  • groundingMetadata Object? グラウンディングメタデータ
  • usageMetadata Object? 使用量メタデータ(最終チャンク)

RagOptions

Type: Object

Properties

  • corpusId string RAG ID
  • vectorDistanceThreshold number? ベクトル距離の閾値
  • llmRankerModel string? LLMランカーのモデル名
  • rankServiceModel string? ランクサービスのモデル名
  • topK number? トップK

CraftExtra

Type: Object

Properties

FunctionDeclaration

Type: Object

Properties

  • name string 関数名
  • description string? 関数の説明
  • parameters Object? パラメータのJSONスキーマ

StandardGeminiTools

Type: Object

Properties

FunctionCallingConfig

Type: Object

Properties

  • mode ("AUTO" | "ANY" | "NONE")? Function calling mode
  • allowedFunctionNames Array<string>? 許可する関数名のリスト

StandardGeminiToolConfig

Type: Object

Properties

GeminiContentParams

Type: Object

Properties

  • model string モデル(必須) 利用可能なモデル:* ‘gemini-2.5-flash’: Gemini 2.5 Flash
    • ’gemini-2.5-flash-lite’: Gemini 2.5 Flash Lite
    • ’gemini-2.5-pro’: Gemini 2.5 Pro
    • ’gemini-3-flash-preview’: Gemini 3 Flash Preview(マルチモーダル+推論、thinkingLevel: minimal/low/medium/high)
    • ‘gemini-3.1-pro-preview’: Gemini 3.1 Pro Preview(高度な推論、thinkingLevel: low/medium/high)
    • ‘gemini-3.1-flash-lite-preview’: Gemini 3.1 Flash Lite Preview(軽量版、thinkingLevel: minimal/low/medium/high)
  • contents Array<Content> 会話のメッセージ配列。各要素はContentオブジェクト(Content, ContentPart型を参照)
  • systemInstruction string? システムインストラクション
  • generationConfig GeminiGenerationConfig? 生成設定
  • safetySettings Array<GeminiSafetySetting>? 安全性設定
  • tools StandardGeminiTools? ツール設定(Function callingのみ)
  • toolConfig StandardGeminiToolConfig? ツール設定(Function calling設定のみ)
  • craftExtra CraftExtra? Craft固有の追加設定(RAGオプションなど)

GeminiStreamParams

Extends GeminiContentParams

Type: Object

FunctionCall

Type: Object

Properties

  • name string 呼び出す関数の名前
  • args Object 関数に渡す引数

FunctionResponse

Type: Object

Properties

  • name string 呼び出された関数の名前
  • response Object 関数からのレスポンス

GeminiResultValue

Type: Object

Properties

  • usageMetadata Object 使用量メタデータ

    • usageMetadata.candidatesTokenCount number 候補のトークン数
    • usageMetadata.totalTokenCount number トークン総数
    • usageMetadata.promptTokenCount number プロンプトのトークン数
    • usageMetadata.thoughtsTokenCount number? 思考のトークン数
  • candidates Array<Object> 回答内容

    • candidates[].content Object 回答の内容

      • candidates[].content.role string 役割
      • candidates[].content.parts Array<Object> 回答の部分
      • candidates[].content.parts string [].text - 回答のテキスト
      • candidates[].content.parts FunctionCall [].functionCall - functionCall
      • candidates[].content.parts FunctionResponse [].functionResponse - functionResponse
    • candidates[].finishReason string 回答終了理由

InlineData

Type: Object

Properties

  • mimeType string MIMEタイプ(例: ‘image/png’, ‘image/jpeg’, ‘application/pdf’)
  • data string Base64エンコードされたデータ

ContentPart

Type: Object

Properties

  • text string? テキストコンテンツ
  • inlineData InlineData? インラインデータ(画像、PDF等)
  • functionCall FunctionCall? 関数呼び出し(モデルからの応答に含まれる)
  • functionResponse FunctionResponse? 関数の実行結果(ユーザーからの入力として使用)
  • thoughtSignature string? Gemini 3モデル用の思考署名。 マルチターン会話で推論コンテキストを維持するために使用。 モデルからのレスポンスに含まれ、次のリクエストにそのまま含める必要あり(改変不可)。 Function Callingでは必須(ない場合400エラー)。

Content

Type: Object

Properties

  • role ("user" | "model") メッセージの送信者。‘user’はユーザー、‘model’はAIモデル
  • parts Array<ContentPart> メッセージの内容(複数のパーツで構成可能)

Examples

// テキストのみのユーザーメッセージ
{ role: 'user', parts: [{ text: 'こんにちは' }] }
// 画像を含むユーザーメッセージ
{
role: 'user',
parts: [
{ text: 'この画像について説明してください' },
{ inlineData: { mimeType: 'image/jpeg', data: 'base64encodeddata...' } }
]
}
// Function Callingを使用した会話
// 1. ユーザーの質問
{ role: 'user', parts: [{ text: '東京の天気を教えて' }] }
// 2. モデルからの関数呼び出し要求(レスポンス)
{ role: 'model', parts: [{ functionCall: { name: 'getWeather', args: { location: '東京' } } }] }
// 3. ユーザーからの関数実行結果
{ role: 'user', parts: [{ functionResponse: { name: 'getWeather', response: { temp: 25, condition: '晴れ' } } }] }
// 4. モデルの最終回答(レスポンス)
{ role: 'model', parts: [{ text: '東京の現在の天気は晴れで、気温は25度です。' }] }

StreamChunk

Type: Object

Properties

  • delta Object? 増分の回答内容

  • finishReason string? 回答終了理由

  • usageMetadata Object? 使用量メタデータ (最後のチャンクでのみ)

ThinkingConfig

Type: Object

Properties

  • includeThoughts boolean? 思考の要約を有効にするかどうか
  • thinkingBudget number? 思考処理のための予算(トークン数)

GenerationConfig

Type: Object

Properties

  • maxOutputTokens number? 最大出力トークン数
  • temperature number? 生成時の多様性を制御するパラメータ
  • topP number? 確率の高いトークンから選択する閾値
  • responseMimeType string? レスポンスタイプ
  • responseSchema Object? レスポンス構造を定義するスキーマ
  • thinkingConfig ThinkingConfig? 思考処理の設定

EmbeddingsResultValue

Type: Object

Properties

  • predictions Array<Object> 予測結果

    • predictions[].embeddings Object Embeddings
      • predictions[].embeddings.values Array<number>
      • predictions[].embeddings.statistics Object 統計情報
        • predictions[].embeddings.statistics.truncated boolean 切り捨てられたかどうか
        • predictions[].embeddings.statistics.token_count number トークン数
  • metadata Object メタデータ

    • metadata.billableCharacterCount number 課金文字数

MultiEmbedding

Type: Object

Properties

  • textEmbedding Array<number>? The text embedding array.
  • imageEmbedding Array<number>? The image embedding array.

MultiEmbeddingsResultValue

Type: Object

Properties

TextEmbeddingInstance

Type: Object

Properties

  • content string コンテンツ
  • title string? タイトル (optional) - RETRIEVAL_DOCUMENTタスクタイプでのみ使用可能
  • task_type string? タスクタイプ (optional) - 以下の値が使用可能。デフォルトは ‘RETRIEVAL_QUERY’:* ‘RETRIEVAL_QUERY’: 検索クエリ用
    • ’RETRIEVAL_DOCUMENT’: 検索対象のドキュメント用
    • ’SEMANTIC_SIMILARITY’: 意味的類似性の比較用
    • ’CLASSIFICATION’: 分類タスク用
    • ’CLUSTERING’: クラスタリングタスク用
    • ’QUESTION_ANSWERING’: 質問応答システム用
    • ’FACT_VERIFICATION’: 事実検証用
    • ’CODE_RETRIEVAL_QUERY’: コード検索クエリ用

TextEmbeddingParameters

Type: Object

Properties

  • autoTruncate boolean? 自動切り詰め (optional)
  • outputDimensionality number? 出力次元数 (optional)

RerankRecord

Type: Object

Properties

  • id string レコードのID
  • title string レコードのタイトル
  • content string レコードのコンテンツ

RankedRecord

Type: Object

Properties

  • id string レコードのID
  • title string? レコードのタイトル。ignoreRecordDetailsInResponse が true の場合は省略される。
  • content string? レコードのコンテンツ。ignoreRecordDetailsInResponse が true の場合は省略される。
  • score number ランキングスコア

RerankResultValue

Type: Object

Properties