Model Studio provides SDKs for Python and Java (also called DashScope SDK), and invocation methods compatible with OpenAI SDKs for Python, Node.js, Java, and Go. This topic describes how to install Open AI SDK and DashScope SDK.
Procedure
Python
Step 1: Check Python version
Step 2: Configure virtual environment (optional)
Step 3: Install Python SDK
Java
Step 1: Check Java version
Run the following command in the terminal:
java -version
# (Optional) If you use Maven to manage and build Java projects, make sure that Maven is installed in your development environment
mvn --version
Take Windows CMD as an example:
DashScope Java SDK requires Java 8 or higher. The first line of the output shows your Java version. For example, openjdk version "16.0.1" 2021-04-20
indicates Java 16 is installed. If Java is not installed or the installed version is earlier than Java 8, go to Java Downloads to download and install the appropriate version.
Step 2: Install Java SDK
DashScope
After Step 1 is complete, you can install DashScope SDK for Java. Run the following command to include the Java SDK dependency in your project. Replace the-latest-version
with the actual latest version number.
XML
Open the
pom.xml
file of your Maven project.Add the dependency information within the
<dependencies>
tag.<dependency> <groupId>com.alibaba</groupId> <artifactId>dashscope-sdk-java</artifactId> <!-- Replace 'the-latest-version' with the latest version number: https://mvnrepository.com/artifact/com.alibaba/dashscope-sdk-java --> <version>the-latest-version</version> </dependency>
Save
pom.xml
.Use Maven commands, such as
mvn compile
ormvn clean install
, to refresh your project's dependencies. DashScope Java SDK will be downloaded and integrated into your project automatically.
Take Windows IDEA as an example:
Gradle
Open the
build.gradle
file of your Gradle project.Add the dependency information within the
dependencies
block.dependencies { // Replace 'the-latest-version' with the latest version number: https://mvnrepository.com/artifact/com.alibaba/dashscope-sdk-java implementation group: 'com.alibaba', name: 'dashscope-sdk-java', version: 'the-latest-version' }
Save
build.gradle
.Navigate to your project's root directory in the command line and run the following Gradle command to refresh your project dependencies. DashScope Java SDK will be downloaded and integrated into your project automatically.
./gradlew build --refresh-dependencies
Take Windows IDEA as an example:
OpenAI
After Step 1 is complete, you can install OpenAI SDK for Java. Run the following command to include the Java SDK dependency in your project. Replace the-latest-version
with the actual latest version number.
XML
Open the
pom.xml
file of your Maven project.Add the dependency information within the
<dependencies>
tag.<dependency> <groupId>com.openai</groupId> <artifactId>openai-java</artifactId> <version>the-latest-version</version> </dependency>
Save
pom.xml
.Use Maven commands, such as
mvn compile
ormvn clean install
, to refresh your project's dependencies. OpenAI Java SDK will be downloaded and integrated into your project automatically.
Gradle
Open the
build.gradle
file of your Gradle project.Add the dependency information within the
dependencies
block.dependencies { // Replace 'the-latest-version' with the latest version number: https://mvnrepository.com/artifact/com.openai/openai-java implementation group: 'com.openai', name: 'openai-java', version: 'the-latest-version' }
Save
build.gradle
.Navigate to your project's root directory in the command line and run the following Gradle command to refresh your project dependencies. OpenAI Java SDK will be downloaded and integrated into your project automatically.
./gradlew build --refresh-dependencies
This SDK is currently in beta.
Node.js
Step 1: Check Node.js installation status
Step 2: Install the SDK
Go
OpenAI provides an SDK for Go. You can install it by running the following command:
go get github.com/openai/openai-go@v0.1.0-alpha.62
Version v0.1.0-alpha.62 is tested to be relatively stable.
This SDK is currently in beta.
What to do next
Explore sample codes to call models with the OpenAI SDK or DashScope SDK.
References
For a list of models that support the OpenAI SDK, see Compatibility with OpenAI.