OpenAIClient Class
- java.
lang. Object - com.
azure. ai. openai. OpenAIClient
- com.
public final class OpenAIClient
Initializes a new instance of the synchronous OpenAIClient type.
Method Summary
Methods inherited from java.lang.Object
Method Details
generateSpeechFromText
public BinaryData generateSpeechFromText(String deploymentOrModelName, SpeechGenerationOptions speechGenerationOptions)
Generates text-to-speech audio from the input text.
Parameters:
Returns:
generateSpeechFromTextWithResponse
public Response
Generates text-to-speech audio from the input text.
Request Body Schema
{
input: String (Required)
voice: String(alloy/echo/fable/onyx/nova/shimmer) (Required)
response_format: String(mp3/opus/aac/flac) (Optional)
speed: Double (Optional)
}
Response Body Schema
BinaryData
Parameters:
Returns:
getAudioTranscription
public AudioTranscription getAudioTranscription(String deploymentOrModelName, String fileName, AudioTranscriptionOptions audioTranscriptionOptions)
Gets transcribed text and associated metadata from provided spoken audio file data. Audio will be transcribed in the written language corresponding to the language it was spoken in.
Parameters:
Returns:
getAudioTranscriptionAsPlainText
public String getAudioTranscriptionAsPlainText(String deploymentOrModelName, AudioTranscriptionOptions audioTranscriptionOptions)
Gets transcribed text and associated metadata from provided spoken audio data. Audio will be transcribed in the written language corresponding to the language it was spoken in.
Parameters:
Returns:
getAudioTranscriptionText
public String getAudioTranscriptionText(String deploymentOrModelName, String fileName, AudioTranscriptionOptions audioTranscriptionOptions)
Gets transcribed text and associated metadata from provided spoken audio file data. Audio will be transcribed in the written language corresponding to the language it was spoken in.
Parameters:
Returns:
getAudioTranscriptionTextWithResponse
public Response
Gets transcribed text and associated metadata from provided spoken audio file data. Audio will be transcribed in the written language corresponding to the language it was spoken in.
Parameters:
Returns:
getAudioTranscriptionWithResponse
public Response
Gets transcribed text and associated metadata from provided spoken audio file data. Audio will be transcribed in the written language corresponding to the language it was spoken in.
Parameters:
Returns:
getAudioTranslation
public AudioTranslation getAudioTranslation(String deploymentOrModelName, String fileName, AudioTranslationOptions audioTranslationOptions)
Gets English language transcribed text and associated metadata from provided spoken audio file data.
Parameters:
Returns:
getAudioTranslationAsPlainText
public String getAudioTranslationAsPlainText(String deploymentOrModelName, AudioTranslationOptions audioTranslationOptions)
Gets English language transcribed text and associated metadata from provided spoken audio data.
Parameters:
Returns:
getAudioTranslationText
public String getAudioTranslationText(String deploymentOrModelName, String fileName, AudioTranslationOptions audioTranslationOptions)
Gets English language transcribed text and associated metadata from provided spoken audio file data.
Parameters:
Returns:
getAudioTranslationTextWithResponse
public Response
Gets English language transcribed text and associated metadata from provided spoken audio file data.
Parameters:
Returns:
getAudioTranslationWithResponse
public Response
Gets English language transcribed text and associated metadata from provided spoken audio file data.
Parameters:
Returns:
getChatCompletions
public ChatCompletions getChatCompletions(String deploymentOrModelName, ChatCompletionsOptions chatCompletionsOptions)
Gets chat completions for the provided chat messages. Completions support a wide variety of tasks and generate text that continues from or "completes" provided prompt data.
Parameters:
Returns:
getChatCompletionsStream
public IterableStream
Gets chat completions for the provided chat messages in streaming mode. Chat completions support a wide variety of tasks and generate text that continues from or "completes" provided prompt data.
Code Samples
openAIClient.getChatCompletionsStream(deploymentOrModelId, new ChatCompletionsOptions(chatMessages))
.forEach(chatCompletions -> {
if (CoreUtils.isNullOrEmpty(chatCompletions.getChoices())) {
return;
}
ChatResponseMessage delta = chatCompletions.getChoices().get(0).getDelta();
if (delta.getRole() != null) {
System.out.println("Role = " + delta.getRole());
}
if (delta.getContent() != null) {
String content = delta.getContent();
System.out.print(content);
}
});
Parameters:
Returns:
getChatCompletionsStreamWithResponse
public Response<>
Gets chat completions for the provided chat messages in streaming mode. Chat completions support a wide variety of tasks and generate text that continues from or "completes" provided prompt data.
Code Samples
openAIClient.getChatCompletionsStreamWithResponse(deploymentOrModelId, new ChatCompletionsOptions(chatMessages),
new RequestOptions().setHeader("my-header", "my-header-value"))
.getValue()
.forEach(chatCompletions -> {
if (CoreUtils.isNullOrEmpty(chatCompletions.getChoices())) {
return;
}
ChatResponseMessage delta = chatCompletions.getChoices().get(0).getDelta();
if (delta.getRole() != null) {
System.out.println("Role = " + delta.getRole());
}
if (delta.getContent() != null) {
String content = delta.getContent();
System.out.print(content);
}
});
Parameters:
Returns:
getChatCompletionsWithResponse
public Response
Gets chat completions for the provided chat messages. Completions support a wide variety of tasks and generate text that continues from or "completes" provided prompt data.
Request Body Schema
{
messages (Required): [
(Required){
role: String(system/assistant/user) (Required)
content: String (Optional)
}
]
max_tokens: Integer (Optional)
temperature: Double (Optional)
top_p: Double (Optional)
logit_bias (Optional): {
String: int (Optional)
}
user: String (Optional)
n: Integer (Optional)
stop (Optional): [
String (Optional)
]
presence_penalty: Double (Optional)
frequency_penalty: Double (Optional)
stream: Boolean (Optional)
model: String (Optional)
}
Response Body Schema
{
id: String (Required)
created: int (Required)
choices (Required): [
(Required){
message (Optional): {
role: String(system/assistant/user) (Required)
content: String (Optional)
}
index: int (Required)
finish_reason: String(stopped/tokenLimitReached/contentFiltered) (Required)
delta (Optional): {
role: String(system/assistant/user) (Optional)
content: String (Optional)
}
}
]
usage (Required): {
completion_tokens: int (Required)
prompt_tokens: int (Required)
total_tokens: int (Required)
}
}
Parameters:
Returns:
getChatCompletionsWithResponse
public Response
Gets chat completions for the provided chat messages. Completions support a wide variety of tasks and generate text that continues from or "completes" provided prompt data.
Request Body Schema
{
messages (Required): [
(Required){
role: String(system/assistant/user) (Required)
content: String (Optional)
}
]
max_tokens: Integer (Optional)
temperature: Double (Optional)
top_p: Double (Optional)
logit_bias (Optional): {
String: int (Optional)
}
user: String (Optional)
n: Integer (Optional)
stop (Optional): [
String (Optional)
]
presence_penalty: Double (Optional)
frequency_penalty: Double (Optional)
stream: Boolean (Optional)
model: String (Optional)
}
Response Body Schema
{
id: String (Required)
created: int (Required)
choices (Required): [
(Required){
message (Optional): {
role: String(system/assistant/user) (Required)
content: String (Optional)
}
index: int (Required)
finish_reason: String(stopped/tokenLimitReached/contentFiltered) (Required)
delta (Optional): {
role: String(system/assistant/user) (Optional)
content: String (Optional)
}
}
]
usage (Required): {
completion_tokens: int (Required)
prompt_tokens: int (Required)
total_tokens: int (Required)
}
}
Parameters:
Returns:
getCompletions
public Completions getCompletions(String deploymentOrModelName, CompletionsOptions completionsOptions)
Gets completions for the provided input prompts. Completions support a wide variety of tasks and generate text that continues from or "completes" provided prompt data.
Parameters:
Returns:
getCompletions
public Completions getCompletions(String deploymentOrModelName, String prompt)
Gets completions for the provided input prompt. Completions support a wide variety of tasks and generate text that continues from or "completes" provided prompt data.
Parameters:
Returns:
getCompletionsStream
public IterableStream
Gets completions as a stream for the provided input prompts. Completions support a wide variety of tasks and generate text that continues from or "completes" provided prompt data.
Parameters:
Returns:
getCompletionsWithResponse
public Response
Gets completions for the provided input prompts. Completions support a wide variety of tasks and generate text that continues from or "completes" provided prompt data.
Request Body Schema
{
prompt (Required): [
String (Required)
]
max_tokens: Integer (Optional)
temperature: Double (Optional)
top_p: Double (Optional)
logit_bias (Optional): {
String: int (Optional)
}
user: String (Optional)
n: Integer (Optional)
logprobs: Integer (Optional)
echo: Boolean (Optional)
stop (Optional): [
String (Optional)
]
presence_penalty: Double (Optional)
frequency_penalty: Double (Optional)
best_of: Integer (Optional)
stream: Boolean (Optional)
model: String (Optional)
}
Response Body Schema
{
id: String (Required)
created: int (Required)
choices (Required): [
(Required){
text: String (Required)
index: int (Required)
logprobs (Required): {
tokens (Required): [
String (Required)
]
token_logprobs (Required): [
double (Required)
]
top_logprobs (Required): [
(Required){
String: double (Required)
}
]
text_offset (Required): [
int (Required)
]
}
finish_reason: String(stopped/tokenLimitReached/contentFiltered) (Required)
}
]
usage (Required): {
completion_tokens: int (Required)
prompt_tokens: int (Required)
total_tokens: int (Required)
}
}
Parameters:
Returns:
getCompletionsWithResponse
public Response
Gets completions for the provided input prompts. Completions support a wide variety of tasks and generate text that continues from or "completes" provided prompt data.
Request Body Schema
{
prompt (Required): [
String (Required)
]
max_tokens: Integer (Optional)
temperature: Double (Optional)
top_p: Double (Optional)
logit_bias (Optional): {
String: int (Optional)
}
user: String (Optional)
n: Integer (Optional)
logprobs: Integer (Optional)
echo: Boolean (Optional)
stop (Optional): [
String (Optional)
]
presence_penalty: Double (Optional)
frequency_penalty: Double (Optional)
best_of: Integer (Optional)
stream: Boolean (Optional)
model: String (Optional)
}
Response Body Schema
{
id: String (Required)
created: int (Required)
choices (Required): [
(Required){
text: String (Required)
index: int (Required)
logprobs (Required): {
tokens (Required): [
String (Required)
]
token_logprobs (Required): [
double (Required)
]
top_logprobs (Required): [
(Required){
String: double (Required)
}
]
text_offset (Required): [
int (Required)
]
}
finish_reason: String(stopped/tokenLimitReached/contentFiltered) (Required)
}
]
usage (Required): {
completion_tokens: int (Required)
prompt_tokens: int (Required)
total_tokens: int (Required)
}
}
Parameters:
Returns:
getEmbeddings
public Embeddings getEmbeddings(String deploymentOrModelName, EmbeddingsOptions embeddingsOptions)
Return the embeddings for a given prompt.
Parameters:
Returns:
getEmbeddingsWithResponse
public Response
Return the embeddings for a given prompt.
Request Body Schema
{
user: String (Optional)
model: String (Optional)
input (Required): [
String (Required)
]
}
Response Body Schema
{
data (Required): [
(Required){
embedding (Required): [
double (Required)
]
index: int (Required)
}
]
usage (Required): {
prompt_tokens: int (Required)
total_tokens: int (Required)
}
}
Parameters:
Returns:
getEmbeddingsWithResponse
public Response
Return the embeddings for a given prompt.
Request Body Schema
{
user: String (Optional)
model: String (Optional)
input (Required): [
String (Required)
]
}
Response Body Schema
{
data (Required): [
(Required){
embedding (Required): [
double (Required)
]
index: int (Required)
}
]
usage (Required): {
prompt_tokens: int (Required)
total_tokens: int (Required)
}
}
Parameters:
Returns:
getImageGenerations
public ImageGenerations getImageGenerations(String deploymentOrModelName, ImageGenerationOptions imageGenerationOptions)
Creates an image given a prompt.
Parameters:
Returns:
Applies to
Azure SDK for Java
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for