From 6e7b303bb6cdba75542c8a08f754de8f1709ed6e Mon Sep 17 00:00:00 2001 From: David Grieve Date: Thu, 25 Apr 2024 16:20:51 -0400 Subject: [PATCH] add initial assistants src --- .../openai/assistants/Assistant.java | 110 ++++++++++++ .../openai/assistants/AssistantMessage.java | 100 +++++++++++ .../openai/assistants/AssistantMetadata.java | 97 ++++++++++ .../openai/assistants/AssistantService.java | 20 +++ .../assistants/CodeInterpreterTool.java | 12 ++ .../CodeInterpreterToolResource.java | 18 ++ .../assistants/FileCitationAnnotation.java | 42 +++++ .../openai/assistants/FilePathAnnotation.java | 32 ++++ .../openai/assistants/FileSearchTool.java | 13 ++ .../assistants/FileSearchToolResource.java | 13 ++ .../openai/assistants/FunctionTool.java | 32 ++++ .../openai/assistants/ImageFileContent.java | 20 +++ .../aiservices/openai/assistants/Message.java | 111 ++++++++++++ .../openai/assistants/MessageAttachments.java | 22 +++ .../openai/assistants/MessageContent.java | 13 ++ .../openai/assistants/MessageContentType.java | 17 ++ .../openai/assistants/MessageCreation.java | 6 + .../openai/assistants/MessageStatus.java | 18 ++ .../openai/assistants/RequiredAction.java | 10 ++ .../openai/assistants/RequiredActionType.java | 17 ++ .../openai/assistants/ResponseFormat.java | 25 +++ .../aiservices/openai/assistants/Run.java | 169 ++++++++++++++++++ .../openai/assistants/RunError.java | 19 ++ .../openai/assistants/RunErrorCode.java | 19 ++ .../openai/assistants/RunStatus.java | 24 +++ .../aiservices/openai/assistants/RunStep.java | 119 ++++++++++++ .../openai/assistants/RunStepType.java | 18 ++ .../openai/assistants/StepDetails.java | 5 + .../openai/assistants/SubmitToolOutputs.java | 20 +++ .../openai/assistants/TextContent.java | 25 +++ .../assistants/TextContentAnnotation.java | 13 ++ .../assistants/TextContentAnnotationType.java | 18 ++ .../aiservices/openai/assistants/Thread.java | 49 +++++ .../openai/assistants/ThreadType.java | 21 +++ .../aiservices/openai/assistants/Tool.java | 12 ++ .../openai/assistants/ToolCall.java | 25 +++ .../openai/assistants/ToolChoice.java | 20 +++ .../openai/assistants/ToolChoiceType.java | 27 +++ .../openai/assistants/ToolResource.java | 10 ++ .../openai/assistants/ToolType.java | 18 ++ .../openai/assistants/TruncationStrategy.java | 19 ++ .../assistants/TruncationStrategyType.java | 26 +++ .../aiservices/openai/assistants/Usage.java | 24 +++ 43 files changed, 1448 insertions(+) create mode 100644 java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/Assistant.java create mode 100644 java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/AssistantMessage.java create mode 100644 java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/AssistantMetadata.java create mode 100644 java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/AssistantService.java create mode 100644 java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/CodeInterpreterTool.java create mode 100644 java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/CodeInterpreterToolResource.java create mode 100644 java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/FileCitationAnnotation.java create mode 100644 java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/FilePathAnnotation.java create mode 100644 java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/FileSearchTool.java create mode 100644 java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/FileSearchToolResource.java create mode 100644 java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/FunctionTool.java create mode 100644 java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/ImageFileContent.java create mode 100644 java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/Message.java create mode 100644 java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/MessageAttachments.java create mode 100644 java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/MessageContent.java create mode 100644 java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/MessageContentType.java create mode 100644 java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/MessageCreation.java create mode 100644 java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/MessageStatus.java create mode 100644 java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/RequiredAction.java create mode 100644 java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/RequiredActionType.java create mode 100644 java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/ResponseFormat.java create mode 100644 java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/Run.java create mode 100644 java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/RunError.java create mode 100644 java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/RunErrorCode.java create mode 100644 java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/RunStatus.java create mode 100644 java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/RunStep.java create mode 100644 java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/RunStepType.java create mode 100644 java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/StepDetails.java create mode 100644 java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/SubmitToolOutputs.java create mode 100644 java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/TextContent.java create mode 100644 java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/TextContentAnnotation.java create mode 100644 java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/TextContentAnnotationType.java create mode 100644 java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/Thread.java create mode 100644 java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/ThreadType.java create mode 100644 java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/Tool.java create mode 100644 java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/ToolCall.java create mode 100644 java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/ToolChoice.java create mode 100644 java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/ToolChoiceType.java create mode 100644 java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/ToolResource.java create mode 100644 java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/ToolType.java create mode 100644 java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/TruncationStrategy.java create mode 100644 java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/TruncationStrategyType.java create mode 100644 java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/Usage.java diff --git a/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/Assistant.java b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/Assistant.java new file mode 100644 index 000000000000..b95965672e99 --- /dev/null +++ b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/Assistant.java @@ -0,0 +1,110 @@ +package com.microsoft.semantickernel.aiservices.openai.assistants; + +import java.time.OffsetDateTime; +import java.util.List; +import java.util.Map; + +import javax.annotation.Nullable; + +/** + * Represents an OpenAI Assistant object. + */ +public interface Assistant { + + /** + * Get the identifier of the assistant. + * + * @return The identifier of the assistant. + */ + String getId(); + + /** + * Get the object type of the assistant, which is always {@code assistant}. + * + * @return The object type of the assistant. + */ + default String getObjectType() { return "assistant"; }; + + /** + * Get the Unix timestamp for when the assistant was created. + * + * @return The Unix timestamp for when the assistant was created. + */ + OffsetDateTime getCreatedAt(); + + /** + * Get the name of the assistant. + * + * @return The name of the assistant. + */ + @Nullable + String getName(); + + /** + * Get the description of the assistant. + * + * @return The description of the assistant. + */ + @Nullable + String getDescription(); + + /** + * Get the ID of the model used by the assistant. + * + * @return The ID of the model used by the assistant. + */ + String getModel(); + + /** + * Get the system instructions used by the assistant. + * + * @return The system instructions used by the assistant. + */ + @Nullable + String getInstructions(); + + /** + * Get the list of tools enabled on the assistant. + * + * @return The list of tools enabled on the assistant. + */ + List getTools(); + + /** + * Get the set of resources used by the assistant's tools. + * + * @return The set of resources used by the assistant's tools. + */ + @Nullable + Map getToolResources(); + + /** + * Get the metadata attached to the assistant. + * + * @return The metadata attached to the assistant. + */ + Map getMetadata(); + + /** + * Get the sampling temperature used by the assistant. + * + * @return The sampling temperature used by the assistant. + */ + @Nullable + Double getTemperature(); + + /** + * Get the top p value used by the assistant. + * + * @return The top p value used by the assistant. + */ + @Nullable + Double getTopP(); + + /** + * Get the response format used by the assistant. + * + * @return The response format used by the assistant. + */ + String getResponseFormat(); +} \ No newline at end of file diff --git a/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/AssistantMessage.java b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/AssistantMessage.java new file mode 100644 index 000000000000..bbf9bd9c972c --- /dev/null +++ b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/AssistantMessage.java @@ -0,0 +1,100 @@ +package com.microsoft.semantickernel.aiservices.openai.assistants; + +import java.util.List; +import java.util.Map; + +import javax.annotation.Nullable; + +import com.microsoft.semantickernel.services.chatcompletion.AuthorRole; + +/** + * Represents a message within a Thread. + */ +public interface AssistantMessage { + + + /** + * The identifier, which can be referenced in API endpoints. + * @return string + */ + String id(); + + /** + * The object type, which is always thread.message. + * @return string + */ + String getObject(); + + /** + * The Unix timestamp (in seconds) for when the message was created. + * @return integer + */ + int getCreatedAt(); + + /** + * The thread ID that this message belongs to. + * @return string + */ + String getThreadId(); + + /** + * The status of the message, which can be either in_progress, incomplete, or completed. + * @return string + */ + String getStatus(); + + /** + * On an incomplete message, details about why the message is incomplete. + * @return object or null + */ + @Nullable Object getIncompleteDetails(); + + /** + * The Unix timestamp (in seconds UTC) for when the message was completed. + * @return epoch time in UTC, or null + */ + @Nullable Long getCompletedAt(); + + /** + * The Unix timestamp (in seconds in UTC) for when the message was marked as incomplete. + * @return epoch time in UTC, or null + */ + @Nullable Long getIncompleteAt(); + + /** + * The entity that produced the message. One of user or assistant. + * @return string + */ + String getRole(); + + /** + * The content of the message in array of text and/or images. + * @return array + */ + List getContent(); + + /** + * If applicable, the ID of the assistant that authored this message. + * @return string or null + */ + @Nullable String getAssistantId(); + + /** + * The ID of the run associated with the creation of this message. Value is null when messages are created manually using the create message or create thread endpoints. + * @return string or null + */ + @Nullable String getRunId(); + + /** + * A list of file IDs that the assistant should use. Useful for tools like retrieval and code_interpreter that can access files. A maximum of 10 files can be attached to a message. + * @return array + */ + List getFileIds(); + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long. + * @return map + */ + Map getMetadata(); + +} \ No newline at end of file diff --git a/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/AssistantMetadata.java b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/AssistantMetadata.java new file mode 100644 index 000000000000..b4af19edf59d --- /dev/null +++ b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/AssistantMetadata.java @@ -0,0 +1,97 @@ +package com.microsoft.semantickernel.aiservices.openai.assistants; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +public class AssistantMetadata implements Map { + + private final Map metadata; + + public AssistantMetadata() { + this.metadata = new HashMap<>(); + } + + @Override + public int size() { + return metadata.size(); + } + + @Override + public boolean isEmpty() { + return metadata.isEmpty(); + } + + @Override + public boolean containsKey(Object key) { + return metadata.containsKey(key); + } + + @Override + public boolean containsValue(Object value) { + return metadata.containsValue(value); + } + + @Override + public String get(Object key) { + return metadata.get(key); + } + + @Override + public String put(String key, String value) { + if (key.length() > 64 || value.length() > 512) { + throw new IllegalArgumentException("Key must be 64 characters or less and value must be 512 characters or less"); + } + if (metadata.size() >= 16) { + throw new IllegalArgumentException("Metadata can only contain 16 key-value pairs"); + } + return metadata.put(key, value); + } + + @Override + public String remove(Object key) { + return metadata.remove(key); + } + + @Override + public void putAll(Map m) { + m.entrySet().forEach(entry -> put(entry.getKey(), entry.getValue())); + } + + @Override + public void clear() { + metadata.clear(); + } + + @Override + public Set keySet() { + return metadata.keySet(); + } + + @Override + public Collection values() { + return metadata.values(); + } + + @Override + public Set> entrySet() { + return metadata.entrySet(); + } + + @Override + public boolean equals(Object o) { + return metadata.equals(o); + } + + @Override + public int hashCode() { + return metadata.hashCode(); + } + + @Override + public String toString() { + return metadata.toString(); + } + +} diff --git a/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/AssistantService.java b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/AssistantService.java new file mode 100644 index 000000000000..b91f501b4dec --- /dev/null +++ b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/AssistantService.java @@ -0,0 +1,20 @@ +package com.microsoft.semantickernel.aiservices.openai.assistants; + +import javax.annotation.Nullable; + +import com.azure.ai.openai.OpenAIAsyncClient; +import com.microsoft.semantickernel.aiservices.openai.OpenAiService; +/** + * Represents an OpenAI Assistant. + */ +public class AssistantService extends OpenAiService { + + + public AssistantService( + OpenAIAsyncClient client, + @Nullable String serviceId, + String modelId) { + super(client, serviceId, modelId); + } + +} diff --git a/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/CodeInterpreterTool.java b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/CodeInterpreterTool.java new file mode 100644 index 000000000000..56b4843ce89e --- /dev/null +++ b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/CodeInterpreterTool.java @@ -0,0 +1,12 @@ +package com.microsoft.semantickernel.aiservices.openai.assistants; + +/** + * Represents a {@code code_interperter} tool definition. + */ +public interface CodeInterpreterTool extends Tool { + + @Override + default ToolType getType() { + return ToolType.CODE_INTERPRETER; + } +} diff --git a/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/CodeInterpreterToolResource.java b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/CodeInterpreterToolResource.java new file mode 100644 index 000000000000..33a1442ef991 --- /dev/null +++ b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/CodeInterpreterToolResource.java @@ -0,0 +1,18 @@ +package com.microsoft.semantickernel.aiservices.openai.assistants; + +import java.util.List; + +/** Represents a {@code code_interpreter} type of {@code tool_resource} */ +public interface CodeInterpreterToolResource extends ToolResource { + + @Override + default ToolType getType() { + return ToolType.CODE_INTERPRETER; + } + + /** + * A list of file IDs made available to the {@code code_interpreter} tool. + * @return A list of file IDs. + */ + List getFileIds(); +} diff --git a/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/FileCitationAnnotation.java b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/FileCitationAnnotation.java new file mode 100644 index 000000000000..780e9d759d2d --- /dev/null +++ b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/FileCitationAnnotation.java @@ -0,0 +1,42 @@ +package com.microsoft.semantickernel.aiservices.openai.assistants; + +/** + * A citation within the message that points to a specific quote from + * a specific File associated with the assistant or the message. + * Generated when the assistant uses the "file_search" tool to search files. + */ +public interface FileCitationAnnotation extends TextContentAnnotation { + + @Override + default TextContentAnnotationType getType() { return TextContentAnnotationType.FILE_CITATION; } + + /** + * The text in the message content that needs to be replaced. + * @return The text in the message content that needs to be replaced. + */ + String getText(); + + /** + * The ID of the file that the citation is pointing to. + * @return The ID of the file that the citation is pointing to. + */ + String getFileId(); + + /** + * The quote from the file that the citation is pointing to. + * @return The quote from the file that the citation is pointing to. + */ + String getQuote(); + + /** + * The start index of the quote in the file. + * @return The start index of the quote in the file. + */ + int getStartIndex(); + + /** + * The end index of the quote in the file. + * @return The end index of the quote in the file. + */ + int getEndIndex(); +} diff --git a/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/FilePathAnnotation.java b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/FilePathAnnotation.java new file mode 100644 index 000000000000..1c0849a1a867 --- /dev/null +++ b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/FilePathAnnotation.java @@ -0,0 +1,32 @@ +package com.microsoft.semantickernel.aiservices.openai.assistants; + +public interface FilePathAnnotation extends TextContentAnnotation { + + @Override + default TextContentAnnotationType getType() { return TextContentAnnotationType.FILE_PATH; } + + /** + * The text in the message content that needs to be replaced. + * @return The text in the message content that needs to be replaced. + */ + String getText(); + + /** + * The ID of the file that was generated. + * @return The ID of the file that was generated. + */ + String getFileId(); + + /** + * The start index of the quote in the file. + * @return The start index of the quote in the file. + */ + int getStartIndex(); + + /** + * The end index of the quote in the file. + * @return The end index of the quote in the file. + */ + int getEndIndex(); + +} diff --git a/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/FileSearchTool.java b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/FileSearchTool.java new file mode 100644 index 000000000000..13e06d87abef --- /dev/null +++ b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/FileSearchTool.java @@ -0,0 +1,13 @@ +package com.microsoft.semantickernel.aiservices.openai.assistants; + +/** + * Represents a file search tool definition. + */ +public interface FileSearchTool extends Tool { + + @Override + default ToolType getType() { + return ToolType.FILE_SEARCH; + } + +} diff --git a/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/FileSearchToolResource.java b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/FileSearchToolResource.java new file mode 100644 index 000000000000..7d272ed46ec2 --- /dev/null +++ b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/FileSearchToolResource.java @@ -0,0 +1,13 @@ +package com.microsoft.semantickernel.aiservices.openai.assistants; + +import java.util.List; + +public interface FileSearchToolResource extends ToolResource { + + @Override + default ToolType getType() { + return ToolType.FILE_SEARCH; + } + + List getVectorStoreIds(); +} diff --git a/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/FunctionTool.java b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/FunctionTool.java new file mode 100644 index 000000000000..73da9d2a1cce --- /dev/null +++ b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/FunctionTool.java @@ -0,0 +1,32 @@ +package com.microsoft.semantickernel.aiservices.openai.assistants; + +import com.microsoft.semantickernel.semanticfunctions.InputVariable; + +/** + * Represents a tool that is a function. + */ +public interface FunctionTool extends Tool { + + /** + * Get the name of the function to be called. + * + * @return the name of the function to be called. + */ + public String getName(); + + /** + * Get the description of what the function does, used by the model to choose when and how + * to call the function. + * + * @return a description of what the function does. + */ + public String getDescription(); + + /** + * Get the parameters the functions accepts. + * + * @return the parameters value. + */ + public InputVariable getParameters(); + +} diff --git a/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/ImageFileContent.java b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/ImageFileContent.java new file mode 100644 index 000000000000..87cc657d1cd8 --- /dev/null +++ b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/ImageFileContent.java @@ -0,0 +1,20 @@ +package com.microsoft.semantickernel.aiservices.openai.assistants; + +/** + * References an image {@link com.microsoft.semantickernel.aiservices.openai.assistants.File} + * in the content of a message. + */ +public interface ImageFileContent extends MessageContent { + + @Override + default MessageContentType getType() { + return MessageContentType.IMAGE_FILE; + } + + /** + * The ID of the image file. + * @return The ID of the image file. + */ + String getFileId(); + +} diff --git a/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/Message.java b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/Message.java new file mode 100644 index 000000000000..5729e8438764 --- /dev/null +++ b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/Message.java @@ -0,0 +1,111 @@ +package com.microsoft.semantickernel.aiservices.openai.assistants; + +import java.time.OffsetDateTime; +import java.util.List; +import java.util.Map; + +import com.microsoft.semantickernel.services.chatcompletion.AuthorRole; + +/** + * Represents a message within a thread. + */ +public interface Message { + + /** + * Get the identifier, which can be referenced in API endpoints. + * + * @return The identifier. + */ + String getId(); + + /** + * Get the object type, which is always {@code thread.message}. + * + * @return The object type. + */ + default ThreadType getType() { return ThreadType.THREAD_MESSAGE; }; + + /** + * Get the Unix timestamp (in seconds) for when the message was created. + * + * @return The created timestamp. + */ + OffsetDateTime getCreatedAt(); + + /** + * Get the thread ID that this message belongs to. + * + * @return The thread ID. + */ + String getThreadId(); + + /** + * Get the status of the message, which can be either in_progress, incomplete, or completed. + * + * @return The message status. + */ + MessageStatus getStatus(); + + /** + * Get details about why the message is incomplete. + * + * @return The incomplete details. + */ + String getIncompleteDetails(); + + /** + * Get the Unix timestamp (in seconds) for when the message was completed. + * + * @return The completed timestamp. + */ + OffsetDateTime getCompletedAt(); + + /** + * Get the Unix timestamp (in seconds) for when the message was marked as incomplete. + * + * @return The incomplete timestamp. + */ + OffsetDateTime getIncompleteAt(); + + /** + * Get the entity that produced the message. + * + * @return The message role. + */ + AuthorRole getRole(); + + /** + * Get the content of the message in array of text and/or images. + * + * @return The message content. + */ + List getContent(); + + /** + * Get the ID of the assistant that authored this message. + * + * @return The assistant ID. + */ + String getAssistantId(); + + /** + * Get the ID of the run associated with the creation of this message. + * + * @return The run ID. + */ + String getRunId(); + + /** + * Get the list of files attached to the message, and the tools they were added to. + * + * @return The attachments. + */ + List getAttachments(); + + /** + * Get the set of key-value pairs that can be attached to an object. + * + * @return The metadata. + */ + Map getMetadata(); +} \ No newline at end of file diff --git a/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/MessageAttachments.java b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/MessageAttachments.java new file mode 100644 index 000000000000..fdf87b910d18 --- /dev/null +++ b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/MessageAttachments.java @@ -0,0 +1,22 @@ +package com.microsoft.semantickernel.aiservices.openai.assistants; + +import java.util.List; + +/** + * Represents a file attached to the message, and the tools it was added to. + */ +public interface MessageAttachments { + + /** + * The file's identifier. + * @return The file's identifier. + */ + public String getFileId(); + + /** + * The tools that the file was added to. + * @return The tools that the file was added to. + */ + List getTools(); + +} diff --git a/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/MessageContent.java b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/MessageContent.java new file mode 100644 index 000000000000..3d4c70f377bb --- /dev/null +++ b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/MessageContent.java @@ -0,0 +1,13 @@ +package com.microsoft.semantickernel.aiservices.openai.assistants; + +/** + * The content of a message. + */ +public interface MessageContent { + + /** + * The type of the content. + * @return The type of the content. + */ + MessageContentType getType(); +} diff --git a/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/MessageContentType.java b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/MessageContentType.java new file mode 100644 index 000000000000..56ec504cbdf6 --- /dev/null +++ b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/MessageContentType.java @@ -0,0 +1,17 @@ +package com.microsoft.semantickernel.aiservices.openai.assistants; + +public enum MessageContentType { + + IMAGE_FILE("image_file"), + TEXT("text"); + + private final String value; + private MessageContentType(String value) { + this.value = value; + } + + @Override + public String toString() { + return value; + } +} diff --git a/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/MessageCreation.java b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/MessageCreation.java new file mode 100644 index 000000000000..1b4f77e4b7fd --- /dev/null +++ b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/MessageCreation.java @@ -0,0 +1,6 @@ +package com.microsoft.semantickernel.aiservices.openai.assistants; + +public interface MessageCreation { + + String getMessageId(); +} diff --git a/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/MessageStatus.java b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/MessageStatus.java new file mode 100644 index 000000000000..49373d550c77 --- /dev/null +++ b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/MessageStatus.java @@ -0,0 +1,18 @@ +package com.microsoft.semantickernel.aiservices.openai.assistants; + +public enum MessageStatus { + IN_PROGRESS("in_progress"), + INCOMPLETE("incomplete"), + COMPLETED("completed"); + + private final String value; + + MessageStatus(String value) { + this.value = value; + } + + @Override + public String toString() { + return value; + } +} diff --git a/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/RequiredAction.java b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/RequiredAction.java new file mode 100644 index 000000000000..f92073eb83b7 --- /dev/null +++ b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/RequiredAction.java @@ -0,0 +1,10 @@ +package com.microsoft.semantickernel.aiservices.openai.assistants; + +/** + * Details on the action required to continue the run. Will be {@code null} if no action is required. + */ +public interface RequiredAction { + + RequiredActionType getType(); + +} diff --git a/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/RequiredActionType.java b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/RequiredActionType.java new file mode 100644 index 000000000000..cfa89b000b83 --- /dev/null +++ b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/RequiredActionType.java @@ -0,0 +1,17 @@ +package com.microsoft.semantickernel.aiservices.openai.assistants; + +public enum RequiredActionType { + SUBMIT_TOOL_OUTPUTS("submit_tool_outputs"); + + private final String value; + + RequiredActionType(String value) { + this.value = value; + } + + @Override + public String toString() { + return value; + } + +} diff --git a/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/ResponseFormat.java b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/ResponseFormat.java new file mode 100644 index 000000000000..5da80944f60e --- /dev/null +++ b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/ResponseFormat.java @@ -0,0 +1,25 @@ +package com.microsoft.semantickernel.aiservices.openai.assistants; + +/** + * Types for the Assistant response format. + * An object describing the expected output of the model. + * If json_object only function type tools are allowed to + * be passed to the Run. If text the model can return text + * or any value needed + */ +public enum ResponseFormat { + AUTO("auto"), + JSON("json"), + TEXT("text"); + + private final String value; + private ResponseFormat(String value) { + this.value = value; + } + + @Override + public String toString() { + return value; + } + +} diff --git a/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/Run.java b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/Run.java new file mode 100644 index 000000000000..61d72d5f5b14 --- /dev/null +++ b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/Run.java @@ -0,0 +1,169 @@ +package com.microsoft.semantickernel.aiservices.openai.assistants; + +import java.time.OffsetDateTime; +import java.util.List; +import java.util.Map; + +/** + * Represents an execution run on a thread. + */ +public interface Run { + + /** + * Get the identifier, which can be referenced in API endpoints. + * + * @return the identifier + */ + String getId(); + + /** + * Get the object type, which is always {@code thread.run}. + * @return the object type, which is always {@code thread.run} + */ + ThreadType getType(); + + /** + * Get the Unix timestamp for when the run was created. + * @return the Unix timestamp for when the run was created. + */ + OffsetDateTime getCreatedAt(); + + /** + * Get the ID of the thread that was executed on as a part of this run. + * @return the ID of the thread + */ + String getThreadId(); + + /** + * Get the ID of the assistant used for execution of this run. + * @return the ID of the assistant + */ + String getAssistantId(); + + /** + * Get the status of the run. + * @return the status of the run + */ + RunStatus getStatus(); + + /** + * Get details on the action required to continue the run. + * @return the details on the action required, or null if no action is required + */ + RequiredAction getRequiredAction(); + + /** + * Get the last error associated with this run. + * @return the last error, or null if there are no errors + */ + RunError getLastError(); + + /** + * Get the Unix timestamp for when the run will expire. + * @return the Unix timestamp for when the run will expire + */ + OffsetDateTime getExpiresAt(); + + /** + * Get the Unix timestamp for when the run was started. + * @return the Unix timestamp for when the run was started + */ + OffsetDateTime getStartedAt(); + + /** + * Get the Unix timestamp for when the run was cancelled. + * @return the Unix timestamp for when the run was cancelled + */ + OffsetDateTime getCancelledAt(); + + /** + * Get the Unix timestamp for when the run failed. + * @return the Unix timestamp for when the run failed + */ + OffsetDateTime getFailedAt(); + + /** + * Get the Unix timestamp for when the run was completed. + * @return the Unix timestamp for when the run was completed + */ + OffsetDateTime getCompletedAt(); + + /** + * Get details on why the run is incomplete. + * This will point to which specific token limit was reached over the course of the run. + * @return the details on why the run is incomplete, or null if the run is not incomplete + */ + String getIncompleteDetails(); + + /** + * Get the model that the assistant used for this run. + * @return the model used for this run + */ + String getModel(); + + /** + * Get the instructions that the assistant used for this run. + * @return the instructions used for this run + */ + String getInstructions(); + + /** + * Get the list of tools that the assistant used for this run. + * @return the list of tools used for this run + */ + List getTools(); + + /** + * Get the set of 16 key-value pairs that can be attached to an object. + * @return the metadata attached to the object + */ + Map getMetadata(); + + /** + * Get usage statistics related to the run. + * @return the usage statistics related to the run, or null if the run is not in a terminal state + */ + Usage getUsage(); + + /** + * Get the sampling temperature used for this run. + * @return the sampling temperature used for this run. + */ + double getTemperature(); + + /** + * Get the nucleus sampling value used for this run. + * @return the nucleus sampling value used for this run. + */ + double getTopP(); + + /** + * Get the maximum number of prompt tokens specified to have been used over the course of the run. + * @return the maximum number of prompt tokens used over the course of the run + */ + int getMaxPromptTokens(); + + /** + * Get the maximum number of completion tokens specified to have been used over the course of the run. + * @return the maximum number of completion tokens used over the course of the run + */ + int getMaxCompletionTokens(); + + /** + * Get controls for how a thread will be truncated prior to the run. + * @return the controls for truncation strategy + */ + TruncationStrategy getTruncationStrategy(); + + /** + * Get controls which (if any) tool is called by the model. + * @return the controls for tool choice + */ + ToolChoice getToolChoice(); + + /** + * Get the format that the model must output. + * @return the format for the model output + */ + ResponseFormat getResponseFormat(); +} diff --git a/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/RunError.java b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/RunError.java new file mode 100644 index 000000000000..d1303d4c9ebb --- /dev/null +++ b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/RunError.java @@ -0,0 +1,19 @@ +package com.microsoft.semantickernel.aiservices.openai.assistants; + +/** + * Represents an error that occurred during the execution of a run. + */ +public interface RunError { + + /** + * Get the error code. + * @return the error code + */ + RunErrorCode getCode(); + + /** + * Get the error message. + * @return the error message + */ + String getMessage(); +} diff --git a/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/RunErrorCode.java b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/RunErrorCode.java new file mode 100644 index 000000000000..293141d85718 --- /dev/null +++ b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/RunErrorCode.java @@ -0,0 +1,19 @@ +package com.microsoft.semantickernel.aiservices.openai.assistants; + +public enum RunErrorCode { + + SERVER_ERROR("server_error"), + RATE_LIMIT_EXCEEDED("rate_limit_exceeded"), + INVALID_PROMPT("invalid_prompt"); + + private final String value; + + private RunErrorCode(String value) { + this.value = value; + } + + @Override + public String toString() { + return value; + } +} diff --git a/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/RunStatus.java b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/RunStatus.java new file mode 100644 index 000000000000..3f8a7c94dc38 --- /dev/null +++ b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/RunStatus.java @@ -0,0 +1,24 @@ +package com.microsoft.semantickernel.aiservices.openai.assistants; + +public enum RunStatus { + + QUEUED("queued"), + IN_PROGRESS("in_progress"), + REQUIRES_ACTION("requires_action"), + CANCELLING("cancelling"), + CANCELLED("cancelled"), + FAILED("failed"), + COMPLETED("completed"), + EXPIRED("expired"); + + private final String value; + + RunStatus(String value) { + this.value = value; + } + + @Override + public String toString() { + return value; + } +} diff --git a/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/RunStep.java b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/RunStep.java new file mode 100644 index 000000000000..53d8f83e155d --- /dev/null +++ b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/RunStep.java @@ -0,0 +1,119 @@ +package com.microsoft.semantickernel.aiservices.openai.assistants; + +import java.time.OffsetDateTime; +import java.util.Map; + +public interface RunStep { + + /** + * Get the identifier of the run step. + * + * @return The identifier of the run step. + */ + String getId(); + + /** + * Get the object type of the run step. + * + * @return The object type of the run step. + */ + ThreadType getObject(); + + /** + * Get the Unix timestamp for when the run step was created. + * + * @return The Unix timestamp for when the run step was created. + */ + OffsetDateTime getCreatedAt(); + + /** + * Get the ID of the assistant associated with the run step. + * + * @return The ID of the assistant associated with the run step. + */ + String getAssistantId(); + + /** + * Get the ID of the thread that was run. + * + * @return The ID of the thread that was run. + */ + String getThreadId(); + + /** + * Get the ID of the run that this run step is a part of. + * + * @return The ID of the run that this run step is a part of. + */ + String getRunId(); + + /** + * Get the type of run step. + * + * @return The type of run step. + */ + RunStepType getType(); + + /** + * Get the status of the run step. + * + * @return The status of the run step. + */ + RunStatus getStatus(); + + /** + * Get the details of the run step. + * + * @return The details of the run step. + */ + StepDetails getStepDetails(); + + /** + * Get the last error associated with this run step. + * + * @return The last error associated with this run step, or null if there are no errors. + */ + RunError getLastError(); + + /** + * Get the Unix timestamp for when the run step expired. + * + * @return The Unix timestamp for when the run step expired, or null if the step is not expired. + */ + OffsetDateTime getExpiredAt(); + + /** + * Get the Unix timestamp for when the run step was cancelled. + * + * @return The Unix timestamp for when the run step was cancelled, or null if the step was not cancelled. + */ + OffsetDateTime getCancelledAt(); + + /** + * Get the Unix timestamp for when the run step failed. + * + * @return The Unix timestamp for when the run step failed, or null if the step did not fail. + */ + OffsetDateTime getFailedAt(); + + /** + * Get the Unix timestamp for when the run step completed. + * + * @return The Unix timestamp for when the run step completed, or null if the step is not completed. + */ + OffsetDateTime getCompletedAt(); + + /** + * Get the metadata of the run step. + * + * @return The metadata of the run step. + */ + Map getMetadata(); + + /** + * Get the usage statistics related to the run step. + * + * @return The usage statistics related to the run step, or null if the status is in_progress. + */ + Usage getUsage(); +} \ No newline at end of file diff --git a/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/RunStepType.java b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/RunStepType.java new file mode 100644 index 000000000000..82d2affa8e0d --- /dev/null +++ b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/RunStepType.java @@ -0,0 +1,18 @@ +package com.microsoft.semantickernel.aiservices.openai.assistants; + +public enum RunStepType { + + MESSAGE_CREATION("message_creation"), + TOOL_CALLS("tool_calls"); + + private final String value; + + private RunStepType(String value) { + this.value = value; + } + + @Override + public String toString() { + return value; + } +} diff --git a/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/StepDetails.java b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/StepDetails.java new file mode 100644 index 000000000000..455de5a8b5eb --- /dev/null +++ b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/StepDetails.java @@ -0,0 +1,5 @@ +package com.microsoft.semantickernel.aiservices.openai.assistants; + +public interface StepDetails { + MessageCreation getMessageCreation(); +} \ No newline at end of file diff --git a/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/SubmitToolOutputs.java b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/SubmitToolOutputs.java new file mode 100644 index 000000000000..497351f9f46c --- /dev/null +++ b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/SubmitToolOutputs.java @@ -0,0 +1,20 @@ +package com.microsoft.semantickernel.aiservices.openai.assistants; + +import java.util.List; + +/** + * Details on the tool outputs needed for this run to continue. + */ +public interface SubmitToolOutputs extends RequiredAction { + + @Override + default RequiredActionType getType() { + return RequiredActionType.SUBMIT_TOOL_OUTPUTS; + } + + /** + * The tool outputs that need to be submitted. + */ + List getToolOutputs(); + +} diff --git a/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/TextContent.java b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/TextContent.java new file mode 100644 index 000000000000..c4f2c7208e8a --- /dev/null +++ b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/TextContent.java @@ -0,0 +1,25 @@ + +package com.microsoft.semantickernel.aiservices.openai.assistants; + +import java.util.List; + +/** + * Represents text content within a message. + */ +public interface TextContent extends MessageContent { + + @Override + default MessageContentType getType() { return MessageContentType.TEXT; } + + /** + * The data that makes up the text. + * @return The data that makes up the text. + */ + public String getValue(); + + /** + * Metadata about the text. + * @return Metadata about the text. + */ + public List getAnnotations(); +} diff --git a/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/TextContentAnnotation.java b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/TextContentAnnotation.java new file mode 100644 index 000000000000..a3b9c766f596 --- /dev/null +++ b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/TextContentAnnotation.java @@ -0,0 +1,13 @@ +package com.microsoft.semantickernel.aiservices.openai.assistants; + +/** + * Represents a text content annotation. + */ +public interface TextContentAnnotation { + + /** + * The type of the content. + * @return The type of the content. + */ + TextContentAnnotationType getType(); +} diff --git a/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/TextContentAnnotationType.java b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/TextContentAnnotationType.java new file mode 100644 index 000000000000..d74a7447d37d --- /dev/null +++ b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/TextContentAnnotationType.java @@ -0,0 +1,18 @@ +package com.microsoft.semantickernel.aiservices.openai.assistants; + +public enum TextContentAnnotationType { + + FILE_CITATION("file_citation"), + FILE_PATH("file_path"); + + private final String value; + + private TextContentAnnotationType(String value) { + this.value = value; + } + + @Override + public String toString() { + return value; + } +} diff --git a/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/Thread.java b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/Thread.java new file mode 100644 index 000000000000..dd5641a4d22d --- /dev/null +++ b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/Thread.java @@ -0,0 +1,49 @@ +package com.microsoft.semantickernel.aiservices.openai.assistants; + +import java.time.OffsetDateTime; +import java.util.Map; + +/** + * Represents a thread that contains messages. + */ +public interface Thread { + /** + * Gets the identifier, which can be referenced in API endpoints. + * + * @return The identifier. + */ + String getId(); + + /** + * Gets the object type, which is always {@code thread}. + * + * @return The object type. + */ + default String getObjectType() { return "thread"; }; + + /** + * Gets the Unix timestamp (in seconds) for when the thread was created. + * + * @return The creation timestamp. + */ + OffsetDateTime getCreatedAt(); + + /** + * Gets the set of resources that are made available to the assistant's tools in this thread. + * The resources are specific to the type of tool. + * For example, the code_interpreter tool requires a list of file IDs, + * while the file_search tool requires a list of vector store IDs. + * + * @return The tool resources or null if not available. + */ + ToolResource getToolResources(); + + /** + * Gets the set of metadata attached to the object. + * This can be useful for storing additional information about the object in a structured format. + * Keys can be a maximum of 64 characters long and values can be a maximum of 512 characters long. + * + * @return The metadata. + */ + Map getMetadata(); +} diff --git a/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/ThreadType.java b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/ThreadType.java new file mode 100644 index 000000000000..f9c258a3253a --- /dev/null +++ b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/ThreadType.java @@ -0,0 +1,21 @@ +package com.microsoft.semantickernel.aiservices.openai.assistants; + +/** + * Represents the type of message. + */ +public enum ThreadType { + THREAD_MESSAGE("thread.message"), + THREAD_RUN("thread.run"), + THREAD_RUN_STEP("thread.run.step"); + + private final String value; + + ThreadType(String value) { + this.value = value; + } + + @Override + public String toString() { + return value; + } +} diff --git a/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/Tool.java b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/Tool.java new file mode 100644 index 000000000000..8eb58b9d7211 --- /dev/null +++ b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/Tool.java @@ -0,0 +1,12 @@ +package com.microsoft.semantickernel.aiservices.openai.assistants; + +/** + * Represents a tool definition. + */ +public interface Tool { + /** + * Get the identifier of the tool definition. + * @return The identifier of the tool definition. + */ + ToolType getType(); +} diff --git a/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/ToolCall.java b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/ToolCall.java new file mode 100644 index 000000000000..cc37ecc39998 --- /dev/null +++ b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/ToolCall.java @@ -0,0 +1,25 @@ +package com.microsoft.semantickernel.aiservices.openai.assistants; + +/** + * Metadata about a tool call + */ +public interface ToolCall { + + /** + * The ID of the tool call. + * @return The ID of the tool call. + */ + String getId(); + + /** + * The type of tool call the output is required for. + * @return The type of tool call the output is required for. + */ + default ToolType getType() { return ToolType.FUNCTION; } + + /** + * The function definition. + * @return The function definition. + */ + FunctionTool getFunction(); +} diff --git a/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/ToolChoice.java b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/ToolChoice.java new file mode 100644 index 000000000000..307ac66fcf0c --- /dev/null +++ b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/ToolChoice.java @@ -0,0 +1,20 @@ +package com.microsoft.semantickernel.aiservices.openai.assistants; + +/** + * Controls which (if any) tool is called by the model + */ +public interface ToolChoice { + + /** + * The type of tool choice + * @return the type of tool choice + */ + ToolChoiceType getType(); + + /** + * If the type is {@code function}, the function to call + * @return the function to call, or @code null} if the type is not {@code function} + */ + String getFunction(); + +} diff --git a/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/ToolChoiceType.java b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/ToolChoiceType.java new file mode 100644 index 000000000000..4b708449a224 --- /dev/null +++ b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/ToolChoiceType.java @@ -0,0 +1,27 @@ +package com.microsoft.semantickernel.aiservices.openai.assistants; + +/** + * Controls which (if any) tool is called by the model. + * {@code none} means the model will not call any tools and instead + * generates a message. {@code auto} is the default value and means + * the model can pick between generating a message or calling a tool. + * Specifying a particular tool like {"type": "file_search"} or {"type": "function", "function": {"name": "my_function"}} forces the model to call that tool. + */ +public enum ToolChoiceType { + + NONE("none"), + AUTO("auto"), + REQUIRED("required"); + + private final String value; + + private ToolChoiceType(String value) { + this.value = value; + } + + @Override + public String toString() { + return value; + } + +} diff --git a/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/ToolResource.java b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/ToolResource.java new file mode 100644 index 000000000000..94cc168cce87 --- /dev/null +++ b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/ToolResource.java @@ -0,0 +1,10 @@ +package com.microsoft.semantickernel.aiservices.openai.assistants; + +/** Represents a {@code tool_resources} object */ +public interface ToolResource { + /** + * Get the identifier of the tool resource definition. + * @return The identifier of the tool resource definition. + */ + ToolType getType(); +} diff --git a/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/ToolType.java b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/ToolType.java new file mode 100644 index 000000000000..ac655b54108f --- /dev/null +++ b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/ToolType.java @@ -0,0 +1,18 @@ +package com.microsoft.semantickernel.aiservices.openai.assistants; + +public enum ToolType { + CODE_INTERPRETER("code_interpreter"), + FILE_SEARCH("file_search"), + FUNCTION("function"); + + private final String value; + + ToolType(String value) { + this.value = value; + } + + @Override + public String toString() { + return value; + } +} diff --git a/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/TruncationStrategy.java b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/TruncationStrategy.java new file mode 100644 index 000000000000..7418d5d4a5f8 --- /dev/null +++ b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/TruncationStrategy.java @@ -0,0 +1,19 @@ +package com.microsoft.semantickernel.aiservices.openai.assistants; + +/** + * Controls for how a thread will be truncated prior to the run. Use this to control the intial context window of the run + */ +public interface TruncationStrategy { + + /** + * The truncation strategy to use for the thread + * @return the truncation strategy to use for the thread + */ + TruncationStrategyType getType(); + + /** + * The number of most recent messages from the thread when constructing the context for the run + * @return the number of most recent messages from the thread when constructing the context for the run + */ + int getLastMessages(); +} diff --git a/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/TruncationStrategyType.java b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/TruncationStrategyType.java new file mode 100644 index 000000000000..bd8ebdb9ae7e --- /dev/null +++ b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/TruncationStrategyType.java @@ -0,0 +1,26 @@ +package com.microsoft.semantickernel.aiservices.openai.assistants; + +/** + * The truncation strategy to use for the thread. + * The default is {@code auto}. + * If set to {@code last_messages}, the thread will be truncated to the + * {@code n} most recent messages in the thread. + * When set to {@code auto}, messages in the middle of the thread will + * be dropped to fit the context length of the model, + * {@code max_prompt_tokens}. +*/ +public enum TruncationStrategyType { + AUTO("auto"), + LAST_MESSAGES("last_messages"); + + private final String value; + + private TruncationStrategyType(String value) { + this.value = value; + } + + @Override + public String toString() { + return value; + } +} \ No newline at end of file diff --git a/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/Usage.java b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/Usage.java new file mode 100644 index 000000000000..d7deae42398a --- /dev/null +++ b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/assistants/Usage.java @@ -0,0 +1,24 @@ +package com.microsoft.semantickernel.aiservices.openai.assistants; + +public interface Usage { + /** + * Get the number of completion tokens used over the course of the run step. + * + * @return The number of completion tokens used. + */ + int getCompletionTokens(); + + /** + * Get the number of prompt tokens used over the course of the run step. + * + * @return The number of prompt tokens used. + */ + int getPromptTokens(); + + /** + * Get the total number of tokens used (prompt + completion) over the course of the run step. + * + * @return The total number of tokens used. + */ + int getTotalTokens(); +} \ No newline at end of file