SAP’s Generative AI SDK offers powerful tools for integrating AI capabilities into your business applications.
This blog will guide you through the libraries available for Python, JavaScript, and Java, and how to use them effectively.
1.šµĀ SAP Generative AI SDK for Python
The SAP Generative AI SDK for Python allows developers to leverage generative models from the SAP AI Core. This SDK supports models from providers like OpenAI, Amazon, and Google, and integrates with LangChain for enhanced functionality.
Documentation and Examples :Ā https://help.sap.com/doc/generative-ai-hub-sdk/CLOUD/en-US/index.htmlĀ
Installation:Ā To install the SDK, use the following command:
pip install sap-ai-sdk-gen[all]
You can also install specific model providers:
pip install “sap-ai-sdk-gen[google, amazon]”
Configuration:Ā Set up your environment variables or configuration file to authenticate and connect to SAP AI Core:
export AICORE_CLIENT_ID=”your_client_id”
export AICORE_CLIENT_SECRET=”your_client_secret”
export AICORE_AUTH_URL=”your_auth_url”
export AICORE_BASE_URL=”your_base_url”
Usage:Ā Here’s a simple example to generate text using the OpenAI model:
from sap_ai_sdk_gen import OpenAI
client = OpenAI()
response = client.generate_text(prompt=”Hello, world!”)
print(response)
2.šµĀ SAP Generative AI SDK for JavaScript
The JavaScript SDK enables Node.js applications to interact with SAP AI Core, providing seamless integration with generative models.
https://github.com/SAP/ai-sdk-jsĀ
Installation:Ā Install the SDK via npm:
npm install -ai-sdk/ai-api
Configuration:Ā Ensure your environment variables are set up correctly:
export AICORE_CLIENT_ID=”your_client_id”
export AICORE_CLIENT_SECRET=”your_client_secret”
export AICORE_AUTH_URL=”your_auth_url”
export AICORE_BASE_URL=”your_base_url”
Usage:Ā Here’s a basic example to generate text:
import { OpenAI } from ‘@sap-ai-sdk/ai-api’;
const client = new OpenAI();
client.generateText(‘Hello, world!’).then(response => {
console.log(response);
});
3.šµĀ SAP Generative AI SDK for Java
The Java SDK integrates AI capabilities into Java-based applications, leveraging the SAP AI Core’s generative models.
https://github.com/SAP/ai-sdk-java
Installation:Ā Add the SDK to your Maven project:
Ā
<dependency>
<groupId>com.sap.ai</groupId>
<artifactId>sap-ai-sdk</artifactId>
<version>5.6.0</version>
</dependency>
Ā
Configuration:Ā Configure your application properties:
aicore.client.id=your_client_id
aicore.client.secret=your_client_secret
aicore.auth.url=your_auth_url
aicore.base.url=your_base_url
Usage:Ā Here’s an example to generate text:
import com.sap.ai.sdk.OpenAI;
public class Main {
public static void main(String[] args) {
OpenAI client = new OpenAI();
String response = client.generateText(“Hello, world!”);
System.out.println(response);
}
}
Conclusion
SAP’s Generative AI SDKs for Python, JavaScript, and Java provide robust tools for integrating AI into your applications. By following the installation, configuration, and usage examples provided, you can start leveraging the power of generative AI in your projects.
Feel free to reach out if you have any questions or need further assistance! Happy coding!
Ā
Ā
Ā
āĀ SAP’s Generative AI SDK offers powerful tools for integrating AI capabilities into your business applications.This blog will guide you through the libraries available for Python, JavaScript, and Java, and how to use them effectively.1.šµĀ SAP Generative AI SDK for PythonThe SAP Generative AI SDK for Python allows developers to leverage generative models from the SAP AI Core. This SDK supports models from providers like OpenAI, Amazon, and Google, and integrates with LangChain for enhanced functionality.Documentation and Examples :Ā https://help.sap.com/doc/generative-ai-hub-sdk/CLOUD/en-US/index.htmlĀ Installation:Ā To install the SDK, use the following command:pip install sap-ai-sdk-gen[all]You can also install specific model providers:pip install “sap-ai-sdk-gen[google, amazon]”Configuration:Ā Set up your environment variables or configuration file to authenticate and connect to SAP AI Core:export AICORE_CLIENT_ID=”your_client_id”
export AICORE_CLIENT_SECRET=”your_client_secret”
export AICORE_AUTH_URL=”your_auth_url”
export AICORE_BASE_URL=”your_base_url”Usage:Ā Here’s a simple example to generate text using the OpenAI model:from sap_ai_sdk_gen import OpenAI
client = OpenAI()
response = client.generate_text(prompt=”Hello, world!”)
print(response)2.šµĀ SAP Generative AI SDK for JavaScriptThe JavaScript SDK enables Node.js applications to interact with SAP AI Core, providing seamless integration with generative models.https://github.com/SAP/ai-sdk-jsĀ Installation:Ā Install the SDK via npm:npm install -ai-sdk/ai-apiConfiguration:Ā Ensure your environment variables are set up correctly:export AICORE_CLIENT_ID=”your_client_id”
export AICORE_CLIENT_SECRET=”your_client_secret”
export AICORE_AUTH_URL=”your_auth_url”
export AICORE_BASE_URL=”your_base_url”Usage:Ā Here’s a basic example to generate text:import { OpenAI } from ‘@sap-ai-sdk/ai-api’;
const client = new OpenAI();
client.generateText(‘Hello, world!’).then(response => {
console.log(response);
});3.šµĀ SAP Generative AI SDK for JavaThe Java SDK integrates AI capabilities into Java-based applications, leveraging the SAP AI Core’s generative models.https://github.com/SAP/ai-sdk-javaInstallation:Ā Add the SDK to your Maven project:Ā <dependency>
<groupId>com.sap.ai</groupId>
<artifactId>sap-ai-sdk</artifactId>
<version>5.6.0</version>
</dependency>Ā Configuration:Ā Configure your application properties:aicore.client.id=your_client_id
aicore.client.secret=your_client_secret
aicore.auth.url=your_auth_url
aicore.base.url=your_base_urlUsage:Ā Here’s an example to generate text:import com.sap.ai.sdk.OpenAI;
public class Main {
public static void main(String[] args) {
OpenAI client = new OpenAI();
String response = client.generateText(“Hello, world!”);
System.out.println(response);
}
}ConclusionSAP’s Generative AI SDKs for Python, JavaScript, and Java provide robust tools for integrating AI into your applications. By following the installation, configuration, and usage examples provided, you can start leveraging the power of generative AI in your projects.Feel free to reach out if you have any questions or need further assistance! Happy coding!Ā Ā Ā Ā Ā Read MoreĀ Technology Blog Posts by SAP articlesĀ
#SAP
#SAPTechnologyblog