mcpField
S
sap-cloud-sdk-ai

sap-cloud-sdk-ai

github.com/secondsky開発480693 回インストール3 週間前に更新
リポジトリ

sap-cloud-sdk-ai について

SAP AI Core、Generative AI Hub、Orchestration Service を利用する JavaScript・Java SDK、SAP Cloud SDK for AI のガイドスキルです。SAP BTP アプリに AI 機能を組み込む開発者向けに、モデル呼び出しやグラウンディング、フィルタリング、連携方法を説明します。

主な機能

  1. 01チャット補完とストリーミング
  2. 02関数・ツール呼び出し
  3. 03コンテンツフィルタリングとデータマスキング
  4. 04ドキュメントグラウンディングとプロンプト管理
  5. 05CAP、LangChain、Spring AI のガイド

活用シーン

  1. 01SAP BTP アプリへの LLM チャット追加
  2. 02ドキュメントに基づく応答のグラウンディング
  3. 03コンテンツフィルターとマスキングの適用
  4. 04AI 呼び出しを含む CAP サービスの構築

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/secondsky/sap-skills --skill sap-cloud-sdk-ai

インストール後、Claude Code で/sap-cloud-sdk-aiを入力して読み込まれたか確認します。

同梱ファイル

SKILL.md と一緒にインストールされる参考資料やスクリプト。

README.md
agents/
openai.yaml
references/
agentic-workflows.md
ai-core-api-guide.md
connecting-to-ai-core.md
error-handling.md
foundation-models-guide.md
langchain-guide.md
orchestration-guide.md
spring-ai-guide.md
v1-to-v2-migration.md

詳細

SAP Cloud SDK for AI

関連スキル

  • sap-cap-capire:イベントハンドラーパターンや非同期 LLM オーケストレーションなど、AI サービスを利用する CAP アプリケーションの構築に使用します
  • sap-ai-core:AI Core プラットフォームのセットアップ、オーケストレーションの設定、モデルのデプロイに使用します
  • sap-dependency-security:npm パッケージのアップグレード、ロックファイルのポリシー、安全な依存関係ワークフローに関する強化ガイダンス

SAP AI Core、SAP Generative AI Hub、Orchestration Service 向けの公式 SDK です。パッケージのバージョンは公開レジストリに照らして検証されていますが、AI Core テナントでの実行と、利用可能な正確なモデルについては、対象テナントでの検証が必要です。

このスキルを使用する場面

次のような場合にこのスキルを使用します:

  • SAP BTP アプリケーションへの AI/LLM 機能の統合
  • チャット補完機能や埋め込み機能の構築
  • SAP AI Core 経由で、テナントで承認された OpenAI、Claude、Gemini、Amazon、Mistral、またはその他のモデルファミリーを使用する
  • コンテンツフィルタリング、データマスキング、ドキュメントグラウンディングの実装
  • LangChain または Spring AI を使用したエージェント型ワークフローの作成
  • Prompt Registry を使用したプロンプトの管理
  • SAP AI Core での AI モデルのデプロイ

目次

クイックスタート

注:このスキルでは、2026-06-15 時点の公開パッケージレジストリの情報に基づき、SAP Cloud SDK for AI JavaScript v2.11.0+ および Java v1.19.0+ を使用します。v1.x から移行する場合は、破壊的変更について V1 から V2 への移行ガイドを参照してください。

JavaScript/TypeScript
npm install @sap-ai-sdk/orchestration@^2
import { OrchestrationClient } from '@sap-ai-sdk/orchestration';

const client = new OrchestrationClient({
  promptTemplating: {
    model: { name: 'gpt-4o' },
    prompt: [{ role: 'user', content: '{{?question}}' }]
  }
});

const response = await client.chatCompletion({
  placeholderValues: { question: 'What is SAP?' }
});
console.log(response.getContent());
Java
<dependency>
  <groupId>com.sap.ai.sdk</groupId>
  <artifactId>orchestration</artifactId>
  <version>${ai-sdk.version}</version>
</dependency>
var client = new OrchestrationClient();
var config = new OrchestrationModuleConfig()
    .withLlmConfig(OrchestrationAiModel.GPT_4O);
var prompt = new OrchestrationPrompt("What is SAP?");
var result = client.chatCompletion(prompt, config);
System.out.println(result.getContent());

前提条件

  • Node.js 20+(JavaScript)または Java 17+(Java)
  • SAP AI Core サービスインスタンス(extended または sap-internal プラン)
  • AI Core の Orchestration deployment(デフォルトのリソースグループに含まれています)

接続のセットアップ

BTP ランタイム(Cloud Foundry/Kyma)

AI Core サービスインスタンスをアプリケーションにバインドします。SDK は VCAP_SERVICES またはマウントされたシークレットを自動検出します。

ローカル開発

環境変数を設定します:

export AICORE_SERVICE_KEY='{"clientid":"...","clientsecret":"...","url":"...","serviceurls":{"AI_API_URL":"..."}}'

または CAP ハイブリッドモードを使用します:

# JavaScript
cds bind -2 <AICORE_INSTANCE> && cds-tsx watch --profile hybrid

# Java
cds bind --to aicore --exec mvn spring-boot:run

接続オプションの詳細については、references/connecting-to-ai-core.md を参照してください。

利用可能なパッケージ

JavaScript/TypeScript
パッケージ用途
@sap-ai-sdk/orchestrationチャット補完、フィルタリング、グラウンディング
@sap-ai-sdk/foundation-modelsモデルへの直接アクセス(OpenAI)
@sap-ai-sdk/langchainLangChain との統合
@sap-ai-sdk/ai-apiデプロイメント、アーティファクト、設定
@sap-ai-sdk/document-groundingPipeline、Vector、Retrieval API
@sap-ai-sdk/prompt-registryプロンプトテンプレートの管理
Java
アーティファクト用途
orchestrationチャット補完、フィルタリング、グラウンディング
openai (foundationmodels)OpenAI モデルへの直接アクセス
core基本的な接続
document-groundingPipeline、Vector、Retrieval API
prompt-registryプロンプトテンプレートの管理

サポートされているモデル

モデル ID とバージョンはテナントによって異なります。アプリケーションコードに例をコピーする前に、SAP AI Launchpad Model Library または AI Core のモデル一覧 API で対象カタログを確認してください。

モデルファミリーの例
  • OpenAI:利用権限がある場合の GPT ファミリーのチャット、マルチモーダル、推論、埋め込みモデル
  • Anthropic (AWS):利用権限がある場合の Claude ファミリーのモデル
  • Amazon:利用権限がある場合の Nova/Titan ファミリーのモデル
  • Google:利用権限がある場合の Gemini ファミリーのモデル
  • Mistral:利用権限がある場合の Mistral ファミリーのモデル
非推奨モデル (代替を使用)
非推奨代わりに使用
text-embedding-ada-002text-embedding-3-small/large
gpt-35-turbo (すべてのバリアント)gpt-4o-mini
gpt-4-32kgpt-4o
gpt-4 (ベース)gpt-4o または gpt-4.1
gemini-1.0-progemini-2.0-flash
gemini-1.5-pro/flashgemini-2.5-flash
mistralai--mixtral-8x7bmistralai--mistral-small-instruct

主な機能

ストリーミングによるチャット完了
// JavaScript
const stream = client.stream({
  placeholderValues: { question: 'Explain SAP CAP' }
});

for await (const chunk of stream.toContentStream()) {
  process.stdout.write(chunk);
}
// Java
client.streamChatCompletion(prompt, config)
    .forEach(chunk -> System.out.print(chunk.getDeltaContent()));
関数/ツール呼び出し
// JavaScript
const tools = [{
  type: 'function',
  function: {
    name: 'get_weather',
    parameters: { type: 'object', properties: { city: { type: 'string' } } }
  }
}];

const response = await client.chatCompletion({
  placeholderValues: { question: 'Weather in Berlin?' }
}, { tools });

const toolCalls = response.getToolCalls();
コンテンツフィルタリング
// JavaScript
import { buildAzureContentSafetyFilter } from '@sap-ai-sdk/orchestration';

const client = new OrchestrationClient({
  promptTemplating: { model: { name: 'gpt-4o' } },
  filtering: {
    input: buildAzureContentSafetyFilter({ Hate: 'ALLOW_SAFE' }),
    output: buildAzureContentSafetyFilter({ Violence: 'ALLOW_SAFE' })
  }
});
データマスキング
// JavaScript
const client = new OrchestrationClient({
  promptTemplating: { model: { name: 'gpt-4o' } },
  masking: {
    masking_providers: [{
      type: 'sap_data_privacy_integration',
      method: 'anonymization',
      entities: [{ type: 'profile-email' }, { type: 'profile-person' }]
    }]
  }
});
ドキュメントグラウンディング
// JavaScript
const client = new OrchestrationClient({
  promptTemplating: { model: { name: 'gpt-4o' } },
  grounding: {
    grounding_input: ['{{?question}}'],
    grounding_output: ['{{?context}}'],
    data_repositories: [{ type: 'vector', id: 'my-repo-id' }]
  }
});
CAP 統合

SDK は CAP イベントハンドラーとネイティブに統合されています。CAP サービスクラス内で OrchestrationClient を使用すると、CAP サービスに AI 機能を追加できます。

MTA でのサービスバインディング:

resources:
  - name: my-ai-core
    type: org.cloudfoundry.managed-service
    parameters:
      service: aicore
      service-plan: extended

AI を使用した CAP イベントハンドラー:

import { OrchestrationClient } from '@sap-ai-sdk/orchestration';
import cds from '@sap/cds';

export default class AnalysisService extends cds.ApplicationService {
  async init() {
    const client = new OrchestrationClient({
      promptTemplating: {
        model: { name: 'gpt-4o' },
        prompt: [
          { role: 'system', content: 'Analyze and categorize as JSON.' },
          { role: 'user', content: '{{?input}}' }
        ]
      }
    });

    this.on('analyzeText', async (req) => {
      const response = await client.chatCompletion({
        placeholderValues: { input: req.data.text }
      });
      return response.getContent();
    });

    return super.init();
  }
}

重要: 本番環境の LLM 呼び出しには非同期処理を使用してください。 LLM の応答には 30~60 秒かかることがあり、BTP ロードバランサーのタイムアウトを超えてしまいます。202 Accepted を返してバックグラウンドで処理してください:

this.on('analyzeText', async (req) => {
  const entry = await INSERT.into('Results').entries({
    text: req.data.text, status: 'processing'
  });
  cds.spawn(() => processLLM(entry.id, req.data.text, client));
  return req.reply(202, { id: entry.id, status: 'processing' });
});

RAG 用の HANA Vector 型やプロンプトの外部化を含む、CAP + AI 統合の完全なガイドについては、sap-cap-capire スキルを参照してください。

レスポンスヘルパー

JavaScript SDK はヘルパーメソッドを提供します:

const response = await client.chatCompletion({ placeholderValues });

response.getContent();          // Model output string
response.getTokenUsage();       // { prompt_tokens, completion_tokens, total_tokens }
response.getFinishReason();     // 'stop', 'length', 'tool_calls', etc.
response.getToolCalls();        // Array of function calls
response.getDeltaToolCalls();   // Partial tool calls (streaming)
response.getAllMessages();      // Full message history
response.getAssistantMessage(); // Assistant response only
response.getRefusal();          // Refusal message if blocked

ストリーミングレスポンスメソッド:

const stream = client.stream({ placeholderValues });
for await (const chunk of stream.toContentStream()) {
  process.stdout.write(chunk);
}
// After stream ends:
stream.getFinishReason();
stream.getTokenUsage();

高度なトピック

詳細なガイダンスについては以下を参照してください:

  • オーケストレーション機能: references/orchestration-guide.md
  • 基盤モデル (直接 OpenAI): references/foundation-models-guide.md
  • LangChain 統合: references/langchain-guide.md
  • Spring AI 統合: references/spring-ai-guide.md
  • AI Core 管理: references/ai-core-api-guide.md

バンドルされたリソース

リファレンスドキュメント
  • references/foundation-models-guide.md - 基盤モデルと料金
  • references/ai-core-api-guide.md - AI Core サービス API リファレンス
  • references/orchestration-guide.md - オーケストレーションサービスガイド
  • references/langchain-guide.md - LangChain.js 統合
  • references/spring-ai-guide.md - Spring AI 統合
  • references/agentic-workflows.md - エージェント型ワークフローパターン
  • references/connecting-to-ai-core.md - 接続設定ガイド
  • references/error-handling.md - エラー処理パターン
  • references/v1-to-v2-migration.md - V1 から V2 への移行ガイド

バージョン情報

SDK現在のバージョンNode/Java の要件
JavaScript2.11.0+Node.js 20+
Java1.19.0+Java 17+ (21 LTS 推奨)

バージョンの根拠: docs/project/package-evidence/2026-06-15.json。これはパッケージレジストリの証拠のみであり、実際の AI Core ランタイムの証拠ではありません。

注意: 生成されたモデルクラス (...model パッケージ内) はマイナーリリースで変更される可能性がありますが、使用しても安全です。

一般的なエラー

エラー原因解決策
"Could not find service bindings for 'aicore'"AI Core バインディングの欠落AI Core サービスをバインドするか、AICORE_SERVICE_KEY を設定します
"Orchestration deployment not found"リソースグループにデプロイメントがないAI Core でオーケストレーションをデプロイするか、別のリソースグループを使用します
コンテンツフィルター違反入力/出力がブロックされたフィルターしきい値を調整するか、コンテンツを変更します
トークン制限を超過応答が長すぎるmax_tokens パラメーターを設定します

ドキュメントのソース

以下のソースを使用してこのスキルを最新の状態に保ってください:

コメント