Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@
import com.azure.core.util.IterableStream;
import com.azure.core.util.logging.ClientLogger;
import com.azure.core.util.polling.SyncPoller;
import reactor.core.Exceptions;
import reactor.core.publisher.Flux;

import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.ByteBuffer;
import reactor.core.Exceptions;
import reactor.core.publisher.Flux;

/** Initializes a new instance of the synchronous OpenAIClient type. */
@ServiceClient(builder = OpenAIClientBuilder.class)
public final class OpenAIClient {

private static final ClientLogger LOGGER = new ClientLogger(OpenAIClient.class);

@Generated private final OpenAIClientImpl serviceClient;
Expand Down Expand Up @@ -481,22 +481,23 @@ public IterableStream<ChatCompletions> getChatCompletionsStream(
public ImageResponse getImages(ImageGenerationOptions imageGenerationOptions) {
RequestOptions requestOptions = new RequestOptions();
BinaryData imageGenerationOptionsBinaryData = BinaryData.fromObject(imageGenerationOptions);

if (openAIServiceClient != null) {
return openAIServiceClient
.generateImageWithResponse(imageGenerationOptionsBinaryData, requestOptions)
.getValue()
.toObject(ImageResponse.class);
.generateImageWithResponse(imageGenerationOptionsBinaryData, requestOptions)
.getValue()
.toObject(ImageResponse.class);
} else {
// TODO: Currently, we use async client block() to avoid a unknown LRO status "notRunning" which Azure Core will
// TODO: Currently, we use async client block() to avoid a unknown LRO status "notRunning" which Azure Core
// will
// fix the issue in August release and we will reuse the method
// "SyncPoller<BinaryData, BinaryData> beginBeginAzureBatchImageGeneration()" after.
try {
return this.serviceClient.beginBeginAzureBatchImageGenerationAsync(imageGenerationOptionsBinaryData,
requestOptions)
.last()
.flatMap(it -> it.getFinalResult())
.map(it -> it.toObject(ImageOperationResponse.class).getResult()).block();
return this.serviceClient
.beginBeginAzureBatchImageGenerationAsync(imageGenerationOptionsBinaryData, requestOptions)
.last()
.flatMap(it -> it.getFinalResult())
.map(it -> it.toObject(ImageOperationResponse.class).getResult())
.block();
} catch (Exception e) {
Throwable unwrapped = Exceptions.unwrap(e);
if (unwrapped instanceof RuntimeException) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ public Response<BinaryData> getEmbeddingsWithResponse(
* <pre>{@code
* {
* id: String (Required)
* created: int (Required)
* created: long (Required)
* prompt_annotations (Optional): [
* (Optional){
* prompt_index: int (Required)
Expand Down Expand Up @@ -596,7 +596,7 @@ public Mono<Response<BinaryData>> getCompletionsWithResponseAsync(
* <pre>{@code
* {
* id: String (Required)
* created: int (Required)
* created: long (Required)
* prompt_annotations (Optional): [
* (Optional){
* prompt_index: int (Required)
Expand Down Expand Up @@ -680,7 +680,7 @@ public Response<BinaryData> getCompletionsWithResponse(
* messages (Required): [
* (Required){
* role: String(system/assistant/user/function) (Required)
* content: String (Optional)
* content: String (Required)
* name: String (Optional)
* function_call (Optional): {
* name: String (Required)
Expand Down Expand Up @@ -719,12 +719,12 @@ public Response<BinaryData> getCompletionsWithResponse(
* <pre>{@code
* {
* id: String (Required)
* created: int (Required)
* created: long (Required)
* choices (Required): [
* (Required){
* message (Optional): {
* role: String(system/assistant/user/function) (Required)
* content: String (Optional)
* content: String (Required)
* name: String (Optional)
* function_call (Optional): {
* name: String (Required)
Expand Down Expand Up @@ -799,7 +799,7 @@ public Mono<Response<BinaryData>> getChatCompletionsWithResponseAsync(
* messages (Required): [
* (Required){
* role: String(system/assistant/user/function) (Required)
* content: String (Optional)
* content: String (Required)
* name: String (Optional)
* function_call (Optional): {
* name: String (Required)
Expand Down Expand Up @@ -838,12 +838,12 @@ public Mono<Response<BinaryData>> getChatCompletionsWithResponseAsync(
* <pre>{@code
* {
* id: String (Required)
* created: int (Required)
* created: long (Required)
* choices (Required): [
* (Required){
* message (Optional): {
* role: String(system/assistant/user/function) (Required)
* content: String (Optional)
* content: String (Required)
* name: String (Optional)
* function_call (Optional): {
* name: String (Required)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
import com.azure.core.annotation.Immutable;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.time.Instant;
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
import java.util.List;

/**
Expand Down Expand Up @@ -39,27 +42,6 @@ public final class ChatCompletions {
@JsonProperty(value = "usage")
private CompletionsUsage usage;

/**
* Creates an instance of ChatCompletions class.
*
* @param id the id value to set.
* @param createdAt the createdAt value to set.
* @param choices the choices value to set.
* @param usage the usage value to set.
*/
@Generated
@JsonCreator
private ChatCompletions(
@JsonProperty(value = "id") String id,
@JsonProperty(value = "created") int createdAt,
@JsonProperty(value = "choices") List<ChatChoice> choices,
@JsonProperty(value = "usage") CompletionsUsage usage) {
this.id = id;
this.createdAt = createdAt;
this.choices = choices;
this.usage = usage;
}

/**
* Get the id property: A unique identifier associated with this chat completions response.
*
Expand Down Expand Up @@ -99,7 +81,7 @@ public CompletionsUsage getUsage() {
*/
@Generated
@JsonProperty(value = "created")
private int createdAt;
private long createdAt;

/**
* Get the createdAt property: The first timestamp associated with generation activity for this completions
Expand All @@ -108,8 +90,8 @@ public CompletionsUsage getUsage() {
* @return the createdAt value.
*/
@Generated
public int getCreatedAt() {
return this.createdAt;
public OffsetDateTime getCreatedAt() {
return OffsetDateTime.ofInstant(Instant.ofEpochSecond(this.createdAt), ZoneOffset.UTC);
}

/*
Expand All @@ -130,4 +112,30 @@ public int getCreatedAt() {
public List<PromptFilterResult> getPromptFilterResults() {
return this.promptFilterResults;
}

/**
* Creates an instance of ChatCompletions class.
*
* @param id the id value to set.
* @param createdAt the createdAt value to set.
* @param choices the choices value to set.
* @param usage the usage value to set.
*/
@Generated
private ChatCompletions(String id, OffsetDateTime createdAt, List<ChatChoice> choices, CompletionsUsage usage) {
this.id = id;
this.createdAt = createdAt.toEpochSecond();
this.choices = choices;
this.usage = usage;
}

@Generated
@JsonCreator
private ChatCompletions(
@JsonProperty(value = "id") String id,
@JsonProperty(value = "created") long createdAt,
@JsonProperty(value = "choices") List<ChatChoice> choices,
@JsonProperty(value = "usage") CompletionsUsage usage) {
this(id, OffsetDateTime.ofInstant(Instant.ofEpochSecond(createdAt), ZoneOffset.UTC), choices, usage);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,6 @@ public final class ChatMessage {
@JsonProperty(value = "content")
private String content;

/**
* Creates an instance of ChatMessage class.
*
* @param role the role value to set.
*/
@Generated
@JsonCreator
public ChatMessage(@JsonProperty(value = "role") ChatRole role) {
this.role = role;
}

/**
* Get the role property: The role associated with this message payload.
*
Expand All @@ -57,18 +46,6 @@ public String getContent() {
return this.content;
}

/**
* Set the content property: The text associated with this message payload.
*
* @param content the content value to set.
* @return the ChatMessage object itself.
*/
@Generated
public ChatMessage setContent(String content) {
this.content = content;
return this;
}

/*
* The name of the author of this message. `name` is required if role is `function`, and it should be the name of
* the
Expand Down Expand Up @@ -136,4 +113,17 @@ public ChatMessage setFunctionCall(FunctionCall functionCall) {
this.functionCall = functionCall;
return this;
}

/**
* Creates an instance of ChatMessage class.
*
* @param role the role value to set.
* @param content the content value to set.
*/
@Generated
@JsonCreator
public ChatMessage(@JsonProperty(value = "role") ChatRole role, @JsonProperty(value = "content") String content) {
this.role = role;
this.content = content;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
import com.azure.core.annotation.Immutable;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.time.Instant;
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
import java.util.List;

/**
Expand All @@ -23,14 +26,6 @@ public final class Completions {
@JsonProperty(value = "id")
private String id;

/*
* The first timestamp associated with generation activity for this completions response,
* represented as seconds since the beginning of the Unix epoch of 00:00 on 1 Jan 1970.
*/
@Generated
@JsonProperty(value = "created")
private int created;

/*
* The collection of completions choices associated with this completions response.
* Generally, `n` choices are generated per provided prompt with a default value of 1.
Expand All @@ -47,27 +42,6 @@ public final class Completions {
@JsonProperty(value = "usage")
private CompletionsUsage usage;

/**
* Creates an instance of Completions class.
*
* @param id the id value to set.
* @param created the created value to set.
* @param choices the choices value to set.
* @param usage the usage value to set.
*/
@Generated
@JsonCreator
private Completions(
@JsonProperty(value = "id") String id,
@JsonProperty(value = "created") int created,
@JsonProperty(value = "choices") List<Choice> choices,
@JsonProperty(value = "usage") CompletionsUsage usage) {
this.id = id;
this.created = created;
this.choices = choices;
this.usage = usage;
}

/**
* Get the id property: A unique identifier associated with this completions response.
*
Expand All @@ -78,17 +52,6 @@ public String getId() {
return this.id;
}

/**
* Get the created property: The first timestamp associated with generation activity for this completions response,
* represented as seconds since the beginning of the Unix epoch of 00:00 on 1 Jan 1970.
*
* @return the created value.
*/
@Generated
public int getCreated() {
return this.created;
}

/**
* Get the choices property: The collection of completions choices associated with this completions response.
* Generally, `n` choices are generated per provided prompt with a default value of 1. Token limits and other
Expand Down Expand Up @@ -130,4 +93,49 @@ public CompletionsUsage getUsage() {
public List<PromptFilterResult> getPromptFilterResults() {
return this.promptFilterResults;
}

/*
* The first timestamp associated with generation activity for this completions response,
* represented as seconds since the beginning of the Unix epoch of 00:00 on 1 Jan 1970.
*/
@Generated
@JsonProperty(value = "created")
private long createdAt;

/**
* Creates an instance of Completions class.
*
* @param id the id value to set.
* @param createdAt the createdAt value to set.
* @param choices the choices value to set.
* @param usage the usage value to set.
*/
@Generated
private Completions(String id, OffsetDateTime createdAt, List<Choice> choices, CompletionsUsage usage) {
this.id = id;
this.createdAt = createdAt.toEpochSecond();
this.choices = choices;
this.usage = usage;
}

@Generated
@JsonCreator
private Completions(
@JsonProperty(value = "id") String id,
@JsonProperty(value = "created") long createdAt,
@JsonProperty(value = "choices") List<Choice> choices,
@JsonProperty(value = "usage") CompletionsUsage usage) {
this(id, OffsetDateTime.ofInstant(Instant.ofEpochSecond(createdAt), ZoneOffset.UTC), choices, usage);
}

/**
* Get the createdAt property: The first timestamp associated with generation activity for this completions
* response, represented as seconds since the beginning of the Unix epoch of 00:00 on 1 Jan 1970.
*
* @return the createdAt value.
*/
@Generated
public OffsetDateTime getCreatedAt() {
return OffsetDateTime.ofInstant(Instant.ofEpochSecond(this.createdAt), ZoneOffset.UTC);
}
}
Loading