Craft AI Modules Google
const { aiModules } = MODULES;利用可能なモデルとモデルごとの制約は利用可能なモデル一覧をご確認ください。 料金はCraft AIトークンとコストをご確認ください。
Table of Contents
Section titled “Table of Contents”- aiModules
- ALLOWED_GEMINI_MODELS
- validateGeminiModel
- GeminiGenerationConfig
- GeminiSafetySetting
- GeminiCandidate
- GeminiResponse
- GeminiStreamChunk
- RagOptions
- CraftExtra
- FunctionDeclaration
- StandardGeminiTools
- FunctionCallingConfig
- StandardGeminiToolConfig
- GeminiContentParams
- GeminiStreamCallbacks
- GeminiStreamParams
- FunctionCall
- FunctionResponse
- GeminiResultValue
- InlineData
- ContentPart
- Content
- StreamChunk
- ThinkingConfig
- GenerationConfig
- EmbeddingsResultValue
- MultiEmbedding
- MultiEmbeddingsResultValue
- TextEmbeddingInstance
- TextEmbeddingParameters
- RerankRecord
- RankedRecord
- RerankResultValue
aiModules
Section titled “aiModules”Standard AI modules for GCP services
gcpGeminiGenerateContent
Section titled “gcpGeminiGenerateContent”Geminiにリクエストを送信する
Parameters
Section titled “Parameters”paramsGeminiContentParams パラメータ
Returns Promise<GeminiResultValue>
gcpGeminiGenerateContentStream
Section titled “gcpGeminiGenerateContentStream”Geminiにストリーミングリクエストを送信する
最初のチャンクを受信する前にエラーが発生した場合、onErrorへエラーを渡し、Promiseがrejectされます。 チャンク受信後にエラーが発生した場合、onMessageへ{error: ‘エラーメッセージ’}を渡し、onCompleteで終了します。
Parameters
Section titled “Parameters”paramsGeminiStreamParams パラメータ
Returns Promise<void>
gcpEmbeddingsText
Section titled “gcpEmbeddingsText”TextEmbeddingsにリクエストを送信する
Parameters
Section titled “Parameters”-
paramObjectparam.textstring テキストの内容 (deprecated, use instances instead)param.instancesArray<TextEmbeddingInstance>? インスタンスの配列。gemini-embedding-2 は入力ごとに最大5件ずつ並列実行し、結果を入力順に返しますparam.parametersTextEmbeddingParameters? パラメータ。gemini-embedding-2 では autoTruncate=false は不可、outputDimensionality は 128〜3,072 の整数param.modelstring? モデル名 (optional)。利用可能なモデルは利用可能なモデル一覧を参照
Returns Promise<EmbeddingsResultValue>
gcpEmbeddingsMulti
Section titled “gcpEmbeddingsMulti”MultiModalEmbeddingsにリクエストを送信する
Parameters
Section titled “Parameters”-
paramObjectparam.textstring? テキストの内容param.dimensionnumber? 次元数param.bytesBase64Encodedstring? 画像をBase64エンコードしたバイト列param.modelstring? モデル名 (optional)。利用可能なモデルは利用可能なモデル一覧を参照
- Throws Error failed. text or bytesBase64Encoded is required
Returns Promise<MultiEmbeddingsResultValue>
gcpRerank
Section titled “gcpRerank”GCP Rerank APIにリクエストを送信する
Parameters
Section titled “Parameters”-
paramObjectparam.querystring 検索クエリparam.recordsArray<RerankRecord> ランク付けするレコードの配列param.modelstring? モデル名 (optional)。利用可能なモデルは利用可能なモデル一覧を参照param.ignoreRecordDetailsInResponseboolean? レコードのタイトルとコンテンツも返さないか(デフォルト: true)param.topNnumber? 返される上位レコードの数(デフォルト: 10)
- Throws Error failed. query and records are required
Returns Promise<RerankResultValue>
ALLOWED_GEMINI_MODELS
Section titled “ALLOWED_GEMINI_MODELS”Standard版で利用可能なGeminiモデル
validateGeminiModel
Section titled “validateGeminiModel”Geminiモデルのバリデーション
Parameters
Section titled “Parameters”modelstring モデル名。利用可能なモデルは利用可能なモデル一覧を参照
- Throws Error モデルが許可されていない場合
GeminiGenerationConfig
Section titled “GeminiGenerationConfig”Type: Object
Properties
Section titled “Properties”-
maxOutputTokensnumber? 最大出力トークン数 -
temperaturenumber? 温度パラメータ (0-2)。gemini-3.5-flash-liteとgemini-4-argonではカスタム値は無視されます -
topPnumber? Top-p サンプリング。gemini-3.5-flash-liteとgemini-4-argonではカスタム値は無視されます -
responseMimeTypestring? レスポンスのMIMEタイプ -
responseSchemaObject? レスポンススキーマ -
thinkingConfigObject? Thinking mode設定
GeminiSafetySetting
Section titled “GeminiSafetySetting”Type: Object
Properties
Section titled “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
Section titled “GeminiCandidate”Type: Object
Properties
Section titled “Properties”GeminiResponse
Section titled “GeminiResponse”Type: Object
Properties
Section titled “Properties”-
candidatesArray<GeminiCandidate> 候補リスト -
usageMetadataObject 使用量メタデータ -
groundingMetadataObject? グラウンディングメタデータ
GeminiStreamChunk
Section titled “GeminiStreamChunk”Type: Object
Properties
Section titled “Properties”deltaObject? デルタコンテンツfinishReasonstring? 終了理由groundingMetadataObject? グラウンディングメタデータusageMetadataObject? 使用量メタデータ(最終チャンク)errorstring? チャンク受信後に発生したエラーのメッセージ
RagOptions
Section titled “RagOptions”Type: Object
Properties
Section titled “Properties”corpusIdstring RAG IDvectorDistanceThresholdnumber? ベクトル距離の閾値llmRankerModelstring? LLMランカーのモデル名rankServiceModelstring? ランクサービスのモデル名topKnumber? トップKmetadataFilterstring? メタデータフィルタ文字列(CEL構文、例: ‘category == “HR”’)
CraftExtra
Section titled “CraftExtra”Type: Object
Properties
Section titled “Properties”ragOptionsRagOptions? RAGオプション
FunctionDeclaration
Section titled “FunctionDeclaration”Type: Object
Properties
Section titled “Properties”StandardGeminiTools
Section titled “StandardGeminiTools”Type: Object
Properties
Section titled “Properties”functionDeclarationsArray<FunctionDeclaration>? Function calling宣言
FunctionCallingConfig
Section titled “FunctionCallingConfig”Type: Object
Properties
Section titled “Properties”mode("AUTO"|"ANY"|"NONE")? Function calling modeallowedFunctionNamesArray<string>? 許可する関数名のリスト
StandardGeminiToolConfig
Section titled “StandardGeminiToolConfig”Type: Object
Properties
Section titled “Properties”functionCallingConfigFunctionCallingConfig? Function calling設定
GeminiContentParams
Section titled “GeminiContentParams”Type: Object
Properties
Section titled “Properties”modelstring モデル(必須)。利用可能なモデルは利用可能なモデル一覧を参照contentsArray<Content> 会話のメッセージ配列。各要素はContentオブジェクト(Content, ContentPart型を参照)。gemini-3.5-flash-liteでは末尾のroleにmodelを指定できませんsystemInstructionstring? システムインストラクションgenerationConfigGeminiGenerationConfig? 生成設定safetySettingsArray<GeminiSafetySetting>? 安全性設定toolsStandardGeminiTools? ツール設定(Function callingのみ)toolConfigStandardGeminiToolConfig? ツール設定(Function calling設定のみ)craftExtraCraftExtra? Craft固有の追加設定(RAGオプションなど)
GeminiStreamCallbacks
Section titled “GeminiStreamCallbacks”Type: Object
Properties
Section titled “Properties”onMessagefunction (GeminiStreamChunk): void メッセージ受信時のコールバックonErrorfunction (Error): void? エラー発生時のコールバックonCompletefunction (): void? ストリーミング完了時のコールバック
GeminiStreamParams
Section titled “GeminiStreamParams”Type: Object
Properties
Section titled “Properties”modelstring モデル(必須)。利用可能なモデルは利用可能なモデル一覧を参照contentsArray<Content> 会話のメッセージ配列。各要素はContentオブジェクト(Content, ContentPart型を参照)。gemini-3.5-flash-liteでは末尾のroleにmodelを指定できませんsystemInstructionstring? システムインストラクションgenerationConfigGeminiGenerationConfig? 生成設定safetySettingsArray<GeminiSafetySetting>? 安全性設定toolsStandardGeminiTools? ツール設定(Function callingのみ)toolConfigStandardGeminiToolConfig? ツール設定(Function calling設定のみ)craftExtraCraftExtra? Craft固有の追加設定(RAGオプションなど)onMessagefunction (GeminiStreamChunk): void メッセージ受信時のコールバックonErrorfunction (Error): void? エラー発生時のコールバックonCompletefunction (): void? ストリーミング完了時のコールバック
FunctionCall
Section titled “FunctionCall”Type: Object
Properties
Section titled “Properties”FunctionResponse
Section titled “FunctionResponse”Type: Object
Properties
Section titled “Properties”GeminiResultValue
Section titled “GeminiResultValue”Type: Object
Properties
Section titled “Properties”-
usageMetadataObject 使用量メタデータ -
-
candidates[].contentObject 回答の内容-
candidates[].content.rolestring 役割 -
candidates[].content.partsArray<Object> 回答の部分candidates[].content.parts[].textstring 回答のテキストcandidates[].content.parts[].thoughtboolean? 思考プロセスかどうかcandidates[].content.parts[].functionCallFunctionCall functionCallcandidates[].content.parts[].functionResponseFunctionResponse functionResponse
-
-
candidates[].finishReasonstring 回答終了理由
-
InlineData
Section titled “InlineData”Type: Object
Properties
Section titled “Properties”mimeTypestring MIMEタイプ(例: ‘image/png’, ‘image/jpeg’, ‘application/pdf’)datastring Base64エンコードされたデータ
ContentPart
Section titled “ContentPart”Type: Object
Properties
Section titled “Properties”textstring? テキストコンテンツinlineDataInlineData? インラインデータ(画像、PDF等)functionCallFunctionCall? 関数呼び出し(モデルからの応答に含まれる)functionResponseFunctionResponse? 関数の実行結果(ユーザーからの入力として使用)thoughtSignaturestring? モデルが返す思考署名。 マルチターン会話で推論コンテキストを維持するために使用。 モデルからのレスポンスに含まれ、次のリクエストにそのまま含める必要あり(改変不可)。 Function Callingでは必須(ない場合400エラー)。
Content
Section titled “Content”Type: Object
Properties
Section titled “Properties”role("user"|"model") メッセージの送信者。‘user’はユーザー、‘model’はAIモデルpartsArray<ContentPart> メッセージの内容(複数のパーツで構成可能)
Examples
Section titled “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
Section titled “StreamChunk”Type: Object
Properties
Section titled “Properties”ThinkingConfig
Section titled “ThinkingConfig”Type: Object
Properties
Section titled “Properties”GenerationConfig
Section titled “GenerationConfig”Type: Object
Properties
Section titled “Properties”maxOutputTokensnumber? 最大出力トークン数temperaturenumber? 生成時の多様性を制御するパラメータtopPnumber? 確率の高いトークンから選択する閾値responseMimeTypestring? レスポンスタイプresponseSchemaObject? レスポンス構造を定義するスキーマthinkingConfigThinkingConfig? 思考処理の設定
EmbeddingsResultValue
Section titled “EmbeddingsResultValue”Type: Object
Properties
Section titled “Properties”-
predictionsArray<Object> 予測結果(gemini-embedding-2のstatisticsは取得できた項目のみ返却) -
metadataObject メタデータ(gemini-embedding-2のusageMetadataは入力順に並び、未取得の入力に対応する要素はnull)
MultiEmbedding
Section titled “MultiEmbedding”Type: Object
Properties
Section titled “Properties”textEmbeddingArray<number>? The text embedding array.imageEmbeddingArray<number>? The image embedding array.
MultiEmbeddingsResultValue
Section titled “MultiEmbeddingsResultValue”Type: Object
Properties
Section titled “Properties”predictionsArray<MultiEmbedding> An array of embedding objects.
TextEmbeddingInstance
Section titled “TextEmbeddingInstance”Type: Object
Properties
Section titled “Properties”contentstring コンテンツtitlestring? タイトル (optional) - RETRIEVAL_DOCUMENTタスクタイプでのみ使用可能。gemini-embedding-2 では title/text 指示に変換task_typestring? タスクタイプ (optional) - 以下の値が使用可能。デフォルトは ‘RETRIEVAL_QUERY’。gemini-embedding-2 では公式のタスク指示へ変換し API の task_type には含めません:* ‘RETRIEVAL_QUERY’: 検索クエリ用- ‘RETRIEVAL_DOCUMENT’: 検索対象のドキュメント用
- ‘SEMANTIC_SIMILARITY’: 意味的類似性の比較用
- ‘CLASSIFICATION’: 分類タスク用
- ‘CLUSTERING’: クラスタリングタスク用
- ‘QUESTION_ANSWERING’: 質問応答システム用
- ‘FACT_VERIFICATION’: 事実検証用
- ‘CODE_RETRIEVAL_QUERY’: コード検索クエリ用
TextEmbeddingParameters
Section titled “TextEmbeddingParameters”Type: Object
Properties
Section titled “Properties”autoTruncateboolean? 自動切り詰め (optional)。gemini-embedding-2 は 8,192 トークン超を常に暗黙に切り詰めるため false は指定できませんoutputDimensionalitynumber? 出力次元数 (optional)。gemini-embedding-2 は 128〜3,072 の整数(既定値3,072)
RerankRecord
Section titled “RerankRecord”Type: Object
Properties
Section titled “Properties”RankedRecord
Section titled “RankedRecord”Type: Object
Properties
Section titled “Properties”idstring レコードのIDtitlestring? レコードのタイトル。ignoreRecordDetailsInResponse が true の場合は省略される。contentstring? レコードのコンテンツ。ignoreRecordDetailsInResponse が true の場合は省略される。scorenumber ランキングスコア
RerankResultValue
Section titled “RerankResultValue”Type: Object
Properties
Section titled “Properties”recordsArray<RankedRecord> ランク付けされたレコードの配列