From 6f63676e11cd2e65d3de86d9f5ebfff84e97e47d Mon Sep 17 00:00:00 2001 From: Travis Wilson Date: Fri, 15 Dec 2023 14:30:18 -0800 Subject: [PATCH 01/15] initial azure-sdk-for-net commit for Assistants library --- .../Azure.AI.OpenAI.Assistants/.gitignore | 4 + .../Azure.AI.OpenAI.Assistants.sln | 41 + .../Azure.AI.OpenAI.Assistants/CHANGELOG.md | 9 + .../Directory.Build.props | 6 + .../Azure.AI.OpenAI.Assistants/README.md | 357 ++ ...ure.AI.OpenAI.Assistants.netstandard2.0.cs | 566 +++ .../src/Azure.AI.OpenAI.Assistants.csproj | 34 + .../src/Convenience/AssistantsClient.cs | 138 + .../src/Convenience/FunctionToolDefinition.cs | 36 + .../src/Convenience/PageableList.cs | 38 + .../src/Convenience/README.md | 4 + .../src/Custom/AssistantsClient.cs | 718 ++++ .../src/Custom/AssistantsModelFactory.cs | 240 ++ .../src/Custom/CodeInterpreterToolCall.cs | 26 + .../src/Custom/FunctionToolCall.cs | 27 + .../src/Custom/FunctionToolDefinition.cs | 57 + .../MessageFileCitationTextAnnotation.cs | 24 + .../Custom/MessageFilePathTextAnnotation.cs | 21 + .../src/Custom/MessageImageFileContent.cs | 21 + .../src/Custom/MessageTextContent.cs | 26 + .../src/Custom/PageableList.cs | 80 + .../src/Custom/README.md | 3 + .../src/Custom/RunStep.cs | 40 + .../src/Custom/SubmitToolOutputsAction.cs | 25 + .../src/Custom/ThreadRun.cs | 41 + .../src/Custom/ToolOutput.cs | 56 + .../Custom/UploadFileRequest.Serialization.cs | 33 + .../src/Custom/Visibility/Assistant.cs | 17 + .../src/Custom/Visibility/AssistantFile.cs | 17 + .../src/Custom/Visibility/AssistantThread.cs | 17 + .../src/Custom/Visibility/ListSortOrder.cs | 15 + .../src/Custom/Visibility/MessageFile.cs | 17 + .../src/Custom/Visibility/OpenAIFile.cs | 17 + .../src/Custom/Visibility/RunStep.cs | 17 + .../src/Custom/Visibility/ThreadMessage.cs | 17 + .../src/Custom/Visibility/ThreadRun.cs | 17 + ...OpenAIAssistantsClientBuilderExtensions.cs | 46 + .../src/Generated/Assistant.Serialization.cs | 132 + .../src/Generated/Assistant.cs | 95 + .../AssistantCreationOptions.Serialization.cs | 77 + .../src/Generated/AssistantCreationOptions.cs | 68 + .../Generated/AssistantFile.Serialization.cs | 60 + .../src/Generated/AssistantFile.cs | 52 + ...istantModificationOptions.Serialization.cs | 80 + .../Generated/AssistantModificationOptions.cs | 62 + .../AssistantThread.Serialization.cs | 71 + .../src/Generated/AssistantThread.cs | 51 + ...tantThreadCreationOptions.Serialization.cs | 50 + .../AssistantThreadCreationOptions.cs | 37 + .../src/Generated/AssistantsClient.cs | 3720 +++++++++++++++++ .../src/Generated/AssistantsClientOptions.cs | 37 + .../src/Generated/AssistantsModelFactory.cs | 133 + ...odeInterpreterImageOutput.Serialization.cs | 47 + .../Generated/CodeInterpreterImageOutput.cs | 38 + ...InterpreterImageReference.Serialization.cs | 41 + .../CodeInterpreterImageReference.cs | 29 + .../CodeInterpreterLogOutput.Serialization.cs | 47 + .../src/Generated/CodeInterpreterLogOutput.cs | 38 + .../CodeInterpreterToolCall.Serialization.cs | 53 + .../src/Generated/CodeInterpreterToolCall.cs | 41 + ...InterpreterToolCallOutput.Serialization.cs | 40 + .../CodeInterpreterToolCallOutput.cs | 32 + ...InterpreterToolDefinition.Serialization.cs | 58 + .../CodeInterpreterToolDefinition.cs | 25 + ...CreateAndRunThreadOptions.Serialization.cs | 67 + .../Generated/CreateAndRunThreadOptions.cs | 63 + ...reateAssistantFileRequest.Serialization.cs | 31 + .../Generated/CreateAssistantFileRequest.cs | 29 + .../CreateMessageRequest.Serialization.cs | 54 + .../src/Generated/CreateMessageRequest.cs | 53 + .../CreateRunRequest.Serialization.cs | 62 + .../src/Generated/CreateRunRequest.cs | 59 + .../FunctionToolCall.Serialization.cs | 53 + .../src/Generated/FunctionToolCall.cs | 41 + .../FunctionToolDefinition.Serialization.cs | 66 + .../src/Generated/FunctionToolDefinition.cs | 24 + ...alAssistantDeletionStatus.Serialization.cs | 47 + .../InternalAssistantDeletionStatus.cs | 30 + .../InternalAssistantDeletionStatusObject.cs | 48 + ...sistantFileDeletionStatus.Serialization.cs | 47 + .../InternalAssistantFileDeletionStatus.cs | 30 + ...ternalAssistantFileDeletionStatusObject.cs | 48 + ...nterpreterToolCallDetails.Serialization.cs | 53 + .../InternalCodeInterpreterToolCallDetails.cs | 49 + .../src/Generated/InternalDeletionStatus.cs | 23 + ...nternalFileDeletionStatus.Serialization.cs | 53 + .../Generated/InternalFileDeletionStatus.cs | 43 + .../InternalFileDeletionStatusObject.cs | 48 + .../InternalFileListResponse.Serialization.cs | 53 + .../src/Generated/InternalFileListResponse.cs | 43 + .../InternalFileListResponseObject.cs | 48 + ...nternalFunctionDefinition.Serialization.cs | 82 + .../Generated/InternalFunctionDefinition.cs | 68 + ...alFunctionToolCallDetails.Serialization.cs | 59 + .../InternalFunctionToolCallDetails.cs | 47 + ...nalMessageFilePathDetails.Serialization.cs | 58 + .../InternalMessageFilePathDetails.cs | 29 + ...alMessageImageFileDetails.Serialization.cs | 58 + .../InternalMessageImageFileDetails.cs | 29 + ...MessageImageFileIdDetails.Serialization.cs | 58 + .../InternalMessageImageFileIdDetails.cs | 29 + ...nternalMessageTextDetails.Serialization.cs | 77 + .../Generated/InternalMessageTextDetails.cs | 49 + ...geTextFileCitationDetails.Serialization.cs | 66 + .../InternalMessageTextFileCitationDetails.cs | 34 + ...AIPageableListOfAssistant.Serialization.cs | 71 + .../InternalOpenAIPageableListOfAssistant.cs | 63 + ...geableListOfAssistantFile.Serialization.cs | 71 + ...ternalOpenAIPageableListOfAssistantFile.cs | 63 + ...PageableListOfMessageFile.Serialization.cs | 71 + ...InternalOpenAIPageableListOfMessageFile.cs | 63 + ...enAIPageableListOfRunStep.Serialization.cs | 71 + .../InternalOpenAIPageableListOfRunStep.cs | 63 + ...geableListOfThreadMessage.Serialization.cs | 71 + ...ternalOpenAIPageableListOfThreadMessage.cs | 63 + ...AIPageableListOfThreadRun.Serialization.cs | 71 + .../InternalOpenAIPageableListOfThreadRun.cs | 63 + ...lSubmitToolOutputsDetails.Serialization.cs | 47 + .../InternalSubmitToolOutputsDetails.cs | 42 + .../src/Generated/ListSortOrder.cs | 51 + .../Generated/MessageContent.Serialization.cs | 57 + .../src/Generated/MessageContent.cs | 32 + .../Generated/MessageFile.Serialization.cs | 60 + .../src/Generated/MessageFile.cs | 52 + ...ileCitationTextAnnotation.Serialization.cs | 65 + .../MessageFileCitationTextAnnotation.cs | 48 + ...ageFilePathTextAnnotation.Serialization.cs | 65 + .../MessageFilePathTextAnnotation.cs | 42 + .../MessageImageFileContent.Serialization.cs | 47 + .../src/Generated/MessageImageFileContent.cs | 35 + .../src/Generated/MessageRole.cs | 51 + .../MessageTextAnnotation.Serialization.cs | 63 + .../src/Generated/MessageTextAnnotation.cs | 56 + .../MessageTextContent.Serialization.cs | 47 + .../src/Generated/MessageTextContent.cs | 35 + .../ModifyMessageRequest.Serialization.cs | 40 + .../src/Generated/ModifyMessageRequest.cs | 32 + .../ModifyRunRequest.Serialization.cs | 40 + .../src/Generated/ModifyRunRequest.cs | 32 + .../ModifyThreadRequest.Serialization.cs | 40 + .../src/Generated/ModifyThreadRequest.cs | 32 + .../src/Generated/OpenAIFile.Serialization.cs | 72 + .../src/Generated/OpenAIFile.cs | 63 + .../src/Generated/OpenAIFilePurpose.cs | 57 + ...OpenAIPageableListOfAssistantFileObject.cs | 48 + .../OpenAIPageableListOfAssistantObject.cs | 48 + .../OpenAIPageableListOfMessageFileObject.cs | 48 + .../OpenAIPageableListOfRunStepObject.cs | 48 + ...OpenAIPageableListOfThreadMessageObject.cs | 48 + .../OpenAIPageableListOfThreadRunObject.cs | 48 + .../Generated/RequiredAction.Serialization.cs | 39 + .../src/Generated/RequiredAction.cs | 32 + .../RetrievalToolCall.Serialization.cs | 59 + .../src/Generated/RetrievalToolCall.cs | 45 + .../RetrievalToolDefinition.Serialization.cs | 58 + .../src/Generated/RetrievalToolDefinition.cs | 25 + .../src/Generated/RunError.Serialization.cs | 47 + .../src/Generated/RunError.cs | 34 + .../src/Generated/RunStatus.cs | 69 + .../src/Generated/RunStep.Serialization.cs | 142 + .../src/Generated/RunStep.cs | 117 + .../Generated/RunStepDetails.Serialization.cs | 40 + .../src/Generated/RunStepDetails.cs | 32 + .../Generated/RunStepError.Serialization.cs | 47 + .../src/Generated/RunStepError.cs | 33 + .../src/Generated/RunStepErrorCode.cs | 51 + ...tepMessageCreationDetails.Serialization.cs | 47 + .../RunStepMessageCreationDetails.cs | 38 + ...pMessageCreationReference.Serialization.cs | 41 + .../RunStepMessageCreationReference.cs | 29 + .../src/Generated/RunStepStatus.cs | 60 + .../RunStepToolCallDetails.Serialization.cs | 53 + .../src/Generated/RunStepToolCallDetails.cs | 44 + .../src/Generated/RunStepType.cs | 51 + ...bmitRunToolOutputsRequest.Serialization.cs | 36 + .../Generated/SubmitRunToolOutputsRequest.cs | 38 + .../SubmitToolOutputsAction.Serialization.cs | 47 + .../src/Generated/SubmitToolOutputsAction.cs | 35 + .../ThreadDeletionStatus.Serialization.cs | 47 + .../src/Generated/ThreadDeletionStatus.cs | 30 + .../Generated/ThreadDeletionStatusObject.cs | 48 + .../Generated/ThreadMessage.Serialization.cs | 176 + .../src/Generated/ThreadMessage.cs | 100 + .../src/Generated/ThreadRun.Serialization.cs | 175 + .../src/Generated/ThreadRun.cs | 138 + .../src/Generated/ToolCall.Serialization.cs | 41 + .../src/Generated/ToolCall.cs | 45 + .../Generated/ToolDefinition.Serialization.cs | 58 + .../src/Generated/ToolDefinition.cs | 32 + .../src/Generated/ToolOutput.Serialization.cs | 39 + .../src/Generated/ToolOutput.cs | 23 + ...InterpreterToolCallOutput.Serialization.cs | 41 + .../UnknownCodeInterpreterToolCallOutput.cs | 24 + .../UnknownMessageContent.Serialization.cs | 41 + .../src/Generated/UnknownMessageContent.cs | 24 + ...nownMessageTextAnnotation.Serialization.cs | 59 + .../Generated/UnknownMessageTextAnnotation.cs | 35 + .../UnknownRequiredAction.Serialization.cs | 41 + .../src/Generated/UnknownRequiredAction.cs | 24 + .../UnknownRunStepDetails.Serialization.cs | 41 + .../src/Generated/UnknownRunStepDetails.cs | 24 + .../UnknownToolCall.Serialization.cs | 47 + .../src/Generated/UnknownToolCall.cs | 31 + .../UnknownToolDefinition.Serialization.cs | 41 + .../src/Generated/UnknownToolDefinition.cs | 24 + .../UploadFileRequest.Serialization.cs | 30 + .../src/Generated/UploadFileRequest.cs | 61 + .../src/Helpers/CustomSerializationHelpers.cs | 23 + .../src/Properties/AssemblyInfo.cs | 14 + .../Azure.AI.OpenAI.Assistants/src/README.md | 13 + .../tests/AssistantsModelFactoryTests.cs | 316 ++ .../tests/AssistantsTestBase.cs | 141 + .../tests/AssistantsTests.cs | 284 ++ .../Azure.AI.OpenAI.Assistants.Tests.csproj | 29 + .../tests/FilesTests.cs | 104 + .../tests/FunctionsTests.cs | 142 + .../tests/OpenAITestEnvironment.cs | 42 + .../tests/Samples/Samples_AssistantsClient.cs | 115 + .../tests/Samples/Samples_Functions.cs | 193 + .../tests/Samples/Samples_Retrieval.cs | 96 + .../tests/TestHelpers.cs | 56 + .../tsp-location.yaml | 3 + 222 files changed, 16985 insertions(+) create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/.gitignore create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/Azure.AI.OpenAI.Assistants.sln create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/CHANGELOG.md create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/Directory.Build.props create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/README.md create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/api/Azure.AI.OpenAI.Assistants.netstandard2.0.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Azure.AI.OpenAI.Assistants.csproj create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Convenience/AssistantsClient.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Convenience/FunctionToolDefinition.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Convenience/PageableList.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Convenience/README.md create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/AssistantsClient.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/AssistantsModelFactory.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/CodeInterpreterToolCall.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/FunctionToolCall.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/FunctionToolDefinition.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/MessageFileCitationTextAnnotation.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/MessageFilePathTextAnnotation.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/MessageImageFileContent.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/MessageTextContent.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/PageableList.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/README.md create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/RunStep.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/SubmitToolOutputsAction.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/ThreadRun.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/ToolOutput.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/UploadFileRequest.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/Visibility/Assistant.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/Visibility/AssistantFile.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/Visibility/AssistantThread.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/Visibility/ListSortOrder.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/Visibility/MessageFile.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/Visibility/OpenAIFile.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/Visibility/RunStep.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/Visibility/ThreadMessage.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/Visibility/ThreadRun.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AIOpenAIAssistantsClientBuilderExtensions.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/Assistant.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/Assistant.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantCreationOptions.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantCreationOptions.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantFile.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantFile.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantModificationOptions.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantModificationOptions.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantThread.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantThread.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantThreadCreationOptions.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantThreadCreationOptions.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsClient.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsClientOptions.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsModelFactory.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterImageOutput.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterImageOutput.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterImageReference.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterImageReference.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterLogOutput.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterLogOutput.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterToolCall.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterToolCall.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterToolCallOutput.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterToolCallOutput.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterToolDefinition.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterToolDefinition.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateAndRunThreadOptions.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateAndRunThreadOptions.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateAssistantFileRequest.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateAssistantFileRequest.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateMessageRequest.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateMessageRequest.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateRunRequest.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateRunRequest.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/FunctionToolCall.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/FunctionToolCall.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/FunctionToolDefinition.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/FunctionToolDefinition.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalAssistantDeletionStatus.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalAssistantDeletionStatus.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalAssistantDeletionStatusObject.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalAssistantFileDeletionStatus.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalAssistantFileDeletionStatus.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalAssistantFileDeletionStatusObject.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalCodeInterpreterToolCallDetails.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalCodeInterpreterToolCallDetails.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalDeletionStatus.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFileDeletionStatus.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFileDeletionStatus.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFileDeletionStatusObject.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFileListResponse.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFileListResponse.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFileListResponseObject.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFunctionDefinition.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFunctionDefinition.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFunctionToolCallDetails.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFunctionToolCallDetails.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageFilePathDetails.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageFilePathDetails.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageImageFileDetails.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageImageFileDetails.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageImageFileIdDetails.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageImageFileIdDetails.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextDetails.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextDetails.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextFileCitationDetails.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextFileCitationDetails.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfAssistant.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfAssistant.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfAssistantFile.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfAssistantFile.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfMessageFile.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfMessageFile.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfRunStep.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfRunStep.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfThreadMessage.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfThreadMessage.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfThreadRun.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfThreadRun.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalSubmitToolOutputsDetails.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalSubmitToolOutputsDetails.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ListSortOrder.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageContent.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageContent.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageFile.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageFile.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageFileCitationTextAnnotation.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageFileCitationTextAnnotation.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageFilePathTextAnnotation.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageFilePathTextAnnotation.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageImageFileContent.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageImageFileContent.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageRole.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextAnnotation.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextAnnotation.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextContent.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextContent.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ModifyMessageRequest.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ModifyMessageRequest.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ModifyRunRequest.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ModifyRunRequest.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ModifyThreadRequest.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ModifyThreadRequest.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIFile.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIFile.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIFilePurpose.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIPageableListOfAssistantFileObject.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIPageableListOfAssistantObject.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIPageableListOfMessageFileObject.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIPageableListOfRunStepObject.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIPageableListOfThreadMessageObject.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIPageableListOfThreadRunObject.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RequiredAction.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RequiredAction.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RetrievalToolCall.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RetrievalToolCall.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RetrievalToolDefinition.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RetrievalToolDefinition.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunError.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunError.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStatus.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStep.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStep.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDetails.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDetails.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepError.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepError.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepErrorCode.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepMessageCreationDetails.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepMessageCreationDetails.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepMessageCreationReference.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepMessageCreationReference.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepStatus.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepToolCallDetails.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepToolCallDetails.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepType.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/SubmitRunToolOutputsRequest.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/SubmitRunToolOutputsRequest.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/SubmitToolOutputsAction.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/SubmitToolOutputsAction.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadDeletionStatus.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadDeletionStatus.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadDeletionStatusObject.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadMessage.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadMessage.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadRun.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadRun.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ToolCall.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ToolCall.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ToolDefinition.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ToolDefinition.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ToolOutput.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ToolOutput.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownCodeInterpreterToolCallOutput.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownCodeInterpreterToolCallOutput.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownMessageContent.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownMessageContent.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownMessageTextAnnotation.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownMessageTextAnnotation.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownRequiredAction.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownRequiredAction.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownRunStepDetails.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownRunStepDetails.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownToolCall.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownToolCall.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownToolDefinition.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownToolDefinition.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UploadFileRequest.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UploadFileRequest.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Helpers/CustomSerializationHelpers.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Properties/AssemblyInfo.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/README.md create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/tests/AssistantsModelFactoryTests.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/tests/AssistantsTestBase.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/tests/AssistantsTests.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/tests/Azure.AI.OpenAI.Assistants.Tests.csproj create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/tests/FilesTests.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/tests/FunctionsTests.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/tests/OpenAITestEnvironment.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/tests/Samples/Samples_AssistantsClient.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/tests/Samples/Samples_Functions.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/tests/Samples/Samples_Retrieval.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/tests/TestHelpers.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/tsp-location.yaml diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/.gitignore b/sdk/openai/Azure.AI.OpenAI.Assistants/.gitignore new file mode 100644 index 000000000000..5ff7b673e645 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/.gitignore @@ -0,0 +1,4 @@ +package-lock.json +TempTypeSpecFiles/ +tests/SessionRecords +**/Generated/configuration.json diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/Azure.AI.OpenAI.Assistants.sln b/sdk/openai/Azure.AI.OpenAI.Assistants/Azure.AI.OpenAI.Assistants.sln new file mode 100644 index 000000000000..b526296dd0f6 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/Azure.AI.OpenAI.Assistants.sln @@ -0,0 +1,41 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.6.33927.249 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.AI.OpenAI.Assistants", "src\Azure.AI.OpenAI.Assistants.csproj", "{E33D09D9-D809-472C-82E6-6A26BDB86FC2}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.AI.OpenAI.Assistants.Tests", "tests\Azure.AI.OpenAI.Assistants.Tests.csproj", "{4F476D56-DDE7-43D3-8CB4-BA1E77F5A300}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.Core.TestFramework", "..\..\core\Azure.Core.TestFramework\src\Azure.Core.TestFramework.csproj", "{439F1494-8E96-4931-AB0A-5BBA7EBA15D2}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {E33D09D9-D809-472C-82E6-6A26BDB86FC2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E33D09D9-D809-472C-82E6-6A26BDB86FC2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E33D09D9-D809-472C-82E6-6A26BDB86FC2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E33D09D9-D809-472C-82E6-6A26BDB86FC2}.Release|Any CPU.Build.0 = Release|Any CPU + {4F476D56-DDE7-43D3-8CB4-BA1E77F5A300}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4F476D56-DDE7-43D3-8CB4-BA1E77F5A300}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4F476D56-DDE7-43D3-8CB4-BA1E77F5A300}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4F476D56-DDE7-43D3-8CB4-BA1E77F5A300}.Release|Any CPU.Build.0 = Release|Any CPU + {439F1494-8E96-4931-AB0A-5BBA7EBA15D2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {439F1494-8E96-4931-AB0A-5BBA7EBA15D2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {439F1494-8E96-4931-AB0A-5BBA7EBA15D2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {439F1494-8E96-4931-AB0A-5BBA7EBA15D2}.Release|Any CPU.Build.0 = Release|Any CPU + {71C00248-3DEE-4C44-A2BB-4CCAF994DB32}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {71C00248-3DEE-4C44-A2BB-4CCAF994DB32}.Debug|Any CPU.Build.0 = Debug|Any CPU + {71C00248-3DEE-4C44-A2BB-4CCAF994DB32}.Release|Any CPU.ActiveCfg = Release|Any CPU + {71C00248-3DEE-4C44-A2BB-4CCAF994DB32}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {A97F4B90-2591-4689-B1F8-5F21FE6D6CAE} + EndGlobalSection +EndGlobal diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/CHANGELOG.md b/sdk/openai/Azure.AI.OpenAI.Assistants/CHANGELOG.md new file mode 100644 index 000000000000..1220b9ce89b9 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/CHANGELOG.md @@ -0,0 +1,9 @@ +# Release History + +## 1.0.0-beta.1 (Unreleased) + +### Features Added + +- This is the initial release of `Azure.AI.OpenAI.Assistants`. +- Full support for OpenAI's beta Assistants features is included; see OpenAI's documentation for more: https://platform.openai.com/docs/assistants/overview +- [Azure OpenAI](https://learn.microsoft.com/azure/ai-services/openai/overview) does not yet feature an `/assistants` endpoint and this library will thus currently only work with the `api.openapi.com` endpoint. Stay tuned! diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/Directory.Build.props b/sdk/openai/Azure.AI.OpenAI.Assistants/Directory.Build.props new file mode 100644 index 000000000000..1a9611bd4924 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/Directory.Build.props @@ -0,0 +1,6 @@ + + + + diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/README.md b/sdk/openai/Azure.AI.OpenAI.Assistants/README.md new file mode 100644 index 000000000000..c9e257e88013 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/README.md @@ -0,0 +1,357 @@ +# OpenAI Assistants: Azure's client library for .NET + +> **NOTE**: This is a preview version of the Azure SDK library for OpenAI Assistants. The Azure OpenAI service does not yet include Assistants features and this project is thus currently for sole use with OpenAI's `api.openai.com` endpoints. [OpenAI's Assistants API](https://platform.openai.com/docs/api-reference/assistants) is tagged as beta and both the API surface as well as this library's representation are subject to change. + +The Azure OpenAI Assistants client library for .NET is an adaptation of OpenAI's REST APIs that provides an idiomatic interface +and rich integration with the rest of the Azure SDK ecosystem. It will connect to Azure OpenAI resources *or* to the +non-Azure OpenAI inference endpoint, making it a great choice for even non-Azure OpenAI development. + +Use this library to: + +- Create and manage assistants, threads, messages, and runs +- Configure and use tools with assistants +- Upload and manage files for use with assistants + +## Getting started + +### Prerequisites + +To use Assistants capabilities, you'll need service API access through OpenAI or Azure OpenAI: + +- To use OpenAI (api.openai.com), you'll need an API key obtained from a developer account at https://platform.openai.com +- (Not yet supported) If you'd like to use an Azure OpenAI resource, you must have an [Azure subscription](https://azure.microsoft.com/free/dotnet/) and [Azure OpenAI access](https://learn.microsoft.com/azure/cognitive-services/openai/overview#how-do-i-get-access-to-azure-openai). This will allow you to create an Azure OpenAI resource and get both a connection URL as well as API keys. For more information, see [Quickstart: Get started generating text using Azure OpenAI Service](https://learn.microsoft.com/azure/cognitive-services/openai/quickstart). + +### Install the package + +Install the client library for .NET with [NuGet](https://www.nuget.org/ ): + +```dotnetcli +dotnet add package Azure.AI.OpenAI.Assistants --prerelease +``` + +## Usage + +### Overview + +See [OpenAI's "how assistants work"](https://platform.openai.com/docs/assistants/how-it-works) documentation for an +overview of the concepts and relationships used with assistants. This overview closely follows +[OpenAI's overview example](https://platform.openai.com/docs/assistants/overview) to demonstrate the basics of +creating, running, and using assistants and threads. + +To get started, create an `AssistantsClient`: +```C# Snippet:OverviewCreateClient +AssistantsClient client = isAzureOpenAI + ? new AssistantsClient(new Uri(azureResourceUrl), new AzureKeyCredential(azureApiKey)) + : new AssistantsClient(nonAzureApiKey); +``` + +With a client, an assistant can then be created: +```C# Snippet:OverviewCreateAssistant +Response assistantResponse = await client.CreateAssistantAsync( + new AssistantCreationOptions("gpt-4-1106-preview") + { + Name = "Math Tutor", + Instructions = "You are a personal math tutor. Write and run code to answer math questions.", + Tools = { new CodeInterpreterToolDefinition() } + }); +Assistant assistant = assistantResponse.Value; +``` + +Next, create a thread: +```C# Snippet:OverviewCreateThread +Response threadResponse = await client.CreateThreadAsync(); +AssistantThread thread = threadResponse.Value; +``` + +With a thread created, messages can be created on it: +```C# Snippet:OverviewCreateMessage +Response messageResponse = await client.CreateMessageAsync( + thread.Id, + MessageRole.User, + "I need to solve the equation `3x + 11 = 14`. Can you help me?"); +ThreadMessage message = messageResponse.Value; +``` + +A run can then be started that evaluates the thread against an assistant: +```C# Snippet:OverviewCreateRun +Response runResponse = await client.CreateRunAsync( + thread.Id, + assistant.Id, + overrideInstructions: "Please address the user as Jane Doe. The user has a premium account."); +ThreadRun run = runResponse.Value; +``` + +Once the run has started, it should then be polled until it reaches a terminal status: +```C# Snippet:OverviewWaitForRun +do +{ + await Task.Delay(TimeSpan.FromMilliseconds(500)); + runResponse = await client.RetrieveRunAsync(thread.Id, runResponse.Value.Id); +} +while (runResponse.Value.Status == RunStatus.Queued + || runResponse.Value.Status == RunStatus.InProgress); +``` + +Assuming the run successfully completed, listing messages from the thread that was run will now reflect new information +added by the assistant: +```C# Snippet:OverviewListUpdatedMessages +Response> afterRunMessagesResponse + = await client.GetMessagesAsync(thread.Id); +IReadOnlyList messages = afterRunMessagesResponse.Value.Data; + +// Note: messages iterate from newest to oldest, with the messages[0] being the most recent +foreach (ThreadMessage threadMessage in messages) +{ + Console.Write($"{threadMessage.CreatedAt:yyyy-MM-dd HH:mm:ss} - {threadMessage.Role,10}: "); + foreach (MessageContent contentItem in threadMessage.ContentItems) + { + if (contentItem is MessageTextContent textItem) + { + Console.Write(textItem.Text); + } + else if (contentItem is MessageImageFileContent imageFileItem) + { + Console.Write($" uploadAssistantFileResponse = await client.UploadFileAsync( + localFilePath: "sample_file_for_upload.txt", + purpose: OpenAIFilePurpose.Assistants); +OpenAIFile uploadedAssistantFile = uploadAssistantFileResponse.Value; +``` + +Once uploaded, the file ID can then be provided to an assistant upon creation. Note that file IDs will only be used +if an appropriate tool like Code Interpreter or Retrieval is enabled. +```C# Snippet:CreateAssistantWithFiles +Response assistantResponse = await client.CreateAssistantAsync( + new AssistantCreationOptions("gpt-4-1106-preview") + { + Name = "SDK Test Assistant - Retrieval", + Instructions = "You are a helpful assistant that can help fetch data from files you know about.", + Tools = { new RetrievalToolDefinition() }, + FileIds = { uploadedAssistantFile.Id }, + }); +Assistant assistant = assistantResponse.Value; +``` + +With a file ID association and a supported tool enabled, the assistant will then be able to consume the associated +data when running threads. + + +### Using function tools and parallel function calling + +As [described in OpenAI's documentation for assistant tools](https://platform.openai.com/docs/assistants/tools/function-calling), +tools that reference caller-defined capabilities as functions can be provided to an assistant to allow it to +dynamically resolve and disambiguate during a run. + +Here, outlined is a simple assistant that "knows how to," via caller-provided functions: + +1. Get the user's favorite city +1. Get a nickname for a given city +1. Get the current weather, optionally with a temperature unit, in a city + +To do this, begin by defining the functions to use -- the actual implementations here are merely representative stubs. + +```C# Snippet:FunctionsDefineFunctionTools +// Example of a function that defines no parameters +string GetUserFavoriteCity() => "Seattle, WA"; +FunctionToolDefinition getUserFavoriteCityTool = new("getUserFavoriteCity", "Gets the user's favorite city."); +// Example of a function with a single required parameter +string GetCityNickname(string location) => location switch +{ + "Seattle, WA" => "The Emerald City", + _ => throw new NotImplementedException(), +}; +FunctionToolDefinition getCityNicknameTool = new( + name: "getCityNickname", + description: "Gets the nickname of a city, e.g. 'LA' for 'Los Angeles, CA'.", + parameters: BinaryData.FromObjectAsJson( + new + { + Type = "object", + Properties = new + { + Location = new + { + Type = "string", + Description = "The city and state, e.g. San Francisco, CA", + }, + }, + Required = new[] { "location" }, + }, + new JsonSerializerOptions() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase })); +// Example of a function with one required and one optional, enum parameter +string GetWeatherAtLocation(string location, string temperatureUnit = "f") => location switch +{ + "Seattle, WA" => temperatureUnit == "f" ? "70f" : "21c", + _ => throw new NotImplementedException() +}; +FunctionToolDefinition getCurrentWeatherAtLocationTool = new( + name: "getCurrentWeatherAtLocation", + description: "Gets the current weather at a provided location.", + parameters: BinaryData.FromObjectAsJson( + new + { + Type = "object", + Properties = new + { + Location = new + { + Type = "string", + Description = "The city and state, e.g. San Francisco, CA", + }, + Unit = new + { + Type = "string", + Enum = new[] { "c", "f" }, + }, + }, + Required = new[] { "location" }, + }, + new JsonSerializerOptions() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase })); +``` + +With the functions defined in their appropriate tools, an assistant can be now created that has those tools enabled: + +```C# Snippet:FunctionsCreateAssistantWithFunctionTools +Response assistantResponse = await client.CreateAssistantAsync( + // note: parallel function calling is only supported with newer models like gpt-4-1106-preview + new AssistantCreationOptions("gpt-4-1106-preview") + { + Name = "SDK Test Assistant - Functions", + Instructions = "You are a weather bot. Use the provided functions to help answer questions. " + + "Customize your responses to the user's preferences as much as possible and use friendly " + + "nicknames for cities whenever possible.", + Tools = + { + getUserFavoriteCityTool, + getCityNicknameTool, + getCurrentWeatherAtLocationTool, + }, + }); +Assistant assistant = assistantResponse.Value; +``` + +If the assistant calls tools, the calling code will need to resolve `ToolCall` instances into matching +`ToolOutput` instances. For convenience, a basic example is extracted here: + +```C# Snippet:FunctionsHandleFunctionCalls +ToolOutput GetResolvedToolOutput(ToolCall toolCall) +{ + if (toolCall is FunctionToolCall functionToolCall) + { + if (functionToolCall.Name == getUserFavoriteCityTool.Name) + { + return new ToolOutput(toolCall, GetUserFavoriteCity()); + } + using JsonDocument argumentsJson = JsonDocument.Parse(functionToolCall.Arguments); + if (functionToolCall.Name == getCityNicknameTool.Name) + { + string locationArgument = argumentsJson.RootElement.GetProperty("location").GetString(); + return new ToolOutput(toolCall, GetCityNickname(locationArgument)); + } + if (functionToolCall.Name == getCurrentWeatherAtLocationTool.Name) + { + string locationArgument = argumentsJson.RootElement.GetProperty("location").GetString(); + if (argumentsJson.RootElement.TryGetProperty("unit", out JsonElement unitElement)) + { + string unitArgument = unitElement.GetString(); + return new ToolOutput(toolCall, GetWeatherAtLocation(locationArgument, unitArgument)); + } + return new ToolOutput(toolCall, GetWeatherAtLocation(locationArgument)); + } + } + return null; +} +``` + +To handle user input like "what's the weather like right now in my favorite city?", polling the response for completion +should be supplemented by a `RunStatus` check for `RequiresAction` or, in this case, the presence of the +`RequiredAction` property on the run. Then, the collection of `ToolOutputSubmissions` should be submitted to the +run via the `SubmitRunToolOutputs` method so that the run can continue: + +```C# Snippet:FunctionsHandlePollingWithRequiredAction +do +{ + await Task.Delay(TimeSpan.FromMilliseconds(500)); + runResponse = await client.RetrieveRunAsync(thread.Id, runResponse.Value.Id); + + if (runResponse.Value.Status == RunStatus.RequiresAction + && runResponse.Value.RequiredAction is SubmitToolOutputsAction submitToolOutputsAction) + { + List toolOutputs = new(); + foreach (var toolCall in submitToolOutputsAction.ToolCalls) + { + toolOutputs.Add(GetResolvedToolOutput(toolCall)); + } + runResponse = await client.SubmitRunToolOutputsAsync(runResponse.Value, toolOutputs); + } +} +while (runResponse.Value.Status == RunStatus.Queued + || runResponse.Value.Status == RunStatus.InProgress); +``` + +Note that, when using supported models, the assistant may request that several functions be called in parallel. Older +models may only call one function at a time. + +Once all needed function calls have been resolved, the run will proceed normally and the completed messages on the +thread will contain model output supplemented by the provided function tool outputs. + +## Troubleshooting + +When you interact with Azure OpenAI using the .NET SDK, errors returned by the service correspond to the same HTTP status codes returned for [REST API][openai_rest] requests. + +For example, if you try to create a client using an endpoint that doesn't match your Azure OpenAI Resource endpoint, a `404` error is returned, indicating `Resource Not Found`. + +## Next steps + +* Provide a link to additional code examples, ideally to those sitting alongside the README in the package's `/samples` directory. +* If appropriate, point users to other packages that might be useful. +* If you think there's a good chance that developers might stumble across your package in error (because they're searching for specific functionality and mistakenly think the package provides that functionality), point them to the packages they might be looking for. + +## Contributing + +See the [Azure SDK CONTRIBUTING.md][openai_contrib] for details on building, testing, and contributing to this library. + +This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit [cla.microsoft.com][cla]. + +When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA. + +This project has adopted the [Microsoft Open Source Code of Conduct][code_of_conduct]. For more information see the [Code of Conduct FAQ][code_of_conduct_faq] or contact [opencode@microsoft.com][email_opencode] with any additional questions or comments. + + +[azure_identity]: https://learn.microsoft.com/dotnet/api/overview/azure/identity-readme?view=azure-dotnet +[azure_identity_dac]: https://learn.microsoft.com/dotnet/api/azure.identity.defaultazurecredential?view=azure-dotnet +[msdocs_openai_completion]: https://learn.microsoft.com/azure/cognitive-services/openai/how-to/completions +[msdocs_openai_embedding]: https://learn.microsoft.com/azure/cognitive-services/openai/concepts/understand-embeddings +[style-guide-msft]: https://docs.microsoft.com/style-guide/capitalization +[style-guide-cloud]: https://aka.ms/azsdk/cloud-style-guide +[openai_client_class]: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/openai/Azure.AI.OpenAI/src/Generated/OpenAIClient.cs +[openai_rest]: https://learn.microsoft.com/azure/cognitive-services/openai/reference +[azure_openai_completions_docs]: https://learn.microsoft.com/azure/cognitive-services/openai/how-to/completions +[azure_openai_embeddgings_docs]: https://learn.microsoft.com/azure/cognitive-services/openai/concepts/understand-embeddings +[openai_contrib]: https://github.com/Azure/azure-sdk-for-net/blob/main/CONTRIBUTING.md +[cla]: https://cla.microsoft.com +[code_of_conduct]: https://opensource.microsoft.com/codeofconduct/ +[code_of_conduct_faq]: https://opensource.microsoft.com/codeofconduct/faq/ +[email_opencode]: mailto:opencode@microsoft.com + +![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-net/sdk/openai/Azure.AI.OpenAI/README.png) diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/api/Azure.AI.OpenAI.Assistants.netstandard2.0.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/api/Azure.AI.OpenAI.Assistants.netstandard2.0.cs new file mode 100644 index 000000000000..8139224bea72 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/api/Azure.AI.OpenAI.Assistants.netstandard2.0.cs @@ -0,0 +1,566 @@ +namespace Azure.AI.OpenAI.Assistants +{ + public partial class Assistant + { + internal Assistant() { } + public System.DateTimeOffset CreatedAt { get { throw null; } } + public string Description { get { throw null; } } + public System.Collections.Generic.IReadOnlyList FileIds { get { throw null; } } + public string Id { get { throw null; } } + public string Instructions { get { throw null; } } + public System.Collections.Generic.IReadOnlyDictionary Metadata { get { throw null; } } + public string Model { get { throw null; } } + public string Name { get { throw null; } } + public System.Collections.Generic.IReadOnlyList Tools { get { throw null; } } + } + public partial class AssistantCreationOptions + { + public AssistantCreationOptions(string model) { } + public string Description { get { throw null; } set { } } + public System.Collections.Generic.IList FileIds { get { throw null; } } + public string Instructions { get { throw null; } set { } } + public System.Collections.Generic.IDictionary Metadata { get { throw null; } } + public string Model { get { throw null; } } + public string Name { get { throw null; } set { } } + public System.Collections.Generic.IList Tools { get { throw null; } } + } + public partial class AssistantFile + { + internal AssistantFile() { } + public string AssistantId { get { throw null; } } + public System.DateTimeOffset CreatedAt { get { throw null; } } + public string Id { get { throw null; } } + } + public partial class AssistantModificationOptions + { + public AssistantModificationOptions() { } + public string Description { get { throw null; } set { } } + public System.Collections.Generic.IList FileIds { get { throw null; } } + public string Instructions { get { throw null; } set { } } + public System.Collections.Generic.IDictionary Metadata { get { throw null; } } + public string Model { get { throw null; } set { } } + public string Name { get { throw null; } set { } } + public System.Collections.Generic.IList Tools { get { throw null; } } + } + public partial class AssistantsClient + { + protected AssistantsClient() { } + public AssistantsClient(string openAIApiKey) { } + public AssistantsClient(string openAIApiKey, Azure.AI.OpenAI.Assistants.AssistantsClientOptions options) { } + public AssistantsClient(System.Uri endpoint, Azure.AzureKeyCredential keyCredential) { } + public AssistantsClient(System.Uri endpoint, Azure.AzureKeyCredential keyCredential, Azure.AI.OpenAI.Assistants.AssistantsClientOptions options) { } + public AssistantsClient(System.Uri endpoint, Azure.Core.TokenCredential tokenCredential) { } + public AssistantsClient(System.Uri endpoint, Azure.Core.TokenCredential tokenCredential, Azure.AI.OpenAI.Assistants.AssistantsClientOptions options) { } + public virtual Azure.Core.Pipeline.HttpPipeline Pipeline { get { throw null; } } + public virtual Azure.Response CancelRun(string threadId, string runId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> CancelRunAsync(string threadId, string runId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response CreateAssistant(Azure.AI.OpenAI.Assistants.AssistantCreationOptions assistantCreationOptions, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> CreateAssistantAsync(Azure.AI.OpenAI.Assistants.AssistantCreationOptions assistantCreationOptions, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response CreateMessage(string threadId, Azure.AI.OpenAI.Assistants.MessageRole role, string content, System.Collections.Generic.IEnumerable fileIds = null, System.Collections.Generic.IDictionary metadata = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> CreateMessageAsync(string threadId, Azure.AI.OpenAI.Assistants.MessageRole role, string content, System.Collections.Generic.IEnumerable fileIds = null, System.Collections.Generic.IDictionary metadata = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response CreateRun(string threadId, string assistantId, string overrideModelName = null, string overrideInstructions = null, System.Collections.Generic.IEnumerable overrideTools = null, System.Collections.Generic.IDictionary metadata = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> CreateRunAsync(string threadId, string assistantId, string overrideModelName = null, string overrideInstructions = null, System.Collections.Generic.IEnumerable overrideTools = null, System.Collections.Generic.IDictionary metadata = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response CreateThread(Azure.AI.OpenAI.Assistants.AssistantThreadCreationOptions assistantThreadCreationOptions, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response CreateThread(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response CreateThreadAndRun(Azure.AI.OpenAI.Assistants.CreateAndRunThreadOptions createAndRunThreadOptions, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> CreateThreadAndRunAsync(Azure.AI.OpenAI.Assistants.CreateAndRunThreadOptions createAndRunThreadOptions, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> CreateThreadAsync(Azure.AI.OpenAI.Assistants.AssistantThreadCreationOptions assistantThreadCreationOptions, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> CreateThreadAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response DeleteAssistant(string assistantId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> DeleteAssistantAsync(string assistantId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response DeleteFile(string fileId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> DeleteFileAsync(string fileId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response DeleteThread(string threadId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> DeleteThreadAsync(string threadId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response> GetAssistantFiles(string assistantId, int? limit = default(int?), Azure.AI.OpenAI.Assistants.ListSortOrder? order = default(Azure.AI.OpenAI.Assistants.ListSortOrder?), string after = null, string before = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task>> GetAssistantFilesAsync(string assistantId, int? limit = default(int?), Azure.AI.OpenAI.Assistants.ListSortOrder? order = default(Azure.AI.OpenAI.Assistants.ListSortOrder?), string after = null, string before = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response> GetAssistants(int? limit = default(int?), Azure.AI.OpenAI.Assistants.ListSortOrder? order = default(Azure.AI.OpenAI.Assistants.ListSortOrder?), string after = null, string before = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task>> GetAssistantsAsync(int? limit = default(int?), Azure.AI.OpenAI.Assistants.ListSortOrder? order = default(Azure.AI.OpenAI.Assistants.ListSortOrder?), string after = null, string before = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response> GetFiles(Azure.AI.OpenAI.Assistants.OpenAIFilePurpose? purpose = default(Azure.AI.OpenAI.Assistants.OpenAIFilePurpose?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task>> GetFilesAsync(Azure.AI.OpenAI.Assistants.OpenAIFilePurpose? purpose = default(Azure.AI.OpenAI.Assistants.OpenAIFilePurpose?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response> GetMessageFiles(string threadId, string messageId, int? limit = default(int?), Azure.AI.OpenAI.Assistants.ListSortOrder? order = default(Azure.AI.OpenAI.Assistants.ListSortOrder?), string after = null, string before = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task>> GetMessageFilesAsync(string threadId, string messageId, int? limit = default(int?), Azure.AI.OpenAI.Assistants.ListSortOrder? order = default(Azure.AI.OpenAI.Assistants.ListSortOrder?), string after = null, string before = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response> GetMessages(string threadId, int? limit = default(int?), Azure.AI.OpenAI.Assistants.ListSortOrder? order = default(Azure.AI.OpenAI.Assistants.ListSortOrder?), string after = null, string before = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task>> GetMessagesAsync(string threadId, int? limit = default(int?), Azure.AI.OpenAI.Assistants.ListSortOrder? order = default(Azure.AI.OpenAI.Assistants.ListSortOrder?), string after = null, string before = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response> GetRuns(string threadId, int? limit = default(int?), Azure.AI.OpenAI.Assistants.ListSortOrder? order = default(Azure.AI.OpenAI.Assistants.ListSortOrder?), string after = null, string before = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task>> GetRunsAsync(string threadId, int? limit = default(int?), Azure.AI.OpenAI.Assistants.ListSortOrder? order = default(Azure.AI.OpenAI.Assistants.ListSortOrder?), string after = null, string before = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response> GetRunSteps(Azure.AI.OpenAI.Assistants.ThreadRun run, int? limit = default(int?), Azure.AI.OpenAI.Assistants.ListSortOrder? order = default(Azure.AI.OpenAI.Assistants.ListSortOrder?), string after = null, string before = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response> GetRunSteps(string threadId, string runId, int? limit = default(int?), Azure.AI.OpenAI.Assistants.ListSortOrder? order = default(Azure.AI.OpenAI.Assistants.ListSortOrder?), string after = null, string before = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task>> GetRunStepsAsync(Azure.AI.OpenAI.Assistants.ThreadRun run, int? limit = default(int?), Azure.AI.OpenAI.Assistants.ListSortOrder? order = default(Azure.AI.OpenAI.Assistants.ListSortOrder?), string after = null, string before = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task>> GetRunStepsAsync(string threadId, string runId, int? limit = default(int?), Azure.AI.OpenAI.Assistants.ListSortOrder? order = default(Azure.AI.OpenAI.Assistants.ListSortOrder?), string after = null, string before = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response LinkAssistantFile(string assistantId, string fileId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> LinkAssistantFileAsync(string assistantId, string fileId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response ModifyAssistant(string assistantId, Azure.AI.OpenAI.Assistants.AssistantModificationOptions modificationOptions, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> ModifyAssistantAsync(string assistantId, Azure.AI.OpenAI.Assistants.AssistantModificationOptions modificationOptions, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response ModifyMessage(string threadId, string messageId, System.Collections.Generic.IDictionary metadata = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> ModifyMessageAsync(string threadId, string messageId, System.Collections.Generic.IDictionary metadata = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response ModifyRun(string threadId, string runId, System.Collections.Generic.IDictionary metadata = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> ModifyRunAsync(string threadId, string runId, System.Collections.Generic.IDictionary metadata = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response ModifyThread(string threadId, System.Collections.Generic.IDictionary metadata = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> ModifyThreadAsync(string threadId, System.Collections.Generic.IDictionary metadata = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response RetrieveAssistant(string assistantId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> RetrieveAssistantAsync(string assistantId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response RetrieveAssistantFile(string assistantId, string fileId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> RetrieveAssistantFileAsync(string assistantId, string fileId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response RetrieveFile(string fileId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> RetrieveFileAsync(string fileId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response RetrieveFileContent(string fileId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> RetrieveFileContentAsync(string fileId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response RetrieveMessage(string threadId, string messageId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> RetrieveMessageAsync(string threadId, string messageId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response RetrieveMessageFile(string threadId, string messageId, string fileId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> RetrieveMessageFileAsync(string threadId, string messageId, string fileId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response RetrieveRun(string threadId, string runId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> RetrieveRunAsync(string threadId, string runId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response RetrieveRunStep(string threadId, string runId, string stepId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> RetrieveRunStepAsync(string threadId, string runId, string stepId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response RetrieveThread(string threadId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> RetrieveThreadAsync(string threadId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response SubmitRunToolOutputs(Azure.AI.OpenAI.Assistants.ThreadRun run, System.Collections.Generic.IEnumerable toolOutputs, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response SubmitRunToolOutputs(string threadId, string runId, System.Collections.Generic.IEnumerable toolOutputs, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> SubmitRunToolOutputsAsync(Azure.AI.OpenAI.Assistants.ThreadRun run, System.Collections.Generic.IEnumerable toolOutputs, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> SubmitRunToolOutputsAsync(string threadId, string runId, System.Collections.Generic.IEnumerable toolOutputs, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response UnlinkAssistantFile(string assistantId, string fileId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> UnlinkAssistantFileAsync(string assistantId, string fileId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response UploadFile(System.BinaryData data, Azure.AI.OpenAI.Assistants.OpenAIFilePurpose purpose, string filename = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response UploadFile(string localFilePath, Azure.AI.OpenAI.Assistants.OpenAIFilePurpose purpose, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> UploadFileAsync(System.BinaryData data, Azure.AI.OpenAI.Assistants.OpenAIFilePurpose purpose, string filename = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> UploadFileAsync(string localFilePath, Azure.AI.OpenAI.Assistants.OpenAIFilePurpose purpose, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + } + public partial class AssistantsClientOptions : Azure.Core.ClientOptions + { + public AssistantsClientOptions(Azure.AI.OpenAI.Assistants.AssistantsClientOptions.ServiceVersion version = Azure.AI.OpenAI.Assistants.AssistantsClientOptions.ServiceVersion.V2023_11_06_Beta) { } + public enum ServiceVersion + { + V2023_11_06_Beta = 1, + } + } + public static partial class AssistantsModelFactory + { + public static Azure.AI.OpenAI.Assistants.Assistant Assistant(string id = null, System.DateTimeOffset createdAt = default(System.DateTimeOffset), string name = null, string description = null, string model = null, string instructions = null, System.Collections.Generic.IEnumerable tools = null, System.Collections.Generic.IEnumerable fileIds = null, System.Collections.Generic.IReadOnlyDictionary metadata = null) { throw null; } + public static Azure.AI.OpenAI.Assistants.AssistantFile AssistantFile(string id = null, System.DateTimeOffset createdAt = default(System.DateTimeOffset), string assistantId = null) { throw null; } + public static Azure.AI.OpenAI.Assistants.AssistantThread AssistantThread(string id = null, System.DateTimeOffset createdAt = default(System.DateTimeOffset), System.Collections.Generic.IReadOnlyDictionary metadata = null) { throw null; } + public static Azure.AI.OpenAI.Assistants.CodeInterpreterImageOutput CodeInterpreterImageOutput(Azure.AI.OpenAI.Assistants.CodeInterpreterImageReference image = null) { throw null; } + public static Azure.AI.OpenAI.Assistants.CodeInterpreterImageReference CodeInterpreterImageReference(string fileId = null) { throw null; } + public static Azure.AI.OpenAI.Assistants.CodeInterpreterLogOutput CodeInterpreterLogOutput(string logs = null) { throw null; } + public static Azure.AI.OpenAI.Assistants.CodeInterpreterToolCall CodeInterpreterToolCall(string id, string input, System.Collections.Generic.IReadOnlyList outputs) { throw null; } + public static Azure.AI.OpenAI.Assistants.FunctionToolCall FunctionToolCall(string id, string name, string arguments, string output) { throw null; } + public static Azure.AI.OpenAI.Assistants.MessageFile MessageFile(string id = null, System.DateTimeOffset createdAt = default(System.DateTimeOffset), string messageId = null) { throw null; } + public static Azure.AI.OpenAI.Assistants.MessageFileCitationTextAnnotation MessageFileCitationTextAnnotation(string text, int startIndex, int endIndex, string fileId, string quote) { throw null; } + public static Azure.AI.OpenAI.Assistants.MessageFilePathTextAnnotation MessageFilePathTextAnnotation(string text, int startIndex, int endIndex, string fileId) { throw null; } + public static Azure.AI.OpenAI.Assistants.MessageImageFileContent MessageImageFileContent(string fileId) { throw null; } + public static Azure.AI.OpenAI.Assistants.MessageTextContent MessageTextContent(string text, System.Collections.Generic.IEnumerable annotations) { throw null; } + public static Azure.AI.OpenAI.Assistants.OpenAIFile OpenAIFile(string id = null, int size = 0, string filename = null, System.DateTimeOffset createdAt = default(System.DateTimeOffset), Azure.AI.OpenAI.Assistants.OpenAIFilePurpose purpose = default(Azure.AI.OpenAI.Assistants.OpenAIFilePurpose)) { throw null; } + public static Azure.AI.OpenAI.Assistants.PageableList PageableList(System.Collections.Generic.IReadOnlyList data, string firstId, string lastId, bool hasMore) { throw null; } + public static Azure.AI.OpenAI.Assistants.RetrievalToolCall RetrievalToolCall(string id = null, System.Collections.Generic.IReadOnlyDictionary retrieval = null) { throw null; } + public static Azure.AI.OpenAI.Assistants.RunError RunError(string code = null, string message = null) { throw null; } + public static Azure.AI.OpenAI.Assistants.RunStep RunStep(string id = null, Azure.AI.OpenAI.Assistants.RunStepType type = default(Azure.AI.OpenAI.Assistants.RunStepType), string assistantId = null, string threadId = null, string runId = null, Azure.AI.OpenAI.Assistants.RunStepStatus status = default(Azure.AI.OpenAI.Assistants.RunStepStatus), Azure.AI.OpenAI.Assistants.RunStepDetails stepDetails = null, Azure.AI.OpenAI.Assistants.RunStepError lastError = null, System.DateTimeOffset createdAt = default(System.DateTimeOffset), System.DateTimeOffset? expiredAt = default(System.DateTimeOffset?), System.DateTimeOffset? completedAt = default(System.DateTimeOffset?), System.DateTimeOffset? cancelledAt = default(System.DateTimeOffset?), System.DateTimeOffset? failedAt = default(System.DateTimeOffset?), System.Collections.Generic.IReadOnlyDictionary metadata = null) { throw null; } + public static Azure.AI.OpenAI.Assistants.RunStepError RunStepError(Azure.AI.OpenAI.Assistants.RunStepErrorCode code = default(Azure.AI.OpenAI.Assistants.RunStepErrorCode), string message = null) { throw null; } + public static Azure.AI.OpenAI.Assistants.RunStepMessageCreationDetails RunStepMessageCreationDetails(Azure.AI.OpenAI.Assistants.RunStepMessageCreationReference messageCreation = null) { throw null; } + public static Azure.AI.OpenAI.Assistants.RunStepMessageCreationReference RunStepMessageCreationReference(string messageId = null) { throw null; } + public static Azure.AI.OpenAI.Assistants.RunStepToolCallDetails RunStepToolCallDetails(System.Collections.Generic.IEnumerable toolCalls = null) { throw null; } + public static Azure.AI.OpenAI.Assistants.SubmitToolOutputsAction SubmitToolOutputsAction(System.Collections.Generic.IEnumerable toolCalls) { throw null; } + public static Azure.AI.OpenAI.Assistants.ThreadMessage ThreadMessage(string id = null, System.DateTimeOffset createdAt = default(System.DateTimeOffset), string threadId = null, Azure.AI.OpenAI.Assistants.MessageRole role = default(Azure.AI.OpenAI.Assistants.MessageRole), System.Collections.Generic.IEnumerable contentItems = null, string assistantId = null, string runId = null, System.Collections.Generic.IEnumerable fileIds = null, System.Collections.Generic.IDictionary metadata = null) { throw null; } + public static Azure.AI.OpenAI.Assistants.ThreadRun ThreadRun(string id = null, string threadId = null, string assistantId = null, Azure.AI.OpenAI.Assistants.RunStatus status = default(Azure.AI.OpenAI.Assistants.RunStatus), Azure.AI.OpenAI.Assistants.RequiredAction requiredAction = null, Azure.AI.OpenAI.Assistants.RunError lastError = null, string model = null, string instructions = null, System.Collections.Generic.IEnumerable tools = null, System.Collections.Generic.IEnumerable fileIds = null, System.DateTimeOffset createdAt = default(System.DateTimeOffset), System.DateTimeOffset? expiresAt = default(System.DateTimeOffset?), System.DateTimeOffset? startedAt = default(System.DateTimeOffset?), System.DateTimeOffset? completedAt = default(System.DateTimeOffset?), System.DateTimeOffset? cancelledAt = default(System.DateTimeOffset?), System.DateTimeOffset? failedAt = default(System.DateTimeOffset?), System.Collections.Generic.IReadOnlyDictionary metadata = null) { throw null; } + public static Azure.AI.OpenAI.Assistants.ToolCall ToolCall(string type = null, string id = null) { throw null; } + } + public partial class AssistantThread + { + internal AssistantThread() { } + public System.DateTimeOffset CreatedAt { get { throw null; } } + public string Id { get { throw null; } } + public System.Collections.Generic.IReadOnlyDictionary Metadata { get { throw null; } } + } + public partial class AssistantThreadCreationOptions + { + public AssistantThreadCreationOptions() { } + public System.Collections.Generic.IList Messages { get { throw null; } } + public System.Collections.Generic.IDictionary Metadata { get { throw null; } } + } + public partial class CodeInterpreterImageOutput : Azure.AI.OpenAI.Assistants.CodeInterpreterToolCallOutput + { + internal CodeInterpreterImageOutput() { } + public Azure.AI.OpenAI.Assistants.CodeInterpreterImageReference Image { get { throw null; } } + } + public partial class CodeInterpreterImageReference + { + internal CodeInterpreterImageReference() { } + public string FileId { get { throw null; } } + } + public partial class CodeInterpreterLogOutput : Azure.AI.OpenAI.Assistants.CodeInterpreterToolCallOutput + { + internal CodeInterpreterLogOutput() { } + public string Logs { get { throw null; } } + } + public partial class CodeInterpreterToolCall : Azure.AI.OpenAI.Assistants.ToolCall + { + internal CodeInterpreterToolCall() : base (default(string)) { } + public string Input { get { throw null; } } + public System.Collections.Generic.IReadOnlyList Outputs { get { throw null; } } + } + public abstract partial class CodeInterpreterToolCallOutput + { + protected CodeInterpreterToolCallOutput() { } + } + public partial class CodeInterpreterToolDefinition : Azure.AI.OpenAI.Assistants.ToolDefinition + { + public CodeInterpreterToolDefinition() { } + } + public partial class CreateAndRunThreadOptions + { + public CreateAndRunThreadOptions(string assistantId) { } + public string AssistantId { get { throw null; } } + public System.Collections.Generic.IDictionary Metadata { get { throw null; } } + public string OverrideInstructions { get { throw null; } set { } } + public string OverrideModelName { get { throw null; } set { } } + public System.Collections.Generic.IList OverrideTools { get { throw null; } } + public Azure.AI.OpenAI.Assistants.AssistantThreadCreationOptions Thread { get { throw null; } set { } } + } + public partial class FunctionToolCall : Azure.AI.OpenAI.Assistants.ToolCall + { + internal FunctionToolCall() : base (default(string)) { } + public string Arguments { get { throw null; } } + public string Name { get { throw null; } } + public string Output { get { throw null; } } + } + public partial class FunctionToolDefinition : Azure.AI.OpenAI.Assistants.ToolDefinition + { + public FunctionToolDefinition(string name, string description) { } + public FunctionToolDefinition(string name, string description, System.BinaryData parameters) { } + public string Description { get { throw null; } } + public string Name { get { throw null; } } + public System.BinaryData Parameters { get { throw null; } } + public override bool Equals(object obj) { throw null; } + public override int GetHashCode() { throw null; } + public static bool operator ==(Azure.AI.OpenAI.Assistants.FunctionToolCall functionToolCall, Azure.AI.OpenAI.Assistants.FunctionToolDefinition functionToolDefinition) { throw null; } + public static bool operator ==(Azure.AI.OpenAI.Assistants.FunctionToolDefinition functionToolDefinition, Azure.AI.OpenAI.Assistants.FunctionToolCall functionToolCall) { throw null; } + public static bool operator !=(Azure.AI.OpenAI.Assistants.FunctionToolCall functionToolCall, Azure.AI.OpenAI.Assistants.FunctionToolDefinition functionToolDefinition) { throw null; } + public static bool operator !=(Azure.AI.OpenAI.Assistants.FunctionToolDefinition functionToolDefinition, Azure.AI.OpenAI.Assistants.FunctionToolCall functionToolCall) { throw null; } + } + [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] + public readonly partial struct ListSortOrder : System.IEquatable + { + private readonly object _dummy; + private readonly int _dummyPrimitive; + public ListSortOrder(string value) { throw null; } + public static Azure.AI.OpenAI.Assistants.ListSortOrder Ascending { get { throw null; } } + public static Azure.AI.OpenAI.Assistants.ListSortOrder Descending { get { throw null; } } + public bool Equals(Azure.AI.OpenAI.Assistants.ListSortOrder other) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + public override bool Equals(object obj) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + public override int GetHashCode() { throw null; } + public static bool operator ==(Azure.AI.OpenAI.Assistants.ListSortOrder left, Azure.AI.OpenAI.Assistants.ListSortOrder right) { throw null; } + public static implicit operator Azure.AI.OpenAI.Assistants.ListSortOrder (string value) { throw null; } + public static bool operator !=(Azure.AI.OpenAI.Assistants.ListSortOrder left, Azure.AI.OpenAI.Assistants.ListSortOrder right) { throw null; } + public override string ToString() { throw null; } + } + public abstract partial class MessageContent + { + protected MessageContent() { } + } + public partial class MessageFile + { + internal MessageFile() { } + public System.DateTimeOffset CreatedAt { get { throw null; } } + public string Id { get { throw null; } } + public string MessageId { get { throw null; } } + } + public partial class MessageFileCitationTextAnnotation : Azure.AI.OpenAI.Assistants.MessageTextAnnotation + { + internal MessageFileCitationTextAnnotation() : base (default(string), default(int), default(int)) { } + public string FileId { get { throw null; } } + public string Quote { get { throw null; } } + } + public partial class MessageFilePathTextAnnotation : Azure.AI.OpenAI.Assistants.MessageTextAnnotation + { + internal MessageFilePathTextAnnotation() : base (default(string), default(int), default(int)) { } + public string FileId { get { throw null; } } + } + public partial class MessageImageFileContent : Azure.AI.OpenAI.Assistants.MessageContent + { + internal MessageImageFileContent() { } + public string FileId { get { throw null; } } + } + [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] + public readonly partial struct MessageRole : System.IEquatable + { + private readonly object _dummy; + private readonly int _dummyPrimitive; + public MessageRole(string value) { throw null; } + public static Azure.AI.OpenAI.Assistants.MessageRole Assistant { get { throw null; } } + public static Azure.AI.OpenAI.Assistants.MessageRole User { get { throw null; } } + public bool Equals(Azure.AI.OpenAI.Assistants.MessageRole other) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + public override bool Equals(object obj) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + public override int GetHashCode() { throw null; } + public static bool operator ==(Azure.AI.OpenAI.Assistants.MessageRole left, Azure.AI.OpenAI.Assistants.MessageRole right) { throw null; } + public static implicit operator Azure.AI.OpenAI.Assistants.MessageRole (string value) { throw null; } + public static bool operator !=(Azure.AI.OpenAI.Assistants.MessageRole left, Azure.AI.OpenAI.Assistants.MessageRole right) { throw null; } + public override string ToString() { throw null; } + } + public abstract partial class MessageTextAnnotation + { + protected MessageTextAnnotation(string text, int startIndex, int endIndex) { } + public int EndIndex { get { throw null; } set { } } + public int StartIndex { get { throw null; } set { } } + public string Text { get { throw null; } set { } } + } + public partial class MessageTextContent : Azure.AI.OpenAI.Assistants.MessageContent + { + internal MessageTextContent() { } + public System.Collections.Generic.IReadOnlyList Annotations { get { throw null; } } + public string Text { get { throw null; } } + } + public partial class OpenAIFile + { + internal OpenAIFile() { } + public System.DateTimeOffset CreatedAt { get { throw null; } } + public string Filename { get { throw null; } } + public string Id { get { throw null; } } + public Azure.AI.OpenAI.Assistants.OpenAIFilePurpose Purpose { get { throw null; } } + public int Size { get { throw null; } } + } + [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] + public readonly partial struct OpenAIFilePurpose : System.IEquatable + { + private readonly object _dummy; + private readonly int _dummyPrimitive; + public OpenAIFilePurpose(string value) { throw null; } + public static Azure.AI.OpenAI.Assistants.OpenAIFilePurpose Assistants { get { throw null; } } + public static Azure.AI.OpenAI.Assistants.OpenAIFilePurpose AssistantsOutput { get { throw null; } } + public static Azure.AI.OpenAI.Assistants.OpenAIFilePurpose FineTune { get { throw null; } } + public static Azure.AI.OpenAI.Assistants.OpenAIFilePurpose FineTuneResults { get { throw null; } } + public bool Equals(Azure.AI.OpenAI.Assistants.OpenAIFilePurpose other) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + public override bool Equals(object obj) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + public override int GetHashCode() { throw null; } + public static bool operator ==(Azure.AI.OpenAI.Assistants.OpenAIFilePurpose left, Azure.AI.OpenAI.Assistants.OpenAIFilePurpose right) { throw null; } + public static implicit operator Azure.AI.OpenAI.Assistants.OpenAIFilePurpose (string value) { throw null; } + public static bool operator !=(Azure.AI.OpenAI.Assistants.OpenAIFilePurpose left, Azure.AI.OpenAI.Assistants.OpenAIFilePurpose right) { throw null; } + public override string ToString() { throw null; } + } + public partial class PageableList : System.Collections.Generic.IEnumerable, System.Collections.IEnumerable + { + internal PageableList() { } + public System.Collections.Generic.IReadOnlyList Data { get { throw null; } } + public string FirstId { get { throw null; } } + public bool HasMore { get { throw null; } } + public T this[int index] { get { throw null; } } + public string LastId { get { throw null; } } + public System.Collections.Generic.IEnumerator GetEnumerator() { throw null; } + System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { throw null; } + } + public abstract partial class RequiredAction + { + protected RequiredAction() { } + } + public partial class RetrievalToolCall : Azure.AI.OpenAI.Assistants.ToolCall + { + internal RetrievalToolCall() : base (default(string)) { } + public System.Collections.Generic.IReadOnlyDictionary Retrieval { get { throw null; } } + } + public partial class RetrievalToolDefinition : Azure.AI.OpenAI.Assistants.ToolDefinition + { + public RetrievalToolDefinition() { } + } + public partial class RunError + { + internal RunError() { } + public string Code { get { throw null; } } + public string Message { get { throw null; } } + } + [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] + public readonly partial struct RunStatus : System.IEquatable + { + private readonly object _dummy; + private readonly int _dummyPrimitive; + public RunStatus(string value) { throw null; } + public static Azure.AI.OpenAI.Assistants.RunStatus Cancelled { get { throw null; } } + public static Azure.AI.OpenAI.Assistants.RunStatus Cancelling { get { throw null; } } + public static Azure.AI.OpenAI.Assistants.RunStatus Completed { get { throw null; } } + public static Azure.AI.OpenAI.Assistants.RunStatus Expired { get { throw null; } } + public static Azure.AI.OpenAI.Assistants.RunStatus Failed { get { throw null; } } + public static Azure.AI.OpenAI.Assistants.RunStatus InProgress { get { throw null; } } + public static Azure.AI.OpenAI.Assistants.RunStatus Queued { get { throw null; } } + public static Azure.AI.OpenAI.Assistants.RunStatus RequiresAction { get { throw null; } } + public bool Equals(Azure.AI.OpenAI.Assistants.RunStatus other) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + public override bool Equals(object obj) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + public override int GetHashCode() { throw null; } + public static bool operator ==(Azure.AI.OpenAI.Assistants.RunStatus left, Azure.AI.OpenAI.Assistants.RunStatus right) { throw null; } + public static implicit operator Azure.AI.OpenAI.Assistants.RunStatus (string value) { throw null; } + public static bool operator !=(Azure.AI.OpenAI.Assistants.RunStatus left, Azure.AI.OpenAI.Assistants.RunStatus right) { throw null; } + public override string ToString() { throw null; } + } + public partial class RunStep + { + internal RunStep() { } + public string AssistantId { get { throw null; } } + public System.DateTimeOffset? CancelledAt { get { throw null; } } + public System.DateTimeOffset? CompletedAt { get { throw null; } } + public System.DateTimeOffset CreatedAt { get { throw null; } } + public System.DateTimeOffset? ExpiredAt { get { throw null; } } + public System.DateTimeOffset? FailedAt { get { throw null; } } + public string Id { get { throw null; } } + public Azure.AI.OpenAI.Assistants.RunStepError LastError { get { throw null; } } + public System.Collections.Generic.IReadOnlyDictionary Metadata { get { throw null; } } + public string RunId { get { throw null; } } + public Azure.AI.OpenAI.Assistants.RunStepStatus Status { get { throw null; } } + public Azure.AI.OpenAI.Assistants.RunStepDetails StepDetails { get { throw null; } } + public string ThreadId { get { throw null; } } + public Azure.AI.OpenAI.Assistants.RunStepType Type { get { throw null; } } + } + public abstract partial class RunStepDetails + { + protected RunStepDetails() { } + } + public partial class RunStepError + { + internal RunStepError() { } + public Azure.AI.OpenAI.Assistants.RunStepErrorCode Code { get { throw null; } } + public string Message { get { throw null; } } + } + [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] + public readonly partial struct RunStepErrorCode : System.IEquatable + { + private readonly object _dummy; + private readonly int _dummyPrimitive; + public RunStepErrorCode(string value) { throw null; } + public static Azure.AI.OpenAI.Assistants.RunStepErrorCode RateLimitExceeded { get { throw null; } } + public static Azure.AI.OpenAI.Assistants.RunStepErrorCode ServerError { get { throw null; } } + public bool Equals(Azure.AI.OpenAI.Assistants.RunStepErrorCode other) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + public override bool Equals(object obj) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + public override int GetHashCode() { throw null; } + public static bool operator ==(Azure.AI.OpenAI.Assistants.RunStepErrorCode left, Azure.AI.OpenAI.Assistants.RunStepErrorCode right) { throw null; } + public static implicit operator Azure.AI.OpenAI.Assistants.RunStepErrorCode (string value) { throw null; } + public static bool operator !=(Azure.AI.OpenAI.Assistants.RunStepErrorCode left, Azure.AI.OpenAI.Assistants.RunStepErrorCode right) { throw null; } + public override string ToString() { throw null; } + } + public partial class RunStepMessageCreationDetails : Azure.AI.OpenAI.Assistants.RunStepDetails + { + internal RunStepMessageCreationDetails() { } + public Azure.AI.OpenAI.Assistants.RunStepMessageCreationReference MessageCreation { get { throw null; } } + } + public partial class RunStepMessageCreationReference + { + internal RunStepMessageCreationReference() { } + public string MessageId { get { throw null; } } + } + [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] + public readonly partial struct RunStepStatus : System.IEquatable + { + private readonly object _dummy; + private readonly int _dummyPrimitive; + public RunStepStatus(string value) { throw null; } + public static Azure.AI.OpenAI.Assistants.RunStepStatus Cancelled { get { throw null; } } + public static Azure.AI.OpenAI.Assistants.RunStepStatus Completed { get { throw null; } } + public static Azure.AI.OpenAI.Assistants.RunStepStatus Expired { get { throw null; } } + public static Azure.AI.OpenAI.Assistants.RunStepStatus Failed { get { throw null; } } + public static Azure.AI.OpenAI.Assistants.RunStepStatus InProgress { get { throw null; } } + public bool Equals(Azure.AI.OpenAI.Assistants.RunStepStatus other) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + public override bool Equals(object obj) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + public override int GetHashCode() { throw null; } + public static bool operator ==(Azure.AI.OpenAI.Assistants.RunStepStatus left, Azure.AI.OpenAI.Assistants.RunStepStatus right) { throw null; } + public static implicit operator Azure.AI.OpenAI.Assistants.RunStepStatus (string value) { throw null; } + public static bool operator !=(Azure.AI.OpenAI.Assistants.RunStepStatus left, Azure.AI.OpenAI.Assistants.RunStepStatus right) { throw null; } + public override string ToString() { throw null; } + } + public partial class RunStepToolCallDetails : Azure.AI.OpenAI.Assistants.RunStepDetails + { + internal RunStepToolCallDetails() { } + public System.Collections.Generic.IReadOnlyList ToolCalls { get { throw null; } } + } + [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] + public readonly partial struct RunStepType : System.IEquatable + { + private readonly object _dummy; + private readonly int _dummyPrimitive; + public RunStepType(string value) { throw null; } + public static Azure.AI.OpenAI.Assistants.RunStepType MessageCreation { get { throw null; } } + public static Azure.AI.OpenAI.Assistants.RunStepType ToolCalls { get { throw null; } } + public bool Equals(Azure.AI.OpenAI.Assistants.RunStepType other) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + public override bool Equals(object obj) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + public override int GetHashCode() { throw null; } + public static bool operator ==(Azure.AI.OpenAI.Assistants.RunStepType left, Azure.AI.OpenAI.Assistants.RunStepType right) { throw null; } + public static implicit operator Azure.AI.OpenAI.Assistants.RunStepType (string value) { throw null; } + public static bool operator !=(Azure.AI.OpenAI.Assistants.RunStepType left, Azure.AI.OpenAI.Assistants.RunStepType right) { throw null; } + public override string ToString() { throw null; } + } + public partial class SubmitToolOutputsAction : Azure.AI.OpenAI.Assistants.RequiredAction + { + internal SubmitToolOutputsAction() { } + public System.Collections.Generic.IReadOnlyList ToolCalls { get { throw null; } } + } + public partial class ThreadMessage + { + public ThreadMessage(string id, System.DateTimeOffset createdAt, string threadId, Azure.AI.OpenAI.Assistants.MessageRole role, System.Collections.Generic.IEnumerable contentItems, System.Collections.Generic.IEnumerable fileIds) { } + public string AssistantId { get { throw null; } set { } } + public System.Collections.Generic.IList ContentItems { get { throw null; } } + public System.DateTimeOffset CreatedAt { get { throw null; } set { } } + public System.Collections.Generic.IList FileIds { get { throw null; } } + public string Id { get { throw null; } set { } } + public System.Collections.Generic.IDictionary Metadata { get { throw null; } } + public Azure.AI.OpenAI.Assistants.MessageRole Role { get { throw null; } set { } } + public string RunId { get { throw null; } set { } } + public string ThreadId { get { throw null; } set { } } + } + public partial class ThreadRun + { + internal ThreadRun() { } + public string AssistantId { get { throw null; } } + public System.DateTimeOffset? CancelledAt { get { throw null; } } + public System.DateTimeOffset? CompletedAt { get { throw null; } } + public System.DateTimeOffset CreatedAt { get { throw null; } } + public System.DateTimeOffset? ExpiresAt { get { throw null; } } + public System.DateTimeOffset? FailedAt { get { throw null; } } + public System.Collections.Generic.IReadOnlyList FileIds { get { throw null; } } + public string Id { get { throw null; } } + public string Instructions { get { throw null; } } + public Azure.AI.OpenAI.Assistants.RunError LastError { get { throw null; } } + public System.Collections.Generic.IReadOnlyDictionary Metadata { get { throw null; } } + public string Model { get { throw null; } } + public Azure.AI.OpenAI.Assistants.RequiredAction RequiredAction { get { throw null; } } + public System.DateTimeOffset? StartedAt { get { throw null; } } + public Azure.AI.OpenAI.Assistants.RunStatus Status { get { throw null; } } + public string ThreadId { get { throw null; } } + public System.Collections.Generic.IReadOnlyList Tools { get { throw null; } } + } + public abstract partial class ToolCall + { + protected ToolCall(string id) { } + public string Id { get { throw null; } } + } + public abstract partial class ToolDefinition + { + protected ToolDefinition() { } + } + public partial class ToolOutput + { + public ToolOutput() { } + public ToolOutput(Azure.AI.OpenAI.Assistants.ToolCall toolCall) { } + public ToolOutput(Azure.AI.OpenAI.Assistants.ToolCall toolCall, string output) { } + public ToolOutput(string toolCallId) { } + public ToolOutput(string toolCallId, string output) { } + public string Output { get { throw null; } set { } } + public string ToolCallId { get { throw null; } set { } } + } +} +namespace Microsoft.Extensions.Azure +{ + public static partial class AIOpenAIAssistantsClientBuilderExtensions + { + public static Azure.Core.Extensions.IAzureClientBuilder AddAssistantsClient(this TBuilder builder, System.Uri endpoint) where TBuilder : Azure.Core.Extensions.IAzureClientFactoryBuilderWithCredential { throw null; } + public static Azure.Core.Extensions.IAzureClientBuilder AddAssistantsClient(this TBuilder builder, System.Uri endpoint, Azure.AzureKeyCredential credential) where TBuilder : Azure.Core.Extensions.IAzureClientFactoryBuilder { throw null; } + public static Azure.Core.Extensions.IAzureClientBuilder AddAssistantsClient(this TBuilder builder, TConfiguration configuration) where TBuilder : Azure.Core.Extensions.IAzureClientFactoryBuilderWithConfiguration { throw null; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Azure.AI.OpenAI.Assistants.csproj b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Azure.AI.OpenAI.Assistants.csproj new file mode 100644 index 000000000000..f4ec7c0c46c2 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Azure.AI.OpenAI.Assistants.csproj @@ -0,0 +1,34 @@ + + + + Azure's official .NET library for OpenAI assistants. + Works with Azure OpenAI resources as well as the non-Azure OpenAI endpoint. + + Microsoft Azure.AI.OpenAI.Assistants client library + 1.0.0-beta.1 + Microsoft Azure OpenAI + true + $(RequiredTargetFrameworks) + true + $(NoWarn);CS1591;AZC0012;AZC0001 + true + + + + + + + + + + + + + + + + + + + + diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Convenience/AssistantsClient.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Convenience/AssistantsClient.cs new file mode 100644 index 000000000000..6cf40156af0f --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Convenience/AssistantsClient.cs @@ -0,0 +1,138 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +#nullable disable + +using System; +using System.Collections.Generic; +using System.IO; +using System.Threading; +using System.Threading.Tasks; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants; + +/* + * CUSTOM CODE DESCRIPTION: + * + * These convenience helpers bring additive capabilities to address client methods more ergonomically: + * - Use response value instances of types like AssistantThread and ThreadRun instead of raw IDs from those instances + * a la thread.Id and run.Id. + * - Allow direct file-path-based file upload (with inferred filename parameter placement) in lieu of requiring + * manual I/O prior to getting a byte array + */ + +public partial class AssistantsClient +{ + /// + /// Creates a new, empty thread using a default instance. + /// + /// The cancellation token to use. + public virtual Response CreateThread(CancellationToken cancellationToken = default) + => CreateThread(new AssistantThreadCreationOptions(), cancellationToken); + + /// + /// Creates a new, empty thread using a default instance. + /// + /// The cancellation token to use. + public virtual Task> CreateThreadAsync( + CancellationToken cancellationToken = default) + => CreateThreadAsync(new AssistantThreadCreationOptions(), cancellationToken); + + /// Returns a list of run steps associated an assistant thread run. + /// The instance from which run steps should be listed. + /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. + /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order. + /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list. + /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. + /// The cancellation token to use. + /// is null. + public virtual Response> GetRunSteps( + ThreadRun run, + int? limit = null, + ListSortOrder? order = null, + string after = null, + string before = null, + CancellationToken cancellationToken = default) + { + Argument.AssertNotNull(run, nameof(run)); + return GetRunSteps(run.ThreadId, run.Id, limit, order, after, before, cancellationToken); + } + + /// Returns a list of run steps associated an assistant thread run. + /// The instance from which run steps should be listed. + /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. + /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order. + /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list. + /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. + /// The cancellation token to use. + /// is null. + public virtual Task>> GetRunStepsAsync( + ThreadRun run, + int? limit = null, + ListSortOrder? order = null, + string after = null, + string before = null, + CancellationToken cancellationToken = default) + { + Argument.AssertNotNull(run, nameof(run)); + return GetRunStepsAsync(run.ThreadId, run.Id, limit, order, after, before, cancellationToken); + } + + /// Submits outputs from tool calls as requested by a run with a status of 'requires_action' with required_action.type of 'submit_tool_outputs'. + /// The that the tool outputs should be submitted to. + /// The list of tool call outputs to provide as part of an output submission to an assistant thread run. + /// The cancellation token to use. + /// is null. + public virtual Response SubmitRunToolOutputs(ThreadRun run, IEnumerable toolOutputs, CancellationToken cancellationToken = default) + { + Argument.AssertNotNull(run, nameof(run)); + return SubmitRunToolOutputs(run.ThreadId, run.Id, toolOutputs, cancellationToken); + } + + /// Submits outputs from tool calls as requested by a run with a status of 'requires_action' with required_action.type of 'submit_tool_outputs'. + /// The that the tool outputs should be submitted to. + /// The list of tool call outputs to provide as part of an output submission to an assistant thread run. + /// The cancellation token to use. + /// is null. + public virtual Task> SubmitRunToolOutputsAsync(ThreadRun run, IEnumerable toolOutputs, CancellationToken cancellationToken = default) + { + Argument.AssertNotNull(run, nameof(run)); + return SubmitRunToolOutputsAsync(run.ThreadId, run.Id, toolOutputs, cancellationToken); + } + + /// + /// Uploads a file from a local file path accessible to . + /// + /// The local file path. + /// The intended purpose of the uploaded file. + /// The cancellation token to use. + public virtual Response UploadFile( + string localFilePath, + OpenAIFilePurpose purpose, + CancellationToken cancellationToken = default) + { + FileInfo localFileInfo = new(localFilePath); + using FileStream localFileStream = localFileInfo.OpenRead(); + BinaryData localFileData = BinaryData.FromStream(localFileStream); + return UploadFile(localFileData, purpose, localFileInfo.Name, cancellationToken); + } + + /// + /// Uploads a file from a local file path accessible to . + /// + /// The local file path. + /// The intended purpose of the uploaded file. + /// The cancellation token to use. + public virtual async Task> UploadFileAsync( + string localFilePath, + OpenAIFilePurpose purpose, + CancellationToken cancellationToken = default) + { + FileInfo localFileInfo = new(localFilePath); + using FileStream localFileStream = localFileInfo.OpenRead(); + BinaryData localFileData + = await BinaryData.FromStreamAsync(localFileStream, cancellationToken).ConfigureAwait(false); + return await UploadFileAsync(localFileData, purpose, localFileInfo.Name, cancellationToken).ConfigureAwait(false); + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Convenience/FunctionToolDefinition.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Convenience/FunctionToolDefinition.cs new file mode 100644 index 000000000000..765d83c74215 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Convenience/FunctionToolDefinition.cs @@ -0,0 +1,36 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +#nullable disable + +using System; + +namespace Azure.AI.OpenAI.Assistants; + +/* + * CUSTOM CODE DESCRIPTION: + * + * These additions simply allow easy comparison between tool calls and tool definitions. + */ + +public partial class FunctionToolDefinition +{ + public static bool operator ==(FunctionToolDefinition functionToolDefinition, FunctionToolCall functionToolCall) + => functionToolDefinition.Name == functionToolDefinition.Name; + + public static bool operator !=(FunctionToolDefinition functionToolDefinition, FunctionToolCall functionToolCall) + => functionToolDefinition.Name != functionToolDefinition.Name; + + public static bool operator ==(FunctionToolCall functionToolCall, FunctionToolDefinition functionToolDefinition) + => functionToolCall.Name == functionToolDefinition.Name; + + public static bool operator !=(FunctionToolCall functionToolCall, FunctionToolDefinition functionToolDefinition) + => functionToolCall.Name != functionToolDefinition.Name; + + /// + public override bool Equals(object obj) + => ReferenceEquals(this, obj) ? true : ReferenceEquals(obj, null) ? false : throw new NotImplementedException(); + + /// + public override int GetHashCode() => InternalFunction.GetHashCode(); +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Convenience/PageableList.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Convenience/PageableList.cs new file mode 100644 index 000000000000..5616165a8f80 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Convenience/PageableList.cs @@ -0,0 +1,38 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +#nullable disable + +using System.Collections; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI.Assistants; + +/* + * CUSTOM CODE DESCRIPTION: + * + * These additions to the custom PageableList type aren't necessary for the dimension of code generation customization + * but do facilitate easier "list-like" use of the type. + */ + +public partial class PageableList : IEnumerable +{ + /// + /// Gets the data item at the specified index. + /// + /// The index of the data item to retrieve. + /// The indexed data item. + public T this[int index] => Data[index]; + + /// + public IEnumerator GetEnumerator() + { + return Data.GetEnumerator(); + } + + /// + IEnumerator IEnumerable.GetEnumerator() + { + return ((IEnumerable)Data).GetEnumerator(); + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Convenience/README.md b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Convenience/README.md new file mode 100644 index 000000000000..9a982be09a65 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Convenience/README.md @@ -0,0 +1,4 @@ +## Convenience additions + +This folder contains additional functionality for library types that does not modify or impact the behavior of generated +code. diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/AssistantsClient.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/AssistantsClient.cs new file mode 100644 index 000000000000..8d25e4846791 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/AssistantsClient.cs @@ -0,0 +1,718 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; +using Azure.Core; +using Azure.Core.Pipeline; + +namespace Azure.AI.OpenAI.Assistants; +public partial class AssistantsClient +{ + /* + * CUSTOM CODE DESCRIPTION: + * + * Constructors are replaced to provide overloads that configure client instances to use the platform.openai.com + * OpenAI endpoint instead of an Azure OpenAI resource. + * + */ + + private static readonly string s_openAIEndpoint = "https://api.openai.com/v1"; + private static readonly string s_aoaiNotYetSupportedMessage = "Azure OpenAI does not yet support Assistants."; + + private bool _isConfiguredForAzure; + + /// + /// Creates a new instance of for use with an Azure OpenAI resource. + /// + /// An Azure OpenAI resource URL, e.g. https://my-resource.openai.azure.com. + /// The authentication information for the Azure OpenAI resource. + /// Additional options for customizing the behavior of the client. + /// + /// or is null. + /// + /// + /// Always thrown until Azure OpenAI support for /assistants is available. + /// + public AssistantsClient(Uri endpoint, AzureKeyCredential keyCredential, AssistantsClientOptions options) + { + Argument.AssertNotNull(endpoint, nameof(endpoint)); + Argument.AssertNotNull(keyCredential, nameof(keyCredential)); + options ??= new AssistantsClientOptions(); + + ClientDiagnostics = new ClientDiagnostics(options, true); + _isConfiguredForAzure = true; + _keyCredential = keyCredential; + _pipeline = HttpPipelineBuilder.Build(options, Array.Empty(), new HttpPipelinePolicy[] { new AzureKeyCredentialPolicy(_keyCredential, AuthorizationHeader) }, new ResponseClassifier()); + _endpoint = endpoint; + _apiVersion = options.Version; + + throw new NotSupportedException(s_aoaiNotYetSupportedMessage); + } + + /// + /// Creates a new instance of for use with an Azure OpenAI resource. + /// + /// An Azure OpenAI resource URL, e.g. https://my-resource.openai.azure.com. + /// The authentication information for the Azure OpenAI resource. + /// + /// or is null. + /// + /// + /// Always thrown until Azure OpenAI support for /assistants is available. + /// + public AssistantsClient(Uri endpoint, AzureKeyCredential keyCredential) + : this(endpoint, keyCredential, new AssistantsClientOptions()) + { + } + + /// + /// Creates a new instance of for use with an Azure OpenAI resource. + /// + /// An Azure OpenAI resource URL, e.g. https://my-resource.openai.azure.com. + /// The authentication information for the Azure OpenAI resource. + /// Additional options for customizing the behavior of the client. + /// + /// or is null. + /// + /// + /// Always thrown until Azure OpenAI support for /assistants is available. + /// + public AssistantsClient(Uri endpoint, TokenCredential tokenCredential, AssistantsClientOptions options) + { + Argument.AssertNotNull(endpoint, nameof(endpoint)); + Argument.AssertNotNull(tokenCredential, nameof(tokenCredential)); + options ??= new AssistantsClientOptions(); + + ClientDiagnostics = new ClientDiagnostics(options, true); + _isConfiguredForAzure = true; + _tokenCredential = tokenCredential; + _pipeline = HttpPipelineBuilder.Build( + options, + Array.Empty(), + new HttpPipelinePolicy[] { + new BearerTokenAuthenticationPolicy(_tokenCredential, AuthorizationScopes) + }, + new ResponseClassifier()); + _endpoint = endpoint; + _apiVersion = options.Version; + + throw new NotSupportedException(s_aoaiNotYetSupportedMessage); + } + + /// + /// Creates a new instance of for use with an Azure OpenAI resource. + /// + /// An Azure OpenAI resource URL, e.g. https://my-resource.openai.azure.com. + /// The authentication information for the Azure OpenAI resource. + /// + /// is null. + /// + /// + /// Always thrown until Azure OpenAI support for /assistants is available. + /// + public AssistantsClient(Uri endpoint, TokenCredential tokenCredential) + : this(endpoint, tokenCredential, new AssistantsClientOptions()) + { + } + + /// + /// Creates a new instance of for use with OpenAI's api.openai.com endpoint. + /// + /// An OpenAI API key as obtained from platform.openai.com. + /// Additional options for customizing the behavior of the client. + /// is null. + public AssistantsClient(string openAIApiKey, AssistantsClientOptions options) + { + Argument.AssertNotNull(openAIApiKey, nameof(openAIApiKey)); + options ??= new AssistantsClientOptions(); + + ClientDiagnostics = new ClientDiagnostics(options, true); + _isConfiguredForAzure = false; + _tokenCredential = CreateDelegatedToken(openAIApiKey); + _pipeline = HttpPipelineBuilder.Build( + options, + Array.Empty(), + new HttpPipelinePolicy[] { + new BearerTokenAuthenticationPolicy(_tokenCredential, AuthorizationScopes) + }, + new ResponseClassifier()); + _endpoint = new Uri(s_openAIEndpoint); + _apiVersion = options.Version; + } + + /// + /// Creates a new instance of for use with OpenAI's api.openai.com endpoint. + /// + /// An OpenAI API key as obtained from platform.openai.com. + /// is null. + public AssistantsClient(string openAIApiKey) + : this(openAIApiKey, new AssistantsClientOptions()) + { + } + + /* + * CUSTOM CODE DESCRIPTION: + * + * Generated methods that return trivial response value types (e.g. "DeletionStatus" that has nothing but a + * "Deleted" property) are shimmed to directly use the underlying data as their response value type. + * + */ + + /// Deletes an assistant. + /// The ID of the assistant to delete. + /// The cancellation token to use. + /// is null. + /// is an empty string, and was expected to be non-empty. + public virtual Response DeleteAssistant(string assistantId, CancellationToken cancellationToken = default) + { + Response baseResponse = InternalDeleteAssistant(assistantId, cancellationToken); + bool simplifiedValue = + baseResponse.GetRawResponse() != null + && !baseResponse.GetRawResponse().IsError + && baseResponse.Value != null + && baseResponse.Value.Deleted; + return Response.FromValue(simplifiedValue, baseResponse.GetRawResponse()); + } + + /// Deletes an assistant. + /// The ID of the assistant to delete. + /// The cancellation token to use. + /// is null. + /// is an empty string, and was expected to be non-empty. + public virtual async Task> DeleteAssistantAsync( + string assistantId, + CancellationToken cancellationToken = default) + { + Response baseResponse + = await InternalDeleteAssistantAsync(assistantId, cancellationToken).ConfigureAwait(false); + bool simplifiedValue = + baseResponse.GetRawResponse() != null + && !baseResponse.GetRawResponse().IsError + && baseResponse.Value != null + && baseResponse.Value.Deleted; + return Response.FromValue(simplifiedValue, baseResponse.GetRawResponse()); + } + + /// Deletes a thread. + /// The ID of the thread to delete. + /// The cancellation token to use. + /// is null. + /// is an empty string, and was expected to be non-empty. + public virtual Response DeleteThread( + string threadId, + CancellationToken cancellationToken = default) + { + Response baseResponse + = InternalDeleteThread(threadId, cancellationToken); + bool simplifiedValue = + baseResponse.GetRawResponse() != null + && !baseResponse.GetRawResponse().IsError + && baseResponse.Value != null + && baseResponse.Value.Deleted; + return Response.FromValue(simplifiedValue, baseResponse.GetRawResponse()); + } + + /// Deletes a thread. + /// The ID of the thread to delete. + /// The cancellation token to use. + /// is null. + /// is an empty string, and was expected to be non-empty. + public virtual async Task> DeleteThreadAsync( + string threadId, + CancellationToken cancellationToken = default) + { + Response baseResponse + = await InternalDeleteThreadAsync(threadId, cancellationToken).ConfigureAwait(false); + bool simplifiedValue = + baseResponse.GetRawResponse() != null + && !baseResponse.GetRawResponse().IsError + && baseResponse.Value != null + && baseResponse.Value.Deleted; + return Response.FromValue(simplifiedValue, baseResponse.GetRawResponse()); + } + + /// Associates a previously uploaded file with an assistant for use by supported tools. + /// The ID of the assistant associated with the attached file to delete. + /// The ID of the attached file to delete. + /// The cancellation token to use. + /// or is null. + /// or is an empty string, and was expected to be non-empty. + public virtual Response UnlinkAssistantFile( + string assistantId, + string fileId, + CancellationToken cancellationToken = default) + { + Response baseResponse + = InternalUnlinkAssistantFile(assistantId, fileId, cancellationToken); + bool simplifiedValue = + baseResponse.GetRawResponse() != null + && !baseResponse.GetRawResponse().IsError + && baseResponse.Value != null + && baseResponse.Value.Deleted; + return Response.FromValue(simplifiedValue, baseResponse.GetRawResponse()); + } + + /// + /// Removes an association between an uploaded file and an assistant, making it inaccessible to supported tools + /// for that assistant. + /// + /// + /// This operation only removes the link between the file and assistant; it does not delete the file itself. + /// To delete the file, use , instead. + /// + /// The ID of the assistant associated with the attached file to delete. + /// The ID of the attached file to delete. + /// The cancellation token to use. + /// or is null. + /// or is an empty string, and was expected to be non-empty. + public virtual async Task> UnlinkAssistantFileAsync( + string assistantId, + string fileId, + CancellationToken cancellationToken = default) + { + Response baseResponse + = await InternalUnlinkAssistantFileAsync(assistantId, fileId, cancellationToken).ConfigureAwait(false); + bool simplifiedValue = + baseResponse.GetRawResponse() != null + && !baseResponse.GetRawResponse().IsError + && baseResponse.Value != null + && baseResponse.Value.Deleted; + return Response.FromValue(simplifiedValue, baseResponse.GetRawResponse()); + } + + /// Returns a list of files that belong to the user's organization. + /// Limits files in the response to those with the specified purpose. + /// The cancellation token to use. + public virtual Response> GetFiles(OpenAIFilePurpose? purpose = null, CancellationToken cancellationToken = default) + { + Response baseResponse = InternalListFiles(purpose, cancellationToken); + return Response.FromValue(baseResponse.Value?.Data, baseResponse.GetRawResponse()); + } + + /// Returns a list of files that belong to the user's organization. + /// Limits files in the response to those with the specified purpose. + /// The cancellation token to use. + public virtual async Task>> GetFilesAsync( + OpenAIFilePurpose? purpose = null, + CancellationToken cancellationToken = default) + { + Response baseResponse = await InternalListFilesAsync(purpose, cancellationToken).ConfigureAwait(false); + return Response.FromValue(baseResponse.Value?.Data, baseResponse.GetRawResponse()); + } + + /// Delete a previously uploaded file. + /// The ID of the file to delete. + /// The cancellation token to use. + /// is null. + /// is an empty string, and was expected to be non-empty. + public virtual Response DeleteFile(string fileId, CancellationToken cancellationToken = default) + { + Response baseResponse = InternalDeleteFile(fileId, cancellationToken); + bool simplifiedValue = + baseResponse.GetRawResponse() != null + && !baseResponse.GetRawResponse().IsError + && baseResponse.Value != null + && baseResponse.Value.Deleted; + return Response.FromValue(simplifiedValue, baseResponse.GetRawResponse()); + } + + /// Delete a previously uploaded file. + /// The ID of the file to delete. + /// The cancellation token to use. + /// is null. + /// is an empty string, and was expected to be non-empty. + public virtual async Task> DeleteFileAsync(string fileId, CancellationToken cancellationToken = default) + { + Response baseResponse = await InternalDeleteFileAsync(fileId, cancellationToken).ConfigureAwait(false); + bool simplifiedValue = + baseResponse.GetRawResponse() != null + && !baseResponse.GetRawResponse().IsError + && baseResponse.Value != null + && baseResponse.Value.Deleted; + return Response.FromValue(simplifiedValue, baseResponse.GetRawResponse()); + } + + /// + public virtual Response> GetAssistants( + int? limit = null, + ListSortOrder? order = null, + string after = null, + string before = null, + CancellationToken cancellationToken = default) + { + Response baseResponse = InternalGetAssistants(limit, order, after, before, cancellationToken); + return Response.FromValue(PageableList.Create(baseResponse.Value), baseResponse.GetRawResponse()); + } + + /// + public virtual async Task>> GetAssistantsAsync( + int? limit = null, + ListSortOrder? order = null, + string after = null, + string before = null, + CancellationToken cancellationToken = default) + { + Response baseResponse + = await InternalGetAssistantsAsync(limit, order, after, before, cancellationToken).ConfigureAwait(false); + return Response.FromValue(PageableList.Create(baseResponse.Value), baseResponse.GetRawResponse()); + } + + /// + public virtual Response> GetAssistantFiles( + string assistantId, + int? limit = null, + ListSortOrder? order = null, + string after = null, + string before = null, + CancellationToken cancellationToken = default) + { + Response baseResponse = InternalGetAssistantFiles(assistantId, limit, order, after, before, cancellationToken); + return Response.FromValue(PageableList.Create(baseResponse.Value), baseResponse.GetRawResponse()); + } + + /// + public virtual async Task>> GetAssistantFilesAsync( + string assistantId, + int? limit = null, + ListSortOrder? order = null, + string after = null, + string before = null, + CancellationToken cancellationToken = default) + { + Response baseResponse + = await InternalGetAssistantFilesAsync(assistantId, limit, order, after, before, cancellationToken).ConfigureAwait(false); + return Response.FromValue(PageableList.Create(baseResponse.Value), baseResponse.GetRawResponse()); + } + + /// + public virtual Response> GetMessageFiles( + string threadId, + string messageId, + int? limit = null, + ListSortOrder? order = null, + string after = null, + string before = null, + CancellationToken cancellationToken = default) + { + Response baseResponse = InternalGetMessageFiles(threadId, messageId, limit, order, after, before, cancellationToken); + return Response.FromValue(PageableList.Create(baseResponse.Value), baseResponse.GetRawResponse()); + } + + /// + public virtual async Task>> GetMessageFilesAsync( + string threadId, + string messageId, + int? limit = null, + ListSortOrder? order = null, + string after = null, + string before = null, + CancellationToken cancellationToken = default) + { + Response baseResponse + = await InternalGetMessageFilesAsync(threadId, messageId, limit, order, after, before, cancellationToken).ConfigureAwait(false); + return Response.FromValue(PageableList.Create(baseResponse.Value), baseResponse.GetRawResponse()); + } + + /// + public virtual Response> GetRunSteps( + string threadId, + string runId, + int? limit = null, + ListSortOrder? order = null, + string after = null, + string before = null, + CancellationToken cancellationToken = default) + { + Response baseResponse = InternalGetRunSteps(threadId, runId, limit, order, after, before, cancellationToken); + return Response.FromValue(PageableList.Create(baseResponse.Value), baseResponse.GetRawResponse()); + } + + /// + public virtual async Task>> GetRunStepsAsync( + string threadId, + string runId, + int? limit = null, + ListSortOrder? order = null, + string after = null, + string before = null, + CancellationToken cancellationToken = default) + { + Response baseResponse + = await InternalGetRunStepsAsync(threadId, runId, limit, order, after, before, cancellationToken).ConfigureAwait(false); + return Response.FromValue(PageableList.Create(baseResponse.Value), baseResponse.GetRawResponse()); + } + + /// + public virtual Response> GetMessages( + string threadId, + int? limit = null, + ListSortOrder? order = null, + string after = null, + string before = null, + CancellationToken cancellationToken = default) + { + Response baseResponse = InternalGetMessages(threadId, limit, order, after, before, cancellationToken); + return Response.FromValue(PageableList.Create(baseResponse.Value), baseResponse.GetRawResponse()); + } + + /// + public virtual async Task>> GetMessagesAsync( + string threadId, + int? limit = null, + ListSortOrder? order = null, + string after = null, + string before = null, + CancellationToken cancellationToken = default) + { + Response baseResponse + = await InternalGetMessagesAsync(threadId, limit, order, after, before, cancellationToken).ConfigureAwait(false); + return Response.FromValue(PageableList.Create(baseResponse.Value), baseResponse.GetRawResponse()); + } + + /// + public virtual Response> GetRuns( + string threadId, + int? limit = null, + ListSortOrder? order = null, + string after = null, + string before = null, + CancellationToken cancellationToken = default) + { + Response baseResponse = InternalGetRuns(threadId, limit, order, after, before, cancellationToken); + return Response.FromValue(PageableList.Create(baseResponse.Value), baseResponse.GetRawResponse()); + } + + /// + public virtual async Task>> GetRunsAsync( + string threadId, + int? limit = null, + ListSortOrder? order = null, + string after = null, + string before = null, + CancellationToken cancellationToken = default) + { + Response baseResponse + = await InternalGetRunsAsync(threadId, limit, order, after, before, cancellationToken).ConfigureAwait(false); + return Response.FromValue(PageableList.Create(baseResponse.Value), baseResponse.GetRawResponse()); + } + + /* + * CUSTOM CODE DESCRIPTION: + * + * Request message methods are replaced to support Azure and non-Azure OpenAI use. + * + */ + + internal HttpMessage CreateRequestMessage( + string operationPath, + RequestContent content, + RequestContext context, + RequestMethod method, + params (string QueryParameterName, string QueryParameterValue)[] queryParameters) + { + HttpMessage message = _pipeline.CreateMessage(context, ResponseClassifier200); + Request request = message.Request; + request.Method = method; + request.Headers.Add(HttpHeader.Common.JsonAccept); + request.Headers.Add(HttpHeader.Common.JsonContentType); + var uri = new RawRequestUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath(operationPath, escape: false); + if (_isConfiguredForAzure) + { + uri.AppendQuery("api-version", _apiVersion, true); + throw new NotImplementedException(); + } + else + { + request.Headers.Add("OpenAI-Beta", "assistants=v1"); + } + foreach ((string key, string value) in queryParameters) + { + if (!string.IsNullOrEmpty(value)) + { + uri.AppendQuery(key, value); + } + } + request.Uri = uri; + request.Content = content; + return message; + } + + internal HttpMessage CreateInternalGetAssistantsRequest( + int? limit, + string order, + string after, + string before, + RequestContext context) + => CreateRequestMessage( + "/assistants", + content: null, + context, + RequestMethod.Get, + ("limit", $"{(limit.HasValue ? limit.Value : string.Empty)}"), + ("order", order), + ("after", after), + ("before", before)); + + internal HttpMessage CreateCreateAssistantRequest(RequestContent content, RequestContext context) + => CreateRequestMessage("/assistants", content, context, RequestMethod.Post); + + internal HttpMessage CreateRetrieveAssistantRequest(string assistantId, RequestContext context) + => CreateRequestMessage($"/assistants/{assistantId}", content: null, context, RequestMethod.Get); + + internal HttpMessage CreateModifyAssistantRequest(string assistantId, RequestContent content, RequestContext context) + => CreateRequestMessage($"/assistants/{assistantId}", content, context, RequestMethod.Post); + + internal HttpMessage CreateInternalDeleteAssistantRequest(string assistantId, RequestContext context) + => CreateRequestMessage($"/assistants/{assistantId}", content: null, context, RequestMethod.Delete); + + internal HttpMessage CreateLinkAssistantFileRequest(string assistantId, RequestContent content, RequestContext context) + => CreateRequestMessage($"/assistants/{assistantId}/files", content, context, RequestMethod.Post); + + internal HttpMessage CreateInternalGetAssistantFilesRequest(string assistantId, int? limit, string order, string after, string before, RequestContext context) + { + return CreateRequestMessage( + $"/assistants/{assistantId}/files", + content: null, + context, + RequestMethod.Get, + ("limit", $"{(limit.HasValue ? limit.Value : string.Empty)}"), + ("order", order), + ("after", after), + ("before", before)); + } + + internal HttpMessage CreateRetrieveAssistantFileRequest(string assistantId, string fileId, RequestContext context) + => CreateRequestMessage($"/assistants/{assistantId}/files/{fileId}", content: null, context, RequestMethod.Get); + + internal HttpMessage CreateInternalUnlinkAssistantFileRequest(string assistantId, string fileId, RequestContext context) + => CreateRequestMessage($"/assistants/{assistantId}/files/{fileId}", content: null, context, RequestMethod.Delete); + + internal HttpMessage CreateCreateThreadRequest(RequestContent content, RequestContext context) + => CreateRequestMessage($"/threads", content, context, RequestMethod.Post); + + internal HttpMessage CreateRetrieveThreadRequest(string threadId, RequestContext context) + => CreateRequestMessage($"/threads/{threadId}", content: null, context, RequestMethod.Get); + internal HttpMessage CreateModifyThreadRequest(string threadId, RequestContent content, RequestContext context) + => CreateRequestMessage($"/threads/{threadId}", content, context, RequestMethod.Post); + internal HttpMessage CreateInternalDeleteThreadRequest(string threadId, RequestContext context) + => CreateRequestMessage($"/threads/{threadId}", content: null, context, RequestMethod.Delete); + + internal HttpMessage CreateCreateMessageRequest(string threadId, RequestContent content, RequestContext context) + => CreateRequestMessage($"/threads/{threadId}/messages", content, context, RequestMethod.Post); + + internal HttpMessage CreateInternalGetMessagesRequest(string threadId, int? limit, string order, string after, string before, RequestContext context) + => CreateRequestMessage( + $"/threads/{threadId}/messages", + content: null, + context, + RequestMethod.Get, + ("limit", $"{(limit.HasValue ? limit.Value : string.Empty)}"), + ("order", order), + ("after", after), + ("before", before)); + + internal HttpMessage CreateRetrieveMessageRequest(string threadId, string messageId, RequestContext context) + => CreateRequestMessage($"/threads/{threadId}/messages/{messageId}", content: null, context, RequestMethod.Get); + + internal HttpMessage CreateModifyMessageRequest(string threadId, string messageId, RequestContent content, RequestContext context) + => CreateRequestMessage($"/threads/{threadId}/messages/{messageId}", content, context, RequestMethod.Post); + internal HttpMessage CreateInternalGetMessageFilesRequest(string threadId, string messageId, int? limit, string order, string after, string before, RequestContext context) + => CreateRequestMessage( + $"/threads/{threadId}/messages/{messageId}/files", + content: null, + context, + RequestMethod.Get, + ("limit", $"{(limit.HasValue ? limit.Value : string.Empty)}"), + ("order", order), + ("after", after), + ("before", before)); + + internal HttpMessage CreateRetrieveMessageFileRequest(string threadId, string messageId, string fileId, RequestContext context) + => CreateRequestMessage( + $"/threads/{threadId}/messages/{messageId}/files/{fileId}", + content: null, + context, + RequestMethod.Get); + + internal HttpMessage CreateCreateRunRequest(string threadId, RequestContent content, RequestContext context) + => CreateRequestMessage($"/threads/{threadId}/runs", content, context, RequestMethod.Post); + + internal HttpMessage CreateInternalGetRunsRequest(string threadId, int? limit, string order, string after, string before, RequestContext context) + => CreateRequestMessage( + $"/threads/{threadId}/runs", + content: null, + context, + RequestMethod.Get, + ("limit", $"{(limit.HasValue ? limit.Value : string.Empty)}"), + ("order", order), + ("after", after), + ("before", before)); + + internal HttpMessage CreateRetrieveRunRequest(string threadId, string runId, RequestContext context) + => CreateRequestMessage($"/threads/{threadId}/runs/{runId}", content: null, context, RequestMethod.Get); + + internal HttpMessage CreateModifyRunRequest(string threadId, string runId, RequestContent content, RequestContext context) + => CreateRequestMessage($"/threads/{threadId}/runs/{runId}", content, context, RequestMethod.Post); + internal HttpMessage CreateSubmitRunToolOutputsRequest(string threadId, string runId, RequestContent content, RequestContext context) + => CreateRequestMessage( + $"/threads/{threadId}/runs/{runId}/submit_tool_outputs", + content, + context, + RequestMethod.Post); + + internal HttpMessage CreateCancelRunRequest(string threadId, string runId, RequestContext context) + => CreateRequestMessage($"/threads/{threadId}/runs/{runId}/cancel", content: null, context, RequestMethod.Post); + + internal HttpMessage CreateCreateThreadAndRunRequest(RequestContent content, RequestContext context) + => CreateRequestMessage($"/threads/runs", content, context, RequestMethod.Post); + + internal HttpMessage CreateRetrieveRunStepRequest(string threadId, string runId, string stepId, RequestContext context) + => CreateRequestMessage( + $"/threads/{threadId}/runs/{runId}/steps/{stepId}", + content: null, + context, + RequestMethod.Get); + + internal HttpMessage CreateInternalGetRunStepsRequest(string threadId, string runId, int? limit, string order, string after, string before, RequestContext context) + => CreateRequestMessage( + $"/threads/{threadId}/runs/{runId}/steps", + content: null, + context, + RequestMethod.Get, + ("limit", $"{(limit.HasValue ? limit.Value : string.Empty)}"), + ("order", order), + ("after", after), + ("before", before)); + + internal HttpMessage CreateInternalListFilesRequest(string purpose, RequestContext context) + => CreateRequestMessage("/files", content: null, context, RequestMethod.Get, ("purpose", purpose)); + + internal HttpMessage CreateUploadFileRequest(RequestContent content, RequestContext context) + { + HttpMessage message = CreateRequestMessage("/files", content, context, RequestMethod.Post); + (content as Azure.Core.MultipartFormDataContent).ApplyToRequest(message.Request); + return message; + } + + internal HttpMessage CreateInternalDeleteFileRequest(string fileId, RequestContext context) + => CreateRequestMessage($"/files/{fileId}", content: null, context, RequestMethod.Delete); + + internal HttpMessage CreateRetrieveFileRequest(string fileId, RequestContext context) + => CreateRequestMessage($"/files/{fileId}", content: null, context, RequestMethod.Get); + + internal HttpMessage CreateRetrieveFileContentRequest(string fileId, RequestContext context) + => CreateRequestMessage($"/files/{fileId}/content", content: null, context, RequestMethod.Get); + + private static TokenCredential CreateDelegatedToken(string token) + { + var accessToken = new AccessToken(token, DateTimeOffset.Now.AddDays(180)); + return DelegatedTokenCredential.Create((_, _) => accessToken); + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/AssistantsModelFactory.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/AssistantsModelFactory.cs new file mode 100644 index 000000000000..dd99669d3dfb --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/AssistantsModelFactory.cs @@ -0,0 +1,240 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Linq; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants; + +/* + * CUSTOM CODE DESCRIPTION: + * + * This file restores substantial portions of generated model factory surface lost via type customization and + * visibility adjustments. + */ + +[CodeGenType("AIOpenAIAssistantsModelFactory")] +public static partial class AssistantsModelFactory +{ + /// Initializes a new instance of . + /// The identifier, which can be referenced in API endpoints. + /// The Unix timestamp, in seconds, representing when this object was created. + /// The name of the assistant. + /// The description of the assistant. + /// The ID of the model to use. + /// The system instructions for the assistant to use. + /// The collection of tools enabled for the assistant. + /// A list of attached file IDs, ordered by creation date in ascending order. + /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. + /// A new instance for mocking. + public static Assistant Assistant(string id = null, DateTimeOffset createdAt = default, string name = null, string description = null, string model = null, string instructions = null, IEnumerable tools = null, IEnumerable fileIds = null, IReadOnlyDictionary metadata = null) + { + tools ??= new List(); + fileIds ??= new List(); + metadata ??= new Dictionary(); + + return new Assistant(id, @object: null, createdAt, name, description, model, instructions, tools?.ToList(), fileIds?.ToList(), metadata); + } + + /// Initializes a new instance of . + /// The identifier, which can be referenced in API endpoints. + /// The Unix timestamp, in seconds, representing when this object was created. + /// The assistant ID that the file is attached to. + /// A new instance for mocking. + public static AssistantFile AssistantFile(string id = null, DateTimeOffset createdAt = default, string assistantId = null) + { + return new AssistantFile(id, createdAt, assistantId); + } + + /// Initializes a new instance of . + /// The identifier, which can be referenced in API endpoints. + /// The Unix timestamp, in seconds, representing when this object was created. + /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. + /// A new instance for mocking. + public static AssistantThread AssistantThread(string id = null, DateTimeOffset createdAt = default, IReadOnlyDictionary metadata = null) + { + metadata ??= new Dictionary(); + + return new AssistantThread(id, @object: null, createdAt, metadata); + } + + /// Initializes a new instance of . + /// The identifier, which can be referenced in API endpoints. + /// The Unix timestamp, in seconds, representing when this object was created. + /// The ID of the message that this file is attached to. + /// A new instance for mocking. + public static MessageFile MessageFile(string id = null, DateTimeOffset createdAt = default, string messageId = null) + { + return new MessageFile(id, createdAt, messageId); + } + + /// Initializes a new instance of . + /// The identifier, which can be referenced in API endpoints. + /// The ID of the thread associated with this run. + /// The ID of the assistant associated with the thread this run was performed against. + /// The status of the assistant thread run. + /// The details of the action required for the assistant thread run to continue. + /// The last error, if any, encountered by this assistant thread run. + /// The ID of the model to use. + /// The overridden system instructions used for this assistant thread run. + /// The overridden enabled tools used for this assistant thread run. + /// A list of attached file IDs, ordered by creation date in ascending order. + /// The Unix timestamp, in seconds, representing when this object was created. + /// The Unix timestamp, in seconds, representing when this item expires. + /// The Unix timestamp, in seconds, representing when this item was started. + /// The Unix timestamp, in seconds, representing when this completed. + /// The Unix timestamp, in seconds, representing when this was cancelled. + /// The Unix timestamp, in seconds, representing when this failed. + /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. + /// A new instance for mocking. + public static ThreadRun ThreadRun(string id = null, string threadId = null, string assistantId = null, RunStatus status = default, RequiredAction requiredAction = null, RunError lastError = null, string model = null, string instructions = null, IEnumerable tools = null, IEnumerable fileIds = null, DateTimeOffset createdAt = default, DateTimeOffset? expiresAt = null, DateTimeOffset? startedAt = null, DateTimeOffset? completedAt = null, DateTimeOffset? cancelledAt = null, DateTimeOffset? failedAt = null, IReadOnlyDictionary metadata = null) + { + tools ??= new List(); + fileIds ??= new List(); + metadata ??= new Dictionary(); + + return new ThreadRun(id, @object: null, threadId, assistantId, status, requiredAction, lastError, model, instructions, tools?.ToList(), fileIds?.ToList(), createdAt, expiresAt, startedAt, completedAt, cancelledAt, failedAt, metadata); + } + + /// Initializes a new instance of . + /// The identifier, which can be referenced in API endpoints. + /// The size of the file, in bytes. + /// The name of the file. + /// The Unix timestamp, in seconds, representing when this object was created. + /// The intended purpose of a file. + /// A new instance for mocking. + public static OpenAIFile OpenAIFile(string id = null, int size = default, string filename = null, DateTimeOffset createdAt = default, OpenAIFilePurpose purpose = default) + { + return new OpenAIFile(id, size, filename, createdAt, purpose); + } + + /// Initializes a new instance of . + /// The identifier, which can be referenced in API endpoints. + /// The type of run step, which can be either message_creation or tool_calls. + /// The ID of the assistant associated with the run step. + /// The ID of the thread that was run. + /// The ID of the run that this run step is a part of. + /// The status of this run step. + /// The details for this run step. + /// If applicable, information about the last error encountered by this run step. + /// The Unix timestamp, in seconds, representing when this object was created. + /// The Unix timestamp, in seconds, representing when this item expired. + /// The Unix timestamp, in seconds, representing when this completed. + /// The Unix timestamp, in seconds, representing when this was cancelled. + /// The Unix timestamp, in seconds, representing when this failed. + /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. + /// A new instance for mocking. + public static RunStep RunStep(string id = null, RunStepType type = default, string assistantId = null, string threadId = null, string runId = null, RunStepStatus status = default, RunStepDetails stepDetails = null, RunStepError lastError = null, DateTimeOffset createdAt = default, DateTimeOffset? expiredAt = null, DateTimeOffset? completedAt = null, DateTimeOffset? cancelledAt = null, DateTimeOffset? failedAt = null, IReadOnlyDictionary metadata = null) + { + metadata ??= new Dictionary(); + + return new RunStep(id, @object: null, type, assistantId, threadId, runId, status, stepDetails, lastError, createdAt, expiredAt, completedAt, cancelledAt, failedAt, metadata); + } + + /// Initializes a new instance of . + /// The identifier, which can be referenced in API endpoints. + /// The Unix timestamp, in seconds, representing when this object was created. + /// The ID of the thread that this message belongs to. + /// The role associated with the assistant thread message. + /// The list of content items associated with the assistant thread message. + /// If applicable, the ID of the assistant that authored this message. + /// If applicable, the ID of the run associated with the authoring of this message. + /// + /// A list of file IDs that the assistant should use. Useful for tools like retrieval and code_interpreter that can + /// access files. + /// + /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. + /// A new instance for mocking. + public static ThreadMessage ThreadMessage(string id = null, DateTimeOffset createdAt = default, string threadId = null, MessageRole role = default, IEnumerable contentItems = null, string assistantId = null, string runId = null, IEnumerable fileIds = null, IDictionary metadata = null) + { + contentItems ??= new List(); + fileIds ??= new List(); + metadata ??= new Dictionary(); + + return new ThreadMessage(id, @object: null, createdAt, threadId, role, contentItems?.ToList(), assistantId, runId, fileIds?.ToList(), metadata); + } + + public static FunctionToolCall FunctionToolCall(string id, string name, string arguments, string output) + { + return new FunctionToolCall(id, new InternalFunctionToolCallDetails(name, arguments, output)); + } + + public static CodeInterpreterToolCall CodeInterpreterToolCall(string id, string input, IReadOnlyList outputs) + { + return new CodeInterpreterToolCall(id, new InternalCodeInterpreterToolCallDetails(input, outputs)); + } + + /// + /// Instantiates a new instance of . + /// + /// The tool calls to include in the mocked action. + /// A new instance of SubmitToolOutputsAction. + public static SubmitToolOutputsAction SubmitToolOutputsAction(IEnumerable toolCalls) + { + return new SubmitToolOutputsAction(new InternalSubmitToolOutputsDetails(toolCalls)); + } + + /// + /// Creates a new instance of MessageTextContent. + /// + /// The text for the content item. + /// The annotations for the content item. + /// A new instance of MessageTextContent. + public static MessageTextContent MessageTextContent(string text, IEnumerable annotations) + { + return new MessageTextContent(new InternalMessageTextDetails(text, annotations)); + } + + /// + /// Creates a new instance of MessageImageFileContent. + /// + /// The file ID for the image file content. + /// A new instance of MessageImageFileContent. + public static MessageImageFileContent MessageImageFileContent(string fileId) + { + return new MessageImageFileContent(new InternalMessageImageFileDetails(new InternalMessageImageFileIdDetails(fileId))); + } + + /// + /// Creates a new instance of MessageFileCitationTextAnnotation. + /// + /// The text for the citation. + /// The start index of the citation. + /// The end index of the citation. + /// The file ID for the citation. + /// The quote for the citation. + /// A new instance of MessageFileCitationTextAnnotation. + public static MessageFileCitationTextAnnotation MessageFileCitationTextAnnotation(string text, int startIndex, int endIndex, string fileId, string quote) + { + return new MessageFileCitationTextAnnotation(text, startIndex, endIndex, new InternalMessageTextFileCitationDetails(fileId, quote)); + } + + /// + /// Creates a new instance of MessageFilePathTextAnnotation. + /// + /// The text for the annotation. + /// The start index for the annotation. + /// The end index for the annotation. + /// The file ID for the annotation. + /// A new instance of MessageFilePathTextAnnotation. + public static MessageFilePathTextAnnotation MessageFilePathTextAnnotation(string text, int startIndex, int endIndex, string fileId) + { + return new MessageFilePathTextAnnotation(text, startIndex, endIndex, new InternalMessageFilePathDetails(fileId)); + } + + /// + /// Creates a new instance of PageableList. + /// + /// The data type of the listed items. + /// The items for the list. + /// The ID of the first item in the list. + /// The ID of the last item in the list. + /// Whether more items not included in the list exist. + /// A new instance of PageableList. + public static PageableList PageableList(IReadOnlyList data, string firstId, string lastId, bool hasMore) + => new(data, firstId, lastId, hasMore); +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/CodeInterpreterToolCall.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/CodeInterpreterToolCall.cs new file mode 100644 index 000000000000..1622bb02a815 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/CodeInterpreterToolCall.cs @@ -0,0 +1,26 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +#nullable disable + +using System.Collections.Generic; + +namespace Azure.AI.OpenAI.Assistants; + +/* + * CUSTOM CODE DESCRIPTION: + * + * These changes facilitate the merging of superficial types introduced by the underlying REST wire format. The goal + * is to avoid having types that contain nothing meaningful beyond a property to another type. + */ + +public partial class CodeInterpreterToolCall +{ + /// + public string Input => InternalDetails.Input; + + /// + public IReadOnlyList Outputs => InternalDetails.Outputs; + + internal InternalCodeInterpreterToolCallDetails InternalDetails { get; } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/FunctionToolCall.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/FunctionToolCall.cs new file mode 100644 index 000000000000..155ec30a0cd9 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/FunctionToolCall.cs @@ -0,0 +1,27 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +#nullable disable + +namespace Azure.AI.OpenAI.Assistants; + +/* + * CUSTOM CODE DESCRIPTION: + * + * These changes facilitate the merging of superficial types introduced by the underlying REST wire format. The goal + * is to avoid having types that contain nothing meaningful beyond a property to another type. + */ + +public partial class FunctionToolCall +{ + /// + public string Name => InternalDetails.Name; + + /// + public string Arguments => InternalDetails.Arguments; + + /// + public string Output => InternalDetails.Output; + + internal InternalFunctionToolCallDetails InternalDetails { get; } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/FunctionToolDefinition.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/FunctionToolDefinition.cs new file mode 100644 index 000000000000..69d753460552 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/FunctionToolDefinition.cs @@ -0,0 +1,57 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants; + +/* + * CUSTOM CODE DESCRIPTION: + * + * Used to superficially combine function tool definitions and their vacuous container tool type. + * Before: new FunctionToolDefinition(new FunctionDefinition(name, description, properties)) + * After : new FunctionToolDefinition(name, description, properties) + */ + +[CodeGenSuppress("FunctionToolDefinition", typeof(InternalFunctionDefinition))] +public partial class FunctionToolDefinition +{ + /// + public string Name => InternalFunction.Name; + + /// + public string Description => InternalFunction.Description; + + /// + public BinaryData Parameters => InternalFunction.Parameters; + + /// The definition of the function that the function tool should call. + internal InternalFunctionDefinition InternalFunction { get; set; } + + /// + /// Initializes a new instance of FunctionToolDefinition. + /// + /// The name of the function to be called. + /// A description of what the function does, used by the model to choose when and how to call the function. + /// The parameters the functions accepts, described as a JSON Schema object. + /// , or is null. + public FunctionToolDefinition(string name, string description, BinaryData parameters) + : this(type: "function", new InternalFunctionDefinition(name, description, parameters)) + { + } + + /// + /// Initializes a new instance of FunctionTool for a function that requires no explicit function parameters. + /// + /// The name of the function to be called. + /// A description of what the function does, used by the model to choose when and how to call the function. + /// or is null. + public FunctionToolDefinition(string name, string description) + : this(name, description, BinaryData.FromObjectAsJson(new { type = "object", properties = new { } })) + { } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/MessageFileCitationTextAnnotation.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/MessageFileCitationTextAnnotation.cs new file mode 100644 index 000000000000..aa2fa86ce3bb --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/MessageFileCitationTextAnnotation.cs @@ -0,0 +1,24 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +#nullable disable + +namespace Azure.AI.OpenAI.Assistants; + +/* + * CUSTOM CODE DESCRIPTION: + * + * These changes facilitate the merging of superficial types introduced by the underlying REST wire format. The goal + * is to avoid having types that contain nothing meaningful beyond a property to another type. + */ + +public partial class MessageFileCitationTextAnnotation +{ + /// + public string FileId => InternalDetails.FileId; + + /// + public string Quote => InternalDetails.Quote; + + internal InternalMessageTextFileCitationDetails InternalDetails { get; } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/MessageFilePathTextAnnotation.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/MessageFilePathTextAnnotation.cs new file mode 100644 index 000000000000..99d3678e63ed --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/MessageFilePathTextAnnotation.cs @@ -0,0 +1,21 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +#nullable disable + +namespace Azure.AI.OpenAI.Assistants; + +/* + * CUSTOM CODE DESCRIPTION: + * + * These changes facilitate the merging of superficial types introduced by the underlying REST wire format. The goal + * is to avoid having types that contain nothing meaningful beyond a property to another type. + */ + +public partial class MessageFilePathTextAnnotation : MessageTextAnnotation +{ + /// + public string FileId => InternalDetails.FileId; + + internal InternalMessageFilePathDetails InternalDetails { get; } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/MessageImageFileContent.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/MessageImageFileContent.cs new file mode 100644 index 000000000000..b716d9357f05 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/MessageImageFileContent.cs @@ -0,0 +1,21 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +#nullable disable + +namespace Azure.AI.OpenAI.Assistants; + +/* + * CUSTOM CODE DESCRIPTION: + * + * These changes facilitate the merging of superficial types introduced by the underlying REST wire format. The goal + * is to avoid having types that contain nothing meaningful beyond a property to another type. + */ + +public partial class MessageImageFileContent +{ + /// + public string FileId => InternalDetails.InternalDetails.FileId; + + internal InternalMessageImageFileDetails InternalDetails { get; } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/MessageTextContent.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/MessageTextContent.cs new file mode 100644 index 000000000000..aae145aea500 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/MessageTextContent.cs @@ -0,0 +1,26 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +#nullable disable + +using System.Collections.Generic; + +namespace Azure.AI.OpenAI.Assistants; + +/* + * CUSTOM CODE DESCRIPTION: + * + * These changes facilitate the merging of superficial types introduced by the underlying REST wire format. The goal + * is to avoid having types that contain nothing meaningful beyond a property to another type. + */ + +public partial class MessageTextContent +{ + /// + public string Text => InternalDetails.Text; + + /// + public IReadOnlyList Annotations => (IReadOnlyList)InternalDetails.Annotations; + + internal InternalMessageTextDetails InternalDetails { get; } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/PageableList.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/PageableList.cs new file mode 100644 index 000000000000..b2689dc97e3b --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/PageableList.cs @@ -0,0 +1,80 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +#nullable disable + +using System.Collections.Generic; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants; + +/* + * CUSTOM CODE DESCRIPTION: + * + * This custom type facilitates common use of list types, which don't trivially emit from TypeSpec into an idiomatic + * form. + */ + +/// +/// Represents a pageable list of data items with item ID cursors representing the start and end of the current page. +/// +/// +/// and can be used as inputs into methods that list items to retrieve +/// additional items before or after the current page's view. +/// +/// The type of the data instances contained in the list. +public partial class PageableList +{ + /// The requested list of items. + public IReadOnlyList Data { get; } + /// The first ID represented in this list. + public string FirstId { get; } + /// The last ID represented in this list. + public string LastId { get; } + /// A value indicating whether there are additional values available not captured in this list. + public bool HasMore { get; } + + internal PageableList( + IReadOnlyList data, + string firstId, + string lastId, + bool hasMore) + { + Data = data; + FirstId = firstId; + LastId = lastId; + HasMore = hasMore; + } + + internal static PageableList Create(InternalOpenAIPageableListOfAssistant internalList) + => new(internalList.Data, internalList.FirstId, internalList.LastId, internalList.HasMore); + internal static PageableList Create(InternalOpenAIPageableListOfAssistantFile internalList) + => new(internalList.Data, internalList.FirstId, internalList.LastId, internalList.HasMore); + internal static PageableList Create(InternalOpenAIPageableListOfThreadMessage internalList) + => new(internalList.Data, internalList.FirstId, internalList.LastId, internalList.HasMore); + internal static PageableList Create(InternalOpenAIPageableListOfMessageFile internalList) + => new(internalList.Data, internalList.FirstId, internalList.LastId, internalList.HasMore); + internal static PageableList Create(InternalOpenAIPageableListOfRunStep internalList) + => new(internalList.Data, internalList.FirstId, internalList.LastId, internalList.HasMore); + internal static PageableList Create(InternalOpenAIPageableListOfThreadRun internalList) + => new(internalList.Data, internalList.FirstId, internalList.LastId, internalList.HasMore); +} + +/* + * CUSTOM CODE DESCRIPTION: + * + * Included here for concision, these perform renames of the rerouted types for clarity. + */ + +[CodeGenType("OpenAIPageableListOfAssistant")] +internal partial class InternalOpenAIPageableListOfAssistant { } +[CodeGenType("OpenAIPageableListOfAssistantFile")] +internal partial class InternalOpenAIPageableListOfAssistantFile { } +[CodeGenType("OpenAIPageableListOfThreadMessage")] +internal partial class InternalOpenAIPageableListOfThreadMessage { } +[CodeGenType("OpenAIPageableListOfMessageFile")] +internal partial class InternalOpenAIPageableListOfMessageFile { } +[CodeGenType("OpenAIPageableListOfRunStep")] +internal partial class InternalOpenAIPageableListOfRunStep { } +[CodeGenType("OpenAIPageableListOfThreadRun")] +internal partial class InternalOpenAIPageableListOfThreadRun { } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/README.md b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/README.md new file mode 100644 index 000000000000..9663cdd42c9d --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/README.md @@ -0,0 +1,3 @@ +## Customized code + +This folder contains code that replaces or modifies the behavior of generated code. diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/RunStep.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/RunStep.cs new file mode 100644 index 000000000000..1877ed552d0c --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/RunStep.cs @@ -0,0 +1,40 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +#nullable disable + +using System; +using System.Runtime.CompilerServices; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants; + +public partial class RunStep +{ + /* + * CUSTOM CODE DESCRIPTION: + * + * "Required but nullable" utcDateTime doesn't emit the appropriate deserialization logic by default. + * + */ + + /// The Unix timestamp, in seconds, representing when this item expired. + [CodeGenMemberSerializationHooks(DeserializationValueHook = nameof(DeserializeNullableDateTimeOffset))] + public DateTimeOffset? ExpiredAt { get; } + /// The Unix timestamp, in seconds, representing when this completed. + [CodeGenMemberSerializationHooks(DeserializationValueHook = nameof(DeserializeNullableDateTimeOffset))] + public DateTimeOffset? CompletedAt { get; } + /// The Unix timestamp, in seconds, representing when this was cancelled. + [CodeGenMemberSerializationHooks(DeserializationValueHook = nameof(DeserializeNullableDateTimeOffset))] + public DateTimeOffset? CancelledAt { get; } + /// The Unix timestamp, in seconds, representing when this failed. + [CodeGenMemberSerializationHooks(DeserializationValueHook = nameof(DeserializeNullableDateTimeOffset))] + public DateTimeOffset? FailedAt { get; } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + internal static void DeserializeNullableDateTimeOffset( + JsonProperty property, + ref DateTimeOffset? targetDateTimeOffset) + => CustomSerializationHelpers.DeserializeNullableDateTimeOffset(property, ref targetDateTimeOffset); +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/SubmitToolOutputsAction.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/SubmitToolOutputsAction.cs new file mode 100644 index 000000000000..12ac6ba63aa3 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/SubmitToolOutputsAction.cs @@ -0,0 +1,25 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +#nullable disable + +using System.Collections.Generic; + +namespace Azure.AI.OpenAI.Assistants; + +public partial class SubmitToolOutputsAction : RequiredAction +{ + /* + * CUSTOM CODE DESCRIPTION: + * + * Used to superficially combine function tool calls and their vacuous container type. + * Before: toolOutputsAction.SubmitToolOutputs.ToolCalls + * After : toolOutputsAction.ToolCalls + */ + + /// + public IReadOnlyList ToolCalls => InternalDetails.ToolCalls; + + /// The details describing tools that should be called to submit tool outputs. + internal InternalSubmitToolOutputsDetails InternalDetails { get; } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/ThreadRun.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/ThreadRun.cs new file mode 100644 index 000000000000..3aabc2d70c33 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/ThreadRun.cs @@ -0,0 +1,41 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Runtime.CompilerServices; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants; + +public partial class ThreadRun +{ + /* + * CUSTOM CODE DESCRIPTION: + * + * "Required but nullable" utcDateTime doesn't emit the appropriate deserialization logic by default. + * + */ + + /// The Unix timestamp, in seconds, representing when this item was started. + [CodeGenMemberSerializationHooks(DeserializationValueHook = nameof(DeserializeNullableDateTimeOffset))] + public DateTimeOffset? StartedAt { get; } + /// The Unix timestamp, in seconds, representing when this item expires. + [CodeGenMemberSerializationHooks(DeserializationValueHook = nameof(DeserializeNullableDateTimeOffset))] + public DateTimeOffset? ExpiresAt { get; } + /// The Unix timestamp, in seconds, representing when this completed. + [CodeGenMemberSerializationHooks(DeserializationValueHook = nameof(DeserializeNullableDateTimeOffset))] + public DateTimeOffset? CompletedAt { get; } + /// The Unix timestamp, in seconds, representing when this was cancelled. + [CodeGenMemberSerializationHooks(DeserializationValueHook = nameof(DeserializeNullableDateTimeOffset))] + public DateTimeOffset? CancelledAt { get; } + /// The Unix timestamp, in seconds, representing when this failed. + [CodeGenMemberSerializationHooks(DeserializationValueHook = nameof(DeserializeNullableDateTimeOffset))] + public DateTimeOffset? FailedAt { get; } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + internal static void DeserializeNullableDateTimeOffset( + JsonProperty property, + ref DateTimeOffset? targetDateTimeOffset) + => CustomSerializationHelpers.DeserializeNullableDateTimeOffset(property, ref targetDateTimeOffset); +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/ToolOutput.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/ToolOutput.cs new file mode 100644 index 000000000000..89a3a37e54c9 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/ToolOutput.cs @@ -0,0 +1,56 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +#nullable disable + +namespace Azure.AI.OpenAI.Assistants; + +/* + * CUSTOM CODE DESCRIPTION: + * + * This extends constructor support to allow broader combinations of tool call and output as parameters. + */ + +public partial class ToolOutput +{ + /// Initializes a new instance of . + /// The ID of the tool call being resolved, as provided in the tool calls of a required action from a run. + /// + /// When using this constructor, the property should be set prior to submission. + /// + public ToolOutput(string toolCallId) + { + ToolCallId = toolCallId; + } + + /// Initializes a new instance of . + /// The ID of the tool call being resolved, as provided in the tool calls of a required action from a run. + /// The output from the tool to be submitted. + public ToolOutput(string toolCallId, string output) + { + ToolCallId = toolCallId; + Output = output; + } + + /// Initializes a new instance of . + /// The tool call the output will resolve, as provided in a required action from a run. + /// + /// When using this constructor, the property should be set prior to submission. + /// + public ToolOutput(ToolCall toolCall) + { + ToolCallId = toolCall.Id; + } + + /// Initializes a new instance of . + /// The tool call the output will resolve, as provided in a required action from a run. + /// The output from the tool to be submitted. + /// + /// When using this constructor, the property should be set prior to submission. + /// + public ToolOutput(ToolCall toolCall, string output) + { + ToolCallId = toolCall.Id; + Output = output; + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/UploadFileRequest.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/UploadFileRequest.Serialization.cs new file mode 100644 index 000000000000..807afb6fe54d --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/UploadFileRequest.Serialization.cs @@ -0,0 +1,33 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +#nullable disable + +using System.Collections.Generic; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants; + +internal partial class UploadFileRequest : IUtf8JsonSerializable +{ + /* + * CUSTOM CODE DESCRIPTION: + * + * Manual, custom multipart/form-data serialization needed. + * + */ + + internal virtual RequestContent ToRequestContent() + { + MultipartFormDataContent content = new(); + + content.Add(MultipartContent.Create(Purpose.ToString()), "purpose", new Dictionary()); + content.Add(MultipartContent.Create(Data), new Dictionary() + { + ["Content-Disposition"] = $"form-data; name=file; filename={(string.IsNullOrEmpty(Filename) ? "file" : Filename)}", + ["Content-Type"] = "text/plain", + }); + + return content; + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/Visibility/Assistant.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/Visibility/Assistant.cs new file mode 100644 index 000000000000..2cba0c9f8c48 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/Visibility/Assistant.cs @@ -0,0 +1,17 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +#nullable disable + +namespace Azure.AI.OpenAI.Assistants; + +/* + * CUSTOM CODE DESCRIPTION: + * + * This change allows us to complete the customization of hiding an unnecessary "Object" discriminator. + */ + +public partial class Assistant +{ + internal string Object { get; } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/Visibility/AssistantFile.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/Visibility/AssistantFile.cs new file mode 100644 index 000000000000..79e88df892f4 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/Visibility/AssistantFile.cs @@ -0,0 +1,17 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +#nullable disable + +namespace Azure.AI.OpenAI.Assistants; + +/* + * CUSTOM CODE DESCRIPTION: + * + * This change allows us to complete the customization of hiding an unnecessary "Object" discriminator. + */ + +public partial class AssistantFile +{ + internal string Object { get; } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/Visibility/AssistantThread.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/Visibility/AssistantThread.cs new file mode 100644 index 000000000000..2caceacf79b0 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/Visibility/AssistantThread.cs @@ -0,0 +1,17 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +#nullable disable + +namespace Azure.AI.OpenAI.Assistants; + +/* + * CUSTOM CODE DESCRIPTION: + * + * This change allows us to complete the customization of hiding an unnecessary "Object" discriminator. + */ + +public partial class AssistantThread +{ + internal string Object { get; } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/Visibility/ListSortOrder.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/Visibility/ListSortOrder.cs new file mode 100644 index 000000000000..d7f3aa8e526f --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/Visibility/ListSortOrder.cs @@ -0,0 +1,15 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +#nullable disable + +namespace Azure.AI.OpenAI.Assistants; + +/* + * CUSTOM CODE DESCRIPTION: + * + * Public visibility. @@access decorators don't currently restore this visibility when the consuming methods are + * internalized. + */ + +public readonly partial struct ListSortOrder { } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/Visibility/MessageFile.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/Visibility/MessageFile.cs new file mode 100644 index 000000000000..7dbdb167d2d5 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/Visibility/MessageFile.cs @@ -0,0 +1,17 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +#nullable disable + +namespace Azure.AI.OpenAI.Assistants; + +/* + * CUSTOM CODE DESCRIPTION: + * + * This change allows us to complete the customization of hiding an unnecessary "Object" discriminator. + */ + +public partial class MessageFile +{ + internal string Object { get; } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/Visibility/OpenAIFile.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/Visibility/OpenAIFile.cs new file mode 100644 index 000000000000..2a456d04eb8a --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/Visibility/OpenAIFile.cs @@ -0,0 +1,17 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +#nullable disable + +namespace Azure.AI.OpenAI.Assistants; + +/* + * CUSTOM CODE DESCRIPTION: + * + * This change allows us to complete the customization of hiding an unnecessary "Object" discriminator. + */ + +public partial class OpenAIFile +{ + internal string Object { get; } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/Visibility/RunStep.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/Visibility/RunStep.cs new file mode 100644 index 000000000000..101513228d0b --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/Visibility/RunStep.cs @@ -0,0 +1,17 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +#nullable disable + +namespace Azure.AI.OpenAI.Assistants; + +/* + * CUSTOM CODE DESCRIPTION: + * + * This change allows us to complete the customization of hiding an unnecessary "Object" discriminator. + */ + +public partial class RunStep +{ + internal string Object { get; } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/Visibility/ThreadMessage.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/Visibility/ThreadMessage.cs new file mode 100644 index 000000000000..aa8f2e762ffb --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/Visibility/ThreadMessage.cs @@ -0,0 +1,17 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +#nullable disable + +namespace Azure.AI.OpenAI.Assistants; + +/* + * CUSTOM CODE DESCRIPTION: + * + * This change allows us to complete the customization of hiding an unnecessary "Object" discriminator. + */ + +public partial class ThreadMessage +{ + internal string Object { get; } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/Visibility/ThreadRun.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/Visibility/ThreadRun.cs new file mode 100644 index 000000000000..d903e1fe1f50 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/Visibility/ThreadRun.cs @@ -0,0 +1,17 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +#nullable disable + +namespace Azure.AI.OpenAI.Assistants; + +/* + * CUSTOM CODE DESCRIPTION: + * + * This change allows us to complete the customization of hiding an unnecessary "Object" discriminator. + */ + +public partial class ThreadRun +{ + internal string Object { get; } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AIOpenAIAssistantsClientBuilderExtensions.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AIOpenAIAssistantsClientBuilderExtensions.cs new file mode 100644 index 000000000000..23b1ed7ab371 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AIOpenAIAssistantsClientBuilderExtensions.cs @@ -0,0 +1,46 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using Azure; +using Azure.AI.OpenAI.Assistants; +using Azure.Core.Extensions; + +namespace Microsoft.Extensions.Azure +{ + /// Extension methods to add to client builder. + public static partial class AIOpenAIAssistantsClientBuilderExtensions + { + /// Registers a instance. + /// The builder to register with. + /// An OpenAI endpoint supporting assistants functionality. + /// A credential used to authenticate to an Azure Service. + public static IAzureClientBuilder AddAssistantsClient(this TBuilder builder, Uri endpoint, AzureKeyCredential credential) + where TBuilder : IAzureClientFactoryBuilder + { + return builder.RegisterClientFactory((options) => new AssistantsClient(endpoint, credential, options)); + } + + /// Registers a instance. + /// The builder to register with. + /// An OpenAI endpoint supporting assistants functionality. + public static IAzureClientBuilder AddAssistantsClient(this TBuilder builder, Uri endpoint) + where TBuilder : IAzureClientFactoryBuilderWithCredential + { + return builder.RegisterClientFactory((options, cred) => new AssistantsClient(endpoint, cred, options)); + } + + /// Registers a instance. + /// The builder to register with. + /// The configuration values. + public static IAzureClientBuilder AddAssistantsClient(this TBuilder builder, TConfiguration configuration) + where TBuilder : IAzureClientFactoryBuilderWithConfiguration + { + return builder.RegisterClientFactory(configuration); + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/Assistant.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/Assistant.Serialization.cs new file mode 100644 index 000000000000..3244fd411502 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/Assistant.Serialization.cs @@ -0,0 +1,132 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Text.Json; +using Azure; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class Assistant + { + internal static Assistant DeserializeAssistant(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string id = default; + string @object = default; + DateTimeOffset createdAt = default; + string name = default; + string description = default; + string model = default; + string instructions = default; + IReadOnlyList tools = default; + IReadOnlyList fileIds = default; + Optional> metadata = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("id"u8)) + { + id = property.Value.GetString(); + continue; + } + if (property.NameEquals("object"u8)) + { + @object = property.Value.GetString(); + continue; + } + if (property.NameEquals("created_at"u8)) + { + createdAt = DateTimeOffset.FromUnixTimeSeconds(property.Value.GetInt64()); + continue; + } + if (property.NameEquals("name"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + name = null; + continue; + } + name = property.Value.GetString(); + continue; + } + if (property.NameEquals("description"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + description = null; + continue; + } + description = property.Value.GetString(); + continue; + } + if (property.NameEquals("model"u8)) + { + model = property.Value.GetString(); + continue; + } + if (property.NameEquals("instructions"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + instructions = null; + continue; + } + instructions = property.Value.GetString(); + continue; + } + if (property.NameEquals("tools"u8)) + { + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(ToolDefinition.DeserializeToolDefinition(item)); + } + tools = array; + continue; + } + if (property.NameEquals("file_ids"u8)) + { + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(item.GetString()); + } + fileIds = array; + continue; + } + if (property.NameEquals("metadata"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + Dictionary dictionary = new Dictionary(); + foreach (var property0 in property.Value.EnumerateObject()) + { + dictionary.Add(property0.Name, property0.Value.GetString()); + } + metadata = dictionary; + continue; + } + } + return new Assistant(id, @object, createdAt, name, description, model, instructions, tools, fileIds, Optional.ToDictionary(metadata)); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static Assistant FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeAssistant(document.RootElement); + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/Assistant.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/Assistant.cs new file mode 100644 index 000000000000..aaa2fb2cc2bd --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/Assistant.cs @@ -0,0 +1,95 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Linq; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + /// Represents an assistant that can call the model and use tools. + public partial class Assistant + { + /// Initializes a new instance of . + /// The identifier, which can be referenced in API endpoints. + /// The Unix timestamp, in seconds, representing when this object was created. + /// The name of the assistant. + /// The description of the assistant. + /// The ID of the model to use. + /// The system instructions for the assistant to use. + /// The collection of tools enabled for the assistant. + /// A list of attached file IDs, ordered by creation date in ascending order. + /// , , or is null. + internal Assistant(string id, DateTimeOffset createdAt, string name, string description, string model, string instructions, IEnumerable tools, IEnumerable fileIds) + { + Argument.AssertNotNull(id, nameof(id)); + Argument.AssertNotNull(model, nameof(model)); + Argument.AssertNotNull(tools, nameof(tools)); + Argument.AssertNotNull(fileIds, nameof(fileIds)); + + Id = id; + CreatedAt = createdAt; + Name = name; + Description = description; + Model = model; + Instructions = instructions; + Tools = tools.ToList(); + FileIds = fileIds.ToList(); + Metadata = new ChangeTrackingDictionary(); + } + + /// Initializes a new instance of . + /// The identifier, which can be referenced in API endpoints. + /// The object type, which is always assistant. + /// The Unix timestamp, in seconds, representing when this object was created. + /// The name of the assistant. + /// The description of the assistant. + /// The ID of the model to use. + /// The system instructions for the assistant to use. + /// The collection of tools enabled for the assistant. + /// A list of attached file IDs, ordered by creation date in ascending order. + /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. + internal Assistant(string id, string @object, DateTimeOffset createdAt, string name, string description, string model, string instructions, IReadOnlyList tools, IReadOnlyList fileIds, IReadOnlyDictionary metadata) + { + Id = id; + Object = @object; + CreatedAt = createdAt; + Name = name; + Description = description; + Model = model; + Instructions = instructions; + Tools = tools; + FileIds = fileIds; + Metadata = metadata; + } + + /// The identifier, which can be referenced in API endpoints. + public string Id { get; } + + /// The Unix timestamp, in seconds, representing when this object was created. + public DateTimeOffset CreatedAt { get; } + /// The name of the assistant. + public string Name { get; } + /// The description of the assistant. + public string Description { get; } + /// The ID of the model to use. + public string Model { get; } + /// The system instructions for the assistant to use. + public string Instructions { get; } + /// + /// The collection of tools enabled for the assistant. + /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. + /// The available derived classes include , and . + /// + public IReadOnlyList Tools { get; } + /// A list of attached file IDs, ordered by creation date in ascending order. + public IReadOnlyList FileIds { get; } + /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. + public IReadOnlyDictionary Metadata { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantCreationOptions.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantCreationOptions.Serialization.cs new file mode 100644 index 000000000000..b604cbd3d676 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantCreationOptions.Serialization.cs @@ -0,0 +1,77 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class AssistantCreationOptions : IUtf8JsonSerializable + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + { + writer.WriteStartObject(); + writer.WritePropertyName("model"u8); + writer.WriteStringValue(Model); + if (Optional.IsDefined(Name)) + { + writer.WritePropertyName("name"u8); + writer.WriteStringValue(Name); + } + if (Optional.IsDefined(Description)) + { + writer.WritePropertyName("description"u8); + writer.WriteStringValue(Description); + } + if (Optional.IsDefined(Instructions)) + { + writer.WritePropertyName("instructions"u8); + writer.WriteStringValue(Instructions); + } + if (Optional.IsCollectionDefined(Tools)) + { + writer.WritePropertyName("tools"u8); + writer.WriteStartArray(); + foreach (var item in Tools) + { + writer.WriteObjectValue(item); + } + writer.WriteEndArray(); + } + if (Optional.IsCollectionDefined(FileIds)) + { + writer.WritePropertyName("file_ids"u8); + writer.WriteStartArray(); + foreach (var item in FileIds) + { + writer.WriteStringValue(item); + } + writer.WriteEndArray(); + } + if (Optional.IsCollectionDefined(Metadata)) + { + writer.WritePropertyName("metadata"u8); + writer.WriteStartObject(); + foreach (var item in Metadata) + { + writer.WritePropertyName(item.Key); + writer.WriteStringValue(item.Value); + } + writer.WriteEndObject(); + } + writer.WriteEndObject(); + } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantCreationOptions.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantCreationOptions.cs new file mode 100644 index 000000000000..f9c15db09c22 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantCreationOptions.cs @@ -0,0 +1,68 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + /// The request details to use when creating a new assistant. + public partial class AssistantCreationOptions + { + /// Initializes a new instance of . + /// The ID of the model to use. + /// is null. + public AssistantCreationOptions(string model) + { + Argument.AssertNotNull(model, nameof(model)); + + Model = model; + Tools = new ChangeTrackingList(); + FileIds = new ChangeTrackingList(); + Metadata = new ChangeTrackingDictionary(); + } + + /// Initializes a new instance of . + /// The ID of the model to use. + /// The name of the new assistant. + /// The description of the new assistant. + /// The system instructions for the new assistant to use. + /// The collection of tools to enable for the new assistant. + /// A list of previously uploaded file IDs to attach to the assistant. + /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. + internal AssistantCreationOptions(string model, string name, string description, string instructions, IList tools, IList fileIds, IDictionary metadata) + { + Model = model; + Name = name; + Description = description; + Instructions = instructions; + Tools = tools; + FileIds = fileIds; + Metadata = metadata; + } + + /// The ID of the model to use. + public string Model { get; } + /// The name of the new assistant. + public string Name { get; set; } + /// The description of the new assistant. + public string Description { get; set; } + /// The system instructions for the new assistant to use. + public string Instructions { get; set; } + /// + /// The collection of tools to enable for the new assistant. + /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. + /// The available derived classes include , and . + /// + public IList Tools { get; } + /// A list of previously uploaded file IDs to attach to the assistant. + public IList FileIds { get; } + /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. + public IDictionary Metadata { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantFile.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantFile.Serialization.cs new file mode 100644 index 000000000000..c431007e9da8 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantFile.Serialization.cs @@ -0,0 +1,60 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Text.Json; +using Azure; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class AssistantFile + { + internal static AssistantFile DeserializeAssistantFile(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string id = default; + string @object = default; + DateTimeOffset createdAt = default; + string assistantId = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("id"u8)) + { + id = property.Value.GetString(); + continue; + } + if (property.NameEquals("object"u8)) + { + @object = property.Value.GetString(); + continue; + } + if (property.NameEquals("created_at"u8)) + { + createdAt = DateTimeOffset.FromUnixTimeSeconds(property.Value.GetInt64()); + continue; + } + if (property.NameEquals("assistant_id"u8)) + { + assistantId = property.Value.GetString(); + continue; + } + } + return new AssistantFile(id, @object, createdAt, assistantId); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static AssistantFile FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeAssistantFile(document.RootElement); + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantFile.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantFile.cs new file mode 100644 index 000000000000..7b51df805c7c --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantFile.cs @@ -0,0 +1,52 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + /// Information about a file attached to an assistant, as used by tools that can read files. + public partial class AssistantFile + { + /// Initializes a new instance of . + /// The identifier, which can be referenced in API endpoints. + /// The Unix timestamp, in seconds, representing when this object was created. + /// The assistant ID that the file is attached to. + /// or is null. + internal AssistantFile(string id, DateTimeOffset createdAt, string assistantId) + { + Argument.AssertNotNull(id, nameof(id)); + Argument.AssertNotNull(assistantId, nameof(assistantId)); + + Id = id; + CreatedAt = createdAt; + AssistantId = assistantId; + } + + /// Initializes a new instance of . + /// The identifier, which can be referenced in API endpoints. + /// The object type, which is always 'assistant.file'. + /// The Unix timestamp, in seconds, representing when this object was created. + /// The assistant ID that the file is attached to. + internal AssistantFile(string id, string @object, DateTimeOffset createdAt, string assistantId) + { + Id = id; + Object = @object; + CreatedAt = createdAt; + AssistantId = assistantId; + } + + /// The identifier, which can be referenced in API endpoints. + public string Id { get; } + + /// The Unix timestamp, in seconds, representing when this object was created. + public DateTimeOffset CreatedAt { get; } + /// The assistant ID that the file is attached to. + public string AssistantId { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantModificationOptions.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantModificationOptions.Serialization.cs new file mode 100644 index 000000000000..1058c697c6c0 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantModificationOptions.Serialization.cs @@ -0,0 +1,80 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class AssistantModificationOptions : IUtf8JsonSerializable + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + { + writer.WriteStartObject(); + if (Optional.IsDefined(Model)) + { + writer.WritePropertyName("model"u8); + writer.WriteStringValue(Model); + } + if (Optional.IsDefined(Name)) + { + writer.WritePropertyName("name"u8); + writer.WriteStringValue(Name); + } + if (Optional.IsDefined(Description)) + { + writer.WritePropertyName("description"u8); + writer.WriteStringValue(Description); + } + if (Optional.IsDefined(Instructions)) + { + writer.WritePropertyName("instructions"u8); + writer.WriteStringValue(Instructions); + } + if (Optional.IsCollectionDefined(Tools)) + { + writer.WritePropertyName("tools"u8); + writer.WriteStartArray(); + foreach (var item in Tools) + { + writer.WriteObjectValue(item); + } + writer.WriteEndArray(); + } + if (Optional.IsCollectionDefined(FileIds)) + { + writer.WritePropertyName("file_ids"u8); + writer.WriteStartArray(); + foreach (var item in FileIds) + { + writer.WriteStringValue(item); + } + writer.WriteEndArray(); + } + if (Optional.IsCollectionDefined(Metadata)) + { + writer.WritePropertyName("metadata"u8); + writer.WriteStartObject(); + foreach (var item in Metadata) + { + writer.WritePropertyName(item.Key); + writer.WriteStringValue(item.Value); + } + writer.WriteEndObject(); + } + writer.WriteEndObject(); + } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantModificationOptions.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantModificationOptions.cs new file mode 100644 index 000000000000..f04d34a95ec5 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantModificationOptions.cs @@ -0,0 +1,62 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Collections.Generic; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + /// The request details to use when modifying an existing assistant. + public partial class AssistantModificationOptions + { + /// Initializes a new instance of . + public AssistantModificationOptions() + { + Tools = new ChangeTrackingList(); + FileIds = new ChangeTrackingList(); + Metadata = new ChangeTrackingDictionary(); + } + + /// Initializes a new instance of . + /// The ID of the model to use. + /// The modified name for the assistant to use. + /// The modified description for the assistant to use. + /// The modified system instructions for the new assistant to use. + /// The modified collection of tools to enable for the assistant. + /// The modified list of previously uploaded fileIDs to attach to the assistant. + /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. + internal AssistantModificationOptions(string model, string name, string description, string instructions, IList tools, IList fileIds, IDictionary metadata) + { + Model = model; + Name = name; + Description = description; + Instructions = instructions; + Tools = tools; + FileIds = fileIds; + Metadata = metadata; + } + + /// The ID of the model to use. + public string Model { get; set; } + /// The modified name for the assistant to use. + public string Name { get; set; } + /// The modified description for the assistant to use. + public string Description { get; set; } + /// The modified system instructions for the new assistant to use. + public string Instructions { get; set; } + /// + /// The modified collection of tools to enable for the assistant. + /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. + /// The available derived classes include , and . + /// + public IList Tools { get; } + /// The modified list of previously uploaded fileIDs to attach to the assistant. + public IList FileIds { get; } + /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. + public IDictionary Metadata { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantThread.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantThread.Serialization.cs new file mode 100644 index 000000000000..5d56d9c5129d --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantThread.Serialization.cs @@ -0,0 +1,71 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Text.Json; +using Azure; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class AssistantThread + { + internal static AssistantThread DeserializeAssistantThread(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string id = default; + string @object = default; + DateTimeOffset createdAt = default; + Optional> metadata = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("id"u8)) + { + id = property.Value.GetString(); + continue; + } + if (property.NameEquals("object"u8)) + { + @object = property.Value.GetString(); + continue; + } + if (property.NameEquals("created_at"u8)) + { + createdAt = DateTimeOffset.FromUnixTimeSeconds(property.Value.GetInt64()); + continue; + } + if (property.NameEquals("metadata"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + Dictionary dictionary = new Dictionary(); + foreach (var property0 in property.Value.EnumerateObject()) + { + dictionary.Add(property0.Name, property0.Value.GetString()); + } + metadata = dictionary; + continue; + } + } + return new AssistantThread(id, @object, createdAt, Optional.ToDictionary(metadata)); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static AssistantThread FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeAssistantThread(document.RootElement); + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantThread.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantThread.cs new file mode 100644 index 000000000000..d4d3b9eb86ca --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantThread.cs @@ -0,0 +1,51 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + /// Information about a single thread associated with an assistant. + public partial class AssistantThread + { + /// Initializes a new instance of . + /// The identifier, which can be referenced in API endpoints. + /// The Unix timestamp, in seconds, representing when this object was created. + /// is null. + internal AssistantThread(string id, DateTimeOffset createdAt) + { + Argument.AssertNotNull(id, nameof(id)); + + Id = id; + CreatedAt = createdAt; + Metadata = new ChangeTrackingDictionary(); + } + + /// Initializes a new instance of . + /// The identifier, which can be referenced in API endpoints. + /// The object type, which is always 'thread'. + /// The Unix timestamp, in seconds, representing when this object was created. + /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. + internal AssistantThread(string id, string @object, DateTimeOffset createdAt, IReadOnlyDictionary metadata) + { + Id = id; + Object = @object; + CreatedAt = createdAt; + Metadata = metadata; + } + + /// The identifier, which can be referenced in API endpoints. + public string Id { get; } + + /// The Unix timestamp, in seconds, representing when this object was created. + public DateTimeOffset CreatedAt { get; } + /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. + public IReadOnlyDictionary Metadata { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantThreadCreationOptions.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantThreadCreationOptions.Serialization.cs new file mode 100644 index 000000000000..90cec5f52808 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantThreadCreationOptions.Serialization.cs @@ -0,0 +1,50 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class AssistantThreadCreationOptions : IUtf8JsonSerializable + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + { + writer.WriteStartObject(); + if (Optional.IsCollectionDefined(Messages)) + { + writer.WritePropertyName("messages"u8); + writer.WriteStartArray(); + foreach (var item in Messages) + { + writer.WriteObjectValue(item); + } + writer.WriteEndArray(); + } + if (Optional.IsCollectionDefined(Metadata)) + { + writer.WritePropertyName("metadata"u8); + writer.WriteStartObject(); + foreach (var item in Metadata) + { + writer.WritePropertyName(item.Key); + writer.WriteStringValue(item.Value); + } + writer.WriteEndObject(); + } + writer.WriteEndObject(); + } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantThreadCreationOptions.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantThreadCreationOptions.cs new file mode 100644 index 000000000000..60ec09eb6b42 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantThreadCreationOptions.cs @@ -0,0 +1,37 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Collections.Generic; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + /// The details used to create a new assistant thread. + public partial class AssistantThreadCreationOptions + { + /// Initializes a new instance of . + public AssistantThreadCreationOptions() + { + Messages = new ChangeTrackingList(); + Metadata = new ChangeTrackingDictionary(); + } + + /// Initializes a new instance of . + /// The messages to associate with the new thread. + /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. + internal AssistantThreadCreationOptions(IList messages, IDictionary metadata) + { + Messages = messages; + Metadata = metadata; + } + + /// The messages to associate with the new thread. + public IList Messages { get; } + /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. + public IDictionary Metadata { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsClient.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsClient.cs new file mode 100644 index 000000000000..64452f9d2878 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsClient.cs @@ -0,0 +1,3720 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Core.Pipeline; + +namespace Azure.AI.OpenAI.Assistants +{ + // Data plane generated client. + /// The Assistants service client. + public partial class AssistantsClient + { + private const string AuthorizationHeader = "api-key"; + private readonly AzureKeyCredential _keyCredential; + private static readonly string[] AuthorizationScopes = new string[] { "https://cognitiveservices.azure.com/.default" }; + private readonly TokenCredential _tokenCredential; + private readonly HttpPipeline _pipeline; + private readonly Uri _endpoint; + private readonly string _apiVersion; + + /// The ClientDiagnostics is used to provide tracing support for the client library. + internal ClientDiagnostics ClientDiagnostics { get; } + + /// The HTTP pipeline for sending and receiving REST requests and responses. + public virtual HttpPipeline Pipeline => _pipeline; + + /// Initializes a new instance of AssistantsClient for mocking. + protected AssistantsClient() + { + } + + /// Creates a new assistant. + /// The request details to use when creating a new assistant. + /// The cancellation token to use. + /// is null. + public virtual async Task> CreateAssistantAsync(AssistantCreationOptions assistantCreationOptions, CancellationToken cancellationToken = default) + { + Argument.AssertNotNull(assistantCreationOptions, nameof(assistantCreationOptions)); + + RequestContext context = FromCancellationToken(cancellationToken); + using RequestContent content = assistantCreationOptions.ToRequestContent(); + Response response = await CreateAssistantAsync(content, context).ConfigureAwait(false); + return Response.FromValue(Assistant.FromResponse(response), response); + } + + /// Creates a new assistant. + /// The request details to use when creating a new assistant. + /// The cancellation token to use. + /// is null. + public virtual Response CreateAssistant(AssistantCreationOptions assistantCreationOptions, CancellationToken cancellationToken = default) + { + Argument.AssertNotNull(assistantCreationOptions, nameof(assistantCreationOptions)); + + RequestContext context = FromCancellationToken(cancellationToken); + using RequestContent content = assistantCreationOptions.ToRequestContent(); + Response response = CreateAssistant(content, context); + return Response.FromValue(Assistant.FromResponse(response), response); + } + + /// + /// [Protocol Method] Creates a new assistant. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// The content to send as the body of the request. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual async Task CreateAssistantAsync(RequestContent content, RequestContext context = null) + { + Argument.AssertNotNull(content, nameof(content)); + + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.CreateAssistant"); + scope.Start(); + try + { + using HttpMessage message = CreateCreateAssistantRequest(content, context); + return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// [Protocol Method] Creates a new assistant. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// The content to send as the body of the request. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual Response CreateAssistant(RequestContent content, RequestContext context = null) + { + Argument.AssertNotNull(content, nameof(content)); + + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.CreateAssistant"); + scope.Start(); + try + { + using HttpMessage message = CreateCreateAssistantRequest(content, context); + return _pipeline.ProcessMessage(message, context); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Gets a list of assistants that were previously created. + /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. + /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order. + /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list. + /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. + /// The cancellation token to use. + internal virtual async Task> InternalGetAssistantsAsync(int? limit = null, ListSortOrder? order = null, string after = null, string before = null, CancellationToken cancellationToken = default) + { + RequestContext context = FromCancellationToken(cancellationToken); + Response response = await InternalGetAssistantsAsync(limit, order?.ToString(), after, before, context).ConfigureAwait(false); + return Response.FromValue(InternalOpenAIPageableListOfAssistant.FromResponse(response), response); + } + + /// Gets a list of assistants that were previously created. + /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. + /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order. + /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list. + /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. + /// The cancellation token to use. + internal virtual Response InternalGetAssistants(int? limit = null, ListSortOrder? order = null, string after = null, string before = null, CancellationToken cancellationToken = default) + { + RequestContext context = FromCancellationToken(cancellationToken); + Response response = InternalGetAssistants(limit, order?.ToString(), after, before, context); + return Response.FromValue(InternalOpenAIPageableListOfAssistant.FromResponse(response), response); + } + + /// + /// [Protocol Method] Gets a list of assistants that were previously created. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. + /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order. Allowed values: "asc" | "desc". + /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list. + /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual async Task InternalGetAssistantsAsync(int? limit, string order, string after, string before, RequestContext context) + { + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.InternalGetAssistants"); + scope.Start(); + try + { + using HttpMessage message = CreateInternalGetAssistantsRequest(limit, order, after, before, context); + return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// [Protocol Method] Gets a list of assistants that were previously created. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. + /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order. Allowed values: "asc" | "desc". + /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list. + /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual Response InternalGetAssistants(int? limit, string order, string after, string before, RequestContext context) + { + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.InternalGetAssistants"); + scope.Start(); + try + { + using HttpMessage message = CreateInternalGetAssistantsRequest(limit, order, after, before, context); + return _pipeline.ProcessMessage(message, context); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Retrieves an existing assistant. + /// The ID of the assistant to retrieve. + /// The cancellation token to use. + /// is null. + /// is an empty string, and was expected to be non-empty. + public virtual async Task> RetrieveAssistantAsync(string assistantId, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId)); + + RequestContext context = FromCancellationToken(cancellationToken); + Response response = await RetrieveAssistantAsync(assistantId, context).ConfigureAwait(false); + return Response.FromValue(Assistant.FromResponse(response), response); + } + + /// Retrieves an existing assistant. + /// The ID of the assistant to retrieve. + /// The cancellation token to use. + /// is null. + /// is an empty string, and was expected to be non-empty. + public virtual Response RetrieveAssistant(string assistantId, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId)); + + RequestContext context = FromCancellationToken(cancellationToken); + Response response = RetrieveAssistant(assistantId, context); + return Response.FromValue(Assistant.FromResponse(response), response); + } + + /// + /// [Protocol Method] Retrieves an existing assistant. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// The ID of the assistant to retrieve. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual async Task RetrieveAssistantAsync(string assistantId, RequestContext context) + { + Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId)); + + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.RetrieveAssistant"); + scope.Start(); + try + { + using HttpMessage message = CreateRetrieveAssistantRequest(assistantId, context); + return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// [Protocol Method] Retrieves an existing assistant. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// The ID of the assistant to retrieve. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual Response RetrieveAssistant(string assistantId, RequestContext context) + { + Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId)); + + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.RetrieveAssistant"); + scope.Start(); + try + { + using HttpMessage message = CreateRetrieveAssistantRequest(assistantId, context); + return _pipeline.ProcessMessage(message, context); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Modifies an existing assistant. + /// The ID of the assistant to modify. + /// The details of the modification to perform on the specified assistant. + /// The cancellation token to use. + /// or is null. + /// is an empty string, and was expected to be non-empty. + public virtual async Task> ModifyAssistantAsync(string assistantId, AssistantModificationOptions modificationOptions, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId)); + Argument.AssertNotNull(modificationOptions, nameof(modificationOptions)); + + RequestContext context = FromCancellationToken(cancellationToken); + using RequestContent content = modificationOptions.ToRequestContent(); + Response response = await ModifyAssistantAsync(assistantId, content, context).ConfigureAwait(false); + return Response.FromValue(Assistant.FromResponse(response), response); + } + + /// Modifies an existing assistant. + /// The ID of the assistant to modify. + /// The details of the modification to perform on the specified assistant. + /// The cancellation token to use. + /// or is null. + /// is an empty string, and was expected to be non-empty. + public virtual Response ModifyAssistant(string assistantId, AssistantModificationOptions modificationOptions, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId)); + Argument.AssertNotNull(modificationOptions, nameof(modificationOptions)); + + RequestContext context = FromCancellationToken(cancellationToken); + using RequestContent content = modificationOptions.ToRequestContent(); + Response response = ModifyAssistant(assistantId, content, context); + return Response.FromValue(Assistant.FromResponse(response), response); + } + + /// + /// [Protocol Method] Modifies an existing assistant. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// The ID of the assistant to modify. + /// The content to send as the body of the request. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// or is null. + /// is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual async Task ModifyAssistantAsync(string assistantId, RequestContent content, RequestContext context = null) + { + Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId)); + Argument.AssertNotNull(content, nameof(content)); + + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.ModifyAssistant"); + scope.Start(); + try + { + using HttpMessage message = CreateModifyAssistantRequest(assistantId, content, context); + return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// [Protocol Method] Modifies an existing assistant. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// The ID of the assistant to modify. + /// The content to send as the body of the request. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// or is null. + /// is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual Response ModifyAssistant(string assistantId, RequestContent content, RequestContext context = null) + { + Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId)); + Argument.AssertNotNull(content, nameof(content)); + + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.ModifyAssistant"); + scope.Start(); + try + { + using HttpMessage message = CreateModifyAssistantRequest(assistantId, content, context); + return _pipeline.ProcessMessage(message, context); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Deletes an assistant. + /// The ID of the assistant to delete. + /// The cancellation token to use. + /// is null. + /// is an empty string, and was expected to be non-empty. + internal virtual async Task> InternalDeleteAssistantAsync(string assistantId, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId)); + + RequestContext context = FromCancellationToken(cancellationToken); + Response response = await InternalDeleteAssistantAsync(assistantId, context).ConfigureAwait(false); + return Response.FromValue(InternalAssistantDeletionStatus.FromResponse(response), response); + } + + /// Deletes an assistant. + /// The ID of the assistant to delete. + /// The cancellation token to use. + /// is null. + /// is an empty string, and was expected to be non-empty. + internal virtual Response InternalDeleteAssistant(string assistantId, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId)); + + RequestContext context = FromCancellationToken(cancellationToken); + Response response = InternalDeleteAssistant(assistantId, context); + return Response.FromValue(InternalAssistantDeletionStatus.FromResponse(response), response); + } + + /// + /// [Protocol Method] Deletes an assistant. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The ID of the assistant to delete. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual async Task InternalDeleteAssistantAsync(string assistantId, RequestContext context) + { + Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId)); + + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.InternalDeleteAssistant"); + scope.Start(); + try + { + using HttpMessage message = CreateInternalDeleteAssistantRequest(assistantId, context); + return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// [Protocol Method] Deletes an assistant. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The ID of the assistant to delete. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual Response InternalDeleteAssistant(string assistantId, RequestContext context) + { + Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId)); + + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.InternalDeleteAssistant"); + scope.Start(); + try + { + using HttpMessage message = CreateInternalDeleteAssistantRequest(assistantId, context); + return _pipeline.ProcessMessage(message, context); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Attaches a previously uploaded file to an assistant for use by tools that can read files. + /// The ID of the assistant to attach the file to. + /// The ID of the previously uploaded file to attach. + /// The cancellation token to use. + /// or is null. + /// is an empty string, and was expected to be non-empty. + public virtual async Task> LinkAssistantFileAsync(string assistantId, string fileId, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId)); + Argument.AssertNotNull(fileId, nameof(fileId)); + + RequestContext context = FromCancellationToken(cancellationToken); + CreateAssistantFileRequest createAssistantFileRequest = new CreateAssistantFileRequest(fileId); + Response response = await LinkAssistantFileAsync(assistantId, createAssistantFileRequest.ToRequestContent(), context).ConfigureAwait(false); + return Response.FromValue(AssistantFile.FromResponse(response), response); + } + + /// Attaches a previously uploaded file to an assistant for use by tools that can read files. + /// The ID of the assistant to attach the file to. + /// The ID of the previously uploaded file to attach. + /// The cancellation token to use. + /// or is null. + /// is an empty string, and was expected to be non-empty. + public virtual Response LinkAssistantFile(string assistantId, string fileId, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId)); + Argument.AssertNotNull(fileId, nameof(fileId)); + + RequestContext context = FromCancellationToken(cancellationToken); + CreateAssistantFileRequest createAssistantFileRequest = new CreateAssistantFileRequest(fileId); + Response response = LinkAssistantFile(assistantId, createAssistantFileRequest.ToRequestContent(), context); + return Response.FromValue(AssistantFile.FromResponse(response), response); + } + + /// + /// [Protocol Method] Attaches a previously uploaded file to an assistant for use by tools that can read files. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// The ID of the assistant to attach the file to. + /// The content to send as the body of the request. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// or is null. + /// is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual async Task LinkAssistantFileAsync(string assistantId, RequestContent content, RequestContext context = null) + { + Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId)); + Argument.AssertNotNull(content, nameof(content)); + + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.LinkAssistantFile"); + scope.Start(); + try + { + using HttpMessage message = CreateLinkAssistantFileRequest(assistantId, content, context); + return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// [Protocol Method] Attaches a previously uploaded file to an assistant for use by tools that can read files. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// The ID of the assistant to attach the file to. + /// The content to send as the body of the request. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// or is null. + /// is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual Response LinkAssistantFile(string assistantId, RequestContent content, RequestContext context = null) + { + Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId)); + Argument.AssertNotNull(content, nameof(content)); + + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.LinkAssistantFile"); + scope.Start(); + try + { + using HttpMessage message = CreateLinkAssistantFileRequest(assistantId, content, context); + return _pipeline.ProcessMessage(message, context); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Gets a list of files attached to a specific assistant, as used by tools that can read files. + /// The ID of the assistant to retrieve the list of attached files for. + /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. + /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order. + /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list. + /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. + /// The cancellation token to use. + /// is null. + /// is an empty string, and was expected to be non-empty. + internal virtual async Task> InternalGetAssistantFilesAsync(string assistantId, int? limit = null, ListSortOrder? order = null, string after = null, string before = null, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId)); + + RequestContext context = FromCancellationToken(cancellationToken); + Response response = await InternalGetAssistantFilesAsync(assistantId, limit, order?.ToString(), after, before, context).ConfigureAwait(false); + return Response.FromValue(InternalOpenAIPageableListOfAssistantFile.FromResponse(response), response); + } + + /// Gets a list of files attached to a specific assistant, as used by tools that can read files. + /// The ID of the assistant to retrieve the list of attached files for. + /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. + /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order. + /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list. + /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. + /// The cancellation token to use. + /// is null. + /// is an empty string, and was expected to be non-empty. + internal virtual Response InternalGetAssistantFiles(string assistantId, int? limit = null, ListSortOrder? order = null, string after = null, string before = null, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId)); + + RequestContext context = FromCancellationToken(cancellationToken); + Response response = InternalGetAssistantFiles(assistantId, limit, order?.ToString(), after, before, context); + return Response.FromValue(InternalOpenAIPageableListOfAssistantFile.FromResponse(response), response); + } + + /// + /// [Protocol Method] Gets a list of files attached to a specific assistant, as used by tools that can read files. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The ID of the assistant to retrieve the list of attached files for. + /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. + /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order. Allowed values: "asc" | "desc". + /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list. + /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual async Task InternalGetAssistantFilesAsync(string assistantId, int? limit, string order, string after, string before, RequestContext context) + { + Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId)); + + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.InternalGetAssistantFiles"); + scope.Start(); + try + { + using HttpMessage message = CreateInternalGetAssistantFilesRequest(assistantId, limit, order, after, before, context); + return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// [Protocol Method] Gets a list of files attached to a specific assistant, as used by tools that can read files. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The ID of the assistant to retrieve the list of attached files for. + /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. + /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order. Allowed values: "asc" | "desc". + /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list. + /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual Response InternalGetAssistantFiles(string assistantId, int? limit, string order, string after, string before, RequestContext context) + { + Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId)); + + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.InternalGetAssistantFiles"); + scope.Start(); + try + { + using HttpMessage message = CreateInternalGetAssistantFilesRequest(assistantId, limit, order, after, before, context); + return _pipeline.ProcessMessage(message, context); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Retrieves a file attached to an assistant. + /// The ID of the assistant associated with the attached file. + /// The ID of the file to retrieve. + /// The cancellation token to use. + /// or is null. + /// or is an empty string, and was expected to be non-empty. + public virtual async Task> RetrieveAssistantFileAsync(string assistantId, string fileId, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId)); + Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); + + RequestContext context = FromCancellationToken(cancellationToken); + Response response = await RetrieveAssistantFileAsync(assistantId, fileId, context).ConfigureAwait(false); + return Response.FromValue(AssistantFile.FromResponse(response), response); + } + + /// Retrieves a file attached to an assistant. + /// The ID of the assistant associated with the attached file. + /// The ID of the file to retrieve. + /// The cancellation token to use. + /// or is null. + /// or is an empty string, and was expected to be non-empty. + public virtual Response RetrieveAssistantFile(string assistantId, string fileId, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId)); + Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); + + RequestContext context = FromCancellationToken(cancellationToken); + Response response = RetrieveAssistantFile(assistantId, fileId, context); + return Response.FromValue(AssistantFile.FromResponse(response), response); + } + + /// + /// [Protocol Method] Retrieves a file attached to an assistant. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// The ID of the assistant associated with the attached file. + /// The ID of the file to retrieve. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// or is null. + /// or is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual async Task RetrieveAssistantFileAsync(string assistantId, string fileId, RequestContext context) + { + Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId)); + Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); + + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.RetrieveAssistantFile"); + scope.Start(); + try + { + using HttpMessage message = CreateRetrieveAssistantFileRequest(assistantId, fileId, context); + return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// [Protocol Method] Retrieves a file attached to an assistant. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// The ID of the assistant associated with the attached file. + /// The ID of the file to retrieve. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// or is null. + /// or is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual Response RetrieveAssistantFile(string assistantId, string fileId, RequestContext context) + { + Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId)); + Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); + + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.RetrieveAssistantFile"); + scope.Start(); + try + { + using HttpMessage message = CreateRetrieveAssistantFileRequest(assistantId, fileId, context); + return _pipeline.ProcessMessage(message, context); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// Unlinks a previously attached file from an assistant, rendering it unavailable for use by tools that can read + /// files. + /// + /// The ID of the assistant from which the specified file should be unlinked. + /// The ID of the file to unlink from the specified assistant. + /// The cancellation token to use. + /// or is null. + /// or is an empty string, and was expected to be non-empty. + internal virtual async Task> InternalUnlinkAssistantFileAsync(string assistantId, string fileId, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId)); + Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); + + RequestContext context = FromCancellationToken(cancellationToken); + Response response = await InternalUnlinkAssistantFileAsync(assistantId, fileId, context).ConfigureAwait(false); + return Response.FromValue(InternalAssistantFileDeletionStatus.FromResponse(response), response); + } + + /// + /// Unlinks a previously attached file from an assistant, rendering it unavailable for use by tools that can read + /// files. + /// + /// The ID of the assistant from which the specified file should be unlinked. + /// The ID of the file to unlink from the specified assistant. + /// The cancellation token to use. + /// or is null. + /// or is an empty string, and was expected to be non-empty. + internal virtual Response InternalUnlinkAssistantFile(string assistantId, string fileId, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId)); + Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); + + RequestContext context = FromCancellationToken(cancellationToken); + Response response = InternalUnlinkAssistantFile(assistantId, fileId, context); + return Response.FromValue(InternalAssistantFileDeletionStatus.FromResponse(response), response); + } + + /// + /// [Protocol Method] Unlinks a previously attached file from an assistant, rendering it unavailable for use by tools that can read + /// files. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The ID of the assistant from which the specified file should be unlinked. + /// The ID of the file to unlink from the specified assistant. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// or is null. + /// or is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual async Task InternalUnlinkAssistantFileAsync(string assistantId, string fileId, RequestContext context) + { + Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId)); + Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); + + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.InternalUnlinkAssistantFile"); + scope.Start(); + try + { + using HttpMessage message = CreateInternalUnlinkAssistantFileRequest(assistantId, fileId, context); + return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// [Protocol Method] Unlinks a previously attached file from an assistant, rendering it unavailable for use by tools that can read + /// files. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The ID of the assistant from which the specified file should be unlinked. + /// The ID of the file to unlink from the specified assistant. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// or is null. + /// or is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual Response InternalUnlinkAssistantFile(string assistantId, string fileId, RequestContext context) + { + Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId)); + Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); + + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.InternalUnlinkAssistantFile"); + scope.Start(); + try + { + using HttpMessage message = CreateInternalUnlinkAssistantFileRequest(assistantId, fileId, context); + return _pipeline.ProcessMessage(message, context); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Creates a new thread. Threads contain messages and can be run by assistants. + /// The details used to create a new assistant thread. + /// The cancellation token to use. + /// is null. + public virtual async Task> CreateThreadAsync(AssistantThreadCreationOptions assistantThreadCreationOptions, CancellationToken cancellationToken = default) + { + Argument.AssertNotNull(assistantThreadCreationOptions, nameof(assistantThreadCreationOptions)); + + RequestContext context = FromCancellationToken(cancellationToken); + using RequestContent content = assistantThreadCreationOptions.ToRequestContent(); + Response response = await CreateThreadAsync(content, context).ConfigureAwait(false); + return Response.FromValue(AssistantThread.FromResponse(response), response); + } + + /// Creates a new thread. Threads contain messages and can be run by assistants. + /// The details used to create a new assistant thread. + /// The cancellation token to use. + /// is null. + public virtual Response CreateThread(AssistantThreadCreationOptions assistantThreadCreationOptions, CancellationToken cancellationToken = default) + { + Argument.AssertNotNull(assistantThreadCreationOptions, nameof(assistantThreadCreationOptions)); + + RequestContext context = FromCancellationToken(cancellationToken); + using RequestContent content = assistantThreadCreationOptions.ToRequestContent(); + Response response = CreateThread(content, context); + return Response.FromValue(AssistantThread.FromResponse(response), response); + } + + /// + /// [Protocol Method] Creates a new thread. Threads contain messages and can be run by assistants. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// The content to send as the body of the request. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual async Task CreateThreadAsync(RequestContent content, RequestContext context = null) + { + Argument.AssertNotNull(content, nameof(content)); + + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.CreateThread"); + scope.Start(); + try + { + using HttpMessage message = CreateCreateThreadRequest(content, context); + return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// [Protocol Method] Creates a new thread. Threads contain messages and can be run by assistants. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// The content to send as the body of the request. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual Response CreateThread(RequestContent content, RequestContext context = null) + { + Argument.AssertNotNull(content, nameof(content)); + + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.CreateThread"); + scope.Start(); + try + { + using HttpMessage message = CreateCreateThreadRequest(content, context); + return _pipeline.ProcessMessage(message, context); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Gets information about an existing thread. + /// The ID of the thread to retrieve information about. + /// The cancellation token to use. + /// is null. + /// is an empty string, and was expected to be non-empty. + public virtual async Task> RetrieveThreadAsync(string threadId, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + + RequestContext context = FromCancellationToken(cancellationToken); + Response response = await RetrieveThreadAsync(threadId, context).ConfigureAwait(false); + return Response.FromValue(AssistantThread.FromResponse(response), response); + } + + /// Gets information about an existing thread. + /// The ID of the thread to retrieve information about. + /// The cancellation token to use. + /// is null. + /// is an empty string, and was expected to be non-empty. + public virtual Response RetrieveThread(string threadId, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + + RequestContext context = FromCancellationToken(cancellationToken); + Response response = RetrieveThread(threadId, context); + return Response.FromValue(AssistantThread.FromResponse(response), response); + } + + /// + /// [Protocol Method] Gets information about an existing thread. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// The ID of the thread to retrieve information about. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual async Task RetrieveThreadAsync(string threadId, RequestContext context) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.RetrieveThread"); + scope.Start(); + try + { + using HttpMessage message = CreateRetrieveThreadRequest(threadId, context); + return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// [Protocol Method] Gets information about an existing thread. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// The ID of the thread to retrieve information about. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual Response RetrieveThread(string threadId, RequestContext context) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.RetrieveThread"); + scope.Start(); + try + { + using HttpMessage message = CreateRetrieveThreadRequest(threadId, context); + return _pipeline.ProcessMessage(message, context); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Modifies an existing thread. + /// The ID of the thread to modify. + /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. + /// The cancellation token to use. + /// is null. + /// is an empty string, and was expected to be non-empty. + public virtual async Task> ModifyThreadAsync(string threadId, IDictionary metadata = null, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + + RequestContext context = FromCancellationToken(cancellationToken); + ModifyThreadRequest modifyThreadRequest = new ModifyThreadRequest(); + if (metadata != null) + { + foreach (var value in metadata) + { + modifyThreadRequest.Metadata.Add(value); + } + } + ModifyThreadRequest modifyThreadRequest0 = modifyThreadRequest; + Response response = await ModifyThreadAsync(threadId, modifyThreadRequest0.ToRequestContent(), context).ConfigureAwait(false); + return Response.FromValue(AssistantThread.FromResponse(response), response); + } + + /// Modifies an existing thread. + /// The ID of the thread to modify. + /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. + /// The cancellation token to use. + /// is null. + /// is an empty string, and was expected to be non-empty. + public virtual Response ModifyThread(string threadId, IDictionary metadata = null, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + + RequestContext context = FromCancellationToken(cancellationToken); + ModifyThreadRequest modifyThreadRequest = new ModifyThreadRequest(); + if (metadata != null) + { + foreach (var value in metadata) + { + modifyThreadRequest.Metadata.Add(value); + } + } + ModifyThreadRequest modifyThreadRequest0 = modifyThreadRequest; + Response response = ModifyThread(threadId, modifyThreadRequest0.ToRequestContent(), context); + return Response.FromValue(AssistantThread.FromResponse(response), response); + } + + /// + /// [Protocol Method] Modifies an existing thread. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// The ID of the thread to modify. + /// The content to send as the body of the request. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// or is null. + /// is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual async Task ModifyThreadAsync(string threadId, RequestContent content, RequestContext context = null) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + Argument.AssertNotNull(content, nameof(content)); + + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.ModifyThread"); + scope.Start(); + try + { + using HttpMessage message = CreateModifyThreadRequest(threadId, content, context); + return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// [Protocol Method] Modifies an existing thread. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// The ID of the thread to modify. + /// The content to send as the body of the request. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// or is null. + /// is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual Response ModifyThread(string threadId, RequestContent content, RequestContext context = null) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + Argument.AssertNotNull(content, nameof(content)); + + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.ModifyThread"); + scope.Start(); + try + { + using HttpMessage message = CreateModifyThreadRequest(threadId, content, context); + return _pipeline.ProcessMessage(message, context); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Deletes an existing thread. + /// The ID of the thread to delete. + /// The cancellation token to use. + /// is null. + /// is an empty string, and was expected to be non-empty. + internal virtual async Task> InternalDeleteThreadAsync(string threadId, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + + RequestContext context = FromCancellationToken(cancellationToken); + Response response = await InternalDeleteThreadAsync(threadId, context).ConfigureAwait(false); + return Response.FromValue(ThreadDeletionStatus.FromResponse(response), response); + } + + /// Deletes an existing thread. + /// The ID of the thread to delete. + /// The cancellation token to use. + /// is null. + /// is an empty string, and was expected to be non-empty. + internal virtual Response InternalDeleteThread(string threadId, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + + RequestContext context = FromCancellationToken(cancellationToken); + Response response = InternalDeleteThread(threadId, context); + return Response.FromValue(ThreadDeletionStatus.FromResponse(response), response); + } + + /// + /// [Protocol Method] Deletes an existing thread. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The ID of the thread to delete. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual async Task InternalDeleteThreadAsync(string threadId, RequestContext context) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.InternalDeleteThread"); + scope.Start(); + try + { + using HttpMessage message = CreateInternalDeleteThreadRequest(threadId, context); + return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// [Protocol Method] Deletes an existing thread. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The ID of the thread to delete. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual Response InternalDeleteThread(string threadId, RequestContext context) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.InternalDeleteThread"); + scope.Start(); + try + { + using HttpMessage message = CreateInternalDeleteThreadRequest(threadId, context); + return _pipeline.ProcessMessage(message, context); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Creates a new message on a specified thread. + /// The ID of the thread to create the new message on. + /// The role to associate with the new message. + /// The textual content for the new message. + /// A list of up to 10 file IDs to associate with the message, as used by tools like 'code_interpreter' or 'retrieval' that can read files. + /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. + /// The cancellation token to use. + /// or is null. + /// is an empty string, and was expected to be non-empty. + public virtual async Task> CreateMessageAsync(string threadId, MessageRole role, string content, IEnumerable fileIds = null, IDictionary metadata = null, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + Argument.AssertNotNull(content, nameof(content)); + + RequestContext context = FromCancellationToken(cancellationToken); + CreateMessageRequest createMessageRequest = new CreateMessageRequest(role, content); + if (fileIds != null) + { + foreach (var value in fileIds) + { + createMessageRequest.FileIds.Add(value); + } + } + if (metadata != null) + { + foreach (var value in metadata) + { + createMessageRequest.Metadata.Add(value); + } + } + CreateMessageRequest createMessageRequest0 = createMessageRequest; + Response response = await CreateMessageAsync(threadId, createMessageRequest0.ToRequestContent(), context).ConfigureAwait(false); + return Response.FromValue(ThreadMessage.FromResponse(response), response); + } + + /// Creates a new message on a specified thread. + /// The ID of the thread to create the new message on. + /// The role to associate with the new message. + /// The textual content for the new message. + /// A list of up to 10 file IDs to associate with the message, as used by tools like 'code_interpreter' or 'retrieval' that can read files. + /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. + /// The cancellation token to use. + /// or is null. + /// is an empty string, and was expected to be non-empty. + public virtual Response CreateMessage(string threadId, MessageRole role, string content, IEnumerable fileIds = null, IDictionary metadata = null, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + Argument.AssertNotNull(content, nameof(content)); + + RequestContext context = FromCancellationToken(cancellationToken); + CreateMessageRequest createMessageRequest = new CreateMessageRequest(role, content); + if (fileIds != null) + { + foreach (var value in fileIds) + { + createMessageRequest.FileIds.Add(value); + } + } + if (metadata != null) + { + foreach (var value in metadata) + { + createMessageRequest.Metadata.Add(value); + } + } + CreateMessageRequest createMessageRequest0 = createMessageRequest; + Response response = CreateMessage(threadId, createMessageRequest0.ToRequestContent(), context); + return Response.FromValue(ThreadMessage.FromResponse(response), response); + } + + /// + /// [Protocol Method] Creates a new message on a specified thread. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// The ID of the thread to create the new message on. + /// The content to send as the body of the request. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// or is null. + /// is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual async Task CreateMessageAsync(string threadId, RequestContent content, RequestContext context = null) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + Argument.AssertNotNull(content, nameof(content)); + + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.CreateMessage"); + scope.Start(); + try + { + using HttpMessage message = CreateCreateMessageRequest(threadId, content, context); + return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// [Protocol Method] Creates a new message on a specified thread. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// The ID of the thread to create the new message on. + /// The content to send as the body of the request. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// or is null. + /// is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual Response CreateMessage(string threadId, RequestContent content, RequestContext context = null) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + Argument.AssertNotNull(content, nameof(content)); + + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.CreateMessage"); + scope.Start(); + try + { + using HttpMessage message = CreateCreateMessageRequest(threadId, content, context); + return _pipeline.ProcessMessage(message, context); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Gets a list of messages that exist on a thread. + /// The ID of the thread to list messages from. + /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. + /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order. + /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list. + /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. + /// The cancellation token to use. + /// is null. + /// is an empty string, and was expected to be non-empty. + internal virtual async Task> InternalGetMessagesAsync(string threadId, int? limit = null, ListSortOrder? order = null, string after = null, string before = null, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + + RequestContext context = FromCancellationToken(cancellationToken); + Response response = await InternalGetMessagesAsync(threadId, limit, order?.ToString(), after, before, context).ConfigureAwait(false); + return Response.FromValue(InternalOpenAIPageableListOfThreadMessage.FromResponse(response), response); + } + + /// Gets a list of messages that exist on a thread. + /// The ID of the thread to list messages from. + /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. + /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order. + /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list. + /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. + /// The cancellation token to use. + /// is null. + /// is an empty string, and was expected to be non-empty. + internal virtual Response InternalGetMessages(string threadId, int? limit = null, ListSortOrder? order = null, string after = null, string before = null, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + + RequestContext context = FromCancellationToken(cancellationToken); + Response response = InternalGetMessages(threadId, limit, order?.ToString(), after, before, context); + return Response.FromValue(InternalOpenAIPageableListOfThreadMessage.FromResponse(response), response); + } + + /// + /// [Protocol Method] Gets a list of messages that exist on a thread. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The ID of the thread to list messages from. + /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. + /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order. Allowed values: "asc" | "desc". + /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list. + /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual async Task InternalGetMessagesAsync(string threadId, int? limit, string order, string after, string before, RequestContext context) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.InternalGetMessages"); + scope.Start(); + try + { + using HttpMessage message = CreateInternalGetMessagesRequest(threadId, limit, order, after, before, context); + return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// [Protocol Method] Gets a list of messages that exist on a thread. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The ID of the thread to list messages from. + /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. + /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order. Allowed values: "asc" | "desc". + /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list. + /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual Response InternalGetMessages(string threadId, int? limit, string order, string after, string before, RequestContext context) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.InternalGetMessages"); + scope.Start(); + try + { + using HttpMessage message = CreateInternalGetMessagesRequest(threadId, limit, order, after, before, context); + return _pipeline.ProcessMessage(message, context); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Gets an existing message from an existing thread. + /// The ID of the thread to retrieve the specified message from. + /// The ID of the message to retrieve from the specified thread. + /// The cancellation token to use. + /// or is null. + /// or is an empty string, and was expected to be non-empty. + public virtual async Task> RetrieveMessageAsync(string threadId, string messageId, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + Argument.AssertNotNullOrEmpty(messageId, nameof(messageId)); + + RequestContext context = FromCancellationToken(cancellationToken); + Response response = await RetrieveMessageAsync(threadId, messageId, context).ConfigureAwait(false); + return Response.FromValue(ThreadMessage.FromResponse(response), response); + } + + /// Gets an existing message from an existing thread. + /// The ID of the thread to retrieve the specified message from. + /// The ID of the message to retrieve from the specified thread. + /// The cancellation token to use. + /// or is null. + /// or is an empty string, and was expected to be non-empty. + public virtual Response RetrieveMessage(string threadId, string messageId, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + Argument.AssertNotNullOrEmpty(messageId, nameof(messageId)); + + RequestContext context = FromCancellationToken(cancellationToken); + Response response = RetrieveMessage(threadId, messageId, context); + return Response.FromValue(ThreadMessage.FromResponse(response), response); + } + + /// + /// [Protocol Method] Gets an existing message from an existing thread. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// The ID of the thread to retrieve the specified message from. + /// The ID of the message to retrieve from the specified thread. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// or is null. + /// or is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual async Task RetrieveMessageAsync(string threadId, string messageId, RequestContext context) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + Argument.AssertNotNullOrEmpty(messageId, nameof(messageId)); + + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.RetrieveMessage"); + scope.Start(); + try + { + using HttpMessage message = CreateRetrieveMessageRequest(threadId, messageId, context); + return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// [Protocol Method] Gets an existing message from an existing thread. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// The ID of the thread to retrieve the specified message from. + /// The ID of the message to retrieve from the specified thread. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// or is null. + /// or is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual Response RetrieveMessage(string threadId, string messageId, RequestContext context) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + Argument.AssertNotNullOrEmpty(messageId, nameof(messageId)); + + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.RetrieveMessage"); + scope.Start(); + try + { + using HttpMessage message = CreateRetrieveMessageRequest(threadId, messageId, context); + return _pipeline.ProcessMessage(message, context); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Modifies an existing message on an existing thread. + /// The ID of the thread containing the specified message to modify. + /// The ID of the message to modify on the specified thread. + /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. + /// The cancellation token to use. + /// or is null. + /// or is an empty string, and was expected to be non-empty. + public virtual async Task> ModifyMessageAsync(string threadId, string messageId, IDictionary metadata = null, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + Argument.AssertNotNullOrEmpty(messageId, nameof(messageId)); + + RequestContext context = FromCancellationToken(cancellationToken); + ModifyMessageRequest modifyMessageRequest = new ModifyMessageRequest(); + if (metadata != null) + { + foreach (var value in metadata) + { + modifyMessageRequest.Metadata.Add(value); + } + } + ModifyMessageRequest modifyMessageRequest0 = modifyMessageRequest; + Response response = await ModifyMessageAsync(threadId, messageId, modifyMessageRequest0.ToRequestContent(), context).ConfigureAwait(false); + return Response.FromValue(ThreadMessage.FromResponse(response), response); + } + + /// Modifies an existing message on an existing thread. + /// The ID of the thread containing the specified message to modify. + /// The ID of the message to modify on the specified thread. + /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. + /// The cancellation token to use. + /// or is null. + /// or is an empty string, and was expected to be non-empty. + public virtual Response ModifyMessage(string threadId, string messageId, IDictionary metadata = null, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + Argument.AssertNotNullOrEmpty(messageId, nameof(messageId)); + + RequestContext context = FromCancellationToken(cancellationToken); + ModifyMessageRequest modifyMessageRequest = new ModifyMessageRequest(); + if (metadata != null) + { + foreach (var value in metadata) + { + modifyMessageRequest.Metadata.Add(value); + } + } + ModifyMessageRequest modifyMessageRequest0 = modifyMessageRequest; + Response response = ModifyMessage(threadId, messageId, modifyMessageRequest0.ToRequestContent(), context); + return Response.FromValue(ThreadMessage.FromResponse(response), response); + } + + /// + /// [Protocol Method] Modifies an existing message on an existing thread. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// The ID of the thread containing the specified message to modify. + /// The ID of the message to modify on the specified thread. + /// The content to send as the body of the request. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// , or is null. + /// or is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual async Task ModifyMessageAsync(string threadId, string messageId, RequestContent content, RequestContext context = null) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + Argument.AssertNotNullOrEmpty(messageId, nameof(messageId)); + Argument.AssertNotNull(content, nameof(content)); + + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.ModifyMessage"); + scope.Start(); + try + { + using HttpMessage message = CreateModifyMessageRequest(threadId, messageId, content, context); + return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// [Protocol Method] Modifies an existing message on an existing thread. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// The ID of the thread containing the specified message to modify. + /// The ID of the message to modify on the specified thread. + /// The content to send as the body of the request. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// , or is null. + /// or is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual Response ModifyMessage(string threadId, string messageId, RequestContent content, RequestContext context = null) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + Argument.AssertNotNullOrEmpty(messageId, nameof(messageId)); + Argument.AssertNotNull(content, nameof(content)); + + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.ModifyMessage"); + scope.Start(); + try + { + using HttpMessage message = CreateModifyMessageRequest(threadId, messageId, content, context); + return _pipeline.ProcessMessage(message, context); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Gets a list of previously uploaded files associated with a message from a thread. + /// The ID of the thread containing the message to list files from. + /// The ID of the message to list files from. + /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. + /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order. + /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list. + /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. + /// The cancellation token to use. + /// or is null. + /// or is an empty string, and was expected to be non-empty. + internal virtual async Task> InternalGetMessageFilesAsync(string threadId, string messageId, int? limit = null, ListSortOrder? order = null, string after = null, string before = null, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + Argument.AssertNotNullOrEmpty(messageId, nameof(messageId)); + + RequestContext context = FromCancellationToken(cancellationToken); + Response response = await InternalGetMessageFilesAsync(threadId, messageId, limit, order?.ToString(), after, before, context).ConfigureAwait(false); + return Response.FromValue(InternalOpenAIPageableListOfMessageFile.FromResponse(response), response); + } + + /// Gets a list of previously uploaded files associated with a message from a thread. + /// The ID of the thread containing the message to list files from. + /// The ID of the message to list files from. + /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. + /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order. + /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list. + /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. + /// The cancellation token to use. + /// or is null. + /// or is an empty string, and was expected to be non-empty. + internal virtual Response InternalGetMessageFiles(string threadId, string messageId, int? limit = null, ListSortOrder? order = null, string after = null, string before = null, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + Argument.AssertNotNullOrEmpty(messageId, nameof(messageId)); + + RequestContext context = FromCancellationToken(cancellationToken); + Response response = InternalGetMessageFiles(threadId, messageId, limit, order?.ToString(), after, before, context); + return Response.FromValue(InternalOpenAIPageableListOfMessageFile.FromResponse(response), response); + } + + /// + /// [Protocol Method] Gets a list of previously uploaded files associated with a message from a thread. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The ID of the thread containing the message to list files from. + /// The ID of the message to list files from. + /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. + /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order. Allowed values: "asc" | "desc". + /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list. + /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// or is null. + /// or is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual async Task InternalGetMessageFilesAsync(string threadId, string messageId, int? limit, string order, string after, string before, RequestContext context) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + Argument.AssertNotNullOrEmpty(messageId, nameof(messageId)); + + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.InternalGetMessageFiles"); + scope.Start(); + try + { + using HttpMessage message = CreateInternalGetMessageFilesRequest(threadId, messageId, limit, order, after, before, context); + return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// [Protocol Method] Gets a list of previously uploaded files associated with a message from a thread. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The ID of the thread containing the message to list files from. + /// The ID of the message to list files from. + /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. + /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order. Allowed values: "asc" | "desc". + /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list. + /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// or is null. + /// or is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual Response InternalGetMessageFiles(string threadId, string messageId, int? limit, string order, string after, string before, RequestContext context) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + Argument.AssertNotNullOrEmpty(messageId, nameof(messageId)); + + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.InternalGetMessageFiles"); + scope.Start(); + try + { + using HttpMessage message = CreateInternalGetMessageFilesRequest(threadId, messageId, limit, order, after, before, context); + return _pipeline.ProcessMessage(message, context); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Gets information about a file attachment to a message within a thread. + /// The ID of the thread containing the message to get information from. + /// The ID of the message to get information from. + /// The ID of the file to get information about. + /// The cancellation token to use. + /// , or is null. + /// , or is an empty string, and was expected to be non-empty. + public virtual async Task> RetrieveMessageFileAsync(string threadId, string messageId, string fileId, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + Argument.AssertNotNullOrEmpty(messageId, nameof(messageId)); + Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); + + RequestContext context = FromCancellationToken(cancellationToken); + Response response = await RetrieveMessageFileAsync(threadId, messageId, fileId, context).ConfigureAwait(false); + return Response.FromValue(MessageFile.FromResponse(response), response); + } + + /// Gets information about a file attachment to a message within a thread. + /// The ID of the thread containing the message to get information from. + /// The ID of the message to get information from. + /// The ID of the file to get information about. + /// The cancellation token to use. + /// , or is null. + /// , or is an empty string, and was expected to be non-empty. + public virtual Response RetrieveMessageFile(string threadId, string messageId, string fileId, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + Argument.AssertNotNullOrEmpty(messageId, nameof(messageId)); + Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); + + RequestContext context = FromCancellationToken(cancellationToken); + Response response = RetrieveMessageFile(threadId, messageId, fileId, context); + return Response.FromValue(MessageFile.FromResponse(response), response); + } + + /// + /// [Protocol Method] Gets information about a file attachment to a message within a thread. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// The ID of the thread containing the message to get information from. + /// The ID of the message to get information from. + /// The ID of the file to get information about. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// , or is null. + /// , or is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual async Task RetrieveMessageFileAsync(string threadId, string messageId, string fileId, RequestContext context) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + Argument.AssertNotNullOrEmpty(messageId, nameof(messageId)); + Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); + + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.RetrieveMessageFile"); + scope.Start(); + try + { + using HttpMessage message = CreateRetrieveMessageFileRequest(threadId, messageId, fileId, context); + return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// [Protocol Method] Gets information about a file attachment to a message within a thread. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// The ID of the thread containing the message to get information from. + /// The ID of the message to get information from. + /// The ID of the file to get information about. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// , or is null. + /// , or is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual Response RetrieveMessageFile(string threadId, string messageId, string fileId, RequestContext context) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + Argument.AssertNotNullOrEmpty(messageId, nameof(messageId)); + Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); + + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.RetrieveMessageFile"); + scope.Start(); + try + { + using HttpMessage message = CreateRetrieveMessageFileRequest(threadId, messageId, fileId, context); + return _pipeline.ProcessMessage(message, context); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Creates a new run for an assistant thread. + /// The ID of the thread to run. + /// The ID of the assistant that should run the thread. + /// The overriden model name that the assistant should use to run the thread. + /// The overridden system instructions that the assistant should use to run the thread. + /// The overridden list of enabled tools that the assistant should use to run the thread. + /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. + /// The cancellation token to use. + /// or is null. + /// is an empty string, and was expected to be non-empty. + public virtual async Task> CreateRunAsync(string threadId, string assistantId, string overrideModelName = null, string overrideInstructions = null, IEnumerable overrideTools = null, IDictionary metadata = null, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + Argument.AssertNotNull(assistantId, nameof(assistantId)); + + RequestContext context = FromCancellationToken(cancellationToken); + CreateRunRequest createRunRequest = new CreateRunRequest(assistantId) + { + OverrideModelName = overrideModelName, + OverrideInstructions = overrideInstructions + }; + if (overrideTools != null) + { + foreach (var value in overrideTools) + { + createRunRequest.OverrideTools.Add(value); + } + } + if (metadata != null) + { + foreach (var value in metadata) + { + createRunRequest.Metadata.Add(value); + } + } + CreateRunRequest createRunRequest0 = createRunRequest; + Response response = await CreateRunAsync(threadId, createRunRequest0.ToRequestContent(), context).ConfigureAwait(false); + return Response.FromValue(ThreadRun.FromResponse(response), response); + } + + /// Creates a new run for an assistant thread. + /// The ID of the thread to run. + /// The ID of the assistant that should run the thread. + /// The overriden model name that the assistant should use to run the thread. + /// The overridden system instructions that the assistant should use to run the thread. + /// The overridden list of enabled tools that the assistant should use to run the thread. + /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. + /// The cancellation token to use. + /// or is null. + /// is an empty string, and was expected to be non-empty. + public virtual Response CreateRun(string threadId, string assistantId, string overrideModelName = null, string overrideInstructions = null, IEnumerable overrideTools = null, IDictionary metadata = null, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + Argument.AssertNotNull(assistantId, nameof(assistantId)); + + RequestContext context = FromCancellationToken(cancellationToken); + CreateRunRequest createRunRequest = new CreateRunRequest(assistantId) + { + OverrideModelName = overrideModelName, + OverrideInstructions = overrideInstructions + }; + if (overrideTools != null) + { + foreach (var value in overrideTools) + { + createRunRequest.OverrideTools.Add(value); + } + } + if (metadata != null) + { + foreach (var value in metadata) + { + createRunRequest.Metadata.Add(value); + } + } + CreateRunRequest createRunRequest0 = createRunRequest; + Response response = CreateRun(threadId, createRunRequest0.ToRequestContent(), context); + return Response.FromValue(ThreadRun.FromResponse(response), response); + } + + /// + /// [Protocol Method] Creates a new run for an assistant thread. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// The ID of the thread to run. + /// The content to send as the body of the request. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// or is null. + /// is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual async Task CreateRunAsync(string threadId, RequestContent content, RequestContext context = null) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + Argument.AssertNotNull(content, nameof(content)); + + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.CreateRun"); + scope.Start(); + try + { + using HttpMessage message = CreateCreateRunRequest(threadId, content, context); + return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// [Protocol Method] Creates a new run for an assistant thread. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// The ID of the thread to run. + /// The content to send as the body of the request. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// or is null. + /// is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual Response CreateRun(string threadId, RequestContent content, RequestContext context = null) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + Argument.AssertNotNull(content, nameof(content)); + + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.CreateRun"); + scope.Start(); + try + { + using HttpMessage message = CreateCreateRunRequest(threadId, content, context); + return _pipeline.ProcessMessage(message, context); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Gets a list of runs for a specified thread. + /// The ID of the thread to list runs from. + /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. + /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order. + /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list. + /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. + /// The cancellation token to use. + /// is null. + /// is an empty string, and was expected to be non-empty. + internal virtual async Task> InternalGetRunsAsync(string threadId, int? limit = null, ListSortOrder? order = null, string after = null, string before = null, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + + RequestContext context = FromCancellationToken(cancellationToken); + Response response = await InternalGetRunsAsync(threadId, limit, order?.ToString(), after, before, context).ConfigureAwait(false); + return Response.FromValue(InternalOpenAIPageableListOfThreadRun.FromResponse(response), response); + } + + /// Gets a list of runs for a specified thread. + /// The ID of the thread to list runs from. + /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. + /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order. + /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list. + /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. + /// The cancellation token to use. + /// is null. + /// is an empty string, and was expected to be non-empty. + internal virtual Response InternalGetRuns(string threadId, int? limit = null, ListSortOrder? order = null, string after = null, string before = null, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + + RequestContext context = FromCancellationToken(cancellationToken); + Response response = InternalGetRuns(threadId, limit, order?.ToString(), after, before, context); + return Response.FromValue(InternalOpenAIPageableListOfThreadRun.FromResponse(response), response); + } + + /// + /// [Protocol Method] Gets a list of runs for a specified thread. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The ID of the thread to list runs from. + /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. + /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order. Allowed values: "asc" | "desc". + /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list. + /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual async Task InternalGetRunsAsync(string threadId, int? limit, string order, string after, string before, RequestContext context) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.InternalGetRuns"); + scope.Start(); + try + { + using HttpMessage message = CreateInternalGetRunsRequest(threadId, limit, order, after, before, context); + return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// [Protocol Method] Gets a list of runs for a specified thread. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The ID of the thread to list runs from. + /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. + /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order. Allowed values: "asc" | "desc". + /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list. + /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual Response InternalGetRuns(string threadId, int? limit, string order, string after, string before, RequestContext context) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.InternalGetRuns"); + scope.Start(); + try + { + using HttpMessage message = CreateInternalGetRunsRequest(threadId, limit, order, after, before, context); + return _pipeline.ProcessMessage(message, context); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Gets an existing run from an existing thread. + /// The ID of the thread to retrieve run information from. + /// The ID of the thread to retrieve information about. + /// The cancellation token to use. + /// or is null. + /// or is an empty string, and was expected to be non-empty. + public virtual async Task> RetrieveRunAsync(string threadId, string runId, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + Argument.AssertNotNullOrEmpty(runId, nameof(runId)); + + RequestContext context = FromCancellationToken(cancellationToken); + Response response = await RetrieveRunAsync(threadId, runId, context).ConfigureAwait(false); + return Response.FromValue(ThreadRun.FromResponse(response), response); + } + + /// Gets an existing run from an existing thread. + /// The ID of the thread to retrieve run information from. + /// The ID of the thread to retrieve information about. + /// The cancellation token to use. + /// or is null. + /// or is an empty string, and was expected to be non-empty. + public virtual Response RetrieveRun(string threadId, string runId, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + Argument.AssertNotNullOrEmpty(runId, nameof(runId)); + + RequestContext context = FromCancellationToken(cancellationToken); + Response response = RetrieveRun(threadId, runId, context); + return Response.FromValue(ThreadRun.FromResponse(response), response); + } + + /// + /// [Protocol Method] Gets an existing run from an existing thread. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// The ID of the thread to retrieve run information from. + /// The ID of the thread to retrieve information about. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// or is null. + /// or is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual async Task RetrieveRunAsync(string threadId, string runId, RequestContext context) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + Argument.AssertNotNullOrEmpty(runId, nameof(runId)); + + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.RetrieveRun"); + scope.Start(); + try + { + using HttpMessage message = CreateRetrieveRunRequest(threadId, runId, context); + return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// [Protocol Method] Gets an existing run from an existing thread. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// The ID of the thread to retrieve run information from. + /// The ID of the thread to retrieve information about. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// or is null. + /// or is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual Response RetrieveRun(string threadId, string runId, RequestContext context) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + Argument.AssertNotNullOrEmpty(runId, nameof(runId)); + + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.RetrieveRun"); + scope.Start(); + try + { + using HttpMessage message = CreateRetrieveRunRequest(threadId, runId, context); + return _pipeline.ProcessMessage(message, context); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Modifies an existing thread run. + /// The ID of the thread associated with the specified run. + /// The ID of the run to modify. + /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. + /// The cancellation token to use. + /// or is null. + /// or is an empty string, and was expected to be non-empty. + public virtual async Task> ModifyRunAsync(string threadId, string runId, IDictionary metadata = null, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + Argument.AssertNotNullOrEmpty(runId, nameof(runId)); + + RequestContext context = FromCancellationToken(cancellationToken); + ModifyRunRequest modifyRunRequest = new ModifyRunRequest(); + if (metadata != null) + { + foreach (var value in metadata) + { + modifyRunRequest.Metadata.Add(value); + } + } + ModifyRunRequest modifyRunRequest0 = modifyRunRequest; + Response response = await ModifyRunAsync(threadId, runId, modifyRunRequest0.ToRequestContent(), context).ConfigureAwait(false); + return Response.FromValue(ThreadRun.FromResponse(response), response); + } + + /// Modifies an existing thread run. + /// The ID of the thread associated with the specified run. + /// The ID of the run to modify. + /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. + /// The cancellation token to use. + /// or is null. + /// or is an empty string, and was expected to be non-empty. + public virtual Response ModifyRun(string threadId, string runId, IDictionary metadata = null, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + Argument.AssertNotNullOrEmpty(runId, nameof(runId)); + + RequestContext context = FromCancellationToken(cancellationToken); + ModifyRunRequest modifyRunRequest = new ModifyRunRequest(); + if (metadata != null) + { + foreach (var value in metadata) + { + modifyRunRequest.Metadata.Add(value); + } + } + ModifyRunRequest modifyRunRequest0 = modifyRunRequest; + Response response = ModifyRun(threadId, runId, modifyRunRequest0.ToRequestContent(), context); + return Response.FromValue(ThreadRun.FromResponse(response), response); + } + + /// + /// [Protocol Method] Modifies an existing thread run. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// The ID of the thread associated with the specified run. + /// The ID of the run to modify. + /// The content to send as the body of the request. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// , or is null. + /// or is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual async Task ModifyRunAsync(string threadId, string runId, RequestContent content, RequestContext context = null) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + Argument.AssertNotNullOrEmpty(runId, nameof(runId)); + Argument.AssertNotNull(content, nameof(content)); + + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.ModifyRun"); + scope.Start(); + try + { + using HttpMessage message = CreateModifyRunRequest(threadId, runId, content, context); + return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// [Protocol Method] Modifies an existing thread run. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// The ID of the thread associated with the specified run. + /// The ID of the run to modify. + /// The content to send as the body of the request. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// , or is null. + /// or is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual Response ModifyRun(string threadId, string runId, RequestContent content, RequestContext context = null) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + Argument.AssertNotNullOrEmpty(runId, nameof(runId)); + Argument.AssertNotNull(content, nameof(content)); + + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.ModifyRun"); + scope.Start(); + try + { + using HttpMessage message = CreateModifyRunRequest(threadId, runId, content, context); + return _pipeline.ProcessMessage(message, context); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Submits outputs from tools as requested by tool calls in a run. Runs that need submitted tool outputs will have a status of 'requires_action' with a required_action.type of 'submit_tool_outputs'. + /// The ID of the the thread that was run. + /// The ID of the run that requires tool outputs. + /// The list of tool outputs requested by tool calls from the specified run. + /// The cancellation token to use. + /// , or is null. + /// or is an empty string, and was expected to be non-empty. + public virtual async Task> SubmitRunToolOutputsAsync(string threadId, string runId, IEnumerable toolOutputs, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + Argument.AssertNotNullOrEmpty(runId, nameof(runId)); + Argument.AssertNotNull(toolOutputs, nameof(toolOutputs)); + + RequestContext context = FromCancellationToken(cancellationToken); + SubmitRunToolOutputsRequest submitRunToolOutputsRequest = new SubmitRunToolOutputsRequest(toolOutputs.ToList()); + Response response = await SubmitRunToolOutputsAsync(threadId, runId, submitRunToolOutputsRequest.ToRequestContent(), context).ConfigureAwait(false); + return Response.FromValue(ThreadRun.FromResponse(response), response); + } + + /// Submits outputs from tools as requested by tool calls in a run. Runs that need submitted tool outputs will have a status of 'requires_action' with a required_action.type of 'submit_tool_outputs'. + /// The ID of the the thread that was run. + /// The ID of the run that requires tool outputs. + /// The list of tool outputs requested by tool calls from the specified run. + /// The cancellation token to use. + /// , or is null. + /// or is an empty string, and was expected to be non-empty. + public virtual Response SubmitRunToolOutputs(string threadId, string runId, IEnumerable toolOutputs, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + Argument.AssertNotNullOrEmpty(runId, nameof(runId)); + Argument.AssertNotNull(toolOutputs, nameof(toolOutputs)); + + RequestContext context = FromCancellationToken(cancellationToken); + SubmitRunToolOutputsRequest submitRunToolOutputsRequest = new SubmitRunToolOutputsRequest(toolOutputs.ToList()); + Response response = SubmitRunToolOutputs(threadId, runId, submitRunToolOutputsRequest.ToRequestContent(), context); + return Response.FromValue(ThreadRun.FromResponse(response), response); + } + + /// + /// [Protocol Method] Submits outputs from tools as requested by tool calls in a run. Runs that need submitted tool outputs will have a status of 'requires_action' with a required_action.type of 'submit_tool_outputs'. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// The ID of the the thread that was run. + /// The ID of the run that requires tool outputs. + /// The content to send as the body of the request. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// , or is null. + /// or is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual async Task SubmitRunToolOutputsAsync(string threadId, string runId, RequestContent content, RequestContext context = null) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + Argument.AssertNotNullOrEmpty(runId, nameof(runId)); + Argument.AssertNotNull(content, nameof(content)); + + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.SubmitRunToolOutputs"); + scope.Start(); + try + { + using HttpMessage message = CreateSubmitRunToolOutputsRequest(threadId, runId, content, context); + return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// [Protocol Method] Submits outputs from tools as requested by tool calls in a run. Runs that need submitted tool outputs will have a status of 'requires_action' with a required_action.type of 'submit_tool_outputs'. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// The ID of the the thread that was run. + /// The ID of the run that requires tool outputs. + /// The content to send as the body of the request. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// , or is null. + /// or is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual Response SubmitRunToolOutputs(string threadId, string runId, RequestContent content, RequestContext context = null) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + Argument.AssertNotNullOrEmpty(runId, nameof(runId)); + Argument.AssertNotNull(content, nameof(content)); + + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.SubmitRunToolOutputs"); + scope.Start(); + try + { + using HttpMessage message = CreateSubmitRunToolOutputsRequest(threadId, runId, content, context); + return _pipeline.ProcessMessage(message, context); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Cancels a thread run. + /// The ID of the thread being run. + /// The ID of the run to cancel. + /// The cancellation token to use. + /// or is null. + /// or is an empty string, and was expected to be non-empty. + public virtual async Task> CancelRunAsync(string threadId, string runId, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + Argument.AssertNotNullOrEmpty(runId, nameof(runId)); + + RequestContext context = FromCancellationToken(cancellationToken); + Response response = await CancelRunAsync(threadId, runId, context).ConfigureAwait(false); + return Response.FromValue(ThreadRun.FromResponse(response), response); + } + + /// Cancels a thread run. + /// The ID of the thread being run. + /// The ID of the run to cancel. + /// The cancellation token to use. + /// or is null. + /// or is an empty string, and was expected to be non-empty. + public virtual Response CancelRun(string threadId, string runId, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + Argument.AssertNotNullOrEmpty(runId, nameof(runId)); + + RequestContext context = FromCancellationToken(cancellationToken); + Response response = CancelRun(threadId, runId, context); + return Response.FromValue(ThreadRun.FromResponse(response), response); + } + + /// + /// [Protocol Method] Cancels a thread run. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// The ID of the thread being run. + /// The ID of the run to cancel. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// or is null. + /// or is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual async Task CancelRunAsync(string threadId, string runId, RequestContext context) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + Argument.AssertNotNullOrEmpty(runId, nameof(runId)); + + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.CancelRun"); + scope.Start(); + try + { + using HttpMessage message = CreateCancelRunRequest(threadId, runId, context); + return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// [Protocol Method] Cancels a thread run. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// The ID of the thread being run. + /// The ID of the run to cancel. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// or is null. + /// or is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual Response CancelRun(string threadId, string runId, RequestContext context) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + Argument.AssertNotNullOrEmpty(runId, nameof(runId)); + + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.CancelRun"); + scope.Start(); + try + { + using HttpMessage message = CreateCancelRunRequest(threadId, runId, context); + return _pipeline.ProcessMessage(message, context); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Creates a new assistant thread and immediately starts a run using that new thread. + /// The details used when creating and immediately running a new assistant thread. + /// The cancellation token to use. + /// is null. + public virtual async Task> CreateThreadAndRunAsync(CreateAndRunThreadOptions createAndRunThreadOptions, CancellationToken cancellationToken = default) + { + Argument.AssertNotNull(createAndRunThreadOptions, nameof(createAndRunThreadOptions)); + + RequestContext context = FromCancellationToken(cancellationToken); + using RequestContent content = createAndRunThreadOptions.ToRequestContent(); + Response response = await CreateThreadAndRunAsync(content, context).ConfigureAwait(false); + return Response.FromValue(ThreadRun.FromResponse(response), response); + } + + /// Creates a new assistant thread and immediately starts a run using that new thread. + /// The details used when creating and immediately running a new assistant thread. + /// The cancellation token to use. + /// is null. + public virtual Response CreateThreadAndRun(CreateAndRunThreadOptions createAndRunThreadOptions, CancellationToken cancellationToken = default) + { + Argument.AssertNotNull(createAndRunThreadOptions, nameof(createAndRunThreadOptions)); + + RequestContext context = FromCancellationToken(cancellationToken); + using RequestContent content = createAndRunThreadOptions.ToRequestContent(); + Response response = CreateThreadAndRun(content, context); + return Response.FromValue(ThreadRun.FromResponse(response), response); + } + + /// + /// [Protocol Method] Creates a new assistant thread and immediately starts a run using that new thread. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// The content to send as the body of the request. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual async Task CreateThreadAndRunAsync(RequestContent content, RequestContext context = null) + { + Argument.AssertNotNull(content, nameof(content)); + + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.CreateThreadAndRun"); + scope.Start(); + try + { + using HttpMessage message = CreateCreateThreadAndRunRequest(content, context); + return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// [Protocol Method] Creates a new assistant thread and immediately starts a run using that new thread. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// The content to send as the body of the request. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual Response CreateThreadAndRun(RequestContent content, RequestContext context = null) + { + Argument.AssertNotNull(content, nameof(content)); + + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.CreateThreadAndRun"); + scope.Start(); + try + { + using HttpMessage message = CreateCreateThreadAndRunRequest(content, context); + return _pipeline.ProcessMessage(message, context); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Gets a single run step from a thread run. + /// The ID of the thread that was run. + /// The ID of the specific run to retrieve the step from. + /// The ID of the step to retrieve information about. + /// The cancellation token to use. + /// , or is null. + /// , or is an empty string, and was expected to be non-empty. + public virtual async Task> RetrieveRunStepAsync(string threadId, string runId, string stepId, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + Argument.AssertNotNullOrEmpty(runId, nameof(runId)); + Argument.AssertNotNullOrEmpty(stepId, nameof(stepId)); + + RequestContext context = FromCancellationToken(cancellationToken); + Response response = await RetrieveRunStepAsync(threadId, runId, stepId, context).ConfigureAwait(false); + return Response.FromValue(RunStep.FromResponse(response), response); + } + + /// Gets a single run step from a thread run. + /// The ID of the thread that was run. + /// The ID of the specific run to retrieve the step from. + /// The ID of the step to retrieve information about. + /// The cancellation token to use. + /// , or is null. + /// , or is an empty string, and was expected to be non-empty. + public virtual Response RetrieveRunStep(string threadId, string runId, string stepId, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + Argument.AssertNotNullOrEmpty(runId, nameof(runId)); + Argument.AssertNotNullOrEmpty(stepId, nameof(stepId)); + + RequestContext context = FromCancellationToken(cancellationToken); + Response response = RetrieveRunStep(threadId, runId, stepId, context); + return Response.FromValue(RunStep.FromResponse(response), response); + } + + /// + /// [Protocol Method] Gets a single run step from a thread run. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// The ID of the thread that was run. + /// The ID of the specific run to retrieve the step from. + /// The ID of the step to retrieve information about. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// , or is null. + /// , or is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual async Task RetrieveRunStepAsync(string threadId, string runId, string stepId, RequestContext context) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + Argument.AssertNotNullOrEmpty(runId, nameof(runId)); + Argument.AssertNotNullOrEmpty(stepId, nameof(stepId)); + + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.RetrieveRunStep"); + scope.Start(); + try + { + using HttpMessage message = CreateRetrieveRunStepRequest(threadId, runId, stepId, context); + return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// [Protocol Method] Gets a single run step from a thread run. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// The ID of the thread that was run. + /// The ID of the specific run to retrieve the step from. + /// The ID of the step to retrieve information about. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// , or is null. + /// , or is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual Response RetrieveRunStep(string threadId, string runId, string stepId, RequestContext context) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + Argument.AssertNotNullOrEmpty(runId, nameof(runId)); + Argument.AssertNotNullOrEmpty(stepId, nameof(stepId)); + + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.RetrieveRunStep"); + scope.Start(); + try + { + using HttpMessage message = CreateRetrieveRunStepRequest(threadId, runId, stepId, context); + return _pipeline.ProcessMessage(message, context); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Gets a list of run steps from a thread run. + /// The ID of the thread that was run. + /// The ID of the run to list steps from. + /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. + /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order. + /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list. + /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. + /// The cancellation token to use. + /// or is null. + /// or is an empty string, and was expected to be non-empty. + internal virtual async Task> InternalGetRunStepsAsync(string threadId, string runId, int? limit = null, ListSortOrder? order = null, string after = null, string before = null, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + Argument.AssertNotNullOrEmpty(runId, nameof(runId)); + + RequestContext context = FromCancellationToken(cancellationToken); + Response response = await InternalGetRunStepsAsync(threadId, runId, limit, order?.ToString(), after, before, context).ConfigureAwait(false); + return Response.FromValue(InternalOpenAIPageableListOfRunStep.FromResponse(response), response); + } + + /// Gets a list of run steps from a thread run. + /// The ID of the thread that was run. + /// The ID of the run to list steps from. + /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. + /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order. + /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list. + /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. + /// The cancellation token to use. + /// or is null. + /// or is an empty string, and was expected to be non-empty. + internal virtual Response InternalGetRunSteps(string threadId, string runId, int? limit = null, ListSortOrder? order = null, string after = null, string before = null, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + Argument.AssertNotNullOrEmpty(runId, nameof(runId)); + + RequestContext context = FromCancellationToken(cancellationToken); + Response response = InternalGetRunSteps(threadId, runId, limit, order?.ToString(), after, before, context); + return Response.FromValue(InternalOpenAIPageableListOfRunStep.FromResponse(response), response); + } + + /// + /// [Protocol Method] Gets a list of run steps from a thread run. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The ID of the thread that was run. + /// The ID of the run to list steps from. + /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. + /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order. Allowed values: "asc" | "desc". + /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list. + /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// or is null. + /// or is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual async Task InternalGetRunStepsAsync(string threadId, string runId, int? limit, string order, string after, string before, RequestContext context) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + Argument.AssertNotNullOrEmpty(runId, nameof(runId)); + + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.InternalGetRunSteps"); + scope.Start(); + try + { + using HttpMessage message = CreateInternalGetRunStepsRequest(threadId, runId, limit, order, after, before, context); + return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// [Protocol Method] Gets a list of run steps from a thread run. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The ID of the thread that was run. + /// The ID of the run to list steps from. + /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. + /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order. Allowed values: "asc" | "desc". + /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list. + /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// or is null. + /// or is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual Response InternalGetRunSteps(string threadId, string runId, int? limit, string order, string after, string before, RequestContext context) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + Argument.AssertNotNullOrEmpty(runId, nameof(runId)); + + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.InternalGetRunSteps"); + scope.Start(); + try + { + using HttpMessage message = CreateInternalGetRunStepsRequest(threadId, runId, limit, order, after, before, context); + return _pipeline.ProcessMessage(message, context); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Gets a list of previously uploaded files. + /// A value that, when provided, limits list results to files matching the corresponding purpose. + /// The cancellation token to use. + internal virtual async Task> InternalListFilesAsync(OpenAIFilePurpose? purpose = null, CancellationToken cancellationToken = default) + { + RequestContext context = FromCancellationToken(cancellationToken); + Response response = await InternalListFilesAsync(purpose?.ToString(), context).ConfigureAwait(false); + return Response.FromValue(InternalFileListResponse.FromResponse(response), response); + } + + /// Gets a list of previously uploaded files. + /// A value that, when provided, limits list results to files matching the corresponding purpose. + /// The cancellation token to use. + internal virtual Response InternalListFiles(OpenAIFilePurpose? purpose = null, CancellationToken cancellationToken = default) + { + RequestContext context = FromCancellationToken(cancellationToken); + Response response = InternalListFiles(purpose?.ToString(), context); + return Response.FromValue(InternalFileListResponse.FromResponse(response), response); + } + + /// + /// [Protocol Method] Gets a list of previously uploaded files. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// A value that, when provided, limits list results to files matching the corresponding purpose. Allowed values: "fine-tune" | "fine-tune-results" | "assistants" | "assistants_output". + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual async Task InternalListFilesAsync(string purpose, RequestContext context) + { + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.InternalListFiles"); + scope.Start(); + try + { + using HttpMessage message = CreateInternalListFilesRequest(purpose, context); + return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// [Protocol Method] Gets a list of previously uploaded files. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// A value that, when provided, limits list results to files matching the corresponding purpose. Allowed values: "fine-tune" | "fine-tune-results" | "assistants" | "assistants_output". + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual Response InternalListFiles(string purpose, RequestContext context) + { + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.InternalListFiles"); + scope.Start(); + try + { + using HttpMessage message = CreateInternalListFilesRequest(purpose, context); + return _pipeline.ProcessMessage(message, context); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Uploads a file for use by other operations. + /// The file data (not filename) to upload. + /// The intended purpose of the file. + /// A filename to associate with the uploaded data. + /// The cancellation token to use. + /// is null. + public virtual async Task> UploadFileAsync(BinaryData data, OpenAIFilePurpose purpose, string filename = null, CancellationToken cancellationToken = default) + { + Argument.AssertNotNull(data, nameof(data)); + + RequestContext context = FromCancellationToken(cancellationToken); + UploadFileRequest uploadFileRequest = new UploadFileRequest(data, purpose) + { + Filename = filename + }; + Response response = await UploadFileAsync(uploadFileRequest.ToRequestContent(), context).ConfigureAwait(false); + return Response.FromValue(OpenAIFile.FromResponse(response), response); + } + + /// Uploads a file for use by other operations. + /// The file data (not filename) to upload. + /// The intended purpose of the file. + /// A filename to associate with the uploaded data. + /// The cancellation token to use. + /// is null. + public virtual Response UploadFile(BinaryData data, OpenAIFilePurpose purpose, string filename = null, CancellationToken cancellationToken = default) + { + Argument.AssertNotNull(data, nameof(data)); + + RequestContext context = FromCancellationToken(cancellationToken); + UploadFileRequest uploadFileRequest = new UploadFileRequest(data, purpose) + { + Filename = filename + }; + Response response = UploadFile(uploadFileRequest.ToRequestContent(), context); + return Response.FromValue(OpenAIFile.FromResponse(response), response); + } + + /// + /// [Protocol Method] Uploads a file for use by other operations. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// The content to send as the body of the request. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual async Task UploadFileAsync(RequestContent content, RequestContext context = null) + { + Argument.AssertNotNull(content, nameof(content)); + + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.UploadFile"); + scope.Start(); + try + { + using HttpMessage message = CreateUploadFileRequest(content, context); + return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// [Protocol Method] Uploads a file for use by other operations. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// The content to send as the body of the request. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual Response UploadFile(RequestContent content, RequestContext context = null) + { + Argument.AssertNotNull(content, nameof(content)); + + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.UploadFile"); + scope.Start(); + try + { + using HttpMessage message = CreateUploadFileRequest(content, context); + return _pipeline.ProcessMessage(message, context); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Delete a previously uploaded file. + /// The ID of the file to delete. + /// The cancellation token to use. + /// is null. + /// is an empty string, and was expected to be non-empty. + internal virtual async Task> InternalDeleteFileAsync(string fileId, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); + + RequestContext context = FromCancellationToken(cancellationToken); + Response response = await InternalDeleteFileAsync(fileId, context).ConfigureAwait(false); + return Response.FromValue(InternalFileDeletionStatus.FromResponse(response), response); + } + + /// Delete a previously uploaded file. + /// The ID of the file to delete. + /// The cancellation token to use. + /// is null. + /// is an empty string, and was expected to be non-empty. + internal virtual Response InternalDeleteFile(string fileId, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); + + RequestContext context = FromCancellationToken(cancellationToken); + Response response = InternalDeleteFile(fileId, context); + return Response.FromValue(InternalFileDeletionStatus.FromResponse(response), response); + } + + /// + /// [Protocol Method] Delete a previously uploaded file. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The ID of the file to delete. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual async Task InternalDeleteFileAsync(string fileId, RequestContext context) + { + Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); + + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.InternalDeleteFile"); + scope.Start(); + try + { + using HttpMessage message = CreateInternalDeleteFileRequest(fileId, context); + return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// [Protocol Method] Delete a previously uploaded file. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The ID of the file to delete. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual Response InternalDeleteFile(string fileId, RequestContext context) + { + Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); + + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.InternalDeleteFile"); + scope.Start(); + try + { + using HttpMessage message = CreateInternalDeleteFileRequest(fileId, context); + return _pipeline.ProcessMessage(message, context); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Returns information about a specific file. Does not retrieve file content. + /// The ID of the file to retrieve. + /// The cancellation token to use. + /// is null. + /// is an empty string, and was expected to be non-empty. + public virtual async Task> RetrieveFileAsync(string fileId, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); + + RequestContext context = FromCancellationToken(cancellationToken); + Response response = await RetrieveFileAsync(fileId, context).ConfigureAwait(false); + return Response.FromValue(OpenAIFile.FromResponse(response), response); + } + + /// Returns information about a specific file. Does not retrieve file content. + /// The ID of the file to retrieve. + /// The cancellation token to use. + /// is null. + /// is an empty string, and was expected to be non-empty. + public virtual Response RetrieveFile(string fileId, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); + + RequestContext context = FromCancellationToken(cancellationToken); + Response response = RetrieveFile(fileId, context); + return Response.FromValue(OpenAIFile.FromResponse(response), response); + } + + /// + /// [Protocol Method] Returns information about a specific file. Does not retrieve file content. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// The ID of the file to retrieve. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual async Task RetrieveFileAsync(string fileId, RequestContext context) + { + Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); + + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.RetrieveFile"); + scope.Start(); + try + { + using HttpMessage message = CreateRetrieveFileRequest(fileId, context); + return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// [Protocol Method] Returns information about a specific file. Does not retrieve file content. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// The ID of the file to retrieve. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual Response RetrieveFile(string fileId, RequestContext context) + { + Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); + + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.RetrieveFile"); + scope.Start(); + try + { + using HttpMessage message = CreateRetrieveFileRequest(fileId, context); + return _pipeline.ProcessMessage(message, context); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Returns the contents of a specified file. + /// The ID of the file to retrieve the contents of. + /// The cancellation token to use. + /// is null. + /// is an empty string, and was expected to be non-empty. + public virtual async Task> RetrieveFileContentAsync(string fileId, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); + + RequestContext context = FromCancellationToken(cancellationToken); + Response response = await RetrieveFileContentAsync(fileId, context).ConfigureAwait(false); + return Response.FromValue(response.Content, response); + } + + /// Returns the contents of a specified file. + /// The ID of the file to retrieve the contents of. + /// The cancellation token to use. + /// is null. + /// is an empty string, and was expected to be non-empty. + public virtual Response RetrieveFileContent(string fileId, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); + + RequestContext context = FromCancellationToken(cancellationToken); + Response response = RetrieveFileContent(fileId, context); + return Response.FromValue(response.Content, response); + } + + /// + /// [Protocol Method] Returns the contents of a specified file. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// The ID of the file to retrieve the contents of. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual async Task RetrieveFileContentAsync(string fileId, RequestContext context) + { + Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); + + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.RetrieveFileContent"); + scope.Start(); + try + { + using HttpMessage message = CreateRetrieveFileContentRequest(fileId, context); + return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// [Protocol Method] Returns the contents of a specified file. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// The ID of the file to retrieve the contents of. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual Response RetrieveFileContent(string fileId, RequestContext context) + { + Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); + + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.RetrieveFileContent"); + scope.Start(); + try + { + using HttpMessage message = CreateRetrieveFileContentRequest(fileId, context); + return _pipeline.ProcessMessage(message, context); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + private static RequestContext DefaultRequestContext = new RequestContext(); + internal static RequestContext FromCancellationToken(CancellationToken cancellationToken = default) + { + if (!cancellationToken.CanBeCanceled) + { + return DefaultRequestContext; + } + + return new RequestContext() { CancellationToken = cancellationToken }; + } + + private static ResponseClassifier _responseClassifier200; + private static ResponseClassifier ResponseClassifier200 => _responseClassifier200 ??= new StatusCodeClassifier(stackalloc ushort[] { 200 }); + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsClientOptions.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsClientOptions.cs new file mode 100644 index 000000000000..0808713f69a1 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsClientOptions.cs @@ -0,0 +1,37 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + /// Client options for AssistantsClient. + public partial class AssistantsClientOptions : ClientOptions + { + private const ServiceVersion LatestVersion = ServiceVersion.V2023_11_06_Beta; + + /// The version of the service to use. + public enum ServiceVersion + { + /// Service version "2023-11-06-beta". + V2023_11_06_Beta = 1, + } + + internal string Version { get; } + + /// Initializes new instance of AssistantsClientOptions. + public AssistantsClientOptions(ServiceVersion version = LatestVersion) + { + Version = version switch + { + ServiceVersion.V2023_11_06_Beta => "2023-11-06-beta", + _ => throw new NotSupportedException() + }; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsModelFactory.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsModelFactory.cs new file mode 100644 index 000000000000..18b27830a1d7 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsModelFactory.cs @@ -0,0 +1,133 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Azure.AI.OpenAI.Assistants +{ + /// Model factory for models. + public static partial class AssistantsModelFactory + { + /// Initializes a new instance of . + /// The status for the error. + /// The human-readable text associated with the error. + /// or is null. + /// A new instance for mocking. + public static RunError RunError(string code = null, string message = null) + { + if (code == null) + { + throw new ArgumentNullException(nameof(code)); + } + if (message == null) + { + throw new ArgumentNullException(nameof(message)); + } + + return new RunError(code, message); + } + + /// Initializes a new instance of . + /// The error code for this error. + /// The human-readable text associated with this error. + /// is null. + /// A new instance for mocking. + public static RunStepError RunStepError(RunStepErrorCode code = default, string message = null) + { + if (message == null) + { + throw new ArgumentNullException(nameof(message)); + } + + return new RunStepError(code, message); + } + + /// Initializes a new instance of . + /// The object type. + /// The ID of the tool call. This ID must be referenced when you submit tool outputs. + /// A new instance for mocking. + public static ToolCall ToolCall(string type = null, string id = null) + { + return new UnknownToolCall(type, id); + } + + /// Initializes a new instance of . + /// The ID of the tool call. This ID must be referenced when you submit tool outputs. + /// The key/value pairs produced by the retrieval tool. + /// A new instance for mocking. + public static RetrievalToolCall RetrievalToolCall(string id = null, IReadOnlyDictionary retrieval = null) + { + retrieval ??= new Dictionary(); + + return new RetrievalToolCall("retrieval", id, retrieval); + } + + /// Initializes a new instance of . + /// The serialized log output emitted by the code interpreter. + /// A new instance for mocking. + public static CodeInterpreterLogOutput CodeInterpreterLogOutput(string logs = null) + { + return new CodeInterpreterLogOutput("logs", logs); + } + + /// Initializes a new instance of . + /// Referential information for the image associated with this output. + /// A new instance for mocking. + public static CodeInterpreterImageOutput CodeInterpreterImageOutput(CodeInterpreterImageReference image = null) + { + return new CodeInterpreterImageOutput("image", image); + } + + /// Initializes a new instance of . + /// The ID of the file associated with this image. + /// is null. + /// A new instance for mocking. + public static CodeInterpreterImageReference CodeInterpreterImageReference(string fileId = null) + { + if (fileId == null) + { + throw new ArgumentNullException(nameof(fileId)); + } + + return new CodeInterpreterImageReference(fileId); + } + + /// Initializes a new instance of . + /// Information about the message creation associated with this run step. + /// A new instance for mocking. + public static RunStepMessageCreationDetails RunStepMessageCreationDetails(RunStepMessageCreationReference messageCreation = null) + { + return new RunStepMessageCreationDetails(RunStepType.MessageCreation, messageCreation); + } + + /// Initializes a new instance of . + /// The ID of the message created by this run step. + /// is null. + /// A new instance for mocking. + public static RunStepMessageCreationReference RunStepMessageCreationReference(string messageId = null) + { + if (messageId == null) + { + throw new ArgumentNullException(nameof(messageId)); + } + + return new RunStepMessageCreationReference(messageId); + } + + /// Initializes a new instance of . + /// A list tool call details for this run step. + /// A new instance for mocking. + public static RunStepToolCallDetails RunStepToolCallDetails(IEnumerable toolCalls = null) + { + toolCalls ??= new List(); + + return new RunStepToolCallDetails(RunStepType.ToolCalls, toolCalls?.ToList()); + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterImageOutput.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterImageOutput.Serialization.cs new file mode 100644 index 000000000000..f6397375eca4 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterImageOutput.Serialization.cs @@ -0,0 +1,47 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class CodeInterpreterImageOutput + { + internal static CodeInterpreterImageOutput DeserializeCodeInterpreterImageOutput(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + CodeInterpreterImageReference image = default; + string type = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("image"u8)) + { + image = CodeInterpreterImageReference.DeserializeCodeInterpreterImageReference(property.Value); + continue; + } + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString(); + continue; + } + } + return new CodeInterpreterImageOutput(type, image); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new CodeInterpreterImageOutput FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeCodeInterpreterImageOutput(document.RootElement); + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterImageOutput.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterImageOutput.cs new file mode 100644 index 000000000000..a29bd099f124 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterImageOutput.cs @@ -0,0 +1,38 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + /// A representation of an image output emitted by a code interpreter tool in response to a tool call by the model. + public partial class CodeInterpreterImageOutput : CodeInterpreterToolCallOutput + { + /// Initializes a new instance of . + /// Referential information for the image associated with this output. + /// is null. + internal CodeInterpreterImageOutput(CodeInterpreterImageReference image) + { + Argument.AssertNotNull(image, nameof(image)); + + Type = "image"; + Image = image; + } + + /// Initializes a new instance of . + /// The object type. + /// Referential information for the image associated with this output. + internal CodeInterpreterImageOutput(string type, CodeInterpreterImageReference image) : base(type) + { + Image = image; + } + + /// Referential information for the image associated with this output. + public CodeInterpreterImageReference Image { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterImageReference.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterImageReference.Serialization.cs new file mode 100644 index 000000000000..32beec637f8f --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterImageReference.Serialization.cs @@ -0,0 +1,41 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class CodeInterpreterImageReference + { + internal static CodeInterpreterImageReference DeserializeCodeInterpreterImageReference(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string fileId = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("file_id"u8)) + { + fileId = property.Value.GetString(); + continue; + } + } + return new CodeInterpreterImageReference(fileId); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static CodeInterpreterImageReference FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeCodeInterpreterImageReference(document.RootElement); + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterImageReference.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterImageReference.cs new file mode 100644 index 000000000000..3e291a443b24 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterImageReference.cs @@ -0,0 +1,29 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + /// An image reference emitted by a code interpreter tool in response to a tool call by the model. + public partial class CodeInterpreterImageReference + { + /// Initializes a new instance of . + /// The ID of the file associated with this image. + /// is null. + internal CodeInterpreterImageReference(string fileId) + { + Argument.AssertNotNull(fileId, nameof(fileId)); + + FileId = fileId; + } + + /// The ID of the file associated with this image. + public string FileId { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterLogOutput.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterLogOutput.Serialization.cs new file mode 100644 index 000000000000..258d3cbba965 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterLogOutput.Serialization.cs @@ -0,0 +1,47 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class CodeInterpreterLogOutput + { + internal static CodeInterpreterLogOutput DeserializeCodeInterpreterLogOutput(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string logs = default; + string type = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("logs"u8)) + { + logs = property.Value.GetString(); + continue; + } + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString(); + continue; + } + } + return new CodeInterpreterLogOutput(type, logs); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new CodeInterpreterLogOutput FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeCodeInterpreterLogOutput(document.RootElement); + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterLogOutput.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterLogOutput.cs new file mode 100644 index 000000000000..a242df685458 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterLogOutput.cs @@ -0,0 +1,38 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + /// A representation of a log output emitted by a code interpreter tool in response to a tool call by the model. + public partial class CodeInterpreterLogOutput : CodeInterpreterToolCallOutput + { + /// Initializes a new instance of . + /// The serialized log output emitted by the code interpreter. + /// is null. + internal CodeInterpreterLogOutput(string logs) + { + Argument.AssertNotNull(logs, nameof(logs)); + + Type = "logs"; + Logs = logs; + } + + /// Initializes a new instance of . + /// The object type. + /// The serialized log output emitted by the code interpreter. + internal CodeInterpreterLogOutput(string type, string logs) : base(type) + { + Logs = logs; + } + + /// The serialized log output emitted by the code interpreter. + public string Logs { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterToolCall.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterToolCall.Serialization.cs new file mode 100644 index 000000000000..d80e710382f6 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterToolCall.Serialization.cs @@ -0,0 +1,53 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class CodeInterpreterToolCall + { + internal static CodeInterpreterToolCall DeserializeCodeInterpreterToolCall(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + InternalCodeInterpreterToolCallDetails codeInterpreter = default; + string type = default; + string id = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("code_interpreter"u8)) + { + codeInterpreter = InternalCodeInterpreterToolCallDetails.DeserializeInternalCodeInterpreterToolCallDetails(property.Value); + continue; + } + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString(); + continue; + } + if (property.NameEquals("id"u8)) + { + id = property.Value.GetString(); + continue; + } + } + return new CodeInterpreterToolCall(type, id, codeInterpreter); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new CodeInterpreterToolCall FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeCodeInterpreterToolCall(document.RootElement); + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterToolCall.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterToolCall.cs new file mode 100644 index 000000000000..5e63c73fd8c2 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterToolCall.cs @@ -0,0 +1,41 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + /// + /// A tool call to a code interpreter tool, issued by the model in evaluation of a configured code interpreter tool, that + /// represents submitted output needed or already fulfilled by the tool for the model to continue. + /// + public partial class CodeInterpreterToolCall : ToolCall + { + /// Initializes a new instance of . + /// The ID of the tool call. This ID must be referenced when you submit tool outputs. + /// The details of the tool call to the code interpreter tool. + /// or is null. + internal CodeInterpreterToolCall(string id, InternalCodeInterpreterToolCallDetails internalDetails) : base(id) + { + Argument.AssertNotNull(id, nameof(id)); + Argument.AssertNotNull(internalDetails, nameof(internalDetails)); + + Type = "code_interpreter"; + InternalDetails = internalDetails; + } + + /// Initializes a new instance of . + /// The object type. + /// The ID of the tool call. This ID must be referenced when you submit tool outputs. + /// The details of the tool call to the code interpreter tool. + internal CodeInterpreterToolCall(string type, string id, InternalCodeInterpreterToolCallDetails internalDetails) : base(type, id) + { + InternalDetails = internalDetails; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterToolCallOutput.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterToolCallOutput.Serialization.cs new file mode 100644 index 000000000000..e4db8114844b --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterToolCallOutput.Serialization.cs @@ -0,0 +1,40 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class CodeInterpreterToolCallOutput + { + internal static CodeInterpreterToolCallOutput DeserializeCodeInterpreterToolCallOutput(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + if (element.TryGetProperty("type", out JsonElement discriminator)) + { + switch (discriminator.GetString()) + { + case "logs": return CodeInterpreterLogOutput.DeserializeCodeInterpreterLogOutput(element); + case "image": return CodeInterpreterImageOutput.DeserializeCodeInterpreterImageOutput(element); + } + } + return UnknownCodeInterpreterToolCallOutput.DeserializeUnknownCodeInterpreterToolCallOutput(element); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static CodeInterpreterToolCallOutput FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeCodeInterpreterToolCallOutput(document.RootElement); + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterToolCallOutput.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterToolCallOutput.cs new file mode 100644 index 000000000000..8409302c7373 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterToolCallOutput.cs @@ -0,0 +1,32 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +namespace Azure.AI.OpenAI.Assistants +{ + /// + /// An abstract representation of an emitted output from a code interpreter tool. + /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. + /// The available derived classes include and . + /// + public abstract partial class CodeInterpreterToolCallOutput + { + /// Initializes a new instance of . + protected CodeInterpreterToolCallOutput() + { + } + + /// Initializes a new instance of . + /// The object type. + internal CodeInterpreterToolCallOutput(string type) + { + Type = type; + } + + /// The object type. + internal string Type { get; set; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterToolDefinition.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterToolDefinition.Serialization.cs new file mode 100644 index 000000000000..e86daf800d77 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterToolDefinition.Serialization.cs @@ -0,0 +1,58 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class CodeInterpreterToolDefinition : IUtf8JsonSerializable + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + { + writer.WriteStartObject(); + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type); + writer.WriteEndObject(); + } + + internal static CodeInterpreterToolDefinition DeserializeCodeInterpreterToolDefinition(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string type = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString(); + continue; + } + } + return new CodeInterpreterToolDefinition(type); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new CodeInterpreterToolDefinition FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeCodeInterpreterToolDefinition(document.RootElement); + } + + /// Convert into a Utf8JsonRequestContent. + internal override RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterToolDefinition.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterToolDefinition.cs new file mode 100644 index 000000000000..a7109a1953fa --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterToolDefinition.cs @@ -0,0 +1,25 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +namespace Azure.AI.OpenAI.Assistants +{ + /// The input definition information for a code interpreter tool as used to configure an assistant. + public partial class CodeInterpreterToolDefinition : ToolDefinition + { + /// Initializes a new instance of . + public CodeInterpreterToolDefinition() + { + Type = "code_interpreter"; + } + + /// Initializes a new instance of . + /// The object type. + internal CodeInterpreterToolDefinition(string type) : base(type) + { + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateAndRunThreadOptions.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateAndRunThreadOptions.Serialization.cs new file mode 100644 index 000000000000..a9d7d6914d60 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateAndRunThreadOptions.Serialization.cs @@ -0,0 +1,67 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class CreateAndRunThreadOptions : IUtf8JsonSerializable + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + { + writer.WriteStartObject(); + writer.WritePropertyName("assistant_id"u8); + writer.WriteStringValue(AssistantId); + if (Optional.IsDefined(Thread)) + { + writer.WritePropertyName("thread"u8); + writer.WriteObjectValue(Thread); + } + if (Optional.IsDefined(OverrideModelName)) + { + writer.WritePropertyName("model"u8); + writer.WriteStringValue(OverrideModelName); + } + if (Optional.IsDefined(OverrideInstructions)) + { + writer.WritePropertyName("instructions"u8); + writer.WriteStringValue(OverrideInstructions); + } + if (Optional.IsCollectionDefined(OverrideTools)) + { + writer.WritePropertyName("tools"u8); + writer.WriteStartArray(); + foreach (var item in OverrideTools) + { + writer.WriteObjectValue(item); + } + writer.WriteEndArray(); + } + if (Optional.IsCollectionDefined(Metadata)) + { + writer.WritePropertyName("metadata"u8); + writer.WriteStartObject(); + foreach (var item in Metadata) + { + writer.WritePropertyName(item.Key); + writer.WriteStringValue(item.Value); + } + writer.WriteEndObject(); + } + writer.WriteEndObject(); + } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateAndRunThreadOptions.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateAndRunThreadOptions.cs new file mode 100644 index 000000000000..6aa505de4abe --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateAndRunThreadOptions.cs @@ -0,0 +1,63 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + /// The details used when creating and immediately running a new assistant thread. + public partial class CreateAndRunThreadOptions + { + /// Initializes a new instance of . + /// The ID of the assistant for which the thread should be created. + /// is null. + public CreateAndRunThreadOptions(string assistantId) + { + Argument.AssertNotNull(assistantId, nameof(assistantId)); + + AssistantId = assistantId; + OverrideTools = new ChangeTrackingList(); + Metadata = new ChangeTrackingDictionary(); + } + + /// Initializes a new instance of . + /// The ID of the assistant for which the thread should be created. + /// The details used to create the new thread. + /// The overridden model that the assistant should use to run the thread. + /// The overridden system instructions the assistant should use to run the thread. + /// The overridden list of enabled tools the assistant should use to run the thread. + /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. + internal CreateAndRunThreadOptions(string assistantId, AssistantThreadCreationOptions thread, string overrideModelName, string overrideInstructions, IList overrideTools, IDictionary metadata) + { + AssistantId = assistantId; + Thread = thread; + OverrideModelName = overrideModelName; + OverrideInstructions = overrideInstructions; + OverrideTools = overrideTools; + Metadata = metadata; + } + + /// The ID of the assistant for which the thread should be created. + public string AssistantId { get; } + /// The details used to create the new thread. + public AssistantThreadCreationOptions Thread { get; set; } + /// The overridden model that the assistant should use to run the thread. + public string OverrideModelName { get; set; } + /// The overridden system instructions the assistant should use to run the thread. + public string OverrideInstructions { get; set; } + /// + /// The overridden list of enabled tools the assistant should use to run the thread. + /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. + /// The available derived classes include , and . + /// + public IList OverrideTools { get; } + /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. + public IDictionary Metadata { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateAssistantFileRequest.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateAssistantFileRequest.Serialization.cs new file mode 100644 index 000000000000..16635b518b79 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateAssistantFileRequest.Serialization.cs @@ -0,0 +1,31 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + internal partial class CreateAssistantFileRequest : IUtf8JsonSerializable + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + { + writer.WriteStartObject(); + writer.WritePropertyName("file_id"u8); + writer.WriteStringValue(FileId); + writer.WriteEndObject(); + } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateAssistantFileRequest.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateAssistantFileRequest.cs new file mode 100644 index 000000000000..762b79d212ed --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateAssistantFileRequest.cs @@ -0,0 +1,29 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + /// The CreateAssistantFileRequest. + internal partial class CreateAssistantFileRequest + { + /// Initializes a new instance of . + /// The ID of the previously uploaded file to attach. + /// is null. + public CreateAssistantFileRequest(string fileId) + { + Argument.AssertNotNull(fileId, nameof(fileId)); + + FileId = fileId; + } + + /// The ID of the previously uploaded file to attach. + public string FileId { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateMessageRequest.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateMessageRequest.Serialization.cs new file mode 100644 index 000000000000..7db59b13eedb --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateMessageRequest.Serialization.cs @@ -0,0 +1,54 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + internal partial class CreateMessageRequest : IUtf8JsonSerializable + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + { + writer.WriteStartObject(); + writer.WritePropertyName("role"u8); + writer.WriteStringValue(Role.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(Content); + if (Optional.IsCollectionDefined(FileIds)) + { + writer.WritePropertyName("file_ids"u8); + writer.WriteStartArray(); + foreach (var item in FileIds) + { + writer.WriteStringValue(item); + } + writer.WriteEndArray(); + } + if (Optional.IsCollectionDefined(Metadata)) + { + writer.WritePropertyName("metadata"u8); + writer.WriteStartObject(); + foreach (var item in Metadata) + { + writer.WritePropertyName(item.Key); + writer.WriteStringValue(item.Value); + } + writer.WriteEndObject(); + } + writer.WriteEndObject(); + } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateMessageRequest.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateMessageRequest.cs new file mode 100644 index 000000000000..5816540bf0c0 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateMessageRequest.cs @@ -0,0 +1,53 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + /// The CreateMessageRequest. + internal partial class CreateMessageRequest + { + /// Initializes a new instance of . + /// The role to associate with the new message. + /// The textual content for the new message. + /// is null. + public CreateMessageRequest(MessageRole role, string content) + { + Argument.AssertNotNull(content, nameof(content)); + + Role = role; + Content = content; + FileIds = new ChangeTrackingList(); + Metadata = new ChangeTrackingDictionary(); + } + + /// Initializes a new instance of . + /// The role to associate with the new message. + /// The textual content for the new message. + /// A list of up to 10 file IDs to associate with the message, as used by tools like 'code_interpreter' or 'retrieval' that can read files. + /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. + internal CreateMessageRequest(MessageRole role, string content, IList fileIds, IDictionary metadata) + { + Role = role; + Content = content; + FileIds = fileIds; + Metadata = metadata; + } + + /// The role to associate with the new message. + public MessageRole Role { get; } + /// The textual content for the new message. + public string Content { get; } + /// A list of up to 10 file IDs to associate with the message, as used by tools like 'code_interpreter' or 'retrieval' that can read files. + public IList FileIds { get; } + /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. + public IDictionary Metadata { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateRunRequest.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateRunRequest.Serialization.cs new file mode 100644 index 000000000000..267ef15e4207 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateRunRequest.Serialization.cs @@ -0,0 +1,62 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + internal partial class CreateRunRequest : IUtf8JsonSerializable + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + { + writer.WriteStartObject(); + writer.WritePropertyName("assistant_id"u8); + writer.WriteStringValue(AssistantId); + if (Optional.IsDefined(OverrideModelName)) + { + writer.WritePropertyName("model"u8); + writer.WriteStringValue(OverrideModelName); + } + if (Optional.IsDefined(OverrideInstructions)) + { + writer.WritePropertyName("instructions"u8); + writer.WriteStringValue(OverrideInstructions); + } + if (Optional.IsCollectionDefined(OverrideTools)) + { + writer.WritePropertyName("tools"u8); + writer.WriteStartArray(); + foreach (var item in OverrideTools) + { + writer.WriteObjectValue(item); + } + writer.WriteEndArray(); + } + if (Optional.IsCollectionDefined(Metadata)) + { + writer.WritePropertyName("metadata"u8); + writer.WriteStartObject(); + foreach (var item in Metadata) + { + writer.WritePropertyName(item.Key); + writer.WriteStringValue(item.Value); + } + writer.WriteEndObject(); + } + writer.WriteEndObject(); + } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateRunRequest.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateRunRequest.cs new file mode 100644 index 000000000000..7704913f9bfd --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateRunRequest.cs @@ -0,0 +1,59 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + /// The CreateRunRequest. + internal partial class CreateRunRequest + { + /// Initializes a new instance of . + /// The ID of the assistant that should run the thread. + /// is null. + public CreateRunRequest(string assistantId) + { + Argument.AssertNotNull(assistantId, nameof(assistantId)); + + AssistantId = assistantId; + OverrideTools = new ChangeTrackingList(); + Metadata = new ChangeTrackingDictionary(); + } + + /// Initializes a new instance of . + /// The ID of the assistant that should run the thread. + /// The overriden model name that the assistant should use to run the thread. + /// The overridden system instructions that the assistant should use to run the thread. + /// The overridden list of enabled tools that the assistant should use to run the thread. + /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. + internal CreateRunRequest(string assistantId, string overrideModelName, string overrideInstructions, IList overrideTools, IDictionary metadata) + { + AssistantId = assistantId; + OverrideModelName = overrideModelName; + OverrideInstructions = overrideInstructions; + OverrideTools = overrideTools; + Metadata = metadata; + } + + /// The ID of the assistant that should run the thread. + public string AssistantId { get; } + /// The overriden model name that the assistant should use to run the thread. + public string OverrideModelName { get; set; } + /// The overridden system instructions that the assistant should use to run the thread. + public string OverrideInstructions { get; set; } + /// + /// The overridden list of enabled tools that the assistant should use to run the thread. + /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. + /// The available derived classes include , and . + /// + public IList OverrideTools { get; } + /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. + public IDictionary Metadata { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/FunctionToolCall.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/FunctionToolCall.Serialization.cs new file mode 100644 index 000000000000..2b7e33546f65 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/FunctionToolCall.Serialization.cs @@ -0,0 +1,53 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class FunctionToolCall + { + internal static FunctionToolCall DeserializeFunctionToolCall(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + InternalFunctionToolCallDetails function = default; + string type = default; + string id = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("function"u8)) + { + function = InternalFunctionToolCallDetails.DeserializeInternalFunctionToolCallDetails(property.Value); + continue; + } + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString(); + continue; + } + if (property.NameEquals("id"u8)) + { + id = property.Value.GetString(); + continue; + } + } + return new FunctionToolCall(type, id, function); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new FunctionToolCall FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeFunctionToolCall(document.RootElement); + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/FunctionToolCall.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/FunctionToolCall.cs new file mode 100644 index 000000000000..4db7d3b5dc4e --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/FunctionToolCall.cs @@ -0,0 +1,41 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + /// + /// A tool call to a function tool, issued by the model in evaluation of a configured function tool, that represents + /// given function inputs and submitted function outputs needed or already fulfilled by the tool for the model to continue. + /// + public partial class FunctionToolCall : ToolCall + { + /// Initializes a new instance of . + /// The ID of the tool call. This ID must be referenced when you submit tool outputs. + /// The detailed information about the function called by the model. + /// or is null. + internal FunctionToolCall(string id, InternalFunctionToolCallDetails internalDetails) : base(id) + { + Argument.AssertNotNull(id, nameof(id)); + Argument.AssertNotNull(internalDetails, nameof(internalDetails)); + + Type = "function"; + InternalDetails = internalDetails; + } + + /// Initializes a new instance of . + /// The object type. + /// The ID of the tool call. This ID must be referenced when you submit tool outputs. + /// The detailed information about the function called by the model. + internal FunctionToolCall(string type, string id, InternalFunctionToolCallDetails internalDetails) : base(type, id) + { + InternalDetails = internalDetails; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/FunctionToolDefinition.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/FunctionToolDefinition.Serialization.cs new file mode 100644 index 000000000000..b27e41a52a5f --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/FunctionToolDefinition.Serialization.cs @@ -0,0 +1,66 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class FunctionToolDefinition : IUtf8JsonSerializable + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + { + writer.WriteStartObject(); + writer.WritePropertyName("function"u8); + writer.WriteObjectValue(InternalFunction); + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type); + writer.WriteEndObject(); + } + + internal static FunctionToolDefinition DeserializeFunctionToolDefinition(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + InternalFunctionDefinition function = default; + string type = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("function"u8)) + { + function = InternalFunctionDefinition.DeserializeInternalFunctionDefinition(property.Value); + continue; + } + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString(); + continue; + } + } + return new FunctionToolDefinition(type, function); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new FunctionToolDefinition FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeFunctionToolDefinition(document.RootElement); + } + + /// Convert into a Utf8JsonRequestContent. + internal override RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/FunctionToolDefinition.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/FunctionToolDefinition.cs new file mode 100644 index 000000000000..2678baf741b0 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/FunctionToolDefinition.cs @@ -0,0 +1,24 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + /// The input definition information for a function tool as used to configure an assistant. + public partial class FunctionToolDefinition : ToolDefinition + { + /// Initializes a new instance of . + /// The object type. + /// The definition of the concrete function that the function tool should call. + internal FunctionToolDefinition(string type, InternalFunctionDefinition internalFunction) : base(type) + { + InternalFunction = internalFunction; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalAssistantDeletionStatus.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalAssistantDeletionStatus.Serialization.cs new file mode 100644 index 000000000000..0c0f7fd2d63c --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalAssistantDeletionStatus.Serialization.cs @@ -0,0 +1,47 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure; + +namespace Azure.AI.OpenAI.Assistants +{ + internal partial class InternalAssistantDeletionStatus + { + internal static InternalAssistantDeletionStatus DeserializeInternalAssistantDeletionStatus(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + InternalAssistantDeletionStatusObject @object = default; + bool deleted = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("object"u8)) + { + @object = new InternalAssistantDeletionStatusObject(property.Value.GetString()); + continue; + } + if (property.NameEquals("deleted"u8)) + { + deleted = property.Value.GetBoolean(); + continue; + } + } + return new InternalAssistantDeletionStatus(deleted, @object); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static InternalAssistantDeletionStatus FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeInternalAssistantDeletionStatus(document.RootElement); + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalAssistantDeletionStatus.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalAssistantDeletionStatus.cs new file mode 100644 index 000000000000..e7dcf0da2c00 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalAssistantDeletionStatus.cs @@ -0,0 +1,30 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +namespace Azure.AI.OpenAI.Assistants +{ + /// The status of an assistant deletion operation. + internal partial class InternalAssistantDeletionStatus : InternalDeletionStatus + { + /// Initializes a new instance of . + /// A value indicating whether deletion was successful. + internal InternalAssistantDeletionStatus(bool deleted) : base(deleted) + { + } + + /// Initializes a new instance of . + /// A value indicating whether deletion was successful. + /// The object type, which is always 'assistant.deleted'. + internal InternalAssistantDeletionStatus(bool deleted, InternalAssistantDeletionStatusObject @object) : base(deleted) + { + Object = @object; + } + + /// The object type, which is always 'assistant.deleted'. + public InternalAssistantDeletionStatusObject Object { get; } = InternalAssistantDeletionStatusObject.AssistantDeleted; + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalAssistantDeletionStatusObject.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalAssistantDeletionStatusObject.cs new file mode 100644 index 000000000000..0a206a9567cd --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalAssistantDeletionStatusObject.cs @@ -0,0 +1,48 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Azure.AI.OpenAI.Assistants +{ + /// The InternalAssistantDeletionStatus_object. + internal readonly partial struct InternalAssistantDeletionStatusObject : IEquatable + { + private readonly string _value; + + /// Initializes a new instance of . + /// is null. + public InternalAssistantDeletionStatusObject(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string AssistantDeletedValue = "assistant.deleted"; + + /// assistant.deleted. + public static InternalAssistantDeletionStatusObject AssistantDeleted { get; } = new InternalAssistantDeletionStatusObject(AssistantDeletedValue); + /// Determines if two values are the same. + public static bool operator ==(InternalAssistantDeletionStatusObject left, InternalAssistantDeletionStatusObject right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(InternalAssistantDeletionStatusObject left, InternalAssistantDeletionStatusObject right) => !left.Equals(right); + /// Converts a string to a . + public static implicit operator InternalAssistantDeletionStatusObject(string value) => new InternalAssistantDeletionStatusObject(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is InternalAssistantDeletionStatusObject other && Equals(other); + /// + public bool Equals(InternalAssistantDeletionStatusObject other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value?.GetHashCode() ?? 0; + /// + public override string ToString() => _value; + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalAssistantFileDeletionStatus.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalAssistantFileDeletionStatus.Serialization.cs new file mode 100644 index 000000000000..d7367e77eea3 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalAssistantFileDeletionStatus.Serialization.cs @@ -0,0 +1,47 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure; + +namespace Azure.AI.OpenAI.Assistants +{ + internal partial class InternalAssistantFileDeletionStatus + { + internal static InternalAssistantFileDeletionStatus DeserializeInternalAssistantFileDeletionStatus(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + InternalAssistantFileDeletionStatusObject @object = default; + bool deleted = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("object"u8)) + { + @object = new InternalAssistantFileDeletionStatusObject(property.Value.GetString()); + continue; + } + if (property.NameEquals("deleted"u8)) + { + deleted = property.Value.GetBoolean(); + continue; + } + } + return new InternalAssistantFileDeletionStatus(deleted, @object); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static InternalAssistantFileDeletionStatus FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeInternalAssistantFileDeletionStatus(document.RootElement); + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalAssistantFileDeletionStatus.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalAssistantFileDeletionStatus.cs new file mode 100644 index 000000000000..ad3c552bd138 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalAssistantFileDeletionStatus.cs @@ -0,0 +1,30 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +namespace Azure.AI.OpenAI.Assistants +{ + /// The status of an assistant file deletion operation. + internal partial class InternalAssistantFileDeletionStatus : InternalDeletionStatus + { + /// Initializes a new instance of . + /// A value indicating whether deletion was successful. + internal InternalAssistantFileDeletionStatus(bool deleted) : base(deleted) + { + } + + /// Initializes a new instance of . + /// A value indicating whether deletion was successful. + /// The object type, which is always 'assistant.file.deleted'. + internal InternalAssistantFileDeletionStatus(bool deleted, InternalAssistantFileDeletionStatusObject @object) : base(deleted) + { + Object = @object; + } + + /// The object type, which is always 'assistant.file.deleted'. + public InternalAssistantFileDeletionStatusObject Object { get; } = InternalAssistantFileDeletionStatusObject.AssistantFileDeleted; + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalAssistantFileDeletionStatusObject.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalAssistantFileDeletionStatusObject.cs new file mode 100644 index 000000000000..45976bbd0937 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalAssistantFileDeletionStatusObject.cs @@ -0,0 +1,48 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Azure.AI.OpenAI.Assistants +{ + /// The InternalAssistantFileDeletionStatus_object. + internal readonly partial struct InternalAssistantFileDeletionStatusObject : IEquatable + { + private readonly string _value; + + /// Initializes a new instance of . + /// is null. + public InternalAssistantFileDeletionStatusObject(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string AssistantFileDeletedValue = "assistant.file.deleted"; + + /// assistant.file.deleted. + public static InternalAssistantFileDeletionStatusObject AssistantFileDeleted { get; } = new InternalAssistantFileDeletionStatusObject(AssistantFileDeletedValue); + /// Determines if two values are the same. + public static bool operator ==(InternalAssistantFileDeletionStatusObject left, InternalAssistantFileDeletionStatusObject right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(InternalAssistantFileDeletionStatusObject left, InternalAssistantFileDeletionStatusObject right) => !left.Equals(right); + /// Converts a string to a . + public static implicit operator InternalAssistantFileDeletionStatusObject(string value) => new InternalAssistantFileDeletionStatusObject(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is InternalAssistantFileDeletionStatusObject other && Equals(other); + /// + public bool Equals(InternalAssistantFileDeletionStatusObject other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value?.GetHashCode() ?? 0; + /// + public override string ToString() => _value; + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalCodeInterpreterToolCallDetails.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalCodeInterpreterToolCallDetails.Serialization.cs new file mode 100644 index 000000000000..961918d214b1 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalCodeInterpreterToolCallDetails.Serialization.cs @@ -0,0 +1,53 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Collections.Generic; +using System.Text.Json; +using Azure; + +namespace Azure.AI.OpenAI.Assistants +{ + internal partial class InternalCodeInterpreterToolCallDetails + { + internal static InternalCodeInterpreterToolCallDetails DeserializeInternalCodeInterpreterToolCallDetails(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string input = default; + IReadOnlyList outputs = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("input"u8)) + { + input = property.Value.GetString(); + continue; + } + if (property.NameEquals("outputs"u8)) + { + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(CodeInterpreterToolCallOutput.DeserializeCodeInterpreterToolCallOutput(item)); + } + outputs = array; + continue; + } + } + return new InternalCodeInterpreterToolCallDetails(input, outputs); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static InternalCodeInterpreterToolCallDetails FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeInternalCodeInterpreterToolCallDetails(document.RootElement); + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalCodeInterpreterToolCallDetails.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalCodeInterpreterToolCallDetails.cs new file mode 100644 index 000000000000..0ca3c2e9f672 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalCodeInterpreterToolCallDetails.cs @@ -0,0 +1,49 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Linq; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + /// The detailed information about a code interpreter invocation by the model. + internal partial class InternalCodeInterpreterToolCallDetails + { + /// Initializes a new instance of . + /// The input provided by the model to the code interpreter tool. + /// The outputs produced by the code interpreter tool back to the model in response to the tool call. + /// or is null. + internal InternalCodeInterpreterToolCallDetails(string input, IEnumerable outputs) + { + Argument.AssertNotNull(input, nameof(input)); + Argument.AssertNotNull(outputs, nameof(outputs)); + + Input = input; + Outputs = outputs.ToList(); + } + + /// Initializes a new instance of . + /// The input provided by the model to the code interpreter tool. + /// The outputs produced by the code interpreter tool back to the model in response to the tool call. + internal InternalCodeInterpreterToolCallDetails(string input, IReadOnlyList outputs) + { + Input = input; + Outputs = outputs; + } + + /// The input provided by the model to the code interpreter tool. + public string Input { get; } + /// + /// The outputs produced by the code interpreter tool back to the model in response to the tool call. + /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. + /// The available derived classes include and . + /// + public IReadOnlyList Outputs { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalDeletionStatus.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalDeletionStatus.cs new file mode 100644 index 000000000000..6ef9d256b527 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalDeletionStatus.cs @@ -0,0 +1,23 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +namespace Azure.AI.OpenAI.Assistants +{ + /// An abstract representation of an OpenAI deletion operation result status. + internal partial class InternalDeletionStatus + { + /// Initializes a new instance of . + /// A value indicating whether deletion was successful. + internal InternalDeletionStatus(bool deleted) + { + Deleted = deleted; + } + + /// A value indicating whether deletion was successful. + public bool Deleted { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFileDeletionStatus.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFileDeletionStatus.Serialization.cs new file mode 100644 index 000000000000..38b3bc738c01 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFileDeletionStatus.Serialization.cs @@ -0,0 +1,53 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure; + +namespace Azure.AI.OpenAI.Assistants +{ + internal partial class InternalFileDeletionStatus + { + internal static InternalFileDeletionStatus DeserializeInternalFileDeletionStatus(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + InternalFileDeletionStatusObject @object = default; + string id = default; + bool deleted = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("object"u8)) + { + @object = new InternalFileDeletionStatusObject(property.Value.GetString()); + continue; + } + if (property.NameEquals("id"u8)) + { + id = property.Value.GetString(); + continue; + } + if (property.NameEquals("deleted"u8)) + { + deleted = property.Value.GetBoolean(); + continue; + } + } + return new InternalFileDeletionStatus(deleted, @object, id); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static InternalFileDeletionStatus FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeInternalFileDeletionStatus(document.RootElement); + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFileDeletionStatus.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFileDeletionStatus.cs new file mode 100644 index 000000000000..765e44d5763b --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFileDeletionStatus.cs @@ -0,0 +1,43 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + /// A status response from a file deletion operation. + internal partial class InternalFileDeletionStatus : InternalDeletionStatus + { + /// Initializes a new instance of . + /// A value indicating whether deletion was successful. + /// The ID of the deleted file. + /// is null. + internal InternalFileDeletionStatus(bool deleted, string id) : base(deleted) + { + Argument.AssertNotNull(id, nameof(id)); + + Id = id; + } + + /// Initializes a new instance of . + /// A value indicating whether deletion was successful. + /// The object type, which is always 'file'. + /// The ID of the deleted file. + internal InternalFileDeletionStatus(bool deleted, InternalFileDeletionStatusObject @object, string id) : base(deleted) + { + Object = @object; + Id = id; + } + + /// The object type, which is always 'file'. + public InternalFileDeletionStatusObject Object { get; } = InternalFileDeletionStatusObject.File; + + /// The ID of the deleted file. + public string Id { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFileDeletionStatusObject.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFileDeletionStatusObject.cs new file mode 100644 index 000000000000..867dfbf1583b --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFileDeletionStatusObject.cs @@ -0,0 +1,48 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Azure.AI.OpenAI.Assistants +{ + /// The InternalFileDeletionStatus_object. + internal readonly partial struct InternalFileDeletionStatusObject : IEquatable + { + private readonly string _value; + + /// Initializes a new instance of . + /// is null. + public InternalFileDeletionStatusObject(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string FileValue = "file"; + + /// file. + public static InternalFileDeletionStatusObject File { get; } = new InternalFileDeletionStatusObject(FileValue); + /// Determines if two values are the same. + public static bool operator ==(InternalFileDeletionStatusObject left, InternalFileDeletionStatusObject right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(InternalFileDeletionStatusObject left, InternalFileDeletionStatusObject right) => !left.Equals(right); + /// Converts a string to a . + public static implicit operator InternalFileDeletionStatusObject(string value) => new InternalFileDeletionStatusObject(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is InternalFileDeletionStatusObject other && Equals(other); + /// + public bool Equals(InternalFileDeletionStatusObject other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value?.GetHashCode() ?? 0; + /// + public override string ToString() => _value; + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFileListResponse.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFileListResponse.Serialization.cs new file mode 100644 index 000000000000..9a50ae200613 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFileListResponse.Serialization.cs @@ -0,0 +1,53 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Collections.Generic; +using System.Text.Json; +using Azure; + +namespace Azure.AI.OpenAI.Assistants +{ + internal partial class InternalFileListResponse + { + internal static InternalFileListResponse DeserializeInternalFileListResponse(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + InternalFileListResponseObject @object = default; + IReadOnlyList data = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("object"u8)) + { + @object = new InternalFileListResponseObject(property.Value.GetString()); + continue; + } + if (property.NameEquals("data"u8)) + { + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(OpenAIFile.DeserializeOpenAIFile(item)); + } + data = array; + continue; + } + } + return new InternalFileListResponse(@object, data); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static InternalFileListResponse FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeInternalFileListResponse(document.RootElement); + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFileListResponse.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFileListResponse.cs new file mode 100644 index 000000000000..dfa3298d3ab3 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFileListResponse.cs @@ -0,0 +1,43 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Linq; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + /// The response data from a file list operation. + internal partial class InternalFileListResponse + { + /// Initializes a new instance of . + /// The files returned for the request. + /// is null. + internal InternalFileListResponse(IEnumerable data) + { + Argument.AssertNotNull(data, nameof(data)); + + Data = data.ToList(); + } + + /// Initializes a new instance of . + /// The object type, which is always 'list'. + /// The files returned for the request. + internal InternalFileListResponse(InternalFileListResponseObject @object, IReadOnlyList data) + { + Object = @object; + Data = data; + } + + /// The object type, which is always 'list'. + public InternalFileListResponseObject Object { get; } = InternalFileListResponseObject.List; + + /// The files returned for the request. + public IReadOnlyList Data { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFileListResponseObject.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFileListResponseObject.cs new file mode 100644 index 000000000000..4690ffa14539 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFileListResponseObject.cs @@ -0,0 +1,48 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Azure.AI.OpenAI.Assistants +{ + /// The InternalFileListResponse_object. + internal readonly partial struct InternalFileListResponseObject : IEquatable + { + private readonly string _value; + + /// Initializes a new instance of . + /// is null. + public InternalFileListResponseObject(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string ListValue = "list"; + + /// list. + public static InternalFileListResponseObject List { get; } = new InternalFileListResponseObject(ListValue); + /// Determines if two values are the same. + public static bool operator ==(InternalFileListResponseObject left, InternalFileListResponseObject right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(InternalFileListResponseObject left, InternalFileListResponseObject right) => !left.Equals(right); + /// Converts a string to a . + public static implicit operator InternalFileListResponseObject(string value) => new InternalFileListResponseObject(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is InternalFileListResponseObject other && Equals(other); + /// + public bool Equals(InternalFileListResponseObject other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value?.GetHashCode() ?? 0; + /// + public override string ToString() => _value; + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFunctionDefinition.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFunctionDefinition.Serialization.cs new file mode 100644 index 000000000000..11a35348bb0a --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFunctionDefinition.Serialization.cs @@ -0,0 +1,82 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Text.Json; +using Azure; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + internal partial class InternalFunctionDefinition : IUtf8JsonSerializable + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + { + writer.WriteStartObject(); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(Name); + writer.WritePropertyName("description"u8); + writer.WriteStringValue(Description); + writer.WritePropertyName("parameters"u8); +#if NET6_0_OR_GREATER + writer.WriteRawValue(Parameters); +#else + using (JsonDocument document = JsonDocument.Parse(Parameters)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + writer.WriteEndObject(); + } + + internal static InternalFunctionDefinition DeserializeInternalFunctionDefinition(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string name = default; + string description = default; + BinaryData parameters = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("name"u8)) + { + name = property.Value.GetString(); + continue; + } + if (property.NameEquals("description"u8)) + { + description = property.Value.GetString(); + continue; + } + if (property.NameEquals("parameters"u8)) + { + parameters = BinaryData.FromString(property.Value.GetRawText()); + continue; + } + } + return new InternalFunctionDefinition(name, description, parameters); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static InternalFunctionDefinition FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeInternalFunctionDefinition(document.RootElement); + } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFunctionDefinition.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFunctionDefinition.cs new file mode 100644 index 000000000000..dcd47a942e97 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFunctionDefinition.cs @@ -0,0 +1,68 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + /// The input definition information for a function. + internal partial class InternalFunctionDefinition + { + /// Initializes a new instance of . + /// The name of the function to be called. + /// A description of what the function does, used by the model to choose when and how to call the function. + /// The parameters the functions accepts, described as a JSON Schema object. + /// , or is null. + public InternalFunctionDefinition(string name, string description, BinaryData parameters) + { + Argument.AssertNotNull(name, nameof(name)); + Argument.AssertNotNull(description, nameof(description)); + Argument.AssertNotNull(parameters, nameof(parameters)); + + Name = name; + Description = description; + Parameters = parameters; + } + + /// The name of the function to be called. + public string Name { get; set; } + /// A description of what the function does, used by the model to choose when and how to call the function. + public string Description { get; set; } + /// + /// The parameters the functions accepts, described as a JSON Schema object. + /// + /// To assign an object to this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + public BinaryData Parameters { get; set; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFunctionToolCallDetails.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFunctionToolCallDetails.Serialization.cs new file mode 100644 index 000000000000..4b2bfb1e5743 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFunctionToolCallDetails.Serialization.cs @@ -0,0 +1,59 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + internal partial class InternalFunctionToolCallDetails + { + internal static InternalFunctionToolCallDetails DeserializeInternalFunctionToolCallDetails(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string name = default; + string arguments = default; + Optional output = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("name"u8)) + { + name = property.Value.GetString(); + continue; + } + if (property.NameEquals("arguments"u8)) + { + arguments = property.Value.GetString(); + continue; + } + if (property.NameEquals("output"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + output = null; + continue; + } + output = property.Value.GetString(); + continue; + } + } + return new InternalFunctionToolCallDetails(name, arguments, output.Value); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static InternalFunctionToolCallDetails FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeInternalFunctionToolCallDetails(document.RootElement); + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFunctionToolCallDetails.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFunctionToolCallDetails.cs new file mode 100644 index 000000000000..1fb8fec11e3c --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFunctionToolCallDetails.cs @@ -0,0 +1,47 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + /// The detailed information about the function called by the model. + internal partial class InternalFunctionToolCallDetails + { + /// Initializes a new instance of . + /// The name of the function. + /// The arguments that the model requires are provided to the named function. + /// or is null. + internal InternalFunctionToolCallDetails(string name, string arguments) + { + Argument.AssertNotNull(name, nameof(name)); + Argument.AssertNotNull(arguments, nameof(arguments)); + + Name = name; + Arguments = arguments; + } + + /// Initializes a new instance of . + /// The name of the function. + /// The arguments that the model requires are provided to the named function. + /// The output of the function, only populated for function calls that have already have had their outputs submitted. + internal InternalFunctionToolCallDetails(string name, string arguments, string output) + { + Name = name; + Arguments = arguments; + Output = output; + } + + /// The name of the function. + public string Name { get; } + /// The arguments that the model requires are provided to the named function. + public string Arguments { get; } + /// The output of the function, only populated for function calls that have already have had their outputs submitted. + public string Output { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageFilePathDetails.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageFilePathDetails.Serialization.cs new file mode 100644 index 000000000000..69246f5698a3 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageFilePathDetails.Serialization.cs @@ -0,0 +1,58 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + internal partial class InternalMessageFilePathDetails : IUtf8JsonSerializable + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + { + writer.WriteStartObject(); + writer.WritePropertyName("file_id"u8); + writer.WriteStringValue(FileId); + writer.WriteEndObject(); + } + + internal static InternalMessageFilePathDetails DeserializeInternalMessageFilePathDetails(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string fileId = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("file_id"u8)) + { + fileId = property.Value.GetString(); + continue; + } + } + return new InternalMessageFilePathDetails(fileId); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static InternalMessageFilePathDetails FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeInternalMessageFilePathDetails(document.RootElement); + } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageFilePathDetails.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageFilePathDetails.cs new file mode 100644 index 000000000000..5ac8e1d63285 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageFilePathDetails.cs @@ -0,0 +1,29 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + /// An encapsulation of an image file ID, as used by message image content. + internal partial class InternalMessageFilePathDetails + { + /// Initializes a new instance of . + /// The ID of the specific file that the citation is from. + /// is null. + public InternalMessageFilePathDetails(string fileId) + { + Argument.AssertNotNull(fileId, nameof(fileId)); + + FileId = fileId; + } + + /// The ID of the specific file that the citation is from. + public string FileId { get; set; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageImageFileDetails.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageImageFileDetails.Serialization.cs new file mode 100644 index 000000000000..f889ce642105 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageImageFileDetails.Serialization.cs @@ -0,0 +1,58 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + internal partial class InternalMessageImageFileDetails : IUtf8JsonSerializable + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + { + writer.WriteStartObject(); + writer.WritePropertyName("file_id"u8); + writer.WriteObjectValue(InternalDetails); + writer.WriteEndObject(); + } + + internal static InternalMessageImageFileDetails DeserializeInternalMessageImageFileDetails(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + InternalMessageImageFileIdDetails fileId = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("file_id"u8)) + { + fileId = InternalMessageImageFileIdDetails.DeserializeInternalMessageImageFileIdDetails(property.Value); + continue; + } + } + return new InternalMessageImageFileDetails(fileId); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static InternalMessageImageFileDetails FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeInternalMessageImageFileDetails(document.RootElement); + } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageImageFileDetails.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageImageFileDetails.cs new file mode 100644 index 000000000000..e5e421864ee0 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageImageFileDetails.cs @@ -0,0 +1,29 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + /// An image reference, as represented in thread message content. + internal partial class InternalMessageImageFileDetails + { + /// Initializes a new instance of . + /// The ID for the file associated with this image. + /// is null. + public InternalMessageImageFileDetails(InternalMessageImageFileIdDetails internalDetails) + { + Argument.AssertNotNull(internalDetails, nameof(internalDetails)); + + InternalDetails = internalDetails; + } + + /// The ID for the file associated with this image. + public InternalMessageImageFileIdDetails InternalDetails { get; set; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageImageFileIdDetails.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageImageFileIdDetails.Serialization.cs new file mode 100644 index 000000000000..2e55a4f2306c --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageImageFileIdDetails.Serialization.cs @@ -0,0 +1,58 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + internal partial class InternalMessageImageFileIdDetails : IUtf8JsonSerializable + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + { + writer.WriteStartObject(); + writer.WritePropertyName("file_id"u8); + writer.WriteStringValue(FileId); + writer.WriteEndObject(); + } + + internal static InternalMessageImageFileIdDetails DeserializeInternalMessageImageFileIdDetails(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string fileId = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("file_id"u8)) + { + fileId = property.Value.GetString(); + continue; + } + } + return new InternalMessageImageFileIdDetails(fileId); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static InternalMessageImageFileIdDetails FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeInternalMessageImageFileIdDetails(document.RootElement); + } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageImageFileIdDetails.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageImageFileIdDetails.cs new file mode 100644 index 000000000000..456283136a29 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageImageFileIdDetails.cs @@ -0,0 +1,29 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + /// An encapsulation of an image file ID, as used by message image content. + internal partial class InternalMessageImageFileIdDetails + { + /// Initializes a new instance of . + /// The ID of the specific image file. + /// is null. + public InternalMessageImageFileIdDetails(string fileId) + { + Argument.AssertNotNull(fileId, nameof(fileId)); + + FileId = fileId; + } + + /// The ID of the specific image file. + public string FileId { get; set; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextDetails.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextDetails.Serialization.cs new file mode 100644 index 000000000000..0344e871c7c6 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextDetails.Serialization.cs @@ -0,0 +1,77 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Collections.Generic; +using System.Text.Json; +using Azure; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + internal partial class InternalMessageTextDetails : IUtf8JsonSerializable + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + { + writer.WriteStartObject(); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(Text); + writer.WritePropertyName("annotations"u8); + writer.WriteStartArray(); + foreach (var item in Annotations) + { + writer.WriteObjectValue(item); + } + writer.WriteEndArray(); + writer.WriteEndObject(); + } + + internal static InternalMessageTextDetails DeserializeInternalMessageTextDetails(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string value = default; + IList annotations = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("value"u8)) + { + value = property.Value.GetString(); + continue; + } + if (property.NameEquals("annotations"u8)) + { + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(MessageTextAnnotation.DeserializeMessageTextAnnotation(item)); + } + annotations = array; + continue; + } + } + return new InternalMessageTextDetails(value, annotations); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static InternalMessageTextDetails FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeInternalMessageTextDetails(document.RootElement); + } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextDetails.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextDetails.cs new file mode 100644 index 000000000000..b3bb32d0f9b9 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextDetails.cs @@ -0,0 +1,49 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Linq; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + /// The text and associated annotations for a single item of assistant thread message content. + internal partial class InternalMessageTextDetails + { + /// Initializes a new instance of . + /// The text data. + /// A list of annotations associated with this text. + /// or is null. + public InternalMessageTextDetails(string text, IEnumerable annotations) + { + Argument.AssertNotNull(text, nameof(text)); + Argument.AssertNotNull(annotations, nameof(annotations)); + + Text = text; + Annotations = annotations.ToList(); + } + + /// Initializes a new instance of . + /// The text data. + /// A list of annotations associated with this text. + internal InternalMessageTextDetails(string text, IList annotations) + { + Text = text; + Annotations = annotations; + } + + /// The text data. + public string Text { get; set; } + /// + /// A list of annotations associated with this text. + /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. + /// The available derived classes include and . + /// + public IList Annotations { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextFileCitationDetails.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextFileCitationDetails.Serialization.cs new file mode 100644 index 000000000000..3b15e9ec02c5 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextFileCitationDetails.Serialization.cs @@ -0,0 +1,66 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + internal partial class InternalMessageTextFileCitationDetails : IUtf8JsonSerializable + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + { + writer.WriteStartObject(); + writer.WritePropertyName("file_id"u8); + writer.WriteStringValue(FileId); + writer.WritePropertyName("quote"u8); + writer.WriteStringValue(Quote); + writer.WriteEndObject(); + } + + internal static InternalMessageTextFileCitationDetails DeserializeInternalMessageTextFileCitationDetails(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string fileId = default; + string quote = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("file_id"u8)) + { + fileId = property.Value.GetString(); + continue; + } + if (property.NameEquals("quote"u8)) + { + quote = property.Value.GetString(); + continue; + } + } + return new InternalMessageTextFileCitationDetails(fileId, quote); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static InternalMessageTextFileCitationDetails FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeInternalMessageTextFileCitationDetails(document.RootElement); + } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextFileCitationDetails.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextFileCitationDetails.cs new file mode 100644 index 000000000000..410c68d3d12d --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextFileCitationDetails.cs @@ -0,0 +1,34 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + /// A representation of a file-based text citation, as used in a file-based annotation of text thread message content. + internal partial class InternalMessageTextFileCitationDetails + { + /// Initializes a new instance of . + /// The ID of the file associated with this citation. + /// The specific quote cited in the associated file. + /// or is null. + public InternalMessageTextFileCitationDetails(string fileId, string quote) + { + Argument.AssertNotNull(fileId, nameof(fileId)); + Argument.AssertNotNull(quote, nameof(quote)); + + FileId = fileId; + Quote = quote; + } + + /// The ID of the file associated with this citation. + public string FileId { get; set; } + /// The specific quote cited in the associated file. + public string Quote { get; set; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfAssistant.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfAssistant.Serialization.cs new file mode 100644 index 000000000000..3d336eb4727b --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfAssistant.Serialization.cs @@ -0,0 +1,71 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Collections.Generic; +using System.Text.Json; +using Azure; + +namespace Azure.AI.OpenAI.Assistants +{ + internal partial class InternalOpenAIPageableListOfAssistant + { + internal static InternalOpenAIPageableListOfAssistant DeserializeInternalOpenAIPageableListOfAssistant(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + OpenAIPageableListOfAssistantObject @object = default; + IReadOnlyList data = default; + string firstId = default; + string lastId = default; + bool hasMore = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("object"u8)) + { + @object = new OpenAIPageableListOfAssistantObject(property.Value.GetString()); + continue; + } + if (property.NameEquals("data"u8)) + { + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(Assistant.DeserializeAssistant(item)); + } + data = array; + continue; + } + if (property.NameEquals("first_id"u8)) + { + firstId = property.Value.GetString(); + continue; + } + if (property.NameEquals("last_id"u8)) + { + lastId = property.Value.GetString(); + continue; + } + if (property.NameEquals("has_more"u8)) + { + hasMore = property.Value.GetBoolean(); + continue; + } + } + return new InternalOpenAIPageableListOfAssistant(@object, data, firstId, lastId, hasMore); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static InternalOpenAIPageableListOfAssistant FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeInternalOpenAIPageableListOfAssistant(document.RootElement); + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfAssistant.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfAssistant.cs new file mode 100644 index 000000000000..f8c45e114523 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfAssistant.cs @@ -0,0 +1,63 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Linq; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + /// The response data for a requested list of items. + internal partial class InternalOpenAIPageableListOfAssistant + { + /// Initializes a new instance of . + /// The requested list of items. + /// The first ID represented in this list. + /// The last ID represented in this list. + /// A value indicating whether there are additional values available not captured in this list. + /// , or is null. + internal InternalOpenAIPageableListOfAssistant(IEnumerable data, string firstId, string lastId, bool hasMore) + { + Argument.AssertNotNull(data, nameof(data)); + Argument.AssertNotNull(firstId, nameof(firstId)); + Argument.AssertNotNull(lastId, nameof(lastId)); + + Data = data.ToList(); + FirstId = firstId; + LastId = lastId; + HasMore = hasMore; + } + + /// Initializes a new instance of . + /// The object type, which is always list. + /// The requested list of items. + /// The first ID represented in this list. + /// The last ID represented in this list. + /// A value indicating whether there are additional values available not captured in this list. + internal InternalOpenAIPageableListOfAssistant(OpenAIPageableListOfAssistantObject @object, IReadOnlyList data, string firstId, string lastId, bool hasMore) + { + Object = @object; + Data = data; + FirstId = firstId; + LastId = lastId; + HasMore = hasMore; + } + + /// The object type, which is always list. + public OpenAIPageableListOfAssistantObject Object { get; } = OpenAIPageableListOfAssistantObject.List; + + /// The requested list of items. + public IReadOnlyList Data { get; } + /// The first ID represented in this list. + public string FirstId { get; } + /// The last ID represented in this list. + public string LastId { get; } + /// A value indicating whether there are additional values available not captured in this list. + public bool HasMore { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfAssistantFile.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfAssistantFile.Serialization.cs new file mode 100644 index 000000000000..416222fe1a03 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfAssistantFile.Serialization.cs @@ -0,0 +1,71 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Collections.Generic; +using System.Text.Json; +using Azure; + +namespace Azure.AI.OpenAI.Assistants +{ + internal partial class InternalOpenAIPageableListOfAssistantFile + { + internal static InternalOpenAIPageableListOfAssistantFile DeserializeInternalOpenAIPageableListOfAssistantFile(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + OpenAIPageableListOfAssistantFileObject @object = default; + IReadOnlyList data = default; + string firstId = default; + string lastId = default; + bool hasMore = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("object"u8)) + { + @object = new OpenAIPageableListOfAssistantFileObject(property.Value.GetString()); + continue; + } + if (property.NameEquals("data"u8)) + { + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(AssistantFile.DeserializeAssistantFile(item)); + } + data = array; + continue; + } + if (property.NameEquals("first_id"u8)) + { + firstId = property.Value.GetString(); + continue; + } + if (property.NameEquals("last_id"u8)) + { + lastId = property.Value.GetString(); + continue; + } + if (property.NameEquals("has_more"u8)) + { + hasMore = property.Value.GetBoolean(); + continue; + } + } + return new InternalOpenAIPageableListOfAssistantFile(@object, data, firstId, lastId, hasMore); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static InternalOpenAIPageableListOfAssistantFile FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeInternalOpenAIPageableListOfAssistantFile(document.RootElement); + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfAssistantFile.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfAssistantFile.cs new file mode 100644 index 000000000000..093d5095f0a2 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfAssistantFile.cs @@ -0,0 +1,63 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Linq; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + /// The response data for a requested list of items. + internal partial class InternalOpenAIPageableListOfAssistantFile + { + /// Initializes a new instance of . + /// The requested list of items. + /// The first ID represented in this list. + /// The last ID represented in this list. + /// A value indicating whether there are additional values available not captured in this list. + /// , or is null. + internal InternalOpenAIPageableListOfAssistantFile(IEnumerable data, string firstId, string lastId, bool hasMore) + { + Argument.AssertNotNull(data, nameof(data)); + Argument.AssertNotNull(firstId, nameof(firstId)); + Argument.AssertNotNull(lastId, nameof(lastId)); + + Data = data.ToList(); + FirstId = firstId; + LastId = lastId; + HasMore = hasMore; + } + + /// Initializes a new instance of . + /// The object type, which is always list. + /// The requested list of items. + /// The first ID represented in this list. + /// The last ID represented in this list. + /// A value indicating whether there are additional values available not captured in this list. + internal InternalOpenAIPageableListOfAssistantFile(OpenAIPageableListOfAssistantFileObject @object, IReadOnlyList data, string firstId, string lastId, bool hasMore) + { + Object = @object; + Data = data; + FirstId = firstId; + LastId = lastId; + HasMore = hasMore; + } + + /// The object type, which is always list. + public OpenAIPageableListOfAssistantFileObject Object { get; } = OpenAIPageableListOfAssistantFileObject.List; + + /// The requested list of items. + public IReadOnlyList Data { get; } + /// The first ID represented in this list. + public string FirstId { get; } + /// The last ID represented in this list. + public string LastId { get; } + /// A value indicating whether there are additional values available not captured in this list. + public bool HasMore { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfMessageFile.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfMessageFile.Serialization.cs new file mode 100644 index 000000000000..799114f747b6 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfMessageFile.Serialization.cs @@ -0,0 +1,71 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Collections.Generic; +using System.Text.Json; +using Azure; + +namespace Azure.AI.OpenAI.Assistants +{ + internal partial class InternalOpenAIPageableListOfMessageFile + { + internal static InternalOpenAIPageableListOfMessageFile DeserializeInternalOpenAIPageableListOfMessageFile(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + OpenAIPageableListOfMessageFileObject @object = default; + IReadOnlyList data = default; + string firstId = default; + string lastId = default; + bool hasMore = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("object"u8)) + { + @object = new OpenAIPageableListOfMessageFileObject(property.Value.GetString()); + continue; + } + if (property.NameEquals("data"u8)) + { + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(MessageFile.DeserializeMessageFile(item)); + } + data = array; + continue; + } + if (property.NameEquals("first_id"u8)) + { + firstId = property.Value.GetString(); + continue; + } + if (property.NameEquals("last_id"u8)) + { + lastId = property.Value.GetString(); + continue; + } + if (property.NameEquals("has_more"u8)) + { + hasMore = property.Value.GetBoolean(); + continue; + } + } + return new InternalOpenAIPageableListOfMessageFile(@object, data, firstId, lastId, hasMore); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static InternalOpenAIPageableListOfMessageFile FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeInternalOpenAIPageableListOfMessageFile(document.RootElement); + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfMessageFile.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfMessageFile.cs new file mode 100644 index 000000000000..6168736cef3e --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfMessageFile.cs @@ -0,0 +1,63 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Linq; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + /// The response data for a requested list of items. + internal partial class InternalOpenAIPageableListOfMessageFile + { + /// Initializes a new instance of . + /// The requested list of items. + /// The first ID represented in this list. + /// The last ID represented in this list. + /// A value indicating whether there are additional values available not captured in this list. + /// , or is null. + internal InternalOpenAIPageableListOfMessageFile(IEnumerable data, string firstId, string lastId, bool hasMore) + { + Argument.AssertNotNull(data, nameof(data)); + Argument.AssertNotNull(firstId, nameof(firstId)); + Argument.AssertNotNull(lastId, nameof(lastId)); + + Data = data.ToList(); + FirstId = firstId; + LastId = lastId; + HasMore = hasMore; + } + + /// Initializes a new instance of . + /// The object type, which is always list. + /// The requested list of items. + /// The first ID represented in this list. + /// The last ID represented in this list. + /// A value indicating whether there are additional values available not captured in this list. + internal InternalOpenAIPageableListOfMessageFile(OpenAIPageableListOfMessageFileObject @object, IReadOnlyList data, string firstId, string lastId, bool hasMore) + { + Object = @object; + Data = data; + FirstId = firstId; + LastId = lastId; + HasMore = hasMore; + } + + /// The object type, which is always list. + public OpenAIPageableListOfMessageFileObject Object { get; } = OpenAIPageableListOfMessageFileObject.List; + + /// The requested list of items. + public IReadOnlyList Data { get; } + /// The first ID represented in this list. + public string FirstId { get; } + /// The last ID represented in this list. + public string LastId { get; } + /// A value indicating whether there are additional values available not captured in this list. + public bool HasMore { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfRunStep.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfRunStep.Serialization.cs new file mode 100644 index 000000000000..dfa4bb0c4359 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfRunStep.Serialization.cs @@ -0,0 +1,71 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Collections.Generic; +using System.Text.Json; +using Azure; + +namespace Azure.AI.OpenAI.Assistants +{ + internal partial class InternalOpenAIPageableListOfRunStep + { + internal static InternalOpenAIPageableListOfRunStep DeserializeInternalOpenAIPageableListOfRunStep(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + OpenAIPageableListOfRunStepObject @object = default; + IReadOnlyList data = default; + string firstId = default; + string lastId = default; + bool hasMore = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("object"u8)) + { + @object = new OpenAIPageableListOfRunStepObject(property.Value.GetString()); + continue; + } + if (property.NameEquals("data"u8)) + { + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(RunStep.DeserializeRunStep(item)); + } + data = array; + continue; + } + if (property.NameEquals("first_id"u8)) + { + firstId = property.Value.GetString(); + continue; + } + if (property.NameEquals("last_id"u8)) + { + lastId = property.Value.GetString(); + continue; + } + if (property.NameEquals("has_more"u8)) + { + hasMore = property.Value.GetBoolean(); + continue; + } + } + return new InternalOpenAIPageableListOfRunStep(@object, data, firstId, lastId, hasMore); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static InternalOpenAIPageableListOfRunStep FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeInternalOpenAIPageableListOfRunStep(document.RootElement); + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfRunStep.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfRunStep.cs new file mode 100644 index 000000000000..3b8704211093 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfRunStep.cs @@ -0,0 +1,63 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Linq; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + /// The response data for a requested list of items. + internal partial class InternalOpenAIPageableListOfRunStep + { + /// Initializes a new instance of . + /// The requested list of items. + /// The first ID represented in this list. + /// The last ID represented in this list. + /// A value indicating whether there are additional values available not captured in this list. + /// , or is null. + internal InternalOpenAIPageableListOfRunStep(IEnumerable data, string firstId, string lastId, bool hasMore) + { + Argument.AssertNotNull(data, nameof(data)); + Argument.AssertNotNull(firstId, nameof(firstId)); + Argument.AssertNotNull(lastId, nameof(lastId)); + + Data = data.ToList(); + FirstId = firstId; + LastId = lastId; + HasMore = hasMore; + } + + /// Initializes a new instance of . + /// The object type, which is always list. + /// The requested list of items. + /// The first ID represented in this list. + /// The last ID represented in this list. + /// A value indicating whether there are additional values available not captured in this list. + internal InternalOpenAIPageableListOfRunStep(OpenAIPageableListOfRunStepObject @object, IReadOnlyList data, string firstId, string lastId, bool hasMore) + { + Object = @object; + Data = data; + FirstId = firstId; + LastId = lastId; + HasMore = hasMore; + } + + /// The object type, which is always list. + public OpenAIPageableListOfRunStepObject Object { get; } = OpenAIPageableListOfRunStepObject.List; + + /// The requested list of items. + public IReadOnlyList Data { get; } + /// The first ID represented in this list. + public string FirstId { get; } + /// The last ID represented in this list. + public string LastId { get; } + /// A value indicating whether there are additional values available not captured in this list. + public bool HasMore { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfThreadMessage.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfThreadMessage.Serialization.cs new file mode 100644 index 000000000000..9fdfad45e9f9 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfThreadMessage.Serialization.cs @@ -0,0 +1,71 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Collections.Generic; +using System.Text.Json; +using Azure; + +namespace Azure.AI.OpenAI.Assistants +{ + internal partial class InternalOpenAIPageableListOfThreadMessage + { + internal static InternalOpenAIPageableListOfThreadMessage DeserializeInternalOpenAIPageableListOfThreadMessage(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + OpenAIPageableListOfThreadMessageObject @object = default; + IReadOnlyList data = default; + string firstId = default; + string lastId = default; + bool hasMore = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("object"u8)) + { + @object = new OpenAIPageableListOfThreadMessageObject(property.Value.GetString()); + continue; + } + if (property.NameEquals("data"u8)) + { + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(ThreadMessage.DeserializeThreadMessage(item)); + } + data = array; + continue; + } + if (property.NameEquals("first_id"u8)) + { + firstId = property.Value.GetString(); + continue; + } + if (property.NameEquals("last_id"u8)) + { + lastId = property.Value.GetString(); + continue; + } + if (property.NameEquals("has_more"u8)) + { + hasMore = property.Value.GetBoolean(); + continue; + } + } + return new InternalOpenAIPageableListOfThreadMessage(@object, data, firstId, lastId, hasMore); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static InternalOpenAIPageableListOfThreadMessage FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeInternalOpenAIPageableListOfThreadMessage(document.RootElement); + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfThreadMessage.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfThreadMessage.cs new file mode 100644 index 000000000000..baa672b694b3 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfThreadMessage.cs @@ -0,0 +1,63 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Linq; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + /// The response data for a requested list of items. + internal partial class InternalOpenAIPageableListOfThreadMessage + { + /// Initializes a new instance of . + /// The requested list of items. + /// The first ID represented in this list. + /// The last ID represented in this list. + /// A value indicating whether there are additional values available not captured in this list. + /// , or is null. + internal InternalOpenAIPageableListOfThreadMessage(IEnumerable data, string firstId, string lastId, bool hasMore) + { + Argument.AssertNotNull(data, nameof(data)); + Argument.AssertNotNull(firstId, nameof(firstId)); + Argument.AssertNotNull(lastId, nameof(lastId)); + + Data = data.ToList(); + FirstId = firstId; + LastId = lastId; + HasMore = hasMore; + } + + /// Initializes a new instance of . + /// The object type, which is always list. + /// The requested list of items. + /// The first ID represented in this list. + /// The last ID represented in this list. + /// A value indicating whether there are additional values available not captured in this list. + internal InternalOpenAIPageableListOfThreadMessage(OpenAIPageableListOfThreadMessageObject @object, IReadOnlyList data, string firstId, string lastId, bool hasMore) + { + Object = @object; + Data = data; + FirstId = firstId; + LastId = lastId; + HasMore = hasMore; + } + + /// The object type, which is always list. + public OpenAIPageableListOfThreadMessageObject Object { get; } = OpenAIPageableListOfThreadMessageObject.List; + + /// The requested list of items. + public IReadOnlyList Data { get; } + /// The first ID represented in this list. + public string FirstId { get; } + /// The last ID represented in this list. + public string LastId { get; } + /// A value indicating whether there are additional values available not captured in this list. + public bool HasMore { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfThreadRun.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfThreadRun.Serialization.cs new file mode 100644 index 000000000000..0fbe99c9997b --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfThreadRun.Serialization.cs @@ -0,0 +1,71 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Collections.Generic; +using System.Text.Json; +using Azure; + +namespace Azure.AI.OpenAI.Assistants +{ + internal partial class InternalOpenAIPageableListOfThreadRun + { + internal static InternalOpenAIPageableListOfThreadRun DeserializeInternalOpenAIPageableListOfThreadRun(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + OpenAIPageableListOfThreadRunObject @object = default; + IReadOnlyList data = default; + string firstId = default; + string lastId = default; + bool hasMore = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("object"u8)) + { + @object = new OpenAIPageableListOfThreadRunObject(property.Value.GetString()); + continue; + } + if (property.NameEquals("data"u8)) + { + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(ThreadRun.DeserializeThreadRun(item)); + } + data = array; + continue; + } + if (property.NameEquals("first_id"u8)) + { + firstId = property.Value.GetString(); + continue; + } + if (property.NameEquals("last_id"u8)) + { + lastId = property.Value.GetString(); + continue; + } + if (property.NameEquals("has_more"u8)) + { + hasMore = property.Value.GetBoolean(); + continue; + } + } + return new InternalOpenAIPageableListOfThreadRun(@object, data, firstId, lastId, hasMore); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static InternalOpenAIPageableListOfThreadRun FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeInternalOpenAIPageableListOfThreadRun(document.RootElement); + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfThreadRun.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfThreadRun.cs new file mode 100644 index 000000000000..51f283ff04f1 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfThreadRun.cs @@ -0,0 +1,63 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Linq; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + /// The response data for a requested list of items. + internal partial class InternalOpenAIPageableListOfThreadRun + { + /// Initializes a new instance of . + /// The requested list of items. + /// The first ID represented in this list. + /// The last ID represented in this list. + /// A value indicating whether there are additional values available not captured in this list. + /// , or is null. + internal InternalOpenAIPageableListOfThreadRun(IEnumerable data, string firstId, string lastId, bool hasMore) + { + Argument.AssertNotNull(data, nameof(data)); + Argument.AssertNotNull(firstId, nameof(firstId)); + Argument.AssertNotNull(lastId, nameof(lastId)); + + Data = data.ToList(); + FirstId = firstId; + LastId = lastId; + HasMore = hasMore; + } + + /// Initializes a new instance of . + /// The object type, which is always list. + /// The requested list of items. + /// The first ID represented in this list. + /// The last ID represented in this list. + /// A value indicating whether there are additional values available not captured in this list. + internal InternalOpenAIPageableListOfThreadRun(OpenAIPageableListOfThreadRunObject @object, IReadOnlyList data, string firstId, string lastId, bool hasMore) + { + Object = @object; + Data = data; + FirstId = firstId; + LastId = lastId; + HasMore = hasMore; + } + + /// The object type, which is always list. + public OpenAIPageableListOfThreadRunObject Object { get; } = OpenAIPageableListOfThreadRunObject.List; + + /// The requested list of items. + public IReadOnlyList Data { get; } + /// The first ID represented in this list. + public string FirstId { get; } + /// The last ID represented in this list. + public string LastId { get; } + /// A value indicating whether there are additional values available not captured in this list. + public bool HasMore { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalSubmitToolOutputsDetails.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalSubmitToolOutputsDetails.Serialization.cs new file mode 100644 index 000000000000..46bd3aab4aeb --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalSubmitToolOutputsDetails.Serialization.cs @@ -0,0 +1,47 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Collections.Generic; +using System.Text.Json; +using Azure; + +namespace Azure.AI.OpenAI.Assistants +{ + internal partial class InternalSubmitToolOutputsDetails + { + internal static InternalSubmitToolOutputsDetails DeserializeInternalSubmitToolOutputsDetails(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + IReadOnlyList toolCalls = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("tool_calls"u8)) + { + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(ToolCall.DeserializeToolCall(item)); + } + toolCalls = array; + continue; + } + } + return new InternalSubmitToolOutputsDetails(toolCalls); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static InternalSubmitToolOutputsDetails FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeInternalSubmitToolOutputsDetails(document.RootElement); + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalSubmitToolOutputsDetails.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalSubmitToolOutputsDetails.cs new file mode 100644 index 000000000000..d12cae50c58a --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalSubmitToolOutputsDetails.cs @@ -0,0 +1,42 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Linq; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + /// The details describing tools that should be called to submit tool outputs. + internal partial class InternalSubmitToolOutputsDetails + { + /// Initializes a new instance of . + /// The list of tool calls that must be resolved for the assistant thread run to continue. + /// is null. + internal InternalSubmitToolOutputsDetails(IEnumerable toolCalls) + { + Argument.AssertNotNull(toolCalls, nameof(toolCalls)); + + ToolCalls = toolCalls.ToList(); + } + + /// Initializes a new instance of . + /// The list of tool calls that must be resolved for the assistant thread run to continue. + internal InternalSubmitToolOutputsDetails(IReadOnlyList toolCalls) + { + ToolCalls = toolCalls; + } + + /// + /// The list of tool calls that must be resolved for the assistant thread run to continue. + /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. + /// The available derived classes include , and . + /// + public IReadOnlyList ToolCalls { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ListSortOrder.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ListSortOrder.cs new file mode 100644 index 000000000000..0a77cab2824b --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ListSortOrder.cs @@ -0,0 +1,51 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Azure.AI.OpenAI.Assistants +{ + /// The available sorting options when requesting a list of response objects. + public readonly partial struct ListSortOrder : IEquatable + { + private readonly string _value; + + /// Initializes a new instance of . + /// is null. + public ListSortOrder(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string AscendingValue = "asc"; + private const string DescendingValue = "desc"; + + /// Specifies an ascending sort order. + public static ListSortOrder Ascending { get; } = new ListSortOrder(AscendingValue); + /// Specifies a descending sort order. + public static ListSortOrder Descending { get; } = new ListSortOrder(DescendingValue); + /// Determines if two values are the same. + public static bool operator ==(ListSortOrder left, ListSortOrder right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(ListSortOrder left, ListSortOrder right) => !left.Equals(right); + /// Converts a string to a . + public static implicit operator ListSortOrder(string value) => new ListSortOrder(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is ListSortOrder other && Equals(other); + /// + public bool Equals(ListSortOrder other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value?.GetHashCode() ?? 0; + /// + public override string ToString() => _value; + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageContent.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageContent.Serialization.cs new file mode 100644 index 000000000000..c872d474934c --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageContent.Serialization.cs @@ -0,0 +1,57 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class MessageContent : IUtf8JsonSerializable + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + { + writer.WriteStartObject(); + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type); + writer.WriteEndObject(); + } + + internal static MessageContent DeserializeMessageContent(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + if (element.TryGetProperty("type", out JsonElement discriminator)) + { + switch (discriminator.GetString()) + { + case "text": return MessageTextContent.DeserializeMessageTextContent(element); + case "image_file": return MessageImageFileContent.DeserializeMessageImageFileContent(element); + } + } + return UnknownMessageContent.DeserializeUnknownMessageContent(element); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static MessageContent FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeMessageContent(document.RootElement); + } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageContent.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageContent.cs new file mode 100644 index 000000000000..a75e867c6a1d --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageContent.cs @@ -0,0 +1,32 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +namespace Azure.AI.OpenAI.Assistants +{ + /// + /// An abstract representation of a single item of thread message content. + /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. + /// The available derived classes include and . + /// + public abstract partial class MessageContent + { + /// Initializes a new instance of . + protected MessageContent() + { + } + + /// Initializes a new instance of . + /// The object type. + internal MessageContent(string type) + { + Type = type; + } + + /// The object type. + internal string Type { get; set; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageFile.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageFile.Serialization.cs new file mode 100644 index 000000000000..6acd4c501c7d --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageFile.Serialization.cs @@ -0,0 +1,60 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Text.Json; +using Azure; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class MessageFile + { + internal static MessageFile DeserializeMessageFile(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string id = default; + string @object = default; + DateTimeOffset createdAt = default; + string messageId = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("id"u8)) + { + id = property.Value.GetString(); + continue; + } + if (property.NameEquals("object"u8)) + { + @object = property.Value.GetString(); + continue; + } + if (property.NameEquals("created_at"u8)) + { + createdAt = DateTimeOffset.FromUnixTimeSeconds(property.Value.GetInt64()); + continue; + } + if (property.NameEquals("message_id"u8)) + { + messageId = property.Value.GetString(); + continue; + } + } + return new MessageFile(id, @object, createdAt, messageId); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static MessageFile FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeMessageFile(document.RootElement); + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageFile.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageFile.cs new file mode 100644 index 000000000000..631254447a24 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageFile.cs @@ -0,0 +1,52 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + /// Information about a file attached to an assistant thread message. + public partial class MessageFile + { + /// Initializes a new instance of . + /// The identifier, which can be referenced in API endpoints. + /// The Unix timestamp, in seconds, representing when this object was created. + /// The ID of the message that this file is attached to. + /// or is null. + internal MessageFile(string id, DateTimeOffset createdAt, string messageId) + { + Argument.AssertNotNull(id, nameof(id)); + Argument.AssertNotNull(messageId, nameof(messageId)); + + Id = id; + CreatedAt = createdAt; + MessageId = messageId; + } + + /// Initializes a new instance of . + /// The identifier, which can be referenced in API endpoints. + /// The object type, which is always 'thread.message.file'. + /// The Unix timestamp, in seconds, representing when this object was created. + /// The ID of the message that this file is attached to. + internal MessageFile(string id, string @object, DateTimeOffset createdAt, string messageId) + { + Id = id; + Object = @object; + CreatedAt = createdAt; + MessageId = messageId; + } + + /// The identifier, which can be referenced in API endpoints. + public string Id { get; } + + /// The Unix timestamp, in seconds, representing when this object was created. + public DateTimeOffset CreatedAt { get; } + /// The ID of the message that this file is attached to. + public string MessageId { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageFileCitationTextAnnotation.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageFileCitationTextAnnotation.Serialization.cs new file mode 100644 index 000000000000..5e614af621a9 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageFileCitationTextAnnotation.Serialization.cs @@ -0,0 +1,65 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class MessageFileCitationTextAnnotation + { + internal static MessageFileCitationTextAnnotation DeserializeMessageFileCitationTextAnnotation(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + InternalMessageTextFileCitationDetails fileCitation = default; + string type = default; + string text = default; + int startIndex = default; + int endIndex = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("file_citation"u8)) + { + fileCitation = InternalMessageTextFileCitationDetails.DeserializeInternalMessageTextFileCitationDetails(property.Value); + continue; + } + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString(); + continue; + } + if (property.NameEquals("text"u8)) + { + text = property.Value.GetString(); + continue; + } + if (property.NameEquals("start_index"u8)) + { + startIndex = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("end_index"u8)) + { + endIndex = property.Value.GetInt32(); + continue; + } + } + return new MessageFileCitationTextAnnotation(type, text, startIndex, endIndex, fileCitation); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new MessageFileCitationTextAnnotation FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeMessageFileCitationTextAnnotation(document.RootElement); + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageFileCitationTextAnnotation.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageFileCitationTextAnnotation.cs new file mode 100644 index 000000000000..362ca9826473 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageFileCitationTextAnnotation.cs @@ -0,0 +1,48 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using Azure.Core; + +namespace Azure.AI.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 'retrieval' tool to search files. + public partial class MessageFileCitationTextAnnotation : MessageTextAnnotation + { + /// Initializes a new instance of . + /// The textual content associated with this text annotation item. + /// The first text index associated with this text annotation. + /// The last text index associated with this text annotation. + /// + /// A citation within the message that points to a specific quote from a specific file. + /// Generated when the assistant uses the "retrieval" tool to search files. + /// + /// or is null. + internal MessageFileCitationTextAnnotation(string text, int startIndex, int endIndex, InternalMessageTextFileCitationDetails internalDetails) : base(text, startIndex, endIndex) + { + Argument.AssertNotNull(text, nameof(text)); + Argument.AssertNotNull(internalDetails, nameof(internalDetails)); + + Type = "file_citation"; + InternalDetails = internalDetails; + } + + /// Initializes a new instance of . + /// The object type. + /// The textual content associated with this text annotation item. + /// The first text index associated with this text annotation. + /// The last text index associated with this text annotation. + /// + /// A citation within the message that points to a specific quote from a specific file. + /// Generated when the assistant uses the "retrieval" tool to search files. + /// + internal MessageFileCitationTextAnnotation(string type, string text, int startIndex, int endIndex, InternalMessageTextFileCitationDetails internalDetails) : base(type, text, startIndex, endIndex) + { + InternalDetails = internalDetails; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageFilePathTextAnnotation.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageFilePathTextAnnotation.Serialization.cs new file mode 100644 index 000000000000..1a56fe587326 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageFilePathTextAnnotation.Serialization.cs @@ -0,0 +1,65 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class MessageFilePathTextAnnotation + { + internal static MessageFilePathTextAnnotation DeserializeMessageFilePathTextAnnotation(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + InternalMessageFilePathDetails filePath = default; + string type = default; + string text = default; + int startIndex = default; + int endIndex = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("file_path"u8)) + { + filePath = InternalMessageFilePathDetails.DeserializeInternalMessageFilePathDetails(property.Value); + continue; + } + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString(); + continue; + } + if (property.NameEquals("text"u8)) + { + text = property.Value.GetString(); + continue; + } + if (property.NameEquals("start_index"u8)) + { + startIndex = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("end_index"u8)) + { + endIndex = property.Value.GetInt32(); + continue; + } + } + return new MessageFilePathTextAnnotation(type, text, startIndex, endIndex, filePath); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new MessageFilePathTextAnnotation FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeMessageFilePathTextAnnotation(document.RootElement); + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageFilePathTextAnnotation.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageFilePathTextAnnotation.cs new file mode 100644 index 000000000000..a2aa3413b979 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageFilePathTextAnnotation.cs @@ -0,0 +1,42 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + /// A citation within the message that points to a file located at a specific path. + public partial class MessageFilePathTextAnnotation : MessageTextAnnotation + { + /// Initializes a new instance of . + /// The textual content associated with this text annotation item. + /// The first text index associated with this text annotation. + /// The last text index associated with this text annotation. + /// A URL for the file that's generated when the assistant used the code_interpreter tool to generate a file. + /// or is null. + internal MessageFilePathTextAnnotation(string text, int startIndex, int endIndex, InternalMessageFilePathDetails internalDetails) : base(text, startIndex, endIndex) + { + Argument.AssertNotNull(text, nameof(text)); + Argument.AssertNotNull(internalDetails, nameof(internalDetails)); + + Type = "file_path"; + InternalDetails = internalDetails; + } + + /// Initializes a new instance of . + /// The object type. + /// The textual content associated with this text annotation item. + /// The first text index associated with this text annotation. + /// The last text index associated with this text annotation. + /// A URL for the file that's generated when the assistant used the code_interpreter tool to generate a file. + internal MessageFilePathTextAnnotation(string type, string text, int startIndex, int endIndex, InternalMessageFilePathDetails internalDetails) : base(type, text, startIndex, endIndex) + { + InternalDetails = internalDetails; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageImageFileContent.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageImageFileContent.Serialization.cs new file mode 100644 index 000000000000..82ae85e4100a --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageImageFileContent.Serialization.cs @@ -0,0 +1,47 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class MessageImageFileContent + { + internal static MessageImageFileContent DeserializeMessageImageFileContent(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + InternalMessageImageFileDetails imageFile = default; + string type = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("image_file"u8)) + { + imageFile = InternalMessageImageFileDetails.DeserializeInternalMessageImageFileDetails(property.Value); + continue; + } + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString(); + continue; + } + } + return new MessageImageFileContent(type, imageFile); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new MessageImageFileContent FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeMessageImageFileContent(document.RootElement); + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageImageFileContent.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageImageFileContent.cs new file mode 100644 index 000000000000..4276cc66bc70 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageImageFileContent.cs @@ -0,0 +1,35 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + /// A representation of image file content in a thread message. + public partial class MessageImageFileContent : MessageContent + { + /// Initializes a new instance of . + /// The image file for this thread message content item. + /// is null. + internal MessageImageFileContent(InternalMessageImageFileDetails internalDetails) + { + Argument.AssertNotNull(internalDetails, nameof(internalDetails)); + + Type = "image_file"; + InternalDetails = internalDetails; + } + + /// Initializes a new instance of . + /// The object type. + /// The image file for this thread message content item. + internal MessageImageFileContent(string type, InternalMessageImageFileDetails internalDetails) : base(type) + { + InternalDetails = internalDetails; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageRole.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageRole.cs new file mode 100644 index 000000000000..d1c7c68c35c5 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageRole.cs @@ -0,0 +1,51 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Azure.AI.OpenAI.Assistants +{ + /// The possible values for roles attributed to messages in a thread. + public readonly partial struct MessageRole : IEquatable + { + private readonly string _value; + + /// Initializes a new instance of . + /// is null. + public MessageRole(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string UserValue = "user"; + private const string AssistantValue = "assistant"; + + /// The role representing the end-user. + public static MessageRole User { get; } = new MessageRole(UserValue); + /// The role representing the assistant. + public static MessageRole Assistant { get; } = new MessageRole(AssistantValue); + /// Determines if two values are the same. + public static bool operator ==(MessageRole left, MessageRole right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(MessageRole left, MessageRole right) => !left.Equals(right); + /// Converts a string to a . + public static implicit operator MessageRole(string value) => new MessageRole(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is MessageRole other && Equals(other); + /// + public bool Equals(MessageRole other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value?.GetHashCode() ?? 0; + /// + public override string ToString() => _value; + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextAnnotation.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextAnnotation.Serialization.cs new file mode 100644 index 000000000000..63de96c5b711 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextAnnotation.Serialization.cs @@ -0,0 +1,63 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class MessageTextAnnotation : IUtf8JsonSerializable + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + { + writer.WriteStartObject(); + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type); + writer.WritePropertyName("text"u8); + writer.WriteStringValue(Text); + writer.WritePropertyName("start_index"u8); + writer.WriteNumberValue(StartIndex); + writer.WritePropertyName("end_index"u8); + writer.WriteNumberValue(EndIndex); + writer.WriteEndObject(); + } + + internal static MessageTextAnnotation DeserializeMessageTextAnnotation(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + if (element.TryGetProperty("type", out JsonElement discriminator)) + { + switch (discriminator.GetString()) + { + case "file_citation": return MessageFileCitationTextAnnotation.DeserializeMessageFileCitationTextAnnotation(element); + case "file_path": return MessageFilePathTextAnnotation.DeserializeMessageFilePathTextAnnotation(element); + } + } + return UnknownMessageTextAnnotation.DeserializeUnknownMessageTextAnnotation(element); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static MessageTextAnnotation FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeMessageTextAnnotation(document.RootElement); + } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextAnnotation.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextAnnotation.cs new file mode 100644 index 000000000000..3ce8b24bfc54 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextAnnotation.cs @@ -0,0 +1,56 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + /// + /// An abstract representation of an annotation to text thread message content. + /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. + /// The available derived classes include and . + /// + public abstract partial class MessageTextAnnotation + { + /// Initializes a new instance of . + /// The textual content associated with this text annotation item. + /// The first text index associated with this text annotation. + /// The last text index associated with this text annotation. + /// is null. + protected MessageTextAnnotation(string text, int startIndex, int endIndex) + { + Argument.AssertNotNull(text, nameof(text)); + + Text = text; + StartIndex = startIndex; + EndIndex = endIndex; + } + + /// Initializes a new instance of . + /// The object type. + /// The textual content associated with this text annotation item. + /// The first text index associated with this text annotation. + /// The last text index associated with this text annotation. + internal MessageTextAnnotation(string type, string text, int startIndex, int endIndex) + { + Type = type; + Text = text; + StartIndex = startIndex; + EndIndex = endIndex; + } + + /// The object type. + internal string Type { get; set; } + /// The textual content associated with this text annotation item. + public string Text { get; set; } + /// The first text index associated with this text annotation. + public int StartIndex { get; set; } + /// The last text index associated with this text annotation. + public int EndIndex { get; set; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextContent.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextContent.Serialization.cs new file mode 100644 index 000000000000..8f76e413ddf1 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextContent.Serialization.cs @@ -0,0 +1,47 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class MessageTextContent + { + internal static MessageTextContent DeserializeMessageTextContent(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + InternalMessageTextDetails text = default; + string type = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("text"u8)) + { + text = InternalMessageTextDetails.DeserializeInternalMessageTextDetails(property.Value); + continue; + } + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString(); + continue; + } + } + return new MessageTextContent(type, text); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new MessageTextContent FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeMessageTextContent(document.RootElement); + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextContent.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextContent.cs new file mode 100644 index 000000000000..12b0e4b8c69d --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextContent.cs @@ -0,0 +1,35 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + /// A representation of a textual item of thread message content. + public partial class MessageTextContent : MessageContent + { + /// Initializes a new instance of . + /// The text and associated annotations for this thread message content item. + /// is null. + internal MessageTextContent(InternalMessageTextDetails internalDetails) + { + Argument.AssertNotNull(internalDetails, nameof(internalDetails)); + + Type = "text"; + InternalDetails = internalDetails; + } + + /// Initializes a new instance of . + /// The object type. + /// The text and associated annotations for this thread message content item. + internal MessageTextContent(string type, InternalMessageTextDetails internalDetails) : base(type) + { + InternalDetails = internalDetails; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ModifyMessageRequest.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ModifyMessageRequest.Serialization.cs new file mode 100644 index 000000000000..29b24626f995 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ModifyMessageRequest.Serialization.cs @@ -0,0 +1,40 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + internal partial class ModifyMessageRequest : IUtf8JsonSerializable + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + { + writer.WriteStartObject(); + if (Optional.IsCollectionDefined(Metadata)) + { + writer.WritePropertyName("metadata"u8); + writer.WriteStartObject(); + foreach (var item in Metadata) + { + writer.WritePropertyName(item.Key); + writer.WriteStringValue(item.Value); + } + writer.WriteEndObject(); + } + writer.WriteEndObject(); + } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ModifyMessageRequest.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ModifyMessageRequest.cs new file mode 100644 index 000000000000..148e4f317cf9 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ModifyMessageRequest.cs @@ -0,0 +1,32 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Collections.Generic; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + /// The ModifyMessageRequest. + internal partial class ModifyMessageRequest + { + /// Initializes a new instance of . + public ModifyMessageRequest() + { + Metadata = new ChangeTrackingDictionary(); + } + + /// Initializes a new instance of . + /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. + internal ModifyMessageRequest(IDictionary metadata) + { + Metadata = metadata; + } + + /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. + public IDictionary Metadata { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ModifyRunRequest.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ModifyRunRequest.Serialization.cs new file mode 100644 index 000000000000..5510dc7b6854 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ModifyRunRequest.Serialization.cs @@ -0,0 +1,40 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + internal partial class ModifyRunRequest : IUtf8JsonSerializable + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + { + writer.WriteStartObject(); + if (Optional.IsCollectionDefined(Metadata)) + { + writer.WritePropertyName("metadata"u8); + writer.WriteStartObject(); + foreach (var item in Metadata) + { + writer.WritePropertyName(item.Key); + writer.WriteStringValue(item.Value); + } + writer.WriteEndObject(); + } + writer.WriteEndObject(); + } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ModifyRunRequest.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ModifyRunRequest.cs new file mode 100644 index 000000000000..b19db8333b70 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ModifyRunRequest.cs @@ -0,0 +1,32 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Collections.Generic; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + /// The ModifyRunRequest. + internal partial class ModifyRunRequest + { + /// Initializes a new instance of . + public ModifyRunRequest() + { + Metadata = new ChangeTrackingDictionary(); + } + + /// Initializes a new instance of . + /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. + internal ModifyRunRequest(IDictionary metadata) + { + Metadata = metadata; + } + + /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. + public IDictionary Metadata { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ModifyThreadRequest.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ModifyThreadRequest.Serialization.cs new file mode 100644 index 000000000000..a650610cfdb9 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ModifyThreadRequest.Serialization.cs @@ -0,0 +1,40 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + internal partial class ModifyThreadRequest : IUtf8JsonSerializable + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + { + writer.WriteStartObject(); + if (Optional.IsCollectionDefined(Metadata)) + { + writer.WritePropertyName("metadata"u8); + writer.WriteStartObject(); + foreach (var item in Metadata) + { + writer.WritePropertyName(item.Key); + writer.WriteStringValue(item.Value); + } + writer.WriteEndObject(); + } + writer.WriteEndObject(); + } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ModifyThreadRequest.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ModifyThreadRequest.cs new file mode 100644 index 000000000000..63a52be45415 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ModifyThreadRequest.cs @@ -0,0 +1,32 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Collections.Generic; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + /// The ModifyThreadRequest. + internal partial class ModifyThreadRequest + { + /// Initializes a new instance of . + public ModifyThreadRequest() + { + Metadata = new ChangeTrackingDictionary(); + } + + /// Initializes a new instance of . + /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. + internal ModifyThreadRequest(IDictionary metadata) + { + Metadata = metadata; + } + + /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. + public IDictionary Metadata { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIFile.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIFile.Serialization.cs new file mode 100644 index 000000000000..297a60918822 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIFile.Serialization.cs @@ -0,0 +1,72 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Text.Json; +using Azure; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class OpenAIFile + { + internal static OpenAIFile DeserializeOpenAIFile(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string @object = default; + string id = default; + int bytes = default; + string filename = default; + DateTimeOffset createdAt = default; + OpenAIFilePurpose purpose = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("object"u8)) + { + @object = property.Value.GetString(); + continue; + } + if (property.NameEquals("id"u8)) + { + id = property.Value.GetString(); + continue; + } + if (property.NameEquals("bytes"u8)) + { + bytes = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("filename"u8)) + { + filename = property.Value.GetString(); + continue; + } + if (property.NameEquals("created_at"u8)) + { + createdAt = DateTimeOffset.FromUnixTimeSeconds(property.Value.GetInt64()); + continue; + } + if (property.NameEquals("purpose"u8)) + { + purpose = new OpenAIFilePurpose(property.Value.GetString()); + continue; + } + } + return new OpenAIFile(@object, id, bytes, filename, createdAt, purpose); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static OpenAIFile FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeOpenAIFile(document.RootElement); + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIFile.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIFile.cs new file mode 100644 index 000000000000..aca056a49a99 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIFile.cs @@ -0,0 +1,63 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + /// Represents an assistant that can call the model and use tools. + public partial class OpenAIFile + { + /// Initializes a new instance of . + /// The identifier, which can be referenced in API endpoints. + /// The size of the file, in bytes. + /// The name of the file. + /// The Unix timestamp, in seconds, representing when this object was created. + /// The intended purpose of a file. + /// or is null. + internal OpenAIFile(string id, int size, string filename, DateTimeOffset createdAt, OpenAIFilePurpose purpose) + { + Argument.AssertNotNull(id, nameof(id)); + Argument.AssertNotNull(filename, nameof(filename)); + + Id = id; + Size = size; + Filename = filename; + CreatedAt = createdAt; + Purpose = purpose; + } + + /// Initializes a new instance of . + /// The object type, which is always 'file'. + /// The identifier, which can be referenced in API endpoints. + /// The size of the file, in bytes. + /// The name of the file. + /// The Unix timestamp, in seconds, representing when this object was created. + /// The intended purpose of a file. + internal OpenAIFile(string @object, string id, int size, string filename, DateTimeOffset createdAt, OpenAIFilePurpose purpose) + { + Object = @object; + Id = id; + Size = size; + Filename = filename; + CreatedAt = createdAt; + Purpose = purpose; + } + + /// The identifier, which can be referenced in API endpoints. + public string Id { get; } + /// The size of the file, in bytes. + public int Size { get; } + /// The name of the file. + public string Filename { get; } + /// The Unix timestamp, in seconds, representing when this object was created. + public DateTimeOffset CreatedAt { get; } + /// The intended purpose of a file. + public OpenAIFilePurpose Purpose { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIFilePurpose.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIFilePurpose.cs new file mode 100644 index 000000000000..5622ece16fdd --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIFilePurpose.cs @@ -0,0 +1,57 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Azure.AI.OpenAI.Assistants +{ + /// The possible values denoting the intended usage of a file. + public readonly partial struct OpenAIFilePurpose : IEquatable + { + private readonly string _value; + + /// Initializes a new instance of . + /// is null. + public OpenAIFilePurpose(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string FineTuneValue = "fine-tune"; + private const string FineTuneResultsValue = "fine-tune-results"; + private const string AssistantsValue = "assistants"; + private const string AssistantsOutputValue = "assistants_output"; + + /// Indicates a file is used for fine tuning input. + public static OpenAIFilePurpose FineTune { get; } = new OpenAIFilePurpose(FineTuneValue); + /// Indicates a file is used for fine tuning results. + public static OpenAIFilePurpose FineTuneResults { get; } = new OpenAIFilePurpose(FineTuneResultsValue); + /// Indicates a file is used as input to assistants. + public static OpenAIFilePurpose Assistants { get; } = new OpenAIFilePurpose(AssistantsValue); + /// Indicates a file is used as output by assistants. + public static OpenAIFilePurpose AssistantsOutput { get; } = new OpenAIFilePurpose(AssistantsOutputValue); + /// Determines if two values are the same. + public static bool operator ==(OpenAIFilePurpose left, OpenAIFilePurpose right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(OpenAIFilePurpose left, OpenAIFilePurpose right) => !left.Equals(right); + /// Converts a string to a . + public static implicit operator OpenAIFilePurpose(string value) => new OpenAIFilePurpose(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is OpenAIFilePurpose other && Equals(other); + /// + public bool Equals(OpenAIFilePurpose other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value?.GetHashCode() ?? 0; + /// + public override string ToString() => _value; + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIPageableListOfAssistantFileObject.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIPageableListOfAssistantFileObject.cs new file mode 100644 index 000000000000..56a4b12929c1 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIPageableListOfAssistantFileObject.cs @@ -0,0 +1,48 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Azure.AI.OpenAI.Assistants +{ + /// The OpenAIPageableListOfAssistantFile_object. + internal readonly partial struct OpenAIPageableListOfAssistantFileObject : IEquatable + { + private readonly string _value; + + /// Initializes a new instance of . + /// is null. + public OpenAIPageableListOfAssistantFileObject(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string ListValue = "list"; + + /// list. + public static OpenAIPageableListOfAssistantFileObject List { get; } = new OpenAIPageableListOfAssistantFileObject(ListValue); + /// Determines if two values are the same. + public static bool operator ==(OpenAIPageableListOfAssistantFileObject left, OpenAIPageableListOfAssistantFileObject right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(OpenAIPageableListOfAssistantFileObject left, OpenAIPageableListOfAssistantFileObject right) => !left.Equals(right); + /// Converts a string to a . + public static implicit operator OpenAIPageableListOfAssistantFileObject(string value) => new OpenAIPageableListOfAssistantFileObject(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is OpenAIPageableListOfAssistantFileObject other && Equals(other); + /// + public bool Equals(OpenAIPageableListOfAssistantFileObject other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value?.GetHashCode() ?? 0; + /// + public override string ToString() => _value; + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIPageableListOfAssistantObject.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIPageableListOfAssistantObject.cs new file mode 100644 index 000000000000..46e773c0c35b --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIPageableListOfAssistantObject.cs @@ -0,0 +1,48 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Azure.AI.OpenAI.Assistants +{ + /// The OpenAIPageableListOfAssistant_object. + internal readonly partial struct OpenAIPageableListOfAssistantObject : IEquatable + { + private readonly string _value; + + /// Initializes a new instance of . + /// is null. + public OpenAIPageableListOfAssistantObject(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string ListValue = "list"; + + /// list. + public static OpenAIPageableListOfAssistantObject List { get; } = new OpenAIPageableListOfAssistantObject(ListValue); + /// Determines if two values are the same. + public static bool operator ==(OpenAIPageableListOfAssistantObject left, OpenAIPageableListOfAssistantObject right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(OpenAIPageableListOfAssistantObject left, OpenAIPageableListOfAssistantObject right) => !left.Equals(right); + /// Converts a string to a . + public static implicit operator OpenAIPageableListOfAssistantObject(string value) => new OpenAIPageableListOfAssistantObject(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is OpenAIPageableListOfAssistantObject other && Equals(other); + /// + public bool Equals(OpenAIPageableListOfAssistantObject other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value?.GetHashCode() ?? 0; + /// + public override string ToString() => _value; + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIPageableListOfMessageFileObject.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIPageableListOfMessageFileObject.cs new file mode 100644 index 000000000000..de78651dc7c7 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIPageableListOfMessageFileObject.cs @@ -0,0 +1,48 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Azure.AI.OpenAI.Assistants +{ + /// The OpenAIPageableListOfMessageFile_object. + internal readonly partial struct OpenAIPageableListOfMessageFileObject : IEquatable + { + private readonly string _value; + + /// Initializes a new instance of . + /// is null. + public OpenAIPageableListOfMessageFileObject(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string ListValue = "list"; + + /// list. + public static OpenAIPageableListOfMessageFileObject List { get; } = new OpenAIPageableListOfMessageFileObject(ListValue); + /// Determines if two values are the same. + public static bool operator ==(OpenAIPageableListOfMessageFileObject left, OpenAIPageableListOfMessageFileObject right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(OpenAIPageableListOfMessageFileObject left, OpenAIPageableListOfMessageFileObject right) => !left.Equals(right); + /// Converts a string to a . + public static implicit operator OpenAIPageableListOfMessageFileObject(string value) => new OpenAIPageableListOfMessageFileObject(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is OpenAIPageableListOfMessageFileObject other && Equals(other); + /// + public bool Equals(OpenAIPageableListOfMessageFileObject other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value?.GetHashCode() ?? 0; + /// + public override string ToString() => _value; + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIPageableListOfRunStepObject.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIPageableListOfRunStepObject.cs new file mode 100644 index 000000000000..c2917cdcb9a6 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIPageableListOfRunStepObject.cs @@ -0,0 +1,48 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Azure.AI.OpenAI.Assistants +{ + /// The OpenAIPageableListOfRunStep_object. + internal readonly partial struct OpenAIPageableListOfRunStepObject : IEquatable + { + private readonly string _value; + + /// Initializes a new instance of . + /// is null. + public OpenAIPageableListOfRunStepObject(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string ListValue = "list"; + + /// list. + public static OpenAIPageableListOfRunStepObject List { get; } = new OpenAIPageableListOfRunStepObject(ListValue); + /// Determines if two values are the same. + public static bool operator ==(OpenAIPageableListOfRunStepObject left, OpenAIPageableListOfRunStepObject right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(OpenAIPageableListOfRunStepObject left, OpenAIPageableListOfRunStepObject right) => !left.Equals(right); + /// Converts a string to a . + public static implicit operator OpenAIPageableListOfRunStepObject(string value) => new OpenAIPageableListOfRunStepObject(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is OpenAIPageableListOfRunStepObject other && Equals(other); + /// + public bool Equals(OpenAIPageableListOfRunStepObject other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value?.GetHashCode() ?? 0; + /// + public override string ToString() => _value; + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIPageableListOfThreadMessageObject.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIPageableListOfThreadMessageObject.cs new file mode 100644 index 000000000000..03431876112e --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIPageableListOfThreadMessageObject.cs @@ -0,0 +1,48 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Azure.AI.OpenAI.Assistants +{ + /// The OpenAIPageableListOfThreadMessage_object. + internal readonly partial struct OpenAIPageableListOfThreadMessageObject : IEquatable + { + private readonly string _value; + + /// Initializes a new instance of . + /// is null. + public OpenAIPageableListOfThreadMessageObject(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string ListValue = "list"; + + /// list. + public static OpenAIPageableListOfThreadMessageObject List { get; } = new OpenAIPageableListOfThreadMessageObject(ListValue); + /// Determines if two values are the same. + public static bool operator ==(OpenAIPageableListOfThreadMessageObject left, OpenAIPageableListOfThreadMessageObject right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(OpenAIPageableListOfThreadMessageObject left, OpenAIPageableListOfThreadMessageObject right) => !left.Equals(right); + /// Converts a string to a . + public static implicit operator OpenAIPageableListOfThreadMessageObject(string value) => new OpenAIPageableListOfThreadMessageObject(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is OpenAIPageableListOfThreadMessageObject other && Equals(other); + /// + public bool Equals(OpenAIPageableListOfThreadMessageObject other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value?.GetHashCode() ?? 0; + /// + public override string ToString() => _value; + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIPageableListOfThreadRunObject.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIPageableListOfThreadRunObject.cs new file mode 100644 index 000000000000..e12f29c2b514 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIPageableListOfThreadRunObject.cs @@ -0,0 +1,48 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Azure.AI.OpenAI.Assistants +{ + /// The OpenAIPageableListOfThreadRun_object. + internal readonly partial struct OpenAIPageableListOfThreadRunObject : IEquatable + { + private readonly string _value; + + /// Initializes a new instance of . + /// is null. + public OpenAIPageableListOfThreadRunObject(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string ListValue = "list"; + + /// list. + public static OpenAIPageableListOfThreadRunObject List { get; } = new OpenAIPageableListOfThreadRunObject(ListValue); + /// Determines if two values are the same. + public static bool operator ==(OpenAIPageableListOfThreadRunObject left, OpenAIPageableListOfThreadRunObject right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(OpenAIPageableListOfThreadRunObject left, OpenAIPageableListOfThreadRunObject right) => !left.Equals(right); + /// Converts a string to a . + public static implicit operator OpenAIPageableListOfThreadRunObject(string value) => new OpenAIPageableListOfThreadRunObject(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is OpenAIPageableListOfThreadRunObject other && Equals(other); + /// + public bool Equals(OpenAIPageableListOfThreadRunObject other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value?.GetHashCode() ?? 0; + /// + public override string ToString() => _value; + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RequiredAction.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RequiredAction.Serialization.cs new file mode 100644 index 000000000000..9eab1cee82ae --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RequiredAction.Serialization.cs @@ -0,0 +1,39 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class RequiredAction + { + internal static RequiredAction DeserializeRequiredAction(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + if (element.TryGetProperty("type", out JsonElement discriminator)) + { + switch (discriminator.GetString()) + { + case "submit_tool_outputs": return SubmitToolOutputsAction.DeserializeSubmitToolOutputsAction(element); + } + } + return UnknownRequiredAction.DeserializeUnknownRequiredAction(element); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static RequiredAction FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeRequiredAction(document.RootElement); + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RequiredAction.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RequiredAction.cs new file mode 100644 index 000000000000..5ed051d278a8 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RequiredAction.cs @@ -0,0 +1,32 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +namespace Azure.AI.OpenAI.Assistants +{ + /// + /// An abstract representation of a required action for an assistant thread run to continue. + /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. + /// The available derived classes include . + /// + public abstract partial class RequiredAction + { + /// Initializes a new instance of . + protected RequiredAction() + { + } + + /// Initializes a new instance of . + /// The object type. + internal RequiredAction(string type) + { + Type = type; + } + + /// The object type. + internal string Type { get; set; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RetrievalToolCall.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RetrievalToolCall.Serialization.cs new file mode 100644 index 000000000000..a53d39532661 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RetrievalToolCall.Serialization.cs @@ -0,0 +1,59 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Collections.Generic; +using System.Text.Json; +using Azure; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class RetrievalToolCall + { + internal static RetrievalToolCall DeserializeRetrievalToolCall(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + IReadOnlyDictionary retrieval = default; + string type = default; + string id = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("retrieval"u8)) + { + Dictionary dictionary = new Dictionary(); + foreach (var property0 in property.Value.EnumerateObject()) + { + dictionary.Add(property0.Name, property0.Value.GetString()); + } + retrieval = dictionary; + continue; + } + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString(); + continue; + } + if (property.NameEquals("id"u8)) + { + id = property.Value.GetString(); + continue; + } + } + return new RetrievalToolCall(type, id, retrieval); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new RetrievalToolCall FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeRetrievalToolCall(document.RootElement); + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RetrievalToolCall.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RetrievalToolCall.cs new file mode 100644 index 000000000000..f4d7e1f8b222 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RetrievalToolCall.cs @@ -0,0 +1,45 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + /// + /// A tool call to a retrieval tool, issued by the model in evaluation of a configured retrieval tool, that represents + /// submitted output needed or already fulfilled by the tool for the model to continue. + /// + public partial class RetrievalToolCall : ToolCall + { + /// Initializes a new instance of . + /// The ID of the tool call. This ID must be referenced when you submit tool outputs. + /// The key/value pairs produced by the retrieval tool. + /// or is null. + internal RetrievalToolCall(string id, IReadOnlyDictionary retrieval) : base(id) + { + Argument.AssertNotNull(id, nameof(id)); + Argument.AssertNotNull(retrieval, nameof(retrieval)); + + Type = "retrieval"; + Retrieval = retrieval; + } + + /// Initializes a new instance of . + /// The object type. + /// The ID of the tool call. This ID must be referenced when you submit tool outputs. + /// The key/value pairs produced by the retrieval tool. + internal RetrievalToolCall(string type, string id, IReadOnlyDictionary retrieval) : base(type, id) + { + Retrieval = retrieval; + } + + /// The key/value pairs produced by the retrieval tool. + public IReadOnlyDictionary Retrieval { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RetrievalToolDefinition.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RetrievalToolDefinition.Serialization.cs new file mode 100644 index 000000000000..b91f51687b42 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RetrievalToolDefinition.Serialization.cs @@ -0,0 +1,58 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class RetrievalToolDefinition : IUtf8JsonSerializable + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + { + writer.WriteStartObject(); + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type); + writer.WriteEndObject(); + } + + internal static RetrievalToolDefinition DeserializeRetrievalToolDefinition(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string type = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString(); + continue; + } + } + return new RetrievalToolDefinition(type); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new RetrievalToolDefinition FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeRetrievalToolDefinition(document.RootElement); + } + + /// Convert into a Utf8JsonRequestContent. + internal override RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RetrievalToolDefinition.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RetrievalToolDefinition.cs new file mode 100644 index 000000000000..28232f82fb20 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RetrievalToolDefinition.cs @@ -0,0 +1,25 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +namespace Azure.AI.OpenAI.Assistants +{ + /// The input definition information for a retrieval tool as used to configure an assistant. + public partial class RetrievalToolDefinition : ToolDefinition + { + /// Initializes a new instance of . + public RetrievalToolDefinition() + { + Type = "retrieval"; + } + + /// Initializes a new instance of . + /// The object type. + internal RetrievalToolDefinition(string type) : base(type) + { + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunError.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunError.Serialization.cs new file mode 100644 index 000000000000..224a74ade6d1 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunError.Serialization.cs @@ -0,0 +1,47 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class RunError + { + internal static RunError DeserializeRunError(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string code = default; + string message = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("code"u8)) + { + code = property.Value.GetString(); + continue; + } + if (property.NameEquals("message"u8)) + { + message = property.Value.GetString(); + continue; + } + } + return new RunError(code, message); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static RunError FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeRunError(document.RootElement); + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunError.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunError.cs new file mode 100644 index 000000000000..5da23eb4495a --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunError.cs @@ -0,0 +1,34 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + /// The details of an error as encountered by an assistant thread run. + public partial class RunError + { + /// Initializes a new instance of . + /// The status for the error. + /// The human-readable text associated with the error. + /// or is null. + internal RunError(string code, string message) + { + Argument.AssertNotNull(code, nameof(code)); + Argument.AssertNotNull(message, nameof(message)); + + Code = code; + Message = message; + } + + /// The status for the error. + public string Code { get; } + /// The human-readable text associated with the error. + public string Message { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStatus.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStatus.cs new file mode 100644 index 000000000000..c673fc9bcf34 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStatus.cs @@ -0,0 +1,69 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Azure.AI.OpenAI.Assistants +{ + /// Possible values for the status of an assistant thread run. + public readonly partial struct RunStatus : IEquatable + { + private readonly string _value; + + /// Initializes a new instance of . + /// is null. + public RunStatus(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string QueuedValue = "queued"; + private const string InProgressValue = "in_progress"; + private const string RequiresActionValue = "requires_action"; + private const string CancellingValue = "cancelling"; + private const string CancelledValue = "cancelled"; + private const string FailedValue = "failed"; + private const string CompletedValue = "completed"; + private const string ExpiredValue = "expired"; + + /// Represents a run that is queued to start. + public static RunStatus Queued { get; } = new RunStatus(QueuedValue); + /// Represents a run that is in progress. + public static RunStatus InProgress { get; } = new RunStatus(InProgressValue); + /// Represents a run that needs another operation, such as tool output submission, to continue. + public static RunStatus RequiresAction { get; } = new RunStatus(RequiresActionValue); + /// Represents a run that is in the process of cancellation. + public static RunStatus Cancelling { get; } = new RunStatus(CancellingValue); + /// Represents a run that has been cancelled. + public static RunStatus Cancelled { get; } = new RunStatus(CancelledValue); + /// Represents a run that failed. + public static RunStatus Failed { get; } = new RunStatus(FailedValue); + /// Represents a run that successfully completed. + public static RunStatus Completed { get; } = new RunStatus(CompletedValue); + /// Represents a run that expired before it could otherwise finish. + public static RunStatus Expired { get; } = new RunStatus(ExpiredValue); + /// Determines if two values are the same. + public static bool operator ==(RunStatus left, RunStatus right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(RunStatus left, RunStatus right) => !left.Equals(right); + /// Converts a string to a . + public static implicit operator RunStatus(string value) => new RunStatus(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is RunStatus other && Equals(other); + /// + public bool Equals(RunStatus other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value?.GetHashCode() ?? 0; + /// + public override string ToString() => _value; + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStep.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStep.Serialization.cs new file mode 100644 index 000000000000..a57e579382eb --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStep.Serialization.cs @@ -0,0 +1,142 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Text.Json; +using Azure; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class RunStep + { + internal static RunStep DeserializeRunStep(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string id = default; + string @object = default; + RunStepType type = default; + string assistantId = default; + string threadId = default; + string runId = default; + RunStepStatus status = default; + RunStepDetails stepDetails = default; + RunStepError lastError = default; + DateTimeOffset createdAt = default; + DateTimeOffset? expiredAt = default; + DateTimeOffset? completedAt = default; + DateTimeOffset? cancelledAt = default; + DateTimeOffset? failedAt = default; + Optional> metadata = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("id"u8)) + { + id = property.Value.GetString(); + continue; + } + if (property.NameEquals("object"u8)) + { + @object = property.Value.GetString(); + continue; + } + if (property.NameEquals("type"u8)) + { + type = new RunStepType(property.Value.GetString()); + continue; + } + if (property.NameEquals("assistant_id"u8)) + { + assistantId = property.Value.GetString(); + continue; + } + if (property.NameEquals("thread_id"u8)) + { + threadId = property.Value.GetString(); + continue; + } + if (property.NameEquals("run_id"u8)) + { + runId = property.Value.GetString(); + continue; + } + if (property.NameEquals("status"u8)) + { + status = new RunStepStatus(property.Value.GetString()); + continue; + } + if (property.NameEquals("step_details"u8)) + { + stepDetails = RunStepDetails.DeserializeRunStepDetails(property.Value); + continue; + } + if (property.NameEquals("last_error"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + lastError = null; + continue; + } + lastError = RunStepError.DeserializeRunStepError(property.Value); + continue; + } + if (property.NameEquals("created_at"u8)) + { + createdAt = DateTimeOffset.FromUnixTimeSeconds(property.Value.GetInt64()); + continue; + } + if (property.NameEquals("expired_at"u8)) + { + DeserializeNullableDateTimeOffset(property, ref expiredAt); + continue; + } + if (property.NameEquals("completed_at"u8)) + { + DeserializeNullableDateTimeOffset(property, ref completedAt); + continue; + } + if (property.NameEquals("cancelled_at"u8)) + { + DeserializeNullableDateTimeOffset(property, ref cancelledAt); + continue; + } + if (property.NameEquals("failed_at"u8)) + { + DeserializeNullableDateTimeOffset(property, ref failedAt); + continue; + } + if (property.NameEquals("metadata"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + Dictionary dictionary = new Dictionary(); + foreach (var property0 in property.Value.EnumerateObject()) + { + dictionary.Add(property0.Name, property0.Value.GetString()); + } + metadata = dictionary; + continue; + } + } + return new RunStep(id, @object, type, assistantId, threadId, runId, status, stepDetails, lastError, createdAt, expiredAt, completedAt, cancelledAt, failedAt, Optional.ToDictionary(metadata)); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static RunStep FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeRunStep(document.RootElement); + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStep.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStep.cs new file mode 100644 index 000000000000..352aa566ae40 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStep.cs @@ -0,0 +1,117 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + /// Detailed information about a single step of an assistant thread run. + public partial class RunStep + { + /// Initializes a new instance of . + /// The identifier, which can be referenced in API endpoints. + /// The type of run step, which can be either message_creation or tool_calls. + /// The ID of the assistant associated with the run step. + /// The ID of the thread that was run. + /// The ID of the run that this run step is a part of. + /// The status of this run step. + /// The details for this run step. + /// If applicable, information about the last error encountered by this run step. + /// The Unix timestamp, in seconds, representing when this object was created. + /// The Unix timestamp, in seconds, representing when this item expired. + /// The Unix timestamp, in seconds, representing when this completed. + /// The Unix timestamp, in seconds, representing when this was cancelled. + /// The Unix timestamp, in seconds, representing when this failed. + /// , , , or is null. + internal RunStep(string id, RunStepType type, string assistantId, string threadId, string runId, RunStepStatus status, RunStepDetails stepDetails, RunStepError lastError, DateTimeOffset createdAt, DateTimeOffset? expiredAt, DateTimeOffset? completedAt, DateTimeOffset? cancelledAt, DateTimeOffset? failedAt) + { + Argument.AssertNotNull(id, nameof(id)); + Argument.AssertNotNull(assistantId, nameof(assistantId)); + Argument.AssertNotNull(threadId, nameof(threadId)); + Argument.AssertNotNull(runId, nameof(runId)); + Argument.AssertNotNull(stepDetails, nameof(stepDetails)); + + Id = id; + Type = type; + AssistantId = assistantId; + ThreadId = threadId; + RunId = runId; + Status = status; + StepDetails = stepDetails; + LastError = lastError; + CreatedAt = createdAt; + ExpiredAt = expiredAt; + CompletedAt = completedAt; + CancelledAt = cancelledAt; + FailedAt = failedAt; + Metadata = new ChangeTrackingDictionary(); + } + + /// Initializes a new instance of . + /// The identifier, which can be referenced in API endpoints. + /// The object type, which is always 'thread.run.step'. + /// The type of run step, which can be either message_creation or tool_calls. + /// The ID of the assistant associated with the run step. + /// The ID of the thread that was run. + /// The ID of the run that this run step is a part of. + /// The status of this run step. + /// The details for this run step. + /// If applicable, information about the last error encountered by this run step. + /// The Unix timestamp, in seconds, representing when this object was created. + /// The Unix timestamp, in seconds, representing when this item expired. + /// The Unix timestamp, in seconds, representing when this completed. + /// The Unix timestamp, in seconds, representing when this was cancelled. + /// The Unix timestamp, in seconds, representing when this failed. + /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. + internal RunStep(string id, string @object, RunStepType type, string assistantId, string threadId, string runId, RunStepStatus status, RunStepDetails stepDetails, RunStepError lastError, DateTimeOffset createdAt, DateTimeOffset? expiredAt, DateTimeOffset? completedAt, DateTimeOffset? cancelledAt, DateTimeOffset? failedAt, IReadOnlyDictionary metadata) + { + Id = id; + Object = @object; + Type = type; + AssistantId = assistantId; + ThreadId = threadId; + RunId = runId; + Status = status; + StepDetails = stepDetails; + LastError = lastError; + CreatedAt = createdAt; + ExpiredAt = expiredAt; + CompletedAt = completedAt; + CancelledAt = cancelledAt; + FailedAt = failedAt; + Metadata = metadata; + } + + /// The identifier, which can be referenced in API endpoints. + public string Id { get; } + + /// The type of run step, which can be either message_creation or tool_calls. + public RunStepType Type { get; } + /// The ID of the assistant associated with the run step. + public string AssistantId { get; } + /// The ID of the thread that was run. + public string ThreadId { get; } + /// The ID of the run that this run step is a part of. + public string RunId { get; } + /// The status of this run step. + public RunStepStatus Status { get; } + /// + /// The details for this run step. + /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. + /// The available derived classes include and . + /// + public RunStepDetails StepDetails { get; } + /// If applicable, information about the last error encountered by this run step. + public RunStepError LastError { get; } + /// The Unix timestamp, in seconds, representing when this object was created. + public DateTimeOffset CreatedAt { get; } + /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. + public IReadOnlyDictionary Metadata { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDetails.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDetails.Serialization.cs new file mode 100644 index 000000000000..89eb4f0e9e17 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDetails.Serialization.cs @@ -0,0 +1,40 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class RunStepDetails + { + internal static RunStepDetails DeserializeRunStepDetails(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + if (element.TryGetProperty("type", out JsonElement discriminator)) + { + switch (discriminator.GetString()) + { + case "message_creation": return RunStepMessageCreationDetails.DeserializeRunStepMessageCreationDetails(element); + case "tool_calls": return RunStepToolCallDetails.DeserializeRunStepToolCallDetails(element); + } + } + return UnknownRunStepDetails.DeserializeUnknownRunStepDetails(element); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static RunStepDetails FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeRunStepDetails(document.RootElement); + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDetails.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDetails.cs new file mode 100644 index 000000000000..1edaf9589694 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDetails.cs @@ -0,0 +1,32 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +namespace Azure.AI.OpenAI.Assistants +{ + /// + /// An abstract representation of the details for a run step. + /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. + /// The available derived classes include and . + /// + public abstract partial class RunStepDetails + { + /// Initializes a new instance of . + protected RunStepDetails() + { + } + + /// Initializes a new instance of . + /// The object type. + internal RunStepDetails(RunStepType type) + { + Type = type; + } + + /// The object type. + internal RunStepType Type { get; set; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepError.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepError.Serialization.cs new file mode 100644 index 000000000000..143e744b02a9 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepError.Serialization.cs @@ -0,0 +1,47 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class RunStepError + { + internal static RunStepError DeserializeRunStepError(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + RunStepErrorCode code = default; + string message = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("code"u8)) + { + code = new RunStepErrorCode(property.Value.GetString()); + continue; + } + if (property.NameEquals("message"u8)) + { + message = property.Value.GetString(); + continue; + } + } + return new RunStepError(code, message); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static RunStepError FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeRunStepError(document.RootElement); + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepError.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepError.cs new file mode 100644 index 000000000000..fc946ebe690f --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepError.cs @@ -0,0 +1,33 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + /// The error information associated with a failed run step. + public partial class RunStepError + { + /// Initializes a new instance of . + /// The error code for this error. + /// The human-readable text associated with this error. + /// is null. + internal RunStepError(RunStepErrorCode code, string message) + { + Argument.AssertNotNull(message, nameof(message)); + + Code = code; + Message = message; + } + + /// The error code for this error. + public RunStepErrorCode Code { get; } + /// The human-readable text associated with this error. + public string Message { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepErrorCode.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepErrorCode.cs new file mode 100644 index 000000000000..394710484faf --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepErrorCode.cs @@ -0,0 +1,51 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Azure.AI.OpenAI.Assistants +{ + /// Possible error code values attributable to a failed run step. + public readonly partial struct RunStepErrorCode : IEquatable + { + private readonly string _value; + + /// Initializes a new instance of . + /// is null. + public RunStepErrorCode(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string ServerErrorValue = "server_error"; + private const string RateLimitExceededValue = "rate_limit_exceeded"; + + /// Represents a server error. + public static RunStepErrorCode ServerError { get; } = new RunStepErrorCode(ServerErrorValue); + /// Represents an error indicating configured rate limits were exceeded. + public static RunStepErrorCode RateLimitExceeded { get; } = new RunStepErrorCode(RateLimitExceededValue); + /// Determines if two values are the same. + public static bool operator ==(RunStepErrorCode left, RunStepErrorCode right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(RunStepErrorCode left, RunStepErrorCode right) => !left.Equals(right); + /// Converts a string to a . + public static implicit operator RunStepErrorCode(string value) => new RunStepErrorCode(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is RunStepErrorCode other && Equals(other); + /// + public bool Equals(RunStepErrorCode other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value?.GetHashCode() ?? 0; + /// + public override string ToString() => _value; + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepMessageCreationDetails.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepMessageCreationDetails.Serialization.cs new file mode 100644 index 000000000000..88ec9daa25ff --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepMessageCreationDetails.Serialization.cs @@ -0,0 +1,47 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class RunStepMessageCreationDetails + { + internal static RunStepMessageCreationDetails DeserializeRunStepMessageCreationDetails(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + RunStepMessageCreationReference messageCreation = default; + RunStepType type = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("message_creation"u8)) + { + messageCreation = RunStepMessageCreationReference.DeserializeRunStepMessageCreationReference(property.Value); + continue; + } + if (property.NameEquals("type"u8)) + { + type = new RunStepType(property.Value.GetString()); + continue; + } + } + return new RunStepMessageCreationDetails(type, messageCreation); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new RunStepMessageCreationDetails FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeRunStepMessageCreationDetails(document.RootElement); + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepMessageCreationDetails.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepMessageCreationDetails.cs new file mode 100644 index 000000000000..2c59cdfa44e0 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepMessageCreationDetails.cs @@ -0,0 +1,38 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + /// The detailed information associated with a message creation run step. + public partial class RunStepMessageCreationDetails : RunStepDetails + { + /// Initializes a new instance of . + /// Information about the message creation associated with this run step. + /// is null. + internal RunStepMessageCreationDetails(RunStepMessageCreationReference messageCreation) + { + Argument.AssertNotNull(messageCreation, nameof(messageCreation)); + + Type = RunStepType.MessageCreation; + MessageCreation = messageCreation; + } + + /// Initializes a new instance of . + /// The object type. + /// Information about the message creation associated with this run step. + internal RunStepMessageCreationDetails(RunStepType type, RunStepMessageCreationReference messageCreation) : base(type) + { + MessageCreation = messageCreation; + } + + /// Information about the message creation associated with this run step. + public RunStepMessageCreationReference MessageCreation { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepMessageCreationReference.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepMessageCreationReference.Serialization.cs new file mode 100644 index 000000000000..c521a3ffc99b --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepMessageCreationReference.Serialization.cs @@ -0,0 +1,41 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class RunStepMessageCreationReference + { + internal static RunStepMessageCreationReference DeserializeRunStepMessageCreationReference(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string messageId = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("message_id"u8)) + { + messageId = property.Value.GetString(); + continue; + } + } + return new RunStepMessageCreationReference(messageId); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static RunStepMessageCreationReference FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeRunStepMessageCreationReference(document.RootElement); + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepMessageCreationReference.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepMessageCreationReference.cs new file mode 100644 index 000000000000..9adfea67a990 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepMessageCreationReference.cs @@ -0,0 +1,29 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + /// The details of a message created as a part of a run step. + public partial class RunStepMessageCreationReference + { + /// Initializes a new instance of . + /// The ID of the message created by this run step. + /// is null. + internal RunStepMessageCreationReference(string messageId) + { + Argument.AssertNotNull(messageId, nameof(messageId)); + + MessageId = messageId; + } + + /// The ID of the message created by this run step. + public string MessageId { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepStatus.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepStatus.cs new file mode 100644 index 000000000000..3422c984e9a4 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepStatus.cs @@ -0,0 +1,60 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Azure.AI.OpenAI.Assistants +{ + /// Possible values for the status of a run step. + public readonly partial struct RunStepStatus : IEquatable + { + private readonly string _value; + + /// Initializes a new instance of . + /// is null. + public RunStepStatus(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string InProgressValue = "in_progress"; + private const string CancelledValue = "cancelled"; + private const string FailedValue = "failed"; + private const string CompletedValue = "completed"; + private const string ExpiredValue = "expired"; + + /// Represents a run step still in progress. + public static RunStepStatus InProgress { get; } = new RunStepStatus(InProgressValue); + /// Represents a run step that was cancelled. + public static RunStepStatus Cancelled { get; } = new RunStepStatus(CancelledValue); + /// Represents a run step that failed. + public static RunStepStatus Failed { get; } = new RunStepStatus(FailedValue); + /// Represents a run step that successfully completed. + public static RunStepStatus Completed { get; } = new RunStepStatus(CompletedValue); + /// Represents a run step that expired before otherwise finishing. + public static RunStepStatus Expired { get; } = new RunStepStatus(ExpiredValue); + /// Determines if two values are the same. + public static bool operator ==(RunStepStatus left, RunStepStatus right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(RunStepStatus left, RunStepStatus right) => !left.Equals(right); + /// Converts a string to a . + public static implicit operator RunStepStatus(string value) => new RunStepStatus(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is RunStepStatus other && Equals(other); + /// + public bool Equals(RunStepStatus other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value?.GetHashCode() ?? 0; + /// + public override string ToString() => _value; + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepToolCallDetails.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepToolCallDetails.Serialization.cs new file mode 100644 index 000000000000..69f3173bd90f --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepToolCallDetails.Serialization.cs @@ -0,0 +1,53 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Collections.Generic; +using System.Text.Json; +using Azure; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class RunStepToolCallDetails + { + internal static RunStepToolCallDetails DeserializeRunStepToolCallDetails(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + IReadOnlyList toolCalls = default; + RunStepType type = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("tool_calls"u8)) + { + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(ToolCall.DeserializeToolCall(item)); + } + toolCalls = array; + continue; + } + if (property.NameEquals("type"u8)) + { + type = new RunStepType(property.Value.GetString()); + continue; + } + } + return new RunStepToolCallDetails(type, toolCalls); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new RunStepToolCallDetails FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeRunStepToolCallDetails(document.RootElement); + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepToolCallDetails.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepToolCallDetails.cs new file mode 100644 index 000000000000..1e26eb6240c7 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepToolCallDetails.cs @@ -0,0 +1,44 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Linq; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + /// The detailed information associated with a run step calling tools. + public partial class RunStepToolCallDetails : RunStepDetails + { + /// Initializes a new instance of . + /// A list tool call details for this run step. + /// is null. + internal RunStepToolCallDetails(IEnumerable toolCalls) + { + Argument.AssertNotNull(toolCalls, nameof(toolCalls)); + + Type = RunStepType.ToolCalls; + ToolCalls = toolCalls.ToList(); + } + + /// Initializes a new instance of . + /// The object type. + /// A list tool call details for this run step. + internal RunStepToolCallDetails(RunStepType type, IReadOnlyList toolCalls) : base(type) + { + ToolCalls = toolCalls; + } + + /// + /// A list tool call details for this run step. + /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. + /// The available derived classes include , and . + /// + public IReadOnlyList ToolCalls { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepType.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepType.cs new file mode 100644 index 000000000000..d532ee6ba08f --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepType.cs @@ -0,0 +1,51 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Azure.AI.OpenAI.Assistants +{ + /// The possible types of run steps. + public readonly partial struct RunStepType : IEquatable + { + private readonly string _value; + + /// Initializes a new instance of . + /// is null. + public RunStepType(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string MessageCreationValue = "message_creation"; + private const string ToolCallsValue = "tool_calls"; + + /// Represents a run step to create a message. + public static RunStepType MessageCreation { get; } = new RunStepType(MessageCreationValue); + /// Represents a run step that calls tools. + public static RunStepType ToolCalls { get; } = new RunStepType(ToolCallsValue); + /// Determines if two values are the same. + public static bool operator ==(RunStepType left, RunStepType right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(RunStepType left, RunStepType right) => !left.Equals(right); + /// Converts a string to a . + public static implicit operator RunStepType(string value) => new RunStepType(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is RunStepType other && Equals(other); + /// + public bool Equals(RunStepType other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value?.GetHashCode() ?? 0; + /// + public override string ToString() => _value; + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/SubmitRunToolOutputsRequest.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/SubmitRunToolOutputsRequest.Serialization.cs new file mode 100644 index 000000000000..009950b7223b --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/SubmitRunToolOutputsRequest.Serialization.cs @@ -0,0 +1,36 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + internal partial class SubmitRunToolOutputsRequest : IUtf8JsonSerializable + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + { + writer.WriteStartObject(); + writer.WritePropertyName("tool_outputs"u8); + writer.WriteStartArray(); + foreach (var item in ToolOutputs) + { + writer.WriteObjectValue(item); + } + writer.WriteEndArray(); + writer.WriteEndObject(); + } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/SubmitRunToolOutputsRequest.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/SubmitRunToolOutputsRequest.cs new file mode 100644 index 000000000000..70cc463b347f --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/SubmitRunToolOutputsRequest.cs @@ -0,0 +1,38 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Linq; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + /// The SubmitRunToolOutputsRequest. + internal partial class SubmitRunToolOutputsRequest + { + /// Initializes a new instance of . + /// The list of tool outputs requested by tool calls from the specified run. + /// is null. + public SubmitRunToolOutputsRequest(IEnumerable toolOutputs) + { + Argument.AssertNotNull(toolOutputs, nameof(toolOutputs)); + + ToolOutputs = toolOutputs.ToList(); + } + + /// Initializes a new instance of . + /// The list of tool outputs requested by tool calls from the specified run. + internal SubmitRunToolOutputsRequest(IList toolOutputs) + { + ToolOutputs = toolOutputs; + } + + /// The list of tool outputs requested by tool calls from the specified run. + public IList ToolOutputs { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/SubmitToolOutputsAction.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/SubmitToolOutputsAction.Serialization.cs new file mode 100644 index 000000000000..199c8c1adf75 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/SubmitToolOutputsAction.Serialization.cs @@ -0,0 +1,47 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class SubmitToolOutputsAction + { + internal static SubmitToolOutputsAction DeserializeSubmitToolOutputsAction(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + InternalSubmitToolOutputsDetails submitToolOutputs = default; + string type = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("submit_tool_outputs"u8)) + { + submitToolOutputs = InternalSubmitToolOutputsDetails.DeserializeInternalSubmitToolOutputsDetails(property.Value); + continue; + } + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString(); + continue; + } + } + return new SubmitToolOutputsAction(type, submitToolOutputs); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new SubmitToolOutputsAction FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeSubmitToolOutputsAction(document.RootElement); + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/SubmitToolOutputsAction.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/SubmitToolOutputsAction.cs new file mode 100644 index 000000000000..9ad109c3fc58 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/SubmitToolOutputsAction.cs @@ -0,0 +1,35 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + /// The details for required tool calls that must be submitted for an assistant thread run to continue. + public partial class SubmitToolOutputsAction : RequiredAction + { + /// Initializes a new instance of . + /// The details describing tools that should be called to submit tool outputs. + /// is null. + internal SubmitToolOutputsAction(InternalSubmitToolOutputsDetails internalDetails) + { + Argument.AssertNotNull(internalDetails, nameof(internalDetails)); + + Type = "submit_tool_outputs"; + InternalDetails = internalDetails; + } + + /// Initializes a new instance of . + /// The object type. + /// The details describing tools that should be called to submit tool outputs. + internal SubmitToolOutputsAction(string type, InternalSubmitToolOutputsDetails internalDetails) : base(type) + { + InternalDetails = internalDetails; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadDeletionStatus.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadDeletionStatus.Serialization.cs new file mode 100644 index 000000000000..06416e70637a --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadDeletionStatus.Serialization.cs @@ -0,0 +1,47 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure; + +namespace Azure.AI.OpenAI.Assistants +{ + internal partial class ThreadDeletionStatus + { + internal static ThreadDeletionStatus DeserializeThreadDeletionStatus(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + ThreadDeletionStatusObject @object = default; + bool deleted = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("object"u8)) + { + @object = new ThreadDeletionStatusObject(property.Value.GetString()); + continue; + } + if (property.NameEquals("deleted"u8)) + { + deleted = property.Value.GetBoolean(); + continue; + } + } + return new ThreadDeletionStatus(deleted, @object); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static ThreadDeletionStatus FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeThreadDeletionStatus(document.RootElement); + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadDeletionStatus.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadDeletionStatus.cs new file mode 100644 index 000000000000..1fbeebd9489c --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadDeletionStatus.cs @@ -0,0 +1,30 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +namespace Azure.AI.OpenAI.Assistants +{ + /// The status of a thread deletion operation. + internal partial class ThreadDeletionStatus : InternalDeletionStatus + { + /// Initializes a new instance of . + /// A value indicating whether deletion was successful. + internal ThreadDeletionStatus(bool deleted) : base(deleted) + { + } + + /// Initializes a new instance of . + /// A value indicating whether deletion was successful. + /// The object type, which is always 'thread.deleted'. + internal ThreadDeletionStatus(bool deleted, ThreadDeletionStatusObject @object) : base(deleted) + { + Object = @object; + } + + /// The object type, which is always 'thread.deleted'. + public ThreadDeletionStatusObject Object { get; } = ThreadDeletionStatusObject.ThreadDeleted; + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadDeletionStatusObject.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadDeletionStatusObject.cs new file mode 100644 index 000000000000..d29c8eb61d1a --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadDeletionStatusObject.cs @@ -0,0 +1,48 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Azure.AI.OpenAI.Assistants +{ + /// The ThreadDeletionStatus_object. + internal readonly partial struct ThreadDeletionStatusObject : IEquatable + { + private readonly string _value; + + /// Initializes a new instance of . + /// is null. + public ThreadDeletionStatusObject(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string ThreadDeletedValue = "thread.deleted"; + + /// thread.deleted. + public static ThreadDeletionStatusObject ThreadDeleted { get; } = new ThreadDeletionStatusObject(ThreadDeletedValue); + /// Determines if two values are the same. + public static bool operator ==(ThreadDeletionStatusObject left, ThreadDeletionStatusObject right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(ThreadDeletionStatusObject left, ThreadDeletionStatusObject right) => !left.Equals(right); + /// Converts a string to a . + public static implicit operator ThreadDeletionStatusObject(string value) => new ThreadDeletionStatusObject(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is ThreadDeletionStatusObject other && Equals(other); + /// + public bool Equals(ThreadDeletionStatusObject other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value?.GetHashCode() ?? 0; + /// + public override string ToString() => _value; + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadMessage.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadMessage.Serialization.cs new file mode 100644 index 000000000000..f180c703bb2b --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadMessage.Serialization.cs @@ -0,0 +1,176 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Text.Json; +using Azure; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class ThreadMessage : IUtf8JsonSerializable + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + { + writer.WriteStartObject(); + writer.WritePropertyName("id"u8); + writer.WriteStringValue(Id); + writer.WritePropertyName("object"u8); + writer.WriteStringValue(Object); + writer.WritePropertyName("created_at"u8); + writer.WriteNumberValue(CreatedAt, "U"); + writer.WritePropertyName("thread_id"u8); + writer.WriteStringValue(ThreadId); + writer.WritePropertyName("role"u8); + writer.WriteStringValue(Role.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStartArray(); + foreach (var item in ContentItems) + { + writer.WriteObjectValue(item); + } + writer.WriteEndArray(); + if (Optional.IsDefined(AssistantId)) + { + writer.WritePropertyName("assistant_id"u8); + writer.WriteStringValue(AssistantId); + } + if (Optional.IsDefined(RunId)) + { + writer.WritePropertyName("run_id"u8); + writer.WriteStringValue(RunId); + } + writer.WritePropertyName("file_ids"u8); + writer.WriteStartArray(); + foreach (var item in FileIds) + { + writer.WriteStringValue(item); + } + writer.WriteEndArray(); + if (Optional.IsCollectionDefined(Metadata)) + { + writer.WritePropertyName("metadata"u8); + writer.WriteStartObject(); + foreach (var item in Metadata) + { + writer.WritePropertyName(item.Key); + writer.WriteStringValue(item.Value); + } + writer.WriteEndObject(); + } + writer.WriteEndObject(); + } + + internal static ThreadMessage DeserializeThreadMessage(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string id = default; + string @object = default; + DateTimeOffset createdAt = default; + string threadId = default; + MessageRole role = default; + IList content = default; + Optional assistantId = default; + Optional runId = default; + IList fileIds = default; + Optional> metadata = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("id"u8)) + { + id = property.Value.GetString(); + continue; + } + if (property.NameEquals("object"u8)) + { + @object = property.Value.GetString(); + continue; + } + if (property.NameEquals("created_at"u8)) + { + createdAt = DateTimeOffset.FromUnixTimeSeconds(property.Value.GetInt64()); + continue; + } + if (property.NameEquals("thread_id"u8)) + { + threadId = property.Value.GetString(); + continue; + } + if (property.NameEquals("role"u8)) + { + role = new MessageRole(property.Value.GetString()); + continue; + } + if (property.NameEquals("content"u8)) + { + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(MessageContent.DeserializeMessageContent(item)); + } + content = array; + continue; + } + if (property.NameEquals("assistant_id"u8)) + { + assistantId = property.Value.GetString(); + continue; + } + if (property.NameEquals("run_id"u8)) + { + runId = property.Value.GetString(); + continue; + } + if (property.NameEquals("file_ids"u8)) + { + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(item.GetString()); + } + fileIds = array; + continue; + } + if (property.NameEquals("metadata"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + Dictionary dictionary = new Dictionary(); + foreach (var property0 in property.Value.EnumerateObject()) + { + dictionary.Add(property0.Name, property0.Value.GetString()); + } + metadata = dictionary; + continue; + } + } + return new ThreadMessage(id, @object, createdAt, threadId, role, content, assistantId.Value, runId.Value, fileIds, Optional.ToDictionary(metadata)); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static ThreadMessage FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeThreadMessage(document.RootElement); + } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadMessage.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadMessage.cs new file mode 100644 index 000000000000..d65e66effcbe --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadMessage.cs @@ -0,0 +1,100 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Linq; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + /// A single message within an assistant thread. + public partial class ThreadMessage + { + /// Initializes a new instance of . + /// The identifier, which can be referenced in API endpoints. + /// The Unix timestamp, in seconds, representing when this object was created. + /// The ID of the thread that this message belongs to. + /// The role associated with the assistant thread message. + /// The list of content items associated with the assistant thread message. + /// + /// A list of file IDs that the assistant should use. Useful for tools like retrieval and code_interpreter that can + /// access files. + /// + /// , , or is null. + public ThreadMessage(string id, DateTimeOffset createdAt, string threadId, MessageRole role, IEnumerable contentItems, IEnumerable fileIds) + { + Argument.AssertNotNull(id, nameof(id)); + Argument.AssertNotNull(threadId, nameof(threadId)); + Argument.AssertNotNull(contentItems, nameof(contentItems)); + Argument.AssertNotNull(fileIds, nameof(fileIds)); + + Id = id; + CreatedAt = createdAt; + ThreadId = threadId; + Role = role; + ContentItems = contentItems.ToList(); + FileIds = fileIds.ToList(); + Metadata = new ChangeTrackingDictionary(); + } + + /// Initializes a new instance of . + /// The identifier, which can be referenced in API endpoints. + /// The object type, which is always 'thread.message'. + /// The Unix timestamp, in seconds, representing when this object was created. + /// The ID of the thread that this message belongs to. + /// The role associated with the assistant thread message. + /// The list of content items associated with the assistant thread message. + /// If applicable, the ID of the assistant that authored this message. + /// If applicable, the ID of the run associated with the authoring of this message. + /// + /// A list of file IDs that the assistant should use. Useful for tools like retrieval and code_interpreter that can + /// access files. + /// + /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. + internal ThreadMessage(string id, string @object, DateTimeOffset createdAt, string threadId, MessageRole role, IList contentItems, string assistantId, string runId, IList fileIds, IDictionary metadata) + { + Id = id; + Object = @object; + CreatedAt = createdAt; + ThreadId = threadId; + Role = role; + ContentItems = contentItems; + AssistantId = assistantId; + RunId = runId; + FileIds = fileIds; + Metadata = metadata; + } + + /// The identifier, which can be referenced in API endpoints. + public string Id { get; set; } + + /// The Unix timestamp, in seconds, representing when this object was created. + public DateTimeOffset CreatedAt { get; set; } + /// The ID of the thread that this message belongs to. + public string ThreadId { get; set; } + /// The role associated with the assistant thread message. + public MessageRole Role { get; set; } + /// + /// The list of content items associated with the assistant thread message. + /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. + /// The available derived classes include and . + /// + public IList ContentItems { get; } + /// If applicable, the ID of the assistant that authored this message. + public string AssistantId { get; set; } + /// If applicable, the ID of the run associated with the authoring of this message. + public string RunId { get; set; } + /// + /// A list of file IDs that the assistant should use. Useful for tools like retrieval and code_interpreter that can + /// access files. + /// + public IList FileIds { get; } + /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. + public IDictionary Metadata { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadRun.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadRun.Serialization.cs new file mode 100644 index 000000000000..57bfbea090bf --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadRun.Serialization.cs @@ -0,0 +1,175 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Text.Json; +using Azure; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class ThreadRun + { + internal static ThreadRun DeserializeThreadRun(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string id = default; + string @object = default; + string threadId = default; + string assistantId = default; + RunStatus status = default; + Optional requiredAction = default; + RunError lastError = default; + string model = default; + string instructions = default; + IReadOnlyList tools = default; + IReadOnlyList fileIds = default; + DateTimeOffset createdAt = default; + DateTimeOffset? expiresAt = default; + DateTimeOffset? startedAt = default; + DateTimeOffset? completedAt = default; + DateTimeOffset? cancelledAt = default; + DateTimeOffset? failedAt = default; + Optional> metadata = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("id"u8)) + { + id = property.Value.GetString(); + continue; + } + if (property.NameEquals("object"u8)) + { + @object = property.Value.GetString(); + continue; + } + if (property.NameEquals("thread_id"u8)) + { + threadId = property.Value.GetString(); + continue; + } + if (property.NameEquals("assistant_id"u8)) + { + assistantId = property.Value.GetString(); + continue; + } + if (property.NameEquals("status"u8)) + { + status = new RunStatus(property.Value.GetString()); + continue; + } + if (property.NameEquals("required_action"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + requiredAction = null; + continue; + } + requiredAction = RequiredAction.DeserializeRequiredAction(property.Value); + continue; + } + if (property.NameEquals("last_error"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + lastError = null; + continue; + } + lastError = RunError.DeserializeRunError(property.Value); + continue; + } + if (property.NameEquals("model"u8)) + { + model = property.Value.GetString(); + continue; + } + if (property.NameEquals("instructions"u8)) + { + instructions = property.Value.GetString(); + continue; + } + if (property.NameEquals("tools"u8)) + { + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(ToolDefinition.DeserializeToolDefinition(item)); + } + tools = array; + continue; + } + if (property.NameEquals("file_ids"u8)) + { + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(item.GetString()); + } + fileIds = array; + continue; + } + if (property.NameEquals("created_at"u8)) + { + createdAt = DateTimeOffset.FromUnixTimeSeconds(property.Value.GetInt64()); + continue; + } + if (property.NameEquals("expires_at"u8)) + { + DeserializeNullableDateTimeOffset(property, ref expiresAt); + continue; + } + if (property.NameEquals("started_at"u8)) + { + DeserializeNullableDateTimeOffset(property, ref startedAt); + continue; + } + if (property.NameEquals("completed_at"u8)) + { + DeserializeNullableDateTimeOffset(property, ref completedAt); + continue; + } + if (property.NameEquals("cancelled_at"u8)) + { + DeserializeNullableDateTimeOffset(property, ref cancelledAt); + continue; + } + if (property.NameEquals("failed_at"u8)) + { + DeserializeNullableDateTimeOffset(property, ref failedAt); + continue; + } + if (property.NameEquals("metadata"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + Dictionary dictionary = new Dictionary(); + foreach (var property0 in property.Value.EnumerateObject()) + { + dictionary.Add(property0.Name, property0.Value.GetString()); + } + metadata = dictionary; + continue; + } + } + return new ThreadRun(id, @object, threadId, assistantId, status, requiredAction.Value, lastError, model, instructions, tools, fileIds, createdAt, expiresAt, startedAt, completedAt, cancelledAt, failedAt, Optional.ToDictionary(metadata)); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static ThreadRun FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeThreadRun(document.RootElement); + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadRun.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadRun.cs new file mode 100644 index 000000000000..2c8f3ab85bd7 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadRun.cs @@ -0,0 +1,138 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Linq; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + /// Data representing a single evaluation run of an assistant thread. + public partial class ThreadRun + { + /// Initializes a new instance of . + /// The identifier, which can be referenced in API endpoints. + /// The ID of the thread associated with this run. + /// The ID of the assistant associated with the thread this run was performed against. + /// The status of the assistant thread run. + /// The last error, if any, encountered by this assistant thread run. + /// The ID of the model to use. + /// The overridden system instructions used for this assistant thread run. + /// The overridden enabled tools used for this assistant thread run. + /// A list of attached file IDs, ordered by creation date in ascending order. + /// The Unix timestamp, in seconds, representing when this object was created. + /// The Unix timestamp, in seconds, representing when this item expires. + /// The Unix timestamp, in seconds, representing when this item was started. + /// The Unix timestamp, in seconds, representing when this completed. + /// The Unix timestamp, in seconds, representing when this was cancelled. + /// The Unix timestamp, in seconds, representing when this failed. + /// , , , , , or is null. + internal ThreadRun(string id, string threadId, string assistantId, RunStatus status, RunError lastError, string model, string instructions, IEnumerable tools, IEnumerable fileIds, DateTimeOffset createdAt, DateTimeOffset? expiresAt, DateTimeOffset? startedAt, DateTimeOffset? completedAt, DateTimeOffset? cancelledAt, DateTimeOffset? failedAt) + { + Argument.AssertNotNull(id, nameof(id)); + Argument.AssertNotNull(threadId, nameof(threadId)); + Argument.AssertNotNull(assistantId, nameof(assistantId)); + Argument.AssertNotNull(model, nameof(model)); + Argument.AssertNotNull(instructions, nameof(instructions)); + Argument.AssertNotNull(tools, nameof(tools)); + Argument.AssertNotNull(fileIds, nameof(fileIds)); + + Id = id; + ThreadId = threadId; + AssistantId = assistantId; + Status = status; + LastError = lastError; + Model = model; + Instructions = instructions; + Tools = tools.ToList(); + FileIds = fileIds.ToList(); + CreatedAt = createdAt; + ExpiresAt = expiresAt; + StartedAt = startedAt; + CompletedAt = completedAt; + CancelledAt = cancelledAt; + FailedAt = failedAt; + Metadata = new ChangeTrackingDictionary(); + } + + /// Initializes a new instance of . + /// The identifier, which can be referenced in API endpoints. + /// The object type, which is always 'thread.run'. + /// The ID of the thread associated with this run. + /// The ID of the assistant associated with the thread this run was performed against. + /// The status of the assistant thread run. + /// The details of the action required for the assistant thread run to continue. + /// The last error, if any, encountered by this assistant thread run. + /// The ID of the model to use. + /// The overridden system instructions used for this assistant thread run. + /// The overridden enabled tools used for this assistant thread run. + /// A list of attached file IDs, ordered by creation date in ascending order. + /// The Unix timestamp, in seconds, representing when this object was created. + /// The Unix timestamp, in seconds, representing when this item expires. + /// The Unix timestamp, in seconds, representing when this item was started. + /// The Unix timestamp, in seconds, representing when this completed. + /// The Unix timestamp, in seconds, representing when this was cancelled. + /// The Unix timestamp, in seconds, representing when this failed. + /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. + internal ThreadRun(string id, string @object, string threadId, string assistantId, RunStatus status, RequiredAction requiredAction, RunError lastError, string model, string instructions, IReadOnlyList tools, IReadOnlyList fileIds, DateTimeOffset createdAt, DateTimeOffset? expiresAt, DateTimeOffset? startedAt, DateTimeOffset? completedAt, DateTimeOffset? cancelledAt, DateTimeOffset? failedAt, IReadOnlyDictionary metadata) + { + Id = id; + Object = @object; + ThreadId = threadId; + AssistantId = assistantId; + Status = status; + RequiredAction = requiredAction; + LastError = lastError; + Model = model; + Instructions = instructions; + Tools = tools; + FileIds = fileIds; + CreatedAt = createdAt; + ExpiresAt = expiresAt; + StartedAt = startedAt; + CompletedAt = completedAt; + CancelledAt = cancelledAt; + FailedAt = failedAt; + Metadata = metadata; + } + + /// The identifier, which can be referenced in API endpoints. + public string Id { get; } + + /// The ID of the thread associated with this run. + public string ThreadId { get; } + /// The ID of the assistant associated with the thread this run was performed against. + public string AssistantId { get; } + /// The status of the assistant thread run. + public RunStatus Status { get; } + /// + /// The details of the action required for the assistant thread run to continue. + /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. + /// The available derived classes include . + /// + public RequiredAction RequiredAction { get; } + /// The last error, if any, encountered by this assistant thread run. + public RunError LastError { get; } + /// The ID of the model to use. + public string Model { get; } + /// The overridden system instructions used for this assistant thread run. + public string Instructions { get; } + /// + /// The overridden enabled tools used for this assistant thread run. + /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. + /// The available derived classes include , and . + /// + public IReadOnlyList Tools { get; } + /// A list of attached file IDs, ordered by creation date in ascending order. + public IReadOnlyList FileIds { get; } + /// The Unix timestamp, in seconds, representing when this object was created. + public DateTimeOffset CreatedAt { get; } + /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. + public IReadOnlyDictionary Metadata { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ToolCall.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ToolCall.Serialization.cs new file mode 100644 index 000000000000..bcf917e9258f --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ToolCall.Serialization.cs @@ -0,0 +1,41 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class ToolCall + { + internal static ToolCall DeserializeToolCall(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + if (element.TryGetProperty("type", out JsonElement discriminator)) + { + switch (discriminator.GetString()) + { + case "code_interpreter": return CodeInterpreterToolCall.DeserializeCodeInterpreterToolCall(element); + case "retrieval": return RetrievalToolCall.DeserializeRetrievalToolCall(element); + case "function": return FunctionToolCall.DeserializeFunctionToolCall(element); + } + } + return UnknownToolCall.DeserializeUnknownToolCall(element); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static ToolCall FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeToolCall(document.RootElement); + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ToolCall.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ToolCall.cs new file mode 100644 index 000000000000..783c92c7119b --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ToolCall.cs @@ -0,0 +1,45 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + /// + /// An abstract representation a tool call, issued by the model in evaluation of a configured tool definition, that must + /// be fulfilled and have its outputs submitted before the model can continue. + /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. + /// The available derived classes include , and . + /// + public abstract partial class ToolCall + { + /// Initializes a new instance of . + /// The ID of the tool call. This ID must be referenced when you submit tool outputs. + /// is null. + protected ToolCall(string id) + { + Argument.AssertNotNull(id, nameof(id)); + + Id = id; + } + + /// Initializes a new instance of . + /// The object type. + /// The ID of the tool call. This ID must be referenced when you submit tool outputs. + internal ToolCall(string type, string id) + { + Type = type; + Id = id; + } + + /// The object type. + internal string Type { get; set; } + /// The ID of the tool call. This ID must be referenced when you submit tool outputs. + public string Id { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ToolDefinition.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ToolDefinition.Serialization.cs new file mode 100644 index 000000000000..a918fe002774 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ToolDefinition.Serialization.cs @@ -0,0 +1,58 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class ToolDefinition : IUtf8JsonSerializable + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + { + writer.WriteStartObject(); + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type); + writer.WriteEndObject(); + } + + internal static ToolDefinition DeserializeToolDefinition(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + if (element.TryGetProperty("type", out JsonElement discriminator)) + { + switch (discriminator.GetString()) + { + case "code_interpreter": return CodeInterpreterToolDefinition.DeserializeCodeInterpreterToolDefinition(element); + case "retrieval": return RetrievalToolDefinition.DeserializeRetrievalToolDefinition(element); + case "function": return FunctionToolDefinition.DeserializeFunctionToolDefinition(element); + } + } + return UnknownToolDefinition.DeserializeUnknownToolDefinition(element); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static ToolDefinition FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeToolDefinition(document.RootElement); + } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ToolDefinition.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ToolDefinition.cs new file mode 100644 index 000000000000..58fdafa2bf54 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ToolDefinition.cs @@ -0,0 +1,32 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +namespace Azure.AI.OpenAI.Assistants +{ + /// + /// An abstract representation of an input tool definition that an assistant can use. + /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. + /// The available derived classes include , and . + /// + public abstract partial class ToolDefinition + { + /// Initializes a new instance of . + protected ToolDefinition() + { + } + + /// Initializes a new instance of . + /// The object type. + internal ToolDefinition(string type) + { + Type = type; + } + + /// The object type. + internal string Type { get; set; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ToolOutput.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ToolOutput.Serialization.cs new file mode 100644 index 000000000000..2edb9ae393c0 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ToolOutput.Serialization.cs @@ -0,0 +1,39 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class ToolOutput : IUtf8JsonSerializable + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + { + writer.WriteStartObject(); + if (Optional.IsDefined(ToolCallId)) + { + writer.WritePropertyName("tool_call_id"u8); + writer.WriteStringValue(ToolCallId); + } + if (Optional.IsDefined(Output)) + { + writer.WritePropertyName("output"u8); + writer.WriteStringValue(Output); + } + writer.WriteEndObject(); + } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ToolOutput.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ToolOutput.cs new file mode 100644 index 000000000000..4e788e8ccff2 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ToolOutput.cs @@ -0,0 +1,23 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +namespace Azure.AI.OpenAI.Assistants +{ + /// The data provided during a tool outputs submission to resolve pending tool calls and allow the model to continue. + public partial class ToolOutput + { + /// Initializes a new instance of . + public ToolOutput() + { + } + + /// The ID of the tool call being resolved, as provided in the tool calls of a required action from a run. + public string ToolCallId { get; set; } + /// The output from the tool to be submitted. + public string Output { get; set; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownCodeInterpreterToolCallOutput.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownCodeInterpreterToolCallOutput.Serialization.cs new file mode 100644 index 000000000000..b8f6a4947e62 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownCodeInterpreterToolCallOutput.Serialization.cs @@ -0,0 +1,41 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure; + +namespace Azure.AI.OpenAI.Assistants +{ + internal partial class UnknownCodeInterpreterToolCallOutput + { + internal static UnknownCodeInterpreterToolCallOutput DeserializeUnknownCodeInterpreterToolCallOutput(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string type = "Unknown"; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString(); + continue; + } + } + return new UnknownCodeInterpreterToolCallOutput(type); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new UnknownCodeInterpreterToolCallOutput FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeUnknownCodeInterpreterToolCallOutput(document.RootElement); + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownCodeInterpreterToolCallOutput.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownCodeInterpreterToolCallOutput.cs new file mode 100644 index 000000000000..9c5bc46d4108 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownCodeInterpreterToolCallOutput.cs @@ -0,0 +1,24 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +namespace Azure.AI.OpenAI.Assistants +{ + /// Unknown version of CodeInterpreterToolCallOutput. + internal partial class UnknownCodeInterpreterToolCallOutput : CodeInterpreterToolCallOutput + { + /// Initializes a new instance of . + internal UnknownCodeInterpreterToolCallOutput() + { + } + + /// Initializes a new instance of . + /// The object type. + internal UnknownCodeInterpreterToolCallOutput(string type) : base(type) + { + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownMessageContent.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownMessageContent.Serialization.cs new file mode 100644 index 000000000000..ed11d5513fed --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownMessageContent.Serialization.cs @@ -0,0 +1,41 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure; + +namespace Azure.AI.OpenAI.Assistants +{ + internal partial class UnknownMessageContent + { + internal static UnknownMessageContent DeserializeUnknownMessageContent(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string type = "Unknown"; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString(); + continue; + } + } + return new UnknownMessageContent(type); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new UnknownMessageContent FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeUnknownMessageContent(document.RootElement); + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownMessageContent.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownMessageContent.cs new file mode 100644 index 000000000000..ec5d8306d117 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownMessageContent.cs @@ -0,0 +1,24 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +namespace Azure.AI.OpenAI.Assistants +{ + /// Unknown version of MessageContent. + internal partial class UnknownMessageContent : MessageContent + { + /// Initializes a new instance of . + internal UnknownMessageContent() + { + } + + /// Initializes a new instance of . + /// The object type. + internal UnknownMessageContent(string type) : base(type) + { + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownMessageTextAnnotation.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownMessageTextAnnotation.Serialization.cs new file mode 100644 index 000000000000..117f1a217fa8 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownMessageTextAnnotation.Serialization.cs @@ -0,0 +1,59 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure; + +namespace Azure.AI.OpenAI.Assistants +{ + internal partial class UnknownMessageTextAnnotation + { + internal static UnknownMessageTextAnnotation DeserializeUnknownMessageTextAnnotation(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string type = "Unknown"; + string text = default; + int startIndex = default; + int endIndex = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString(); + continue; + } + if (property.NameEquals("text"u8)) + { + text = property.Value.GetString(); + continue; + } + if (property.NameEquals("start_index"u8)) + { + startIndex = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("end_index"u8)) + { + endIndex = property.Value.GetInt32(); + continue; + } + } + return new UnknownMessageTextAnnotation(type, text, startIndex, endIndex); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new UnknownMessageTextAnnotation FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeUnknownMessageTextAnnotation(document.RootElement); + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownMessageTextAnnotation.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownMessageTextAnnotation.cs new file mode 100644 index 000000000000..6fbd1ac1d9ab --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownMessageTextAnnotation.cs @@ -0,0 +1,35 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + /// Unknown version of MessageTextAnnotation. + internal partial class UnknownMessageTextAnnotation : MessageTextAnnotation + { + /// Initializes a new instance of . + /// The textual content associated with this text annotation item. + /// The first text index associated with this text annotation. + /// The last text index associated with this text annotation. + /// is null. + internal UnknownMessageTextAnnotation(string text, int startIndex, int endIndex) : base(text, startIndex, endIndex) + { + Argument.AssertNotNull(text, nameof(text)); + } + + /// Initializes a new instance of . + /// The object type. + /// The textual content associated with this text annotation item. + /// The first text index associated with this text annotation. + /// The last text index associated with this text annotation. + internal UnknownMessageTextAnnotation(string type, string text, int startIndex, int endIndex) : base(type, text, startIndex, endIndex) + { + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownRequiredAction.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownRequiredAction.Serialization.cs new file mode 100644 index 000000000000..efefccd1d711 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownRequiredAction.Serialization.cs @@ -0,0 +1,41 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure; + +namespace Azure.AI.OpenAI.Assistants +{ + internal partial class UnknownRequiredAction + { + internal static UnknownRequiredAction DeserializeUnknownRequiredAction(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string type = "Unknown"; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString(); + continue; + } + } + return new UnknownRequiredAction(type); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new UnknownRequiredAction FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeUnknownRequiredAction(document.RootElement); + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownRequiredAction.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownRequiredAction.cs new file mode 100644 index 000000000000..c0eaa5d12b84 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownRequiredAction.cs @@ -0,0 +1,24 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +namespace Azure.AI.OpenAI.Assistants +{ + /// Unknown version of RequiredAction. + internal partial class UnknownRequiredAction : RequiredAction + { + /// Initializes a new instance of . + internal UnknownRequiredAction() + { + } + + /// Initializes a new instance of . + /// The object type. + internal UnknownRequiredAction(string type) : base(type) + { + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownRunStepDetails.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownRunStepDetails.Serialization.cs new file mode 100644 index 000000000000..f054ddaa6d6d --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownRunStepDetails.Serialization.cs @@ -0,0 +1,41 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure; + +namespace Azure.AI.OpenAI.Assistants +{ + internal partial class UnknownRunStepDetails + { + internal static UnknownRunStepDetails DeserializeUnknownRunStepDetails(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + RunStepType type = "Unknown"; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("type"u8)) + { + type = new RunStepType(property.Value.GetString()); + continue; + } + } + return new UnknownRunStepDetails(type); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new UnknownRunStepDetails FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeUnknownRunStepDetails(document.RootElement); + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownRunStepDetails.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownRunStepDetails.cs new file mode 100644 index 000000000000..7899ded79513 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownRunStepDetails.cs @@ -0,0 +1,24 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +namespace Azure.AI.OpenAI.Assistants +{ + /// Unknown version of RunStepDetails. + internal partial class UnknownRunStepDetails : RunStepDetails + { + /// Initializes a new instance of . + internal UnknownRunStepDetails() + { + } + + /// Initializes a new instance of . + /// The object type. + internal UnknownRunStepDetails(RunStepType type) : base(type) + { + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownToolCall.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownToolCall.Serialization.cs new file mode 100644 index 000000000000..976feed0182c --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownToolCall.Serialization.cs @@ -0,0 +1,47 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure; + +namespace Azure.AI.OpenAI.Assistants +{ + internal partial class UnknownToolCall + { + internal static UnknownToolCall DeserializeUnknownToolCall(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string type = "Unknown"; + string id = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString(); + continue; + } + if (property.NameEquals("id"u8)) + { + id = property.Value.GetString(); + continue; + } + } + return new UnknownToolCall(type, id); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new UnknownToolCall FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeUnknownToolCall(document.RootElement); + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownToolCall.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownToolCall.cs new file mode 100644 index 000000000000..905ac16f3ce7 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownToolCall.cs @@ -0,0 +1,31 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + /// Unknown version of ToolCall. + internal partial class UnknownToolCall : ToolCall + { + /// Initializes a new instance of . + /// The ID of the tool call. This ID must be referenced when you submit tool outputs. + /// is null. + internal UnknownToolCall(string id) : base(id) + { + Argument.AssertNotNull(id, nameof(id)); + } + + /// Initializes a new instance of . + /// The object type. + /// The ID of the tool call. This ID must be referenced when you submit tool outputs. + internal UnknownToolCall(string type, string id) : base(type, id) + { + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownToolDefinition.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownToolDefinition.Serialization.cs new file mode 100644 index 000000000000..245df8cfb60d --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownToolDefinition.Serialization.cs @@ -0,0 +1,41 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure; + +namespace Azure.AI.OpenAI.Assistants +{ + internal partial class UnknownToolDefinition + { + internal static UnknownToolDefinition DeserializeUnknownToolDefinition(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string type = "Unknown"; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString(); + continue; + } + } + return new UnknownToolDefinition(type); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new UnknownToolDefinition FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeUnknownToolDefinition(document.RootElement); + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownToolDefinition.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownToolDefinition.cs new file mode 100644 index 000000000000..5b92f0688764 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownToolDefinition.cs @@ -0,0 +1,24 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +namespace Azure.AI.OpenAI.Assistants +{ + /// Unknown version of ToolDefinition. + internal partial class UnknownToolDefinition : ToolDefinition + { + /// Initializes a new instance of . + internal UnknownToolDefinition() + { + } + + /// Initializes a new instance of . + /// The object type. + internal UnknownToolDefinition(string type) : base(type) + { + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UploadFileRequest.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UploadFileRequest.Serialization.cs new file mode 100644 index 000000000000..0206b80fb3ef --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UploadFileRequest.Serialization.cs @@ -0,0 +1,30 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + internal partial class UploadFileRequest : IUtf8JsonSerializable + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + { + writer.WriteStartObject(); + writer.WritePropertyName("file"u8); + writer.WriteBase64StringValue(Data.ToArray(), "D"); + writer.WritePropertyName("purpose"u8); + writer.WriteStringValue(Purpose.ToString()); + if (Optional.IsDefined(Filename)) + { + writer.WritePropertyName("filename"u8); + writer.WriteStringValue(Filename); + } + writer.WriteEndObject(); + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UploadFileRequest.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UploadFileRequest.cs new file mode 100644 index 000000000000..e276c52bea44 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UploadFileRequest.cs @@ -0,0 +1,61 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + /// The UploadFileRequest. + internal partial class UploadFileRequest + { + /// Initializes a new instance of . + /// The file data (not filename) to upload. + /// The intended purpose of the file. + /// is null. + public UploadFileRequest(BinaryData data, OpenAIFilePurpose purpose) + { + Argument.AssertNotNull(data, nameof(data)); + + Data = data; + Purpose = purpose; + } + + /// Initializes a new instance of . + /// The file data (not filename) to upload. + /// The intended purpose of the file. + /// A filename to associate with the uploaded data. + internal UploadFileRequest(BinaryData data, OpenAIFilePurpose purpose, string filename) + { + Data = data; + Purpose = purpose; + Filename = filename; + } + + /// + /// The file data (not filename) to upload. + /// + /// To assign a byte[] to this property use . + /// The byte[] will be serialized to a Base64 encoded string. + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromBytes(new byte[] { 1, 2, 3 }) + /// Creates a payload of "AQID". + /// + /// + /// + /// + public BinaryData Data { get; } + /// The intended purpose of the file. + public OpenAIFilePurpose Purpose { get; } + /// A filename to associate with the uploaded data. + public string Filename { get; set; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Helpers/CustomSerializationHelpers.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Helpers/CustomSerializationHelpers.cs new file mode 100644 index 000000000000..4fb3eb6452a2 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Helpers/CustomSerializationHelpers.cs @@ -0,0 +1,23 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Runtime.CompilerServices; +using System.Text.Json; + +namespace Azure.AI.OpenAI.Assistants; +internal static partial class CustomSerializationHelpers +{ + [MethodImpl(MethodImplOptions.AggressiveInlining)] + internal static void DeserializeNullableDateTimeOffset(JsonProperty property, ref DateTimeOffset? targetDateTimeOffset) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + targetDateTimeOffset = null; + } + else + { + targetDateTimeOffset = DateTimeOffset.FromUnixTimeSeconds(property.Value.GetInt64()); + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Properties/AssemblyInfo.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Properties/AssemblyInfo.cs new file mode 100644 index 000000000000..0d71726cbb05 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Properties/AssemblyInfo.cs @@ -0,0 +1,14 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using Azure.Core; + +[assembly: AzureResourceProviderNamespace("Microsoft.CognitiveServices")] +[assembly: CodeGenSuppressType("Azure.AI.OpenAI.Assistants.AssistantObject")] +[assembly: CodeGenSuppressType("Azure.AI.OpenAI.Assistants.AssistantFileObject")] +[assembly: CodeGenSuppressType("Azure.AI.OpenAI.Assistants.AssistantThreadObject")] +[assembly: CodeGenSuppressType("Azure.AI.OpenAI.Assistants.MessageFileObject")] +[assembly: CodeGenSuppressType("Azure.AI.OpenAI.Assistants.OpenAIFileObject")] +[assembly: CodeGenSuppressType("Azure.AI.OpenAI.Assistants.RunStepObject")] +[assembly: CodeGenSuppressType("Azure.AI.OpenAI.Assistants.ThreadMessageObject")] +[assembly: CodeGenSuppressType("Azure.AI.OpenAI.Assistants.ThreadRunObject")] diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/README.md b/sdk/openai/Azure.AI.OpenAI.Assistants/src/README.md new file mode 100644 index 000000000000..aa977ecb4375 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/README.md @@ -0,0 +1,13 @@ +## Azure.AI.OpenAI.Assistants library source code + +**IMPORTANT**: this project is based on generated code from a common specification and changes either originate from or interact with the specification source. + +You can find the specification project for `OpenAI.Assistants` in the `azure-rest-api-specs` repository: https://github.com/Azure/azure-rest-api-specs/tree/main/specification/ai + +| Folder | Description | +|--|--| +| [/generated](/generated) | Purely generated code based on the specification commit tag described in [../tsp-location.yaml](../tsp-location.yaml) and influenced by the contents of files in [/custom](/custom). | +| [/custom](/custom) | Hand-written code that mutually informs code generation output by redefining types, structure, and other behavior. | +| [/convenience](/convenience) | Hand-written code to add or improve additional capabilities that bears no direction interaction with generated source. | + +To populate the generated code portion, use the appropriate build target via `dotnet build /t:GenerateCode`. diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/tests/AssistantsModelFactoryTests.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/tests/AssistantsModelFactoryTests.cs new file mode 100644 index 000000000000..d55b1c05d4bd --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/tests/AssistantsModelFactoryTests.cs @@ -0,0 +1,316 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using Microsoft.Identity.Client; +using NUnit.Framework; + +namespace Azure.AI.OpenAI.Assistants.Tests; + +public class AssistantsModelFactoryTests +{ + [TestCase] + public void CanMakeListOfAssistants() + { + // AssistantsClient mockClient = new(openAIApiKey: "mock"); + // _ = mockClient.GetAssistants(); + + string[] assistantIds = new string[] { "first_assistant_id", "second_assistant_id", "last_assistant_id" }; + string[] assistantNames = new string[] { "first assistant name", "second assistant name", "last assistant name" }; + string[] assistantDescriptions = new string[] + { + "description of the first assistant", + "description of the second assistant", + "description of the last assistant", + }; + string[] assistantInstructions = new string[] + { + "instructions for the first assistant", + "instructions for the second assistant", + "instructions for the last assistant", + }; + string[] assistantModels = new string[] { "first_assistant_model", "second_assistant_model", "last_assistant_model" }; + DateTime[] assistantCreationTimes = new DateTime[] + { + DateTime.Now - TimeSpan.FromHours(1), + DateTime.Now - TimeSpan.FromMinutes(30), + DateTime.Now - TimeSpan.FromSeconds(30), + }; + string[][] assistantFileIds = new string[][] + { + new string[] { "first_assistant_file_id_1", "first_assistant_file_id_2" }, + null, + new string[] { "last_assistant_file_id_1" }, + }; + Dictionary[] assistantMetadata = new Dictionary[] + { + new() + { + ["first_assistant_metadata_key_1"] = "first_assistant_metadata_value_1", + ["first_assistant_metadata_key_2"] = "first_assistant_metadata_value_2", + }, + null, + new() + { + ["second_assistant_metadata_key_1"] = "second_assistant_metadata_value_1", + }, + }; + ToolDefinition[][] assistantTools = new ToolDefinition[][] + { + new ToolDefinition[] + { + new FunctionToolDefinition("first_assistant_function_name", "description of first assistant's function tool"), + }, + null, + new ToolDefinition[] + { + new FunctionToolDefinition( + "last_assistant_function_name", + "description of last assistant", + BinaryData.FromObjectAsJson(new { type = "object" })), + new RetrievalToolDefinition(), + }, + }; + + List data = new(); + for (int i = 0; i < assistantIds.Length; i++) + { + data.Add(AssistantsModelFactory.Assistant( + id: assistantIds[i], + name: assistantNames[i], + description: assistantDescriptions[i], + createdAt: assistantCreationTimes[i], + instructions: assistantInstructions[i], + tools: assistantTools[i], + model: assistantModels[i], + fileIds: assistantFileIds[i], + metadata: assistantMetadata[i])); + } + PageableList assistants = AssistantsModelFactory.PageableList( + data, + assistantIds[0], + assistantIds[assistantIds.Length - 1], + hasMore: false); + + Assert.That(assistants.FirstId, Is.EqualTo(assistantIds[0])); + Assert.That(assistants.LastId, Is.EqualTo(assistantIds[assistantIds.Length - 1])); + Assert.That(assistants.HasMore, Is.EqualTo(false)); + + Assert.That(assistants.Data.Count, Is.EqualTo(assistantIds.Length)); + for (int i = 0; i < assistants.Data.Count; i++) + { + Assert.That(assistants[i], Is.EqualTo(assistants.Data[i])); + Assert.That(assistants[i].Id, Is.EqualTo(assistantIds[i])); + Assert.That(assistants[i].Name, Is.EqualTo(assistantNames[i])); + Assert.That(assistants[i].Description, Is.EqualTo(assistantDescriptions[i])); + Assert.That(assistants[i].CreatedAt.ToString("o"), Is.EqualTo(assistantCreationTimes[i].ToString("o"))); + Assert.That(assistants[i].Instructions, Is.EqualTo(assistantInstructions[i])); + Assert.That(assistants[i].Model, Is.EqualTo(assistantModels[i])); + Assert.That(assistants[i].FileIds?.Count ?? 0, Is.EqualTo(assistantFileIds[i]?.Length ?? 0)); + if (assistants[i].FileIds != null) + { + for (int fileIdIndex = 0; fileIdIndex < assistants[i].FileIds.Count; fileIdIndex++) + { + Assert.That(assistants[i].FileIds[fileIdIndex], Is.EqualTo(assistantFileIds[i][fileIdIndex])); + } + } + Assert.That(assistants[i].Metadata?.Count ?? 0, Is.EqualTo(assistantMetadata[i]?.Count ?? 0)); + if (assistantMetadata[i] != null) + { + foreach (KeyValuePair expectedKeyValuePair in assistantMetadata[i]) + { + Assert.That(assistants[i].Metadata.ContainsKey(expectedKeyValuePair.Key), Is.True); + Assert.That(assistants[i].Metadata[expectedKeyValuePair.Key], Is.EqualTo(expectedKeyValuePair.Value)); + } + } + Assert.That(assistants[i].Tools?.Count ?? 0, Is.EqualTo(assistantTools[i]?.Length ?? 0)); + if (assistantTools[i] != null) + { + Assert.That(assistants[i].Tools.Count, Is.EqualTo(assistantTools[i].Length)); + for (int toolIndex = 0; toolIndex < assistants[i].Tools.Count; toolIndex++) + { + if (assistants[i].Tools[toolIndex] is FunctionToolDefinition functionTool) + { + FunctionToolDefinition expectedFunctionTool = assistantTools[i][toolIndex] as FunctionToolDefinition; + Assert.That(expectedFunctionTool, Is.Not.Null); + Assert.That(functionTool.Name, Is.EqualTo(expectedFunctionTool.Name)); + Assert.That(functionTool.Description, Is.EqualTo(expectedFunctionTool.Description)); + Assert.That(functionTool.Parameters.ToString(), Is.EqualTo(expectedFunctionTool.Parameters.ToString())); + } + else if (assistants[i].Tools[toolIndex] is RetrievalToolDefinition retrievalTool) + { + RetrievalToolDefinition expectedRetrievalTool = assistantTools[i][toolIndex] as RetrievalToolDefinition; + Assert.That(expectedRetrievalTool, Is.Not.Null); + } + else if (assistants[i].Tools[toolIndex] is CodeInterpreterToolDefinition codeInterpreterTool) + { + CodeInterpreterToolDefinition expectedCodeInterpreterTool = assistantTools[i][toolIndex] as CodeInterpreterToolDefinition; + Assert.That(expectedCodeInterpreterTool, Is.Not.Null); + } + else + { + Assert.Fail($"Unhandled assistant tool definition type: {assistants[i].Tools[toolIndex]}"); + } + } + } + } + } + + [TestCase] + public void CanMakeThread() + { + // _ = mockClient.GetThread(mockThreadId); + + string threadId = "first_thread_id"; + Dictionary threadMetadata = new Dictionary() + { + ["first_thread_metadata_key"] = "first_thread_metadata_value", + }; + AssistantThread mockThread = AssistantsModelFactory.AssistantThread( + id: threadId, + metadata: threadMetadata); + Assert.That(mockThread.Id, Is.EqualTo(threadId)); + Assert.That(mockThread.Metadata?.Count ?? 0, Is.EqualTo(threadMetadata?.Count ?? 0)); + foreach (KeyValuePair expectedKeyValuePair in threadMetadata) + { + Assert.That(mockThread.Metadata.ContainsKey(expectedKeyValuePair.Key), Is.True); + Assert.That(mockThread.Metadata[expectedKeyValuePair.Key], Is.EqualTo(expectedKeyValuePair.Value)); + } + } + + [TestCase] + public void CanCreateToolCalls() + { + string functionToolCallId = "function_tool_call_id"; + string functionCallName = "function_call_name"; + string functionCallArguments = "function_call_arguments"; + string functionCallOutput = "function_call_output"; + FunctionToolCall mockFunctionToolCall = AssistantsModelFactory.FunctionToolCall( + functionToolCallId, + functionCallName, + functionCallArguments, + functionCallOutput); + Assert.That(mockFunctionToolCall.Id, Is.EqualTo(functionToolCallId)); + Assert.That(mockFunctionToolCall.Name, Is.EqualTo(functionCallName)); + Assert.That(mockFunctionToolCall.Arguments, Is.EqualTo(functionCallArguments)); + Assert.That(mockFunctionToolCall.Output, Is.EqualTo(functionCallOutput)); + + string codeInterpreterToolCallId = "code_interpreter_tool_call_id"; + string codeInterpreterToolCallInput = "code_interprter_tool_call_input"; + string codeInterpreterLogOutput = "code_interpreter_log_output"; + string codeInterpreterImageOutputFileId = "code_interpreter_image_file_id"; + CodeInterpreterToolCallOutput[] codeInterpreterOutputs = new CodeInterpreterToolCallOutput[] + { + AssistantsModelFactory.CodeInterpreterLogOutput(codeInterpreterLogOutput), + AssistantsModelFactory.CodeInterpreterImageOutput( + AssistantsModelFactory.CodeInterpreterImageReference(codeInterpreterImageOutputFileId)), + }; + CodeInterpreterToolCall mockCodeInterpreterToolCall = AssistantsModelFactory.CodeInterpreterToolCall( + codeInterpreterToolCallId, + codeInterpreterToolCallInput, + codeInterpreterOutputs); + Assert.That(mockCodeInterpreterToolCall.Id, Is.EqualTo(codeInterpreterToolCallId)); + Assert.That(mockCodeInterpreterToolCall.Input, Is.EqualTo(codeInterpreterToolCallInput)); + Assert.That(mockCodeInterpreterToolCall.Outputs.Count, Is.EqualTo(codeInterpreterOutputs.Length)); + foreach (CodeInterpreterToolCallOutput callOutput in mockCodeInterpreterToolCall.Outputs) + { + if (callOutput is CodeInterpreterLogOutput logOutput) + { + Assert.That(logOutput.Logs, Is.EqualTo(codeInterpreterLogOutput)); + } + else if (callOutput is CodeInterpreterImageOutput imageOutput) + { + Assert.That(imageOutput.Image.FileId, Is.EqualTo(codeInterpreterImageOutputFileId)); + } + else + { + Assert.Fail($"Unexpected code interpreter call type: {callOutput}"); + } + } + + string retrievalToolCallId = "retrieval_tool_call_id"; + Dictionary retrievalToolCallRetrievals = new() + { + ["retrieval_key"] = "retrieval_value", + }; + RetrievalToolCall mockRetrievalToolCall = AssistantsModelFactory.RetrievalToolCall(retrievalToolCallId, retrievalToolCallRetrievals); + Assert.That(mockRetrievalToolCall.Id, Is.EqualTo(retrievalToolCallId)); + Assert.That(mockRetrievalToolCall.Retrieval.Count, Is.EqualTo(retrievalToolCallRetrievals.Count)); + foreach (KeyValuePair expectedRetrievalKeyValuePair in retrievalToolCallRetrievals) + { + Assert.That(mockRetrievalToolCall.Retrieval.ContainsKey(expectedRetrievalKeyValuePair.Key)); + Assert.That(mockRetrievalToolCall.Retrieval[expectedRetrievalKeyValuePair.Key], Is.EqualTo(expectedRetrievalKeyValuePair.Value)); + } + } + + [TestCase] + public void CanInstantiateTypes() + { + // Placeholder pending deeper tests + OpenAIFile mockFile = AssistantsModelFactory.OpenAIFile("id", size: 123, "filename", DateTime.Now, OpenAIFilePurpose.Assistants); + MessageFile mockMessageFile = AssistantsModelFactory.MessageFile("id", DateTime.Now, "messageId"); + RunError mockRunError = AssistantsModelFactory.RunError("errorCode", "errorMessage"); + RunStepDetails mockRunStepDetails = AssistantsModelFactory.RunStepMessageCreationDetails( + AssistantsModelFactory.RunStepMessageCreationReference("messageId")); + RunStepDetails mockRunStepToolCallDetails = AssistantsModelFactory.RunStepToolCallDetails(new ToolCall[] { AssistantsModelFactory.RetrievalToolCall("id", null) }); + RunStepError mockRunStepError = AssistantsModelFactory.RunStepError("errorCode", "errorMessage"); + RunStep mockRunStep = AssistantsModelFactory.RunStep( + "id", + RunStepType.MessageCreation, + "assistantId", + "threadId", + "runId", + RunStepStatus.Completed, + mockRunStepDetails, + mockRunStepError, + DateTime.Now, + DateTime.Now - TimeSpan.FromSeconds(10), + DateTime.Now + TimeSpan.FromSeconds(10), + cancelledAt: null, + failedAt: null, + metadata: null); + ThreadMessage mockMessage = AssistantsModelFactory.ThreadMessage( + "id", + DateTime.Now, + "threadId", + MessageRole.Assistant, + new MessageContent[] + { + AssistantsModelFactory.MessageTextContent( + "text", + new MessageTextAnnotation[] + { + AssistantsModelFactory.MessageFileCitationTextAnnotation("text", 0, 2, "fileId", "quote"), + AssistantsModelFactory.MessageFilePathTextAnnotation("text", 0, 2, "fileId"), + }), + AssistantsModelFactory.MessageImageFileContent("fileId"), + }, + "assistantId", + "runId", + fileIds: null, + metadata: null); + ThreadRun mockRun = AssistantsModelFactory.ThreadRun( + "id", + "threadId", + "assistantId", + RunStatus.Completed, + AssistantsModelFactory.SubmitToolOutputsAction( + new ToolCall[] + { + AssistantsModelFactory.FunctionToolCall("id", "name", "arguments", "output"), + }), + mockRunError, + "model", + "instructions", + tools: null, + fileIds: null, + DateTime.Now, + DateTime.Now + TimeSpan.FromSeconds(10), + startedAt: null, + completedAt: null, + cancelledAt: null, + failedAt: null, + metadata: null); + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/tests/AssistantsTestBase.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/tests/AssistantsTestBase.cs new file mode 100644 index 000000000000..ea57ee2f720f --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/tests/AssistantsTestBase.cs @@ -0,0 +1,141 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Azure.AI.OpenAI.Assistants; +using Azure.Core.TestFramework; +using Azure.Core.TestFramework.Models; +using NUnit.Framework; + +namespace Azure.AI.OpenAI.Assistants.Tests; + +public abstract partial class AssistantsTestBase : RecordedTestBase +{ + protected static readonly string s_testMetadataKey = "aoai_net_sdk_test_run_id"; + private static readonly string s_testMetadataValue = Guid.NewGuid().ToString(); + protected string TestMetadataValue + => Recording?.Mode == RecordedTestMode.Playback ? "RecordedMetadataValue" : s_testMetadataValue; + protected KeyValuePair TestMetadataPair => new(s_testMetadataKey, TestMetadataValue); + + public List<(AssistantsClient, string)> EnsuredFileDeletions = new(); + public List<(AssistantsClient, string)> EnsuredThreadDeletions = new(); + + protected AssistantsTestBase(bool isAsync, RecordedTestMode? mode = null) : base(isAsync, mode) + { + BodyRegexSanitizers.Add(new BodyRegexSanitizer(TestMetadataValue, "RecordedMetadataValue")); + BodyRegexSanitizers.Add(new BodyRegexSanitizer("sig=[^\"]*", "sig=Sanitized")); + BodyRegexSanitizers.Add(new BodyRegexSanitizer("(\"key\" *: *\")[^ \n\"]*(\")", "$1placeholder$2")); + HeaderRegexSanitizers.Add(new HeaderRegexSanitizer("api-key", "***********")); + UriRegexSanitizers.Add(new UriRegexSanitizer("sig=[^\"]*", "sig=Sanitized")); + SanitizedQueryParameters.Add("sig"); + } + + [OneTimeTearDown] + protected async Task ModuleCleanup() + { + if (Recording.Mode != RecordedTestMode.Playback) + { + foreach (OpenAIClientServiceTarget serviceTarget in new OpenAIClientServiceTarget[] + { + OpenAIClientServiceTarget.Azure, + OpenAIClientServiceTarget.NonAzure, + }) + { + try + { + // Best effort attempt to find items with the metadata key/value this run added and remove them + // -- or to remove older runs' entries with the key and a different value. + AssistantsClient client = GetTestClient(serviceTarget); + + Response> assistantListResponse = await client.GetAssistantsAsync(); + + IEnumerable assistantsToDelete = assistantListResponse.Value.Data + .Where(assistant => + { + bool hasMetadataKey = assistant.Metadata?.ContainsKey(s_testMetadataKey) == true; + bool hasCurrentMetadataValue = hasMetadataKey && assistant.Metadata[s_testMetadataKey] == s_testMetadataValue; + bool isOldEnoughToDeleteAnyway = assistant.CreatedAt < DateTime.Now - TimeSpan.FromHours(2); + return hasCurrentMetadataValue || isOldEnoughToDeleteAnyway; + }); + foreach (Assistant assistant in assistantsToDelete) + { + try + { + _ = await client.DeleteAssistantAsync(assistant.Id); + } + catch (Exception) + { } + } + } + catch (Exception) + { } + } + } + } + + [TearDown] + protected async Task TestCleanup() + { + if (Recording.Mode != RecordedTestMode.Playback) + { + foreach ((AssistantsClient client, string fileId) in EnsuredFileDeletions) + { + try + { + await client.DeleteFileAsync(fileId); + } + catch (Exception) + { } + } + foreach ((AssistantsClient client, string threadId) in EnsuredThreadDeletions) + { + try + { + await client.DeleteThreadAsync(threadId); + } + catch (Exception) + { } + } + } + } + + protected void AssertSuccessfulResponse(Response response, bool enforceMetadata = true) + { + Assert.That(response, Is.Not.Null); + + Response rawResponse = response.GetRawResponse(); + Assert.That(rawResponse, Is.Not.Null); + Assert.That(rawResponse.Status, Is.EqualTo(200)); + + string rawResponseContent = rawResponse.Content.ToString(); + Assert.That(rawResponseContent, Is.Not.Null.Or.Empty); + + Assert.That(response.Value, Is.InstanceOf()); + + if (response is Response boolResponse) + { + // Revise if we'd ever *want* a false bool + Assert.That(boolResponse.Value, Is.True); + } + + Func> GetMetadata = response switch + { + Response assistantResponse => () => assistantResponse.Value.Metadata, + Response threadResponse => () => threadResponse.Value.Metadata, + Response messageResponse => () => messageResponse.Value.Metadata as IReadOnlyDictionary, + Response runResponse => () => runResponse.Value.Metadata, + _ => null, + }; + + if (enforceMetadata && GetMetadata != null) + { + Assert.That( + GetMetadata.Invoke()?.Contains(TestMetadataPair), + Is.True, + $"Could not find expected test metadata pair in response value item!"); + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/tests/AssistantsTests.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/tests/AssistantsTests.cs new file mode 100644 index 000000000000..eb937da1a4f8 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/tests/AssistantsTests.cs @@ -0,0 +1,284 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Azure.Core.TestFramework; +using NUnit.Framework; + +namespace Azure.AI.OpenAI.Assistants.Tests; + +public class AssistantsTests : AssistantsTestBase +{ + public AssistantsTests(bool isAsync) + : base(isAsync)//, RecordedTestMode.Live) + { + } + + [RecordedTest] + [TestCase(OpenAIClientServiceTarget.NonAzure)] + public async Task CanCreateRetrieveListAndDeleteAssistants(OpenAIClientServiceTarget target) + { + AssistantsClient client = GetTestClient(target); + + // No assistant should exist with the metadata K/V pair we're going to use + Response> listResponse = await client.GetAssistantsAsync(); + AssertSuccessfulResponse(listResponse); + Assert.That(!listResponse.Value.Any(assistant => assistant.Metadata?.Contains(TestMetadataPair) == true)); + + // Now create that assistant + Response assistantCreationResponse + = await client.CreateAssistantAsync(new AssistantCreationOptions("gpt-4-1106-preview") + { + Name = "AOAI SDK Test Assistant - Delete Me", + Description = "Created by automated tests to exercise the API; should not be used", + Tools = { new CodeInterpreterToolDefinition() }, + Instructions = "You are a very generic assistant.", + Metadata = { TestMetadataPair }, + }); + AssertSuccessfulResponse(assistantCreationResponse); + + // Retrieve the assistant we just created to ensure it's the same + Response retrievalResponse + = await client.RetrieveAssistantAsync(assistantCreationResponse.Value.Id); + AssertSuccessfulResponse(retrievalResponse); + Assert.That(retrievalResponse.Value.Id, Is.EqualTo(assistantCreationResponse.Value.Id)); + + // List the assistants again to ensure it's reporting the one new matching assistant + listResponse = await client.GetAssistantsAsync(); + AssertSuccessfulResponse(listResponse); + Assert.That( + listResponse.Value.Data.Where(assistant => assistant.Metadata?.Contains(TestMetadataPair) == true).Count(), + Is.EqualTo(1)); + + // We shouldn't have the metadata K/V we'll add via modification yet + Assert.That(retrievalResponse.Value.Metadata.ContainsKey("modification_key"), Is.False); + + // Now modify the assistant by adding a k/v + Response modificationResponse = await client.ModifyAssistantAsync( + assistantCreationResponse.Value.Id, + new AssistantModificationOptions() + { + Metadata = + { + [s_testMetadataKey] = TestMetadataValue, + ["modification_key"] = "modification_value", + }, + }); + AssertSuccessfulResponse(modificationResponse); + Assert.That(modificationResponse.Value.Metadata.ContainsKey("modification_key"), Is.True); + + // Delete the assistant we created + Response deletionResponse = await client.DeleteAssistantAsync(assistantCreationResponse.Value.Id); + + // Ensure we again have no list matches + listResponse = await client.GetAssistantsAsync(); + AssertSuccessfulResponse(listResponse); + Assert.That(!listResponse.Value.Data.Any(assistant => assistant.Metadata?.Contains(TestMetadataPair) == true)); + } + + [RecordedTest] + // [TestCase(OpenAIClientServiceTarget.Azure)] + [TestCase(OpenAIClientServiceTarget.NonAzure)] + public async Task CanCreateRetrieveAndDeleteThreads(OpenAIClientServiceTarget serviceTarget) + { + AssistantsClient client = GetTestClient(serviceTarget); + + Response threadCreationResponse + = await client.CreateThreadAsync(new AssistantThreadCreationOptions() + { + Metadata = { TestMetadataPair }, + }); + AssertSuccessfulResponse(threadCreationResponse); + AssistantThread thread = threadCreationResponse.Value; + EnsuredThreadDeletions.Add((client, thread.Id)); + Assert.That(thread.Metadata.Contains(TestMetadataPair)); + + Response retrievalResponse = await client.RetrieveThreadAsync(thread.Id); + AssertSuccessfulResponse(retrievalResponse); + Assert.That(retrievalResponse.Value.Id, Is.EqualTo(thread.Id)); + + Response deletionResponse = await client.DeleteThreadAsync(thread.Id); + AssertSuccessfulResponse(deletionResponse); + EnsuredThreadDeletions.Remove((client, thread.Id)); + } + + [RecordedTest] + // [TestCase(OpenAIClientServiceTarget.Azure)] + [TestCase(OpenAIClientServiceTarget.NonAzure)] + public async Task CanCreateAndModifyMessages(OpenAIClientServiceTarget serviceTarget) + { + AssistantsClient client = GetTestClient(serviceTarget); + + Response threadCreationResponse + = await client.CreateThreadAsync(new AssistantThreadCreationOptions() + { + Metadata = { TestMetadataPair }, + }); + AssertSuccessfulResponse(threadCreationResponse); + EnsuredThreadDeletions.Add((client, threadCreationResponse.Value.Id)); + + Response messageCreationResponse = await client.CreateMessageAsync( + threadCreationResponse.Value.Id, + MessageRole.User, + "Hello, assistant! Can you help me?", + fileIds: null, + metadata: new Dictionary { [s_testMetadataKey] = TestMetadataValue }); + AssertSuccessfulResponse(messageCreationResponse); + + Response retrievalResponse + = await client.RetrieveMessageAsync( + threadCreationResponse.Value.Id, + messageCreationResponse.Value.Id); + AssertSuccessfulResponse(retrievalResponse); + + Assert.That(retrievalResponse.Value.Metadata.ContainsKey("test_modification_key"), Is.False); + + Response modificationResponse + = await client.ModifyMessageAsync( + threadCreationResponse.Value.Id, + messageCreationResponse.Value.Id, + new Dictionary + { + [s_testMetadataKey] = TestMetadataValue, + ["test_modification_key"] = "test_modification_value", + }); + AssertSuccessfulResponse(modificationResponse); + + retrievalResponse = await client.RetrieveMessageAsync( + threadCreationResponse.Value.Id, + messageCreationResponse.Value.Id); + AssertSuccessfulResponse(retrievalResponse); + Assert.That(retrievalResponse.Value.Metadata.ContainsKey("test_modification_key"), Is.True); + + // Delete what we created + Response deletionResponse + = await client.DeleteThreadAsync(threadCreationResponse.Value.Id); + AssertSuccessfulResponse(deletionResponse); + EnsuredThreadDeletions.Remove((client, threadCreationResponse.Value.Id)); + } + + [RecordedTest] + // [TestCase(OpenAIClientServiceTarget.Azure)] + [TestCase(OpenAIClientServiceTarget.NonAzure)] + public async Task CanRunAThread(OpenAIClientServiceTarget serviceTarget) + { + AssistantsClient client = GetTestClient(serviceTarget); + + // Create an assistant + Response assistantCreationResponse + = await client.CreateAssistantAsync(new AssistantCreationOptions("gpt-4-1106-preview") + { + Name = "AOAI SDK Test Assistant - Delete Me", + Description = "Created by automated tests to exercise the API; should not be used", + Tools = { new CodeInterpreterToolDefinition() }, + Instructions = "You are a very generic assistant.", + Metadata = { TestMetadataPair }, + }); + AssertSuccessfulResponse(assistantCreationResponse); + Assistant assistant = assistantCreationResponse.Value; + + // Create a thread + Response threadCreationResponse + = await client.CreateThreadAsync(new AssistantThreadCreationOptions() + { + Metadata = { TestMetadataPair }, + }); + AssertSuccessfulResponse(threadCreationResponse); + EnsuredThreadDeletions.Add((client, threadCreationResponse.Value.Id)); + AssistantThread thread = threadCreationResponse.Value; + + // Create a message on the thread + Response messageCreationResponse = await client.CreateMessageAsync( + threadCreationResponse.Value.Id, + MessageRole.User, + "Hello, assistant! Can you help me?", + fileIds: null, + metadata: new Dictionary { [s_testMetadataKey] = TestMetadataValue }); + AssertSuccessfulResponse(messageCreationResponse); + ThreadMessage userMessage = messageCreationResponse.Value; + + // Create a run of the thread + Response runCreationResponse = await client.CreateRunAsync( + thread.Id, + assistant.Id, + metadata: new Dictionary { [s_testMetadataKey] = TestMetadataValue }); + AssertSuccessfulResponse(runCreationResponse); + ThreadRun run = runCreationResponse.Value; + + // Repeatedly retrieve the run (polling) until it's done + do + { + await Task.Delay(500); + Response runRetrievalResponse = await client.RetrieveRunAsync(thread.Id, run.Id); + AssertSuccessfulResponse(runRetrievalResponse); + run = runRetrievalResponse.Value; + } + while (run.Status == RunStatus.Queued || run.Status == RunStatus.InProgress); + + Assert.That(run.Status, Is.EqualTo(RunStatus.Completed)); + Assert.That(run.AssistantId, Is.EqualTo(assistant.Id)); + Assert.That(run.ThreadId, Is.EqualTo(thread.Id)); + + // List the messages on the thread, now updated from the completed run + Response> messageListResponse = await client.GetMessagesAsync(thread.Id); + AssertSuccessfulResponse(messageListResponse); + IReadOnlyList messages = messageListResponse.Value.Data; + Assert.That(messages.Count, Is.EqualTo(2)); + + // Messages are in reverse order: the *second* index should be the assistant response + Assert.That(messages[1].Role, Is.EqualTo(MessageRole.User)); + Assert.That(messages[1].Id, Is.EqualTo(userMessage.Id)); + Assert.That(messages[1].CreatedAt, Is.GreaterThanOrEqualTo(thread.CreatedAt)); + Assert.That(messages[1].ContentItems, Is.Not.Null.Or.Empty); + Assert.That( + (messages[1].ContentItems[0] as MessageTextContent).Text, + Is.EqualTo((userMessage.ContentItems[0] as MessageTextContent).Text)); + + // Messages are in reverse order: the second index should be the assistant response + Assert.That(messages[0].Role, Is.EqualTo(MessageRole.Assistant)); + Assert.That(messages[0].AssistantId, Is.EqualTo(assistant.Id)); + Assert.That(messages[0].RunId, Is.EqualTo(run.Id)); + Assert.That(messages[0].ContentItems, Is.Not.Null.Or.Empty); + Assert.That( + (messages[0].ContentItems[0] as MessageTextContent).Text, + Is.Not.Null.Or.Empty); + Assert.That(messages[0].CreatedAt, Is.GreaterThan(messages[1].CreatedAt)); + + // Get the steps associated with the run + Response> runStepsResponse = await client.GetRunStepsAsync(run); + AssertSuccessfulResponse(runStepsResponse); + IReadOnlyList runSteps = runStepsResponse.Value.Data; + + Assert.That(runSteps.Count, Is.EqualTo(1)); + Assert.That(runSteps[0].RunId, Is.EqualTo(run.Id)); + Assert.That(runSteps[0].AssistantId, Is.EqualTo(assistant.Id)); + Assert.That(runSteps[0].ThreadId, Is.EqualTo(thread.Id)); + Assert.That(runSteps[0].Status, Is.EqualTo(RunStepStatus.Completed)); + Assert.That(runSteps[0].CancelledAt.HasValue, Is.False); + Assert.That(runSteps[0].CreatedAt, Is.GreaterThanOrEqualTo(thread.CreatedAt)); + Assert.That(runSteps[0].ExpiredAt.HasValue, Is.False); + Assert.That(runSteps[0].FailedAt.HasValue, Is.False); + Assert.That(runSteps[0].LastError, Is.Null); + + // The only step for the run should have created the assistant message + RunStepMessageCreationDetails stepDetails = runSteps[0].StepDetails as RunStepMessageCreationDetails; + Assert.That(stepDetails, Is.Not.Null); + Assert.That(stepDetails.MessageCreation.MessageId, Is.EqualTo(messages[0].Id)); + + // Check that we can retrieve the same run step + Response runStepRetrievalResponse = await client.RetrieveRunStepAsync(thread.Id, run.Id, runSteps[0].Id); + AssertSuccessfulResponse(runStepRetrievalResponse); + + // Delete the assistant we created + Response deletionResponse = await client.DeleteAssistantAsync(assistant.Id); + AssertSuccessfulResponse(deletionResponse); + + // Delete the thread we created + deletionResponse = await client.DeleteThreadAsync(thread.Id); + AssertSuccessfulResponse(deletionResponse); + EnsuredThreadDeletions.Remove((client, thread.Id)); + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/tests/Azure.AI.OpenAI.Assistants.Tests.csproj b/sdk/openai/Azure.AI.OpenAI.Assistants/tests/Azure.AI.OpenAI.Assistants.Tests.csproj new file mode 100644 index 000000000000..ced27dcaa8d7 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/tests/Azure.AI.OpenAI.Assistants.Tests.csproj @@ -0,0 +1,29 @@ + + + $(RequiredTargetFrameworks) + + + $(NoWarn);CS1591 + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/tests/FilesTests.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/tests/FilesTests.cs new file mode 100644 index 000000000000..b92eca1d4649 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/tests/FilesTests.cs @@ -0,0 +1,104 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using Azure.AI.OpenAI.Assistants; +using Azure.Core.TestFramework; +using NUnit.Framework; + +namespace Azure.AI.OpenAI.Assistants.Tests; + +public class FilesTests : AssistantsTestBase +{ + public FilesTests(bool isAsync) + : base(isAsync)//, RecordedTestMode.Live) + { + } + + [RecordedTest] + [TestCase(OpenAIClientServiceTarget.NonAzure)] + public async Task CanWorkWithFiles(OpenAIClientServiceTarget target) + { + AssistantsClient client = GetTestClient(target); + + // Uploading a file should work + OpenAIFile uploadedFile = null; + using (TestRecording.DisableRecordingScope disableBodyRecordingScope = Recording.DisableRequestBodyRecording()) + { + Response uploadFileResponse = await client.UploadFileAsync( + BinaryData.FromString("Hello, world! This is a test."), + OpenAIFilePurpose.Assistants); + AssertSuccessfulResponse(uploadFileResponse); + EnsuredFileDeletions.Add((client, uploadFileResponse.Value.Id)); + uploadedFile = uploadFileResponse.Value; + } + + // Listing files with no purpose filter should work, and our uploaded file should be there + Response> listAllFilesResponse = await client.GetFilesAsync(); + AssertSuccessfulResponse(listAllFilesResponse); + IReadOnlyList allFiles = listAllFilesResponse.Value; + Assert.That(allFiles.Any(file => file.Id == uploadedFile.Id)); + + // Listing files with the same purpose should work, and our uploaded file should still be there + Response> listMatchingPurposeFilesResponse + = await client.GetFilesAsync(OpenAIFilePurpose.Assistants); + AssertSuccessfulResponse(listMatchingPurposeFilesResponse); + IReadOnlyList matchingPurposeFiles = listMatchingPurposeFilesResponse.Value; + Assert.That(matchingPurposeFiles.All(file => file.Purpose == OpenAIFilePurpose.Assistants)); + Assert.That(matchingPurposeFiles.Any(file => file.Id == uploadedFile.Id)); + + // Listing files with a different purpose should work, and our uploaded file should not be there + Response> listNotMatchingPurposeFilesResponse + = await client.GetFilesAsync(OpenAIFilePurpose.FineTuneResults); + AssertSuccessfulResponse(listNotMatchingPurposeFilesResponse); + IReadOnlyList notMatchingPurposeFiles = listNotMatchingPurposeFilesResponse.Value; + Assert.That(notMatchingPurposeFiles.All(file => file.Purpose == OpenAIFilePurpose.FineTuneResults)); + Assert.That(!notMatchingPurposeFiles.Any(file => file.Id == uploadedFile.Id)); + + // Retrieving file information should work + Response retrieveFileResponse = await client.RetrieveFileAsync(uploadedFile.Id); + AssertSuccessfulResponse(retrieveFileResponse); + OpenAIFile retrievedFile = retrieveFileResponse.Value; + Assert.That(retrievedFile.Id, Is.EqualTo(uploadedFile.Id)); + Assert.That(retrievedFile.Purpose, Is.EqualTo(uploadedFile.Purpose)); + + // Note: can't retrieve Assistants file contents + + // Deleting a file should work + Response fileDeleteResponse = await client.DeleteFileAsync(uploadedFile.Id); + AssertSuccessfulResponse(fileDeleteResponse); + Assert.That(fileDeleteResponse.Value, Is.True); + EnsuredFileDeletions.Remove((client, uploadedFile.Id)); + } + + [RecordedTest] + [TestCase(OpenAIClientServiceTarget.NonAzure)] + public async Task ConvenienceMethodWorks(OpenAIClientServiceTarget target) + { + AssistantsClient client = GetTestClient(target); + + string temporaryFilePath = Path.GetTempFileName(); + FileInfo temporaryFileInfo = new(temporaryFilePath); + File.WriteAllText(temporaryFilePath, "Hello, world! This is a test. Please delete me."); + + OpenAIFile uploadedFile = null; + using (TestRecording.DisableRecordingScope disableBodyRecordingScope = Recording.DisableRequestBodyRecording()) + { + Response uploadFileResponse + = await client.UploadFileAsync(temporaryFilePath, OpenAIFilePurpose.Assistants); + AssertSuccessfulResponse(uploadFileResponse); + EnsuredFileDeletions.Add((client, uploadFileResponse.Value.Id)); + uploadedFile = uploadFileResponse.Value; + } + + if (Recording.Mode != RecordedTestMode.Playback) + { + Assert.That(uploadedFile.Filename, Is.EqualTo(temporaryFileInfo.Name)); + } + Assert.That(uploadedFile.Size, Is.EqualTo(temporaryFileInfo.Length)); + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/tests/FunctionsTests.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/tests/FunctionsTests.cs new file mode 100644 index 000000000000..7afd2790d2f5 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/tests/FunctionsTests.cs @@ -0,0 +1,142 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Text.Json; +using System.Threading.Tasks; +using Azure.Core.TestFramework; +using NUnit.Framework; + +namespace Azure.AI.OpenAI.Assistants.Tests; + +public class FunctionsTests : AssistantsTestBase +{ + public FunctionsTests(bool isAsync) + : base(isAsync)//, RecordedTestMode.Live) + { + } + + [RecordedTest] + [TestCase(OpenAIClientServiceTarget.NonAzure)] + public async Task CanCallParallelFunctions(OpenAIClientServiceTarget target) + { + AssistantsClient client = GetTestClient(target); + + FunctionToolDefinition favoriteVacationDestinationFunction = new( + name: "getFavoriteVacationDestination", + description: "Retrieves the user's unambiguously preferred location for vacations."); + FunctionToolDefinition preferredAirlineForSeasonFunction = new( + name: "getPreferredAirlineForSeason", + description: "Given a season like winter or spring, retrieves the user's preferred airline carrier.", + parameters: BinaryData.FromObjectAsJson( + new + { + Type = "object", + Properties = new + { + Season = new + { + Type = "string", + Enum = new[] { "spring", "summer", "fall", "winter" }, + } + } + }, + new JsonSerializerOptions() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase })); + FunctionToolDefinition getFlightPriceFunction = new( + name: "getAirlinePriceToDestinationForSeason", + description: "Given a desired location, airline, and approximate time of year, retrieves estimated prices.", + parameters: BinaryData.FromObjectAsJson( + new + { + Type = "object", + Properties = new + { + Destination = new + { + Type = "string", + Description = "A travel destination location.", + }, + Airline = new + { + Type = "string", + Description = "The name of an airline that flights can be booked on.", + }, + Time = new + { + Type = "string", + Description = "An approximate time of year at which travel is planned.", + }, + } + }, + new JsonSerializerOptions() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase })); + + Response assistantCreationResponse = await client.CreateAssistantAsync(new("gpt-4-1106-preview") + { + Tools = + { + getFlightPriceFunction, + preferredAirlineForSeasonFunction, + favoriteVacationDestinationFunction, + }, + Name = "SDK test - function tools", + Metadata = { TestMetadataPair }, + }); + AssertSuccessfulResponse(assistantCreationResponse); + Assistant assistant = assistantCreationResponse.Value; + + Response threadCreationResponse + = await client.CreateThreadAsync(new AssistantThreadCreationOptions() + { + Metadata = { TestMetadataPair }, + }); + AssertSuccessfulResponse(threadCreationResponse); + EnsuredThreadDeletions.Add((client, threadCreationResponse.Value.Id)); + AssistantThread thread = threadCreationResponse.Value; + + // Create a message on the thread + Response messageCreationResponse = await client.CreateMessageAsync( + threadCreationResponse.Value.Id, + MessageRole.User, + "Assuming both my usual preferred vacation spot and favorite airline carrier, how much would it cost to fly there in September?", + fileIds: null, + metadata: new Dictionary { [s_testMetadataKey] = TestMetadataValue }); + AssertSuccessfulResponse(messageCreationResponse); + ThreadMessage userMessage = messageCreationResponse.Value; + + // Create a run of the thread + Response runCreationResponse = await client.CreateRunAsync( + thread.Id, + assistant.Id, + metadata: new Dictionary { [s_testMetadataKey] = TestMetadataValue }); + AssertSuccessfulResponse(runCreationResponse); + ThreadRun run = runCreationResponse.Value; + + // Repeatedly retrieve the run (polling) until it's done + do + { + await Task.Delay(500); + Response runRetrievalResponse = await client.RetrieveRunAsync(thread.Id, run.Id); + AssertSuccessfulResponse(runRetrievalResponse); + run = runRetrievalResponse.Value; + } + while (run.Status == RunStatus.Queued || run.Status == RunStatus.InProgress); + + Assert.That(run.Status, Is.EqualTo(RunStatus.RequiresAction)); + SubmitToolOutputsAction outputsAction = run.RequiredAction as SubmitToolOutputsAction; + Assert.That(outputsAction, Is.Not.Null); + Assert.That(outputsAction.ToolCalls, Is.Not.Null.Or.Empty); + FunctionToolCall functionCall = outputsAction.ToolCalls[0] as FunctionToolCall; + Assert.That(functionCall, Is.Not.Null); + + Response> listRunStepResponse = await client.GetRunStepsAsync(run); + AssertSuccessfulResponse(listRunStepResponse); + IReadOnlyList runSteps = listRunStepResponse.Value.Data; + Assert.That(runSteps, Is.Not.Null.Or.Empty); + + RunStepToolCallDetails runStepToolCallDetails = runSteps[0].StepDetails as RunStepToolCallDetails; + Assert.That(runStepToolCallDetails, Is.Not.Null); + + await Task.Delay(0); + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/tests/OpenAITestEnvironment.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/tests/OpenAITestEnvironment.cs new file mode 100644 index 000000000000..f9d05b68e492 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/tests/OpenAITestEnvironment.cs @@ -0,0 +1,42 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using Azure.Core.TestFramework; + +namespace Azure.AI.OpenAI.Assistants.Tests; +public class OpenAITestEnvironment : TestEnvironment +{ + public string NonAzureOpenAIApiKey => GetOptionalVariable("OPENAI_API_KEY"); + + public string AzureCognitiveSearchApiKey => GetOptionalVariable("ACS_BYOD_API_KEY"); + + public string TestAudioInputPathEnglish => GetOptionalVariable("OAI_TEST_AUDIO_INPUT_ENGLISH_PATH"); + + public Uri GetUrlVariable(string variableName) => new(GetRecordedVariable(variableName)); + + public AzureKeyCredential GetKeyVariable(string variableName) => new(GetOptionalVariable(variableName) ?? "placeholder"); + + public void ThrowIfCannotDeploy() + { + string[] requiredVariableNames = new string[] + { + "TENANT_ID", + "AUTHORITY_HOST", + "SUBSCRIPTION_ID", + "CLIENT_ID", + "CLIENT_SECRET", + }; + + foreach (string requiredVariableName in requiredVariableNames) + { + string optionalVariableValue = GetOptionalVariable(requiredVariableName); + if (string.IsNullOrEmpty(optionalVariableValue)) + { + throw new InvalidOperationException($"Resource deployment is required and no environment value was found for required variable '{requiredVariableName}'.\n" + + $"'{Mode}' mode requires full environment specification of an Azure application (service principal) " + + "that manages test resources. This includes: Azure tenant ID; Azure authority host; managed subscription ID; and application ID + secret."); + } + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/tests/Samples/Samples_AssistantsClient.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/tests/Samples/Samples_AssistantsClient.cs new file mode 100644 index 000000000000..a0684a021f8a --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/tests/Samples/Samples_AssistantsClient.cs @@ -0,0 +1,115 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using NUnit.Framework; + +namespace Azure.AI.OpenAI.Assistants.Samples; + +public partial class Samples_AssistantsClient +{ + [Test] + [Ignore("Only for sample compilation verification")] + public async Task OverviewSample() + { + // Patterned from https://platform.openai.com/docs/assistants/overview + + bool isAzureOpenAI = false; + string azureResourceUrl = "https://my-resource.openai.azure.com"; + string nonAzureApiKey = Environment.GetEnvironmentVariable("OPENAI_API_KEY"); + string azureApiKey = Environment.GetEnvironmentVariable("AOAI_API_KEY"); + + #region Snippet:OverviewCreateClient + AssistantsClient client = isAzureOpenAI + ? new AssistantsClient(new Uri(azureResourceUrl), new AzureKeyCredential(azureApiKey)) + : new AssistantsClient(nonAzureApiKey); + #endregion + + // Step 1: Create an assistant + #region Snippet:OverviewCreateAssistant + Response assistantResponse = await client.CreateAssistantAsync( + new AssistantCreationOptions("gpt-4-1106-preview") + { + Name = "Math Tutor", + Instructions = "You are a personal math tutor. Write and run code to answer math questions.", + Tools = { new CodeInterpreterToolDefinition() } + }); + Assistant assistant = assistantResponse.Value; + #endregion + + // Intermission: assistant should now be listed + + Response> assistantListResponse = await client.GetAssistantsAsync(); + + // Step 2: Create a thread + #region Snippet:OverviewCreateThread + Response threadResponse = await client.CreateThreadAsync(); + AssistantThread thread = threadResponse.Value; + #endregion + + // Step 3: Add a message to a thread + #region Snippet:OverviewCreateMessage + Response messageResponse = await client.CreateMessageAsync( + thread.Id, + MessageRole.User, + "I need to solve the equation `3x + 11 = 14`. Can you help me?"); + ThreadMessage message = messageResponse.Value; + #endregion + + // Intermission: message is now correlated with thread + // Intermission: listing messages will retrieve the message just added + + Response> messagesListResponse = await client.GetMessagesAsync(thread.Id); + Assert.That(messagesListResponse.Value.Data[0].Id == message.Id); + + // Step 4: Run the assistant + + #region Snippet:OverviewCreateRun + Response runResponse = await client.CreateRunAsync( + thread.Id, + assistant.Id, + overrideInstructions: "Please address the user as Jane Doe. The user has a premium account."); + ThreadRun run = runResponse.Value; + #endregion + + #region Snippet:OverviewWaitForRun + do + { + await Task.Delay(TimeSpan.FromMilliseconds(500)); + runResponse = await client.RetrieveRunAsync(thread.Id, runResponse.Value.Id); + } + while (runResponse.Value.Status == RunStatus.Queued + || runResponse.Value.Status == RunStatus.InProgress); + #endregion + + #region Snippet:OverviewListUpdatedMessages + Response> afterRunMessagesResponse + = await client.GetMessagesAsync(thread.Id); + IReadOnlyList messages = afterRunMessagesResponse.Value.Data; + + // Note: messages iterate from newest to oldest, with the messages[0] being the most recent + foreach (ThreadMessage threadMessage in messages) + { + Console.Write($"{threadMessage.CreatedAt:yyyy-MM-dd HH:mm:ss} - {threadMessage.Role,10}: "); + foreach (MessageContent contentItem in threadMessage.ContentItems) + { + if (contentItem is MessageTextContent textItem) + { + Console.Write(textItem.Text); + } + else if (contentItem is MessageImageFileContent imageFileItem) + { + Console.Write($" "Seattle, WA"; + FunctionToolDefinition getUserFavoriteCityTool = new("getUserFavoriteCity", "Gets the user's favorite city."); + // Example of a function with a single required parameter + string GetCityNickname(string location) => location switch + { + "Seattle, WA" => "The Emerald City", + _ => throw new NotImplementedException(), + }; + FunctionToolDefinition getCityNicknameTool = new( + name: "getCityNickname", + description: "Gets the nickname of a city, e.g. 'LA' for 'Los Angeles, CA'.", + parameters: BinaryData.FromObjectAsJson( + new + { + Type = "object", + Properties = new + { + Location = new + { + Type = "string", + Description = "The city and state, e.g. San Francisco, CA", + }, + }, + Required = new[] { "location" }, + }, + new JsonSerializerOptions() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase })); + // Example of a function with one required and one optional, enum parameter + string GetWeatherAtLocation(string location, string temperatureUnit = "f") => location switch + { + "Seattle, WA" => temperatureUnit == "f" ? "70f" : "21c", + _ => throw new NotImplementedException() + }; + FunctionToolDefinition getCurrentWeatherAtLocationTool = new( + name: "getCurrentWeatherAtLocation", + description: "Gets the current weather at a provided location.", + parameters: BinaryData.FromObjectAsJson( + new + { + Type = "object", + Properties = new + { + Location = new + { + Type = "string", + Description = "The city and state, e.g. San Francisco, CA", + }, + Unit = new + { + Type = "string", + Enum = new[] { "c", "f" }, + }, + }, + Required = new[] { "location" }, + }, + new JsonSerializerOptions() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase })); + #endregion + + #region Snippet:FunctionsHandleFunctionCalls + ToolOutput GetResolvedToolOutput(ToolCall toolCall) + { + if (toolCall is FunctionToolCall functionToolCall) + { + if (functionToolCall.Name == getUserFavoriteCityTool.Name) + { + return new ToolOutput(toolCall, GetUserFavoriteCity()); + } + using JsonDocument argumentsJson = JsonDocument.Parse(functionToolCall.Arguments); + if (functionToolCall.Name == getCityNicknameTool.Name) + { + string locationArgument = argumentsJson.RootElement.GetProperty("location").GetString(); + return new ToolOutput(toolCall, GetCityNickname(locationArgument)); + } + if (functionToolCall.Name == getCurrentWeatherAtLocationTool.Name) + { + string locationArgument = argumentsJson.RootElement.GetProperty("location").GetString(); + if (argumentsJson.RootElement.TryGetProperty("unit", out JsonElement unitElement)) + { + string unitArgument = unitElement.GetString(); + return new ToolOutput(toolCall, GetWeatherAtLocation(locationArgument, unitArgument)); + } + return new ToolOutput(toolCall, GetWeatherAtLocation(locationArgument)); + } + } + return null; + } + #endregion + + #region Snippet:FunctionsCreateAssistantWithFunctionTools + Response assistantResponse = await client.CreateAssistantAsync( + // note: parallel function calling is only supported with newer models like gpt-4-1106-preview + new AssistantCreationOptions("gpt-4-1106-preview") + { + Name = "SDK Test Assistant - Functions", + Instructions = "You are a weather bot. Use the provided functions to help answer questions. " + + "Customize your responses to the user's preferences as much as possible and use friendly " + + "nicknames for cities whenever possible.", + Tools = + { + getUserFavoriteCityTool, + getCityNicknameTool, + getCurrentWeatherAtLocationTool, + }, + }); + Assistant assistant = assistantResponse.Value; + #endregion + + Response threadResponse = await client.CreateThreadAsync(); + AssistantThread thread = threadResponse.Value; + + Response messageResponse = await client.CreateMessageAsync( + thread.Id, + MessageRole.User, + "What's the weather like in my favorite city?"); + ThreadMessage message = messageResponse.Value; + + Response runResponse = await client.CreateRunAsync(thread.Id, assistant.Id); + + #region Snippet:FunctionsHandlePollingWithRequiredAction + do + { + await Task.Delay(TimeSpan.FromMilliseconds(500)); + runResponse = await client.RetrieveRunAsync(thread.Id, runResponse.Value.Id); + + if (runResponse.Value.Status == RunStatus.RequiresAction + && runResponse.Value.RequiredAction is SubmitToolOutputsAction submitToolOutputsAction) + { + List toolOutputs = new(); + foreach (var toolCall in submitToolOutputsAction.ToolCalls) + { + toolOutputs.Add(GetResolvedToolOutput(toolCall)); + } + runResponse = await client.SubmitRunToolOutputsAsync(runResponse.Value, toolOutputs); + } + } + while (runResponse.Value.Status == RunStatus.Queued + || runResponse.Value.Status == RunStatus.InProgress); + #endregion + + Response> afterRunMessagesResponse + = await client.GetMessagesAsync(thread.Id); + IReadOnlyList messages = afterRunMessagesResponse.Value.Data; + + // Note: messages iterate from newest to oldest, with the messages[0] being the most recent + foreach (ThreadMessage threadMessage in messages) + { + Console.Write($"{threadMessage.CreatedAt:yyyy-MM-dd HH:mm:ss} - {threadMessage.Role,10}: "); + foreach (MessageContent contentItem in threadMessage.ContentItems) + { + if (contentItem is MessageTextContent textItem) + { + Console.Write(textItem.Text); + } + else if (contentItem is MessageImageFileContent imageFileItem) + { + Console.Write($" + +#nullable disable + +using System; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using NUnit.Framework; + +namespace Azure.AI.OpenAI.Assistants.Samples; + +public partial class Samples_AssistantsClient +{ + [Test] + [Ignore("Only for sample compilation verification")] + public async Task AssistantsWithFilesSample() + { + // Patterned from https://platform.openai.com/docs/assistants/overview + + bool isAzureOpenAI = false; + string azureResourceUrl = "https://my-resource.openai.azure.com"; + string nonAzureApiKey = Environment.GetEnvironmentVariable("OPENAI_API_KEY"); + string azureApiKey = Environment.GetEnvironmentVariable("AOAI_API_KEY"); + + AssistantsClient client = isAzureOpenAI + ? new AssistantsClient(new Uri(azureResourceUrl), new AzureKeyCredential(azureApiKey)) + : new AssistantsClient(nonAzureApiKey); + + #region Snippet:UploadAssistantFilesToUse + File.WriteAllText( + path: "sample_file_for_upload.txt", + contents: "The word 'apple' uses the code 442345, while the word 'banana' uses the code 673457."); + Response uploadAssistantFileResponse = await client.UploadFileAsync( + localFilePath: "sample_file_for_upload.txt", + purpose: OpenAIFilePurpose.Assistants); + OpenAIFile uploadedAssistantFile = uploadAssistantFileResponse.Value; + #endregion + + #region Snippet:CreateAssistantWithFiles + Response assistantResponse = await client.CreateAssistantAsync( + new AssistantCreationOptions("gpt-4-1106-preview") + { + Name = "SDK Test Assistant - Retrieval", + Instructions = "You are a helpful assistant that can help fetch data from files you know about.", + Tools = { new RetrievalToolDefinition() }, + FileIds = { uploadedAssistantFile.Id }, + }); + Assistant assistant = assistantResponse.Value; + #endregion + + Response threadResponse = await client.CreateThreadAsync(); + AssistantThread thread = threadResponse.Value; + + Response messageResponse = await client.CreateMessageAsync( + thread.Id, + MessageRole.User, + "Can you give me the documented codes for 'banana' and 'orange'?"); + ThreadMessage message = messageResponse.Value; + + Response runResponse = await client.CreateRunAsync(thread.Id, assistant.Id); + + do + { + await Task.Delay(TimeSpan.FromMilliseconds(500)); + runResponse = await client.RetrieveRunAsync(thread.Id, runResponse.Value.Id); + } + while (runResponse.Value.Status == RunStatus.Queued + || runResponse.Value.Status == RunStatus.InProgress); + + Response> afterRunMessagesResponse + = await client.GetMessagesAsync(thread.Id); + IReadOnlyList messages = afterRunMessagesResponse.Value.Data; + + // Note: messages iterate from newest to oldest, with the messages[0] being the most recent + foreach (ThreadMessage threadMessage in messages) + { + Console.Write($"{threadMessage.CreatedAt:yyyy-MM-dd HH:mm:ss} - {threadMessage.Role,10}: "); + foreach (MessageContent contentItem in threadMessage.ContentItems) + { + if (contentItem is MessageTextContent textItem) + { + Console.Write(textItem.Text); + } + else if (contentItem is MessageImageFileContent imageFileItem) + { + Console.Write($" +{ + public enum OpenAIClientServiceTarget + { + Azure, + NonAzure, + } + + public enum OpenAIClientAuthenticationType + { + Unknown, + ApiKey, + Token, + ActiveDirectory, + } + + public AssistantsClient GetTestClient( + OpenAIClientServiceTarget target, + OpenAIClientAuthenticationType authenticationType) + { + return (target, authenticationType) switch + { + (OpenAIClientServiceTarget.NonAzure, OpenAIClientAuthenticationType.ApiKey) + => new AssistantsClient(GetNonAzureApiKey(), GetInstrumentedClientOptions()), + _ => throw new NotImplementedException() + }; + } + + public AssistantsClient GetTestClient(OpenAIClientServiceTarget target) + => GetTestClient(target, OpenAIClientAuthenticationType.ApiKey); + + protected AssistantsClient GetNonAzureClientWithKey() => InstrumentClient( + new AssistantsClient(GetNonAzureApiKey(), GetInstrumentedClientOptions())); + + protected string GetNonAzureApiKey() + { + return TestEnvironment.NonAzureOpenAIApiKey; + } + + private AssistantsClientOptions GetInstrumentedClientOptions( + AssistantsClientOptions.ServiceVersion? azureServiceVersionOverride = null) + { + AssistantsClientOptions uninstrumentedClientOptions = azureServiceVersionOverride.HasValue + ? new AssistantsClientOptions(azureServiceVersionOverride.Value) + : new AssistantsClientOptions(); + return InstrumentClientOptions(uninstrumentedClientOptions); + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/tsp-location.yaml b/sdk/openai/Azure.AI.OpenAI.Assistants/tsp-location.yaml new file mode 100644 index 000000000000..0381021233a2 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/tsp-location.yaml @@ -0,0 +1,3 @@ +directory: specification/ai/OpenAI.Assistants +commit: 7b3bafb8c3220e9873e341b1a70abd57ef69b656 +repo: Azure/azure-rest-api-specs From 8413fdcae72a8fe738ee125f209731542120c4c0 Mon Sep 17 00:00:00 2001 From: Travis Wilson <35748617+trrwilson@users.noreply.github.com> Date: Tue, 9 Jan 2024 16:41:30 -0800 Subject: [PATCH 02/15] minor updates for basic Azure exercise --- .../src/Custom/AssistantsClient.cs | 63 +++++++++++++++++-- .../tests/AssistantsTests.cs | 14 ++++- .../tests/OpenAITestEnvironment.cs | 31 +-------- .../tests/TestHelpers.cs | 24 +++++-- 4 files changed, 90 insertions(+), 42 deletions(-) diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/AssistantsClient.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/AssistantsClient.cs index 8d25e4846791..9211cdeb9c47 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/AssistantsClient.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/AssistantsClient.cs @@ -47,11 +47,16 @@ public AssistantsClient(Uri endpoint, AzureKeyCredential keyCredential, Assistan ClientDiagnostics = new ClientDiagnostics(options, true); _isConfiguredForAzure = true; _keyCredential = keyCredential; - _pipeline = HttpPipelineBuilder.Build(options, Array.Empty(), new HttpPipelinePolicy[] { new AzureKeyCredentialPolicy(_keyCredential, AuthorizationHeader) }, new ResponseClassifier()); + _pipeline = HttpPipelineBuilder.Build( + options, + Array.Empty(), + new HttpPipelinePolicy[] + { + new AzureKeyCredentialPolicy(_keyCredential, AuthorizationHeader) + }, + new ResponseClassifier()); _endpoint = endpoint; _apiVersion = options.Version; - - throw new NotSupportedException(s_aoaiNotYetSupportedMessage); } /// @@ -170,6 +175,8 @@ public AssistantsClient(string openAIApiKey) /// is an empty string, and was expected to be non-empty. public virtual Response DeleteAssistant(string assistantId, CancellationToken cancellationToken = default) { + using DiagnosticScope scope = ClientDiagnostics.CreateScope("AssistantsClient.DeleteAssistant"); + scope.Start(); Response baseResponse = InternalDeleteAssistant(assistantId, cancellationToken); bool simplifiedValue = baseResponse.GetRawResponse() != null @@ -188,6 +195,8 @@ public virtual async Task> DeleteAssistantAsync( string assistantId, CancellationToken cancellationToken = default) { + using DiagnosticScope scope = ClientDiagnostics.CreateScope("AssistantsClient.DeleteAssistant"); + scope.Start(); Response baseResponse = await InternalDeleteAssistantAsync(assistantId, cancellationToken).ConfigureAwait(false); bool simplifiedValue = @@ -207,6 +216,8 @@ public virtual Response DeleteThread( string threadId, CancellationToken cancellationToken = default) { + using DiagnosticScope scope = ClientDiagnostics.CreateScope("AssistantsClient.DeleteThread"); + scope.Start(); Response baseResponse = InternalDeleteThread(threadId, cancellationToken); bool simplifiedValue = @@ -226,6 +237,8 @@ public virtual async Task> DeleteThreadAsync( string threadId, CancellationToken cancellationToken = default) { + using DiagnosticScope scope = ClientDiagnostics.CreateScope("AssistantsClient.DeleteThread"); + scope.Start(); Response baseResponse = await InternalDeleteThreadAsync(threadId, cancellationToken).ConfigureAwait(false); bool simplifiedValue = @@ -247,6 +260,8 @@ public virtual Response UnlinkAssistantFile( string fileId, CancellationToken cancellationToken = default) { + using DiagnosticScope scope = ClientDiagnostics.CreateScope("AssistantsClient.UnlinkAssistantFile"); + scope.Start(); Response baseResponse = InternalUnlinkAssistantFile(assistantId, fileId, cancellationToken); bool simplifiedValue = @@ -275,6 +290,8 @@ public virtual async Task> UnlinkAssistantFileAsync( string fileId, CancellationToken cancellationToken = default) { + using DiagnosticScope scope = ClientDiagnostics.CreateScope("AssistantsClient.UnlinkAssistantFile"); + scope.Start(); Response baseResponse = await InternalUnlinkAssistantFileAsync(assistantId, fileId, cancellationToken).ConfigureAwait(false); bool simplifiedValue = @@ -290,6 +307,8 @@ Response baseResponse /// The cancellation token to use. public virtual Response> GetFiles(OpenAIFilePurpose? purpose = null, CancellationToken cancellationToken = default) { + using DiagnosticScope scope = ClientDiagnostics.CreateScope("AssistantsClient.GetFiles"); + scope.Start(); Response baseResponse = InternalListFiles(purpose, cancellationToken); return Response.FromValue(baseResponse.Value?.Data, baseResponse.GetRawResponse()); } @@ -301,6 +320,8 @@ public virtual async Task>> GetFilesAsync( OpenAIFilePurpose? purpose = null, CancellationToken cancellationToken = default) { + using DiagnosticScope scope = ClientDiagnostics.CreateScope("AssistantsClient.GetFiles"); + scope.Start(); Response baseResponse = await InternalListFilesAsync(purpose, cancellationToken).ConfigureAwait(false); return Response.FromValue(baseResponse.Value?.Data, baseResponse.GetRawResponse()); } @@ -312,6 +333,8 @@ public virtual async Task>> GetFilesAsync( /// is an empty string, and was expected to be non-empty. public virtual Response DeleteFile(string fileId, CancellationToken cancellationToken = default) { + using DiagnosticScope scope = ClientDiagnostics.CreateScope("AssistantsClient.DeleteFile"); + scope.Start(); Response baseResponse = InternalDeleteFile(fileId, cancellationToken); bool simplifiedValue = baseResponse.GetRawResponse() != null @@ -328,6 +351,8 @@ public virtual Response DeleteFile(string fileId, CancellationToken cancel /// is an empty string, and was expected to be non-empty. public virtual async Task> DeleteFileAsync(string fileId, CancellationToken cancellationToken = default) { + using DiagnosticScope scope = ClientDiagnostics.CreateScope("AssistantsClient.DeleteFile"); + scope.Start(); Response baseResponse = await InternalDeleteFileAsync(fileId, cancellationToken).ConfigureAwait(false); bool simplifiedValue = baseResponse.GetRawResponse() != null @@ -345,6 +370,8 @@ public virtual Response> GetAssistants( string before = null, CancellationToken cancellationToken = default) { + using DiagnosticScope scope = ClientDiagnostics.CreateScope("AssistantsClient.GetAssistants"); + scope.Start(); Response baseResponse = InternalGetAssistants(limit, order, after, before, cancellationToken); return Response.FromValue(PageableList.Create(baseResponse.Value), baseResponse.GetRawResponse()); } @@ -357,6 +384,8 @@ public virtual async Task>> GetAssistantsAsync( string before = null, CancellationToken cancellationToken = default) { + using DiagnosticScope scope = ClientDiagnostics.CreateScope("AssistantsClient.GetAssistants"); + scope.Start(); Response baseResponse = await InternalGetAssistantsAsync(limit, order, after, before, cancellationToken).ConfigureAwait(false); return Response.FromValue(PageableList.Create(baseResponse.Value), baseResponse.GetRawResponse()); @@ -371,6 +400,8 @@ public virtual Response> GetAssistantFiles( string before = null, CancellationToken cancellationToken = default) { + using DiagnosticScope scope = ClientDiagnostics.CreateScope("AssistantsClient.GetAssistantFiles"); + scope.Start(); Response baseResponse = InternalGetAssistantFiles(assistantId, limit, order, after, before, cancellationToken); return Response.FromValue(PageableList.Create(baseResponse.Value), baseResponse.GetRawResponse()); } @@ -384,6 +415,8 @@ public virtual async Task>> GetAssistantFil string before = null, CancellationToken cancellationToken = default) { + using DiagnosticScope scope = ClientDiagnostics.CreateScope("AssistantsClient.GetAssistantFiles"); + scope.Start(); Response baseResponse = await InternalGetAssistantFilesAsync(assistantId, limit, order, after, before, cancellationToken).ConfigureAwait(false); return Response.FromValue(PageableList.Create(baseResponse.Value), baseResponse.GetRawResponse()); @@ -399,6 +432,8 @@ public virtual Response> GetMessageFiles( string before = null, CancellationToken cancellationToken = default) { + using DiagnosticScope scope = ClientDiagnostics.CreateScope("AssistantsClient.GetMessageFiles"); + scope.Start(); Response baseResponse = InternalGetMessageFiles(threadId, messageId, limit, order, after, before, cancellationToken); return Response.FromValue(PageableList.Create(baseResponse.Value), baseResponse.GetRawResponse()); } @@ -413,6 +448,8 @@ public virtual async Task>> GetMessageFilesAs string before = null, CancellationToken cancellationToken = default) { + using DiagnosticScope scope = ClientDiagnostics.CreateScope("AssistantsClient.GetMessageFiles"); + scope.Start(); Response baseResponse = await InternalGetMessageFilesAsync(threadId, messageId, limit, order, after, before, cancellationToken).ConfigureAwait(false); return Response.FromValue(PageableList.Create(baseResponse.Value), baseResponse.GetRawResponse()); @@ -428,6 +465,8 @@ public virtual Response> GetRunSteps( string before = null, CancellationToken cancellationToken = default) { + using DiagnosticScope scope = ClientDiagnostics.CreateScope("AssistantsClient.GetRunSteps"); + scope.Start(); Response baseResponse = InternalGetRunSteps(threadId, runId, limit, order, after, before, cancellationToken); return Response.FromValue(PageableList.Create(baseResponse.Value), baseResponse.GetRawResponse()); } @@ -442,6 +481,8 @@ public virtual async Task>> GetRunStepsAsync( string before = null, CancellationToken cancellationToken = default) { + using DiagnosticScope scope = ClientDiagnostics.CreateScope("AssistantsClient.GetRunSteps"); + scope.Start(); Response baseResponse = await InternalGetRunStepsAsync(threadId, runId, limit, order, after, before, cancellationToken).ConfigureAwait(false); return Response.FromValue(PageableList.Create(baseResponse.Value), baseResponse.GetRawResponse()); @@ -456,6 +497,8 @@ public virtual Response> GetMessages( string before = null, CancellationToken cancellationToken = default) { + using DiagnosticScope scope = ClientDiagnostics.CreateScope("AssistantsClient.GetMessages"); + scope.Start(); Response baseResponse = InternalGetMessages(threadId, limit, order, after, before, cancellationToken); return Response.FromValue(PageableList.Create(baseResponse.Value), baseResponse.GetRawResponse()); } @@ -469,6 +512,8 @@ public virtual async Task>> GetMessagesAsyn string before = null, CancellationToken cancellationToken = default) { + using DiagnosticScope scope = ClientDiagnostics.CreateScope("AssistantsClient.GetMessages"); + scope.Start(); Response baseResponse = await InternalGetMessagesAsync(threadId, limit, order, after, before, cancellationToken).ConfigureAwait(false); return Response.FromValue(PageableList.Create(baseResponse.Value), baseResponse.GetRawResponse()); @@ -483,6 +528,8 @@ public virtual Response> GetRuns( string before = null, CancellationToken cancellationToken = default) { + using DiagnosticScope scope = ClientDiagnostics.CreateScope("AssistantsClient.GetRuns"); + scope.Start(); Response baseResponse = InternalGetRuns(threadId, limit, order, after, before, cancellationToken); return Response.FromValue(PageableList.Create(baseResponse.Value), baseResponse.GetRawResponse()); } @@ -496,6 +543,8 @@ public virtual async Task>> GetRunsAsync( string before = null, CancellationToken cancellationToken = default) { + using DiagnosticScope scope = ClientDiagnostics.CreateScope("AssistantsClient.GetRuns"); + scope.Start(); Response baseResponse = await InternalGetRunsAsync(threadId, limit, order, after, before, cancellationToken).ConfigureAwait(false); return Response.FromValue(PageableList.Create(baseResponse.Value), baseResponse.GetRawResponse()); @@ -522,14 +571,16 @@ internal HttpMessage CreateRequestMessage( request.Headers.Add(HttpHeader.Common.JsonContentType); var uri = new RawRequestUriBuilder(); uri.Reset(_endpoint); - uri.AppendPath(operationPath, escape: false); if (_isConfiguredForAzure) { - uri.AppendQuery("api-version", _apiVersion, true); - throw new NotImplementedException(); + uri.AppendPath("openai"); + uri.AppendPath(operationPath, escape: false); + // uri.AppendQuery("api-version", _apiVersion, true); + uri.AppendQuery("api-version", "2024-01-01-preview", true); } else { + uri.AppendPath(operationPath, escape: false); request.Headers.Add("OpenAI-Beta", "assistants=v1"); } foreach ((string key, string value) in queryParameters) diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/tests/AssistantsTests.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/tests/AssistantsTests.cs index eb937da1a4f8..3a6c0ae94c9e 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/tests/AssistantsTests.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/tests/AssistantsTests.cs @@ -19,9 +19,21 @@ public AssistantsTests(bool isAsync) [RecordedTest] [TestCase(OpenAIClientServiceTarget.NonAzure)] + [TestCase(OpenAIClientServiceTarget.Azure)] + public async Task CanListAssistants(OpenAIClientServiceTarget target) + { + AssistantsClient client = GetTestClient(target); + Response> listResponse = await client.GetAssistantsAsync(); + AssertSuccessfulResponse(listResponse); + } + + [RecordedTest] + [TestCase(OpenAIClientServiceTarget.NonAzure)] + [TestCase(OpenAIClientServiceTarget.Azure)] public async Task CanCreateRetrieveListAndDeleteAssistants(OpenAIClientServiceTarget target) { AssistantsClient client = GetTestClient(target); + string deploymentName = GetDeploymentOrModelName(target); // No assistant should exist with the metadata K/V pair we're going to use Response> listResponse = await client.GetAssistantsAsync(); @@ -30,7 +42,7 @@ public async Task CanCreateRetrieveListAndDeleteAssistants(OpenAIClientServiceTa // Now create that assistant Response assistantCreationResponse - = await client.CreateAssistantAsync(new AssistantCreationOptions("gpt-4-1106-preview") + = await client.CreateAssistantAsync(new AssistantCreationOptions(deploymentName) { Name = "AOAI SDK Test Assistant - Delete Me", Description = "Created by automated tests to exercise the API; should not be used", diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/tests/OpenAITestEnvironment.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/tests/OpenAITestEnvironment.cs index f9d05b68e492..0eeae9f770d0 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/tests/OpenAITestEnvironment.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/tests/OpenAITestEnvironment.cs @@ -9,34 +9,7 @@ public class OpenAITestEnvironment : TestEnvironment { public string NonAzureOpenAIApiKey => GetOptionalVariable("OPENAI_API_KEY"); - public string AzureCognitiveSearchApiKey => GetOptionalVariable("ACS_BYOD_API_KEY"); + public string AzureOpenAIResourceUri => GetOptionalVariable("AZURE_OPENAI_RESOURCE_URI"); - public string TestAudioInputPathEnglish => GetOptionalVariable("OAI_TEST_AUDIO_INPUT_ENGLISH_PATH"); - - public Uri GetUrlVariable(string variableName) => new(GetRecordedVariable(variableName)); - - public AzureKeyCredential GetKeyVariable(string variableName) => new(GetOptionalVariable(variableName) ?? "placeholder"); - - public void ThrowIfCannotDeploy() - { - string[] requiredVariableNames = new string[] - { - "TENANT_ID", - "AUTHORITY_HOST", - "SUBSCRIPTION_ID", - "CLIENT_ID", - "CLIENT_SECRET", - }; - - foreach (string requiredVariableName in requiredVariableNames) - { - string optionalVariableValue = GetOptionalVariable(requiredVariableName); - if (string.IsNullOrEmpty(optionalVariableValue)) - { - throw new InvalidOperationException($"Resource deployment is required and no environment value was found for required variable '{requiredVariableName}'.\n" - + $"'{Mode}' mode requires full environment specification of an Azure application (service principal) " - + "that manages test resources. This includes: Azure tenant ID; Azure authority host; managed subscription ID; and application ID + secret."); - } - } - } + public string AzureOpenAIApiKey => GetOptionalVariable("AZURE_OPENAI_API_KEY"); } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/tests/TestHelpers.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/tests/TestHelpers.cs index 58bf324452eb..6f38c889bf28 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/tests/TestHelpers.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/tests/TestHelpers.cs @@ -28,8 +28,8 @@ public AssistantsClient GetTestClient( { return (target, authenticationType) switch { - (OpenAIClientServiceTarget.NonAzure, OpenAIClientAuthenticationType.ApiKey) - => new AssistantsClient(GetNonAzureApiKey(), GetInstrumentedClientOptions()), + (OpenAIClientServiceTarget.NonAzure, OpenAIClientAuthenticationType.ApiKey) => GetNonAzureClientWithKey(), + (OpenAIClientServiceTarget.Azure, OpenAIClientAuthenticationType.ApiKey) => GetAzureClientWithKey(), _ => throw new NotImplementedException() }; } @@ -40,10 +40,14 @@ public AssistantsClient GetTestClient(OpenAIClientServiceTarget target) protected AssistantsClient GetNonAzureClientWithKey() => InstrumentClient( new AssistantsClient(GetNonAzureApiKey(), GetInstrumentedClientOptions())); - protected string GetNonAzureApiKey() - { - return TestEnvironment.NonAzureOpenAIApiKey; - } + protected AssistantsClient GetAzureClientWithKey() => InstrumentClient( + new AssistantsClient(GetAzureResourceUri(), new AzureKeyCredential(GetAzureApiKey()), GetInstrumentedClientOptions())); + + protected string GetNonAzureApiKey() => TestEnvironment.NonAzureOpenAIApiKey; + + protected Uri GetAzureResourceUri() => new(TestEnvironment.AzureOpenAIResourceUri); + + protected string GetAzureApiKey() => TestEnvironment.AzureOpenAIApiKey; private AssistantsClientOptions GetInstrumentedClientOptions( AssistantsClientOptions.ServiceVersion? azureServiceVersionOverride = null) @@ -53,4 +57,12 @@ private AssistantsClientOptions GetInstrumentedClientOptions( : new AssistantsClientOptions(); return InstrumentClientOptions(uninstrumentedClientOptions); } + + protected string GetDeploymentOrModelName(OpenAIClientServiceTarget target) + => target switch + { + OpenAIClientServiceTarget.Azure => "gpt-4-1106", + OpenAIClientServiceTarget.NonAzure => "gpt-4-1106-preview", + _ => throw new NotImplementedException(), + }; } From d097fa9cedbde2340ca6c6bb848b000322c2df2a Mon Sep 17 00:00:00 2001 From: Travis Wilson <35748617+trrwilson@users.noreply.github.com> Date: Wed, 10 Jan 2024 16:33:29 -0800 Subject: [PATCH 03/15] another small commit for testing against Azure --- .../src/Custom/AssistantsClient.cs | 4 ++++ .../tests/AssistantsTests.cs | 9 +++++---- .../tests/FilesTests.cs | 18 +++++++++++------- .../tests/FunctionsTests.cs | 1 + 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/AssistantsClient.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/AssistantsClient.cs index 9211cdeb9c47..5ce0242d7f01 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/AssistantsClient.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/AssistantsClient.cs @@ -574,6 +574,10 @@ internal HttpMessage CreateRequestMessage( if (_isConfiguredForAzure) { uri.AppendPath("openai"); + if (operationPath.ToLowerInvariant().StartsWith("/files")) + { + uri.AppendPath("/beta", escape: false); + } uri.AppendPath(operationPath, escape: false); // uri.AppendQuery("api-version", _apiVersion, true); uri.AppendQuery("api-version", "2024-01-01-preview", true); diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/tests/AssistantsTests.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/tests/AssistantsTests.cs index 3a6c0ae94c9e..797aeeaad2ca 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/tests/AssistantsTests.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/tests/AssistantsTests.cs @@ -13,7 +13,7 @@ namespace Azure.AI.OpenAI.Assistants.Tests; public class AssistantsTests : AssistantsTestBase { public AssistantsTests(bool isAsync) - : base(isAsync)//, RecordedTestMode.Live) + : base(isAsync) // , RecordedTestMode.Live) { } @@ -73,6 +73,7 @@ Response retrievalResponse assistantCreationResponse.Value.Id, new AssistantModificationOptions() { + Model = deploymentName, Metadata = { [s_testMetadataKey] = TestMetadataValue, @@ -92,7 +93,7 @@ Response retrievalResponse } [RecordedTest] - // [TestCase(OpenAIClientServiceTarget.Azure)] + [TestCase(OpenAIClientServiceTarget.Azure)] [TestCase(OpenAIClientServiceTarget.NonAzure)] public async Task CanCreateRetrieveAndDeleteThreads(OpenAIClientServiceTarget serviceTarget) { @@ -118,7 +119,7 @@ Response threadCreationResponse } [RecordedTest] - // [TestCase(OpenAIClientServiceTarget.Azure)] + [TestCase(OpenAIClientServiceTarget.Azure)] [TestCase(OpenAIClientServiceTarget.NonAzure)] public async Task CanCreateAndModifyMessages(OpenAIClientServiceTarget serviceTarget) { @@ -173,7 +174,7 @@ Response deletionResponse } [RecordedTest] - // [TestCase(OpenAIClientServiceTarget.Azure)] + [TestCase(OpenAIClientServiceTarget.Azure)] [TestCase(OpenAIClientServiceTarget.NonAzure)] public async Task CanRunAThread(OpenAIClientServiceTarget serviceTarget) { diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/tests/FilesTests.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/tests/FilesTests.cs index b92eca1d4649..6c49d64c061f 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/tests/FilesTests.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/tests/FilesTests.cs @@ -6,7 +6,6 @@ using System.IO; using System.Linq; using System.Threading.Tasks; -using Azure.AI.OpenAI.Assistants; using Azure.Core.TestFramework; using NUnit.Framework; @@ -21,6 +20,7 @@ public FilesTests(bool isAsync) [RecordedTest] [TestCase(OpenAIClientServiceTarget.NonAzure)] + [TestCase(OpenAIClientServiceTarget.Azure)] public async Task CanWorkWithFiles(OpenAIClientServiceTarget target) { AssistantsClient client = GetTestClient(target); @@ -52,12 +52,15 @@ Response> listMatchingPurposeFilesResponse Assert.That(matchingPurposeFiles.Any(file => file.Id == uploadedFile.Id)); // Listing files with a different purpose should work, and our uploaded file should not be there - Response> listNotMatchingPurposeFilesResponse - = await client.GetFilesAsync(OpenAIFilePurpose.FineTuneResults); - AssertSuccessfulResponse(listNotMatchingPurposeFilesResponse); - IReadOnlyList notMatchingPurposeFiles = listNotMatchingPurposeFilesResponse.Value; - Assert.That(notMatchingPurposeFiles.All(file => file.Purpose == OpenAIFilePurpose.FineTuneResults)); - Assert.That(!notMatchingPurposeFiles.Any(file => file.Id == uploadedFile.Id)); + if (target != OpenAIClientServiceTarget.Azure) + { + Response> listNotMatchingPurposeFilesResponse + = await client.GetFilesAsync(OpenAIFilePurpose.FineTuneResults); + AssertSuccessfulResponse(listNotMatchingPurposeFilesResponse); + IReadOnlyList notMatchingPurposeFiles = listNotMatchingPurposeFilesResponse.Value; + Assert.That(notMatchingPurposeFiles.All(file => file.Purpose == OpenAIFilePurpose.FineTuneResults)); + Assert.That(!notMatchingPurposeFiles.Any(file => file.Id == uploadedFile.Id)); + } // Retrieving file information should work Response retrieveFileResponse = await client.RetrieveFileAsync(uploadedFile.Id); @@ -77,6 +80,7 @@ Response> listNotMatchingPurposeFilesResponse [RecordedTest] [TestCase(OpenAIClientServiceTarget.NonAzure)] + [TestCase(OpenAIClientServiceTarget.Azure)] public async Task ConvenienceMethodWorks(OpenAIClientServiceTarget target) { AssistantsClient client = GetTestClient(target); diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/tests/FunctionsTests.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/tests/FunctionsTests.cs index 7afd2790d2f5..f7a0b29588f4 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/tests/FunctionsTests.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/tests/FunctionsTests.cs @@ -19,6 +19,7 @@ public FunctionsTests(bool isAsync) [RecordedTest] [TestCase(OpenAIClientServiceTarget.NonAzure)] + [TestCase(OpenAIClientServiceTarget.Azure)] public async Task CanCallParallelFunctions(OpenAIClientServiceTarget target) { AssistantsClient client = GetTestClient(target); From c07893e83d48c8340d0fee72b42ed4e494bfe2f5 Mon Sep 17 00:00:00 2001 From: Travis Wilson Date: Fri, 12 Jan 2024 11:49:00 -0800 Subject: [PATCH 04/15] tsp snap to latest typespec --- .../Azure.AI.OpenAI.Assistants/README.md | 8 +- ...ure.AI.OpenAI.Assistants.netstandard2.0.cs | 54 ++- .../src/Convenience/AssistantsClient.cs | 8 +- .../src/Custom/AssistantsClient.cs | 35 +- ....cs => CreateFileRequest.Serialization.cs} | 2 +- .../src/Generated/Assistant.Serialization.cs | 5 +- .../src/Generated/Assistant.cs | 5 +- .../AssistantCreationOptions.Serialization.cs | 52 ++- .../src/Generated/AssistantCreationOptions.cs | 2 +- ...istantModificationOptions.Serialization.cs | 52 ++- .../Generated/AssistantModificationOptions.cs | 2 +- .../AssistantThread.Serialization.cs | 5 +- .../src/Generated/AssistantThread.cs | 5 +- ...tantThreadCreationOptions.Serialization.cs | 19 +- .../AssistantThreadCreationOptions.cs | 2 +- .../src/Generated/AssistantsClient.cs | 435 +++++++----------- .../src/Generated/AssistantsClientOptions.cs | 8 +- ...CreateAndRunThreadOptions.Serialization.cs | 19 +- .../Generated/CreateAndRunThreadOptions.cs | 2 +- ....cs => CreateFileRequest.Serialization.cs} | 2 +- ...oadFileRequest.cs => CreateFileRequest.cs} | 12 +- .../CreateMessageRequest.Serialization.cs | 19 +- .../src/Generated/CreateMessageRequest.cs | 2 +- .../CreateRunRequest.Serialization.cs | 19 +- .../src/Generated/CreateRunRequest.cs | 6 +- ...alAssistantDeletionStatus.Serialization.cs | 14 +- .../InternalAssistantDeletionStatus.cs | 22 +- ...sistantFileDeletionStatus.Serialization.cs | 14 +- .../InternalAssistantFileDeletionStatus.cs | 22 +- .../src/Generated/InternalDeletionStatus.cs | 23 - ...nternalFileDeletionStatus.Serialization.cs | 14 +- .../Generated/InternalFileDeletionStatus.cs | 21 +- ...nternalFunctionDefinition.Serialization.cs | 11 +- .../Generated/InternalFunctionDefinition.cs | 16 +- ...alFunctionToolCallDetails.Serialization.cs | 5 +- .../InternalFunctionToolCallDetails.cs | 13 +- .../ModifyMessageRequest.Serialization.cs | 19 +- .../src/Generated/ModifyMessageRequest.cs | 2 +- .../ModifyRunRequest.Serialization.cs | 19 +- .../src/Generated/ModifyRunRequest.cs | 2 +- .../ModifyThreadRequest.Serialization.cs | 19 +- .../src/Generated/ModifyThreadRequest.cs | 2 +- .../src/Generated/RunStep.Serialization.cs | 5 +- .../src/Generated/RunStep.cs | 5 +- ...tToolOutputsToRunRequest.Serialization.cs} | 2 +- ...st.cs => SubmitToolOutputsToRunRequest.cs} | 12 +- .../ThreadDeletionStatus.Serialization.cs | 14 +- .../src/Generated/ThreadDeletionStatus.cs | 22 +- .../Generated/ThreadMessage.Serialization.cs | 11 +- .../src/Generated/ThreadMessage.cs | 7 +- .../src/Generated/ThreadRun.Serialization.cs | 5 +- .../src/Generated/ThreadRun.cs | 5 +- .../tests/AssistantsTests.cs | 12 +- .../tests/FunctionsTests.cs | 2 +- .../tests/Samples/Samples_AssistantsClient.cs | 2 +- .../tests/Samples/Samples_Functions.cs | 6 +- .../tests/Samples/Samples_Retrieval.cs | 2 +- .../tsp-location.yaml | 2 +- 58 files changed, 594 insertions(+), 538 deletions(-) rename sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/{UploadFileRequest.Serialization.cs => CreateFileRequest.Serialization.cs} (93%) rename sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/{UploadFileRequest.Serialization.cs => CreateFileRequest.Serialization.cs} (92%) rename sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/{UploadFileRequest.cs => CreateFileRequest.cs} (81%) delete mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalDeletionStatus.cs rename sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/{SubmitRunToolOutputsRequest.Serialization.cs => SubmitToolOutputsToRunRequest.Serialization.cs} (92%) rename sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/{SubmitRunToolOutputsRequest.cs => SubmitToolOutputsToRunRequest.cs} (75%) diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/README.md b/sdk/openai/Azure.AI.OpenAI.Assistants/README.md index c9e257e88013..92dcdfb70165 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/README.md +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/README.md @@ -86,7 +86,7 @@ Once the run has started, it should then be polled until it reaches a terminal s do { await Task.Delay(TimeSpan.FromMilliseconds(500)); - runResponse = await client.RetrieveRunAsync(thread.Id, runResponse.Value.Id); + runResponse = await client.GetRunAsync(thread.Id, runResponse.Value.Id); } while (runResponse.Value.Status == RunStatus.Queued || runResponse.Value.Status == RunStatus.InProgress); @@ -292,17 +292,17 @@ run via the `SubmitRunToolOutputs` method so that the run can continue: do { await Task.Delay(TimeSpan.FromMilliseconds(500)); - runResponse = await client.RetrieveRunAsync(thread.Id, runResponse.Value.Id); + runResponse = await client.GetRunAsync(thread.Id, runResponse.Value.Id); if (runResponse.Value.Status == RunStatus.RequiresAction && runResponse.Value.RequiredAction is SubmitToolOutputsAction submitToolOutputsAction) { List toolOutputs = new(); - foreach (var toolCall in submitToolOutputsAction.ToolCalls) + foreach (ToolCall toolCall in submitToolOutputsAction.ToolCalls) { toolOutputs.Add(GetResolvedToolOutput(toolCall)); } - runResponse = await client.SubmitRunToolOutputsAsync(runResponse.Value, toolOutputs); + runResponse = await client.SubmitToolOutputsToRunAsync(runResponse.Value, toolOutputs); } } while (runResponse.Value.Status == RunStatus.Queued diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/api/Azure.AI.OpenAI.Assistants.netstandard2.0.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/api/Azure.AI.OpenAI.Assistants.netstandard2.0.cs index 8139224bea72..b993898b8cdf 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/api/Azure.AI.OpenAI.Assistants.netstandard2.0.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/api/Azure.AI.OpenAI.Assistants.netstandard2.0.cs @@ -19,7 +19,7 @@ public AssistantCreationOptions(string model) { } public string Description { get { throw null; } set { } } public System.Collections.Generic.IList FileIds { get { throw null; } } public string Instructions { get { throw null; } set { } } - public System.Collections.Generic.IDictionary Metadata { get { throw null; } } + public System.Collections.Generic.IDictionary Metadata { get { throw null; } set { } } public string Model { get { throw null; } } public string Name { get { throw null; } set { } } public System.Collections.Generic.IList Tools { get { throw null; } } @@ -37,7 +37,7 @@ public AssistantModificationOptions() { } public string Description { get { throw null; } set { } } public System.Collections.Generic.IList FileIds { get { throw null; } } public string Instructions { get { throw null; } set { } } - public System.Collections.Generic.IDictionary Metadata { get { throw null; } } + public System.Collections.Generic.IDictionary Metadata { get { throw null; } set { } } public string Model { get { throw null; } set { } } public string Name { get { throw null; } set { } } public System.Collections.Generic.IList Tools { get { throw null; } } @@ -72,22 +72,36 @@ public AssistantsClient(System.Uri endpoint, Azure.Core.TokenCredential tokenCre public virtual System.Threading.Tasks.Task> DeleteFileAsync(string fileId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Response DeleteThread(string threadId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task> DeleteThreadAsync(string threadId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response GetAssistant(string assistantId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> GetAssistantAsync(string assistantId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response GetAssistantFile(string assistantId, string fileId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> GetAssistantFileAsync(string assistantId, string fileId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Response> GetAssistantFiles(string assistantId, int? limit = default(int?), Azure.AI.OpenAI.Assistants.ListSortOrder? order = default(Azure.AI.OpenAI.Assistants.ListSortOrder?), string after = null, string before = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task>> GetAssistantFilesAsync(string assistantId, int? limit = default(int?), Azure.AI.OpenAI.Assistants.ListSortOrder? order = default(Azure.AI.OpenAI.Assistants.ListSortOrder?), string after = null, string before = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Response> GetAssistants(int? limit = default(int?), Azure.AI.OpenAI.Assistants.ListSortOrder? order = default(Azure.AI.OpenAI.Assistants.ListSortOrder?), string after = null, string before = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task>> GetAssistantsAsync(int? limit = default(int?), Azure.AI.OpenAI.Assistants.ListSortOrder? order = default(Azure.AI.OpenAI.Assistants.ListSortOrder?), string after = null, string before = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Response> GetFiles(Azure.AI.OpenAI.Assistants.OpenAIFilePurpose? purpose = default(Azure.AI.OpenAI.Assistants.OpenAIFilePurpose?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task>> GetFilesAsync(Azure.AI.OpenAI.Assistants.OpenAIFilePurpose? purpose = default(Azure.AI.OpenAI.Assistants.OpenAIFilePurpose?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response GetMessage(string threadId, string messageId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> GetMessageAsync(string threadId, string messageId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response GetMessageFile(string threadId, string messageId, string fileId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> GetMessageFileAsync(string threadId, string messageId, string fileId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Response> GetMessageFiles(string threadId, string messageId, int? limit = default(int?), Azure.AI.OpenAI.Assistants.ListSortOrder? order = default(Azure.AI.OpenAI.Assistants.ListSortOrder?), string after = null, string before = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task>> GetMessageFilesAsync(string threadId, string messageId, int? limit = default(int?), Azure.AI.OpenAI.Assistants.ListSortOrder? order = default(Azure.AI.OpenAI.Assistants.ListSortOrder?), string after = null, string before = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Response> GetMessages(string threadId, int? limit = default(int?), Azure.AI.OpenAI.Assistants.ListSortOrder? order = default(Azure.AI.OpenAI.Assistants.ListSortOrder?), string after = null, string before = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task>> GetMessagesAsync(string threadId, int? limit = default(int?), Azure.AI.OpenAI.Assistants.ListSortOrder? order = default(Azure.AI.OpenAI.Assistants.ListSortOrder?), string after = null, string before = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response GetRun(string threadId, string runId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> GetRunAsync(string threadId, string runId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Response> GetRuns(string threadId, int? limit = default(int?), Azure.AI.OpenAI.Assistants.ListSortOrder? order = default(Azure.AI.OpenAI.Assistants.ListSortOrder?), string after = null, string before = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task>> GetRunsAsync(string threadId, int? limit = default(int?), Azure.AI.OpenAI.Assistants.ListSortOrder? order = default(Azure.AI.OpenAI.Assistants.ListSortOrder?), string after = null, string before = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response GetRunStep(string threadId, string runId, string stepId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> GetRunStepAsync(string threadId, string runId, string stepId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Response> GetRunSteps(Azure.AI.OpenAI.Assistants.ThreadRun run, int? limit = default(int?), Azure.AI.OpenAI.Assistants.ListSortOrder? order = default(Azure.AI.OpenAI.Assistants.ListSortOrder?), string after = null, string before = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Response> GetRunSteps(string threadId, string runId, int? limit = default(int?), Azure.AI.OpenAI.Assistants.ListSortOrder? order = default(Azure.AI.OpenAI.Assistants.ListSortOrder?), string after = null, string before = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task>> GetRunStepsAsync(Azure.AI.OpenAI.Assistants.ThreadRun run, int? limit = default(int?), Azure.AI.OpenAI.Assistants.ListSortOrder? order = default(Azure.AI.OpenAI.Assistants.ListSortOrder?), string after = null, string before = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task>> GetRunStepsAsync(string threadId, string runId, int? limit = default(int?), Azure.AI.OpenAI.Assistants.ListSortOrder? order = default(Azure.AI.OpenAI.Assistants.ListSortOrder?), string after = null, string before = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response GetThread(string threadId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> GetThreadAsync(string threadId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Response LinkAssistantFile(string assistantId, string fileId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task> LinkAssistantFileAsync(string assistantId, string fileId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Response ModifyAssistant(string assistantId, Azure.AI.OpenAI.Assistants.AssistantModificationOptions modificationOptions, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } @@ -98,28 +112,12 @@ public AssistantsClient(System.Uri endpoint, Azure.Core.TokenCredential tokenCre public virtual System.Threading.Tasks.Task> ModifyRunAsync(string threadId, string runId, System.Collections.Generic.IDictionary metadata = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Response ModifyThread(string threadId, System.Collections.Generic.IDictionary metadata = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task> ModifyThreadAsync(string threadId, System.Collections.Generic.IDictionary metadata = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual Azure.Response RetrieveAssistant(string assistantId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task> RetrieveAssistantAsync(string assistantId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual Azure.Response RetrieveAssistantFile(string assistantId, string fileId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task> RetrieveAssistantFileAsync(string assistantId, string fileId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Response RetrieveFile(string fileId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task> RetrieveFileAsync(string fileId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual Azure.Response RetrieveFileContent(string fileId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task> RetrieveFileContentAsync(string fileId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual Azure.Response RetrieveMessage(string threadId, string messageId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task> RetrieveMessageAsync(string threadId, string messageId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual Azure.Response RetrieveMessageFile(string threadId, string messageId, string fileId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task> RetrieveMessageFileAsync(string threadId, string messageId, string fileId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual Azure.Response RetrieveRun(string threadId, string runId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task> RetrieveRunAsync(string threadId, string runId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual Azure.Response RetrieveRunStep(string threadId, string runId, string stepId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task> RetrieveRunStepAsync(string threadId, string runId, string stepId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual Azure.Response RetrieveThread(string threadId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task> RetrieveThreadAsync(string threadId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual Azure.Response SubmitRunToolOutputs(Azure.AI.OpenAI.Assistants.ThreadRun run, System.Collections.Generic.IEnumerable toolOutputs, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual Azure.Response SubmitRunToolOutputs(string threadId, string runId, System.Collections.Generic.IEnumerable toolOutputs, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task> SubmitRunToolOutputsAsync(Azure.AI.OpenAI.Assistants.ThreadRun run, System.Collections.Generic.IEnumerable toolOutputs, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task> SubmitRunToolOutputsAsync(string threadId, string runId, System.Collections.Generic.IEnumerable toolOutputs, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response SubmitToolOutputsToRun(Azure.AI.OpenAI.Assistants.ThreadRun run, System.Collections.Generic.IEnumerable toolOutputs, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response SubmitToolOutputsToRun(string threadId, string runId, System.Collections.Generic.IEnumerable toolOutputs, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> SubmitToolOutputsToRunAsync(Azure.AI.OpenAI.Assistants.ThreadRun run, System.Collections.Generic.IEnumerable toolOutputs, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> SubmitToolOutputsToRunAsync(string threadId, string runId, System.Collections.Generic.IEnumerable toolOutputs, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Response UnlinkAssistantFile(string assistantId, string fileId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task> UnlinkAssistantFileAsync(string assistantId, string fileId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Response UploadFile(System.BinaryData data, Azure.AI.OpenAI.Assistants.OpenAIFilePurpose purpose, string filename = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } @@ -129,10 +127,10 @@ public AssistantsClient(System.Uri endpoint, Azure.Core.TokenCredential tokenCre } public partial class AssistantsClientOptions : Azure.Core.ClientOptions { - public AssistantsClientOptions(Azure.AI.OpenAI.Assistants.AssistantsClientOptions.ServiceVersion version = Azure.AI.OpenAI.Assistants.AssistantsClientOptions.ServiceVersion.V2023_11_06_Beta) { } + public AssistantsClientOptions(Azure.AI.OpenAI.Assistants.AssistantsClientOptions.ServiceVersion version = Azure.AI.OpenAI.Assistants.AssistantsClientOptions.ServiceVersion.V2024_02_15_Preview) { } public enum ServiceVersion { - V2023_11_06_Beta = 1, + V2024_02_15_Preview = 1, } } public static partial class AssistantsModelFactory @@ -175,7 +173,7 @@ public partial class AssistantThreadCreationOptions { public AssistantThreadCreationOptions() { } public System.Collections.Generic.IList Messages { get { throw null; } } - public System.Collections.Generic.IDictionary Metadata { get { throw null; } } + public System.Collections.Generic.IDictionary Metadata { get { throw null; } set { } } } public partial class CodeInterpreterImageOutput : Azure.AI.OpenAI.Assistants.CodeInterpreterToolCallOutput { @@ -210,7 +208,7 @@ public partial class CreateAndRunThreadOptions { public CreateAndRunThreadOptions(string assistantId) { } public string AssistantId { get { throw null; } } - public System.Collections.Generic.IDictionary Metadata { get { throw null; } } + public System.Collections.Generic.IDictionary Metadata { get { throw null; } set { } } public string OverrideInstructions { get { throw null; } set { } } public string OverrideModelName { get { throw null; } set { } } public System.Collections.Generic.IList OverrideTools { get { throw null; } } @@ -503,13 +501,13 @@ internal SubmitToolOutputsAction() { } } public partial class ThreadMessage { - public ThreadMessage(string id, System.DateTimeOffset createdAt, string threadId, Azure.AI.OpenAI.Assistants.MessageRole role, System.Collections.Generic.IEnumerable contentItems, System.Collections.Generic.IEnumerable fileIds) { } + public ThreadMessage(string id, System.DateTimeOffset createdAt, string threadId, Azure.AI.OpenAI.Assistants.MessageRole role, System.Collections.Generic.IEnumerable contentItems, System.Collections.Generic.IEnumerable fileIds, System.Collections.Generic.IDictionary metadata) { } public string AssistantId { get { throw null; } set { } } public System.Collections.Generic.IList ContentItems { get { throw null; } } public System.DateTimeOffset CreatedAt { get { throw null; } set { } } public System.Collections.Generic.IList FileIds { get { throw null; } } public string Id { get { throw null; } set { } } - public System.Collections.Generic.IDictionary Metadata { get { throw null; } } + public System.Collections.Generic.IDictionary Metadata { get { throw null; } set { } } public Azure.AI.OpenAI.Assistants.MessageRole Role { get { throw null; } set { } } public string RunId { get { throw null; } set { } } public string ThreadId { get { throw null; } set { } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Convenience/AssistantsClient.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Convenience/AssistantsClient.cs index 6cf40156af0f..e8a972d8bb9e 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Convenience/AssistantsClient.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Convenience/AssistantsClient.cs @@ -84,10 +84,10 @@ public virtual Task>> GetRunStepsAsync( /// The list of tool call outputs to provide as part of an output submission to an assistant thread run. /// The cancellation token to use. /// is null. - public virtual Response SubmitRunToolOutputs(ThreadRun run, IEnumerable toolOutputs, CancellationToken cancellationToken = default) + public virtual Response SubmitToolOutputsToRun(ThreadRun run, IEnumerable toolOutputs, CancellationToken cancellationToken = default) { Argument.AssertNotNull(run, nameof(run)); - return SubmitRunToolOutputs(run.ThreadId, run.Id, toolOutputs, cancellationToken); + return SubmitToolOutputsToRun(run.ThreadId, run.Id, toolOutputs, cancellationToken); } /// Submits outputs from tool calls as requested by a run with a status of 'requires_action' with required_action.type of 'submit_tool_outputs'. @@ -95,10 +95,10 @@ public virtual Response SubmitRunToolOutputs(ThreadRun run, IEnumerab /// The list of tool call outputs to provide as part of an output submission to an assistant thread run. /// The cancellation token to use. /// is null. - public virtual Task> SubmitRunToolOutputsAsync(ThreadRun run, IEnumerable toolOutputs, CancellationToken cancellationToken = default) + public virtual Task> SubmitToolOutputsToRunAsync(ThreadRun run, IEnumerable toolOutputs, CancellationToken cancellationToken = default) { Argument.AssertNotNull(run, nameof(run)); - return SubmitRunToolOutputsAsync(run.ThreadId, run.Id, toolOutputs, cancellationToken); + return SubmitToolOutputsToRunAsync(run.ThreadId, run.Id, toolOutputs, cancellationToken); } /// diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/AssistantsClient.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/AssistantsClient.cs index 5ce0242d7f01..fa04e57c24d9 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/AssistantsClient.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/AssistantsClient.cs @@ -24,6 +24,7 @@ public partial class AssistantsClient private static readonly string s_openAIEndpoint = "https://api.openai.com/v1"; private static readonly string s_aoaiNotYetSupportedMessage = "Azure OpenAI does not yet support Assistants."; + private readonly string _apiVersion; private bool _isConfiguredForAzure; /// @@ -56,7 +57,15 @@ public AssistantsClient(Uri endpoint, AzureKeyCredential keyCredential, Assistan }, new ResponseClassifier()); _endpoint = endpoint; - _apiVersion = options.Version; + if (options.Version == "2024-02-15-preview") + { + // Temporary redirection pending Azure versioning finalization + _apiVersion = "2024-01-01-preview"; + } + else + { + _apiVersion = options.Version; + } } /// @@ -579,8 +588,7 @@ internal HttpMessage CreateRequestMessage( uri.AppendPath("/beta", escape: false); } uri.AppendPath(operationPath, escape: false); - // uri.AppendQuery("api-version", _apiVersion, true); - uri.AppendQuery("api-version", "2024-01-01-preview", true); + uri.AppendQuery("api-version", _apiVersion, true); } else { @@ -618,7 +626,7 @@ internal HttpMessage CreateInternalGetAssistantsRequest( internal HttpMessage CreateCreateAssistantRequest(RequestContent content, RequestContext context) => CreateRequestMessage("/assistants", content, context, RequestMethod.Post); - internal HttpMessage CreateRetrieveAssistantRequest(string assistantId, RequestContext context) + internal HttpMessage CreateGetAssistantRequest(string assistantId, RequestContext context) => CreateRequestMessage($"/assistants/{assistantId}", content: null, context, RequestMethod.Get); internal HttpMessage CreateModifyAssistantRequest(string assistantId, RequestContent content, RequestContext context) @@ -643,7 +651,7 @@ internal HttpMessage CreateInternalGetAssistantFilesRequest(string assistantId, ("before", before)); } - internal HttpMessage CreateRetrieveAssistantFileRequest(string assistantId, string fileId, RequestContext context) + internal HttpMessage CreateGetAssistantFileRequest(string assistantId, string fileId, RequestContext context) => CreateRequestMessage($"/assistants/{assistantId}/files/{fileId}", content: null, context, RequestMethod.Get); internal HttpMessage CreateInternalUnlinkAssistantFileRequest(string assistantId, string fileId, RequestContext context) @@ -652,7 +660,7 @@ internal HttpMessage CreateInternalUnlinkAssistantFileRequest(string assistantId internal HttpMessage CreateCreateThreadRequest(RequestContent content, RequestContext context) => CreateRequestMessage($"/threads", content, context, RequestMethod.Post); - internal HttpMessage CreateRetrieveThreadRequest(string threadId, RequestContext context) + internal HttpMessage CreateGetThreadRequest(string threadId, RequestContext context) => CreateRequestMessage($"/threads/{threadId}", content: null, context, RequestMethod.Get); internal HttpMessage CreateModifyThreadRequest(string threadId, RequestContent content, RequestContext context) => CreateRequestMessage($"/threads/{threadId}", content, context, RequestMethod.Post); @@ -673,7 +681,7 @@ internal HttpMessage CreateInternalGetMessagesRequest(string threadId, int? limi ("after", after), ("before", before)); - internal HttpMessage CreateRetrieveMessageRequest(string threadId, string messageId, RequestContext context) + internal HttpMessage CreateGetMessageRequest(string threadId, string messageId, RequestContext context) => CreateRequestMessage($"/threads/{threadId}/messages/{messageId}", content: null, context, RequestMethod.Get); internal HttpMessage CreateModifyMessageRequest(string threadId, string messageId, RequestContent content, RequestContext context) @@ -689,7 +697,7 @@ internal HttpMessage CreateInternalGetMessageFilesRequest(string threadId, strin ("after", after), ("before", before)); - internal HttpMessage CreateRetrieveMessageFileRequest(string threadId, string messageId, string fileId, RequestContext context) + internal HttpMessage CreateGetMessageFileRequest(string threadId, string messageId, string fileId, RequestContext context) => CreateRequestMessage( $"/threads/{threadId}/messages/{messageId}/files/{fileId}", content: null, @@ -710,12 +718,12 @@ internal HttpMessage CreateInternalGetRunsRequest(string threadId, int? limit, s ("after", after), ("before", before)); - internal HttpMessage CreateRetrieveRunRequest(string threadId, string runId, RequestContext context) + internal HttpMessage CreateGetRunRequest(string threadId, string runId, RequestContext context) => CreateRequestMessage($"/threads/{threadId}/runs/{runId}", content: null, context, RequestMethod.Get); internal HttpMessage CreateModifyRunRequest(string threadId, string runId, RequestContent content, RequestContext context) => CreateRequestMessage($"/threads/{threadId}/runs/{runId}", content, context, RequestMethod.Post); - internal HttpMessage CreateSubmitRunToolOutputsRequest(string threadId, string runId, RequestContent content, RequestContext context) + internal HttpMessage CreateSubmitToolOuputsToRunRequest(string threadId, string runId, RequestContent content, RequestContext context) => CreateRequestMessage( $"/threads/{threadId}/runs/{runId}/submit_tool_outputs", content, @@ -728,7 +736,7 @@ internal HttpMessage CreateCancelRunRequest(string threadId, string runId, Reque internal HttpMessage CreateCreateThreadAndRunRequest(RequestContent content, RequestContext context) => CreateRequestMessage($"/threads/runs", content, context, RequestMethod.Post); - internal HttpMessage CreateRetrieveRunStepRequest(string threadId, string runId, string stepId, RequestContext context) + internal HttpMessage CreateGetRunStepRequest(string threadId, string runId, string stepId, RequestContext context) => CreateRequestMessage( $"/threads/{threadId}/runs/{runId}/steps/{stepId}", content: null, @@ -749,7 +757,7 @@ internal HttpMessage CreateInternalGetRunStepsRequest(string threadId, string ru internal HttpMessage CreateInternalListFilesRequest(string purpose, RequestContext context) => CreateRequestMessage("/files", content: null, context, RequestMethod.Get, ("purpose", purpose)); - internal HttpMessage CreateUploadFileRequest(RequestContent content, RequestContext context) + internal HttpMessage CreateCreateFileRequest(RequestContent content, RequestContext context) { HttpMessage message = CreateRequestMessage("/files", content, context, RequestMethod.Post); (content as Azure.Core.MultipartFormDataContent).ApplyToRequest(message.Request); @@ -762,9 +770,6 @@ internal HttpMessage CreateInternalDeleteFileRequest(string fileId, RequestConte internal HttpMessage CreateRetrieveFileRequest(string fileId, RequestContext context) => CreateRequestMessage($"/files/{fileId}", content: null, context, RequestMethod.Get); - internal HttpMessage CreateRetrieveFileContentRequest(string fileId, RequestContext context) - => CreateRequestMessage($"/files/{fileId}/content", content: null, context, RequestMethod.Get); - private static TokenCredential CreateDelegatedToken(string token) { var accessToken = new AccessToken(token, DateTimeOffset.Now.AddDays(180)); diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/UploadFileRequest.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/CreateFileRequest.Serialization.cs similarity index 93% rename from sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/UploadFileRequest.Serialization.cs rename to sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/CreateFileRequest.Serialization.cs index 807afb6fe54d..9e95deaf8bcc 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/UploadFileRequest.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/CreateFileRequest.Serialization.cs @@ -8,7 +8,7 @@ namespace Azure.AI.OpenAI.Assistants; -internal partial class UploadFileRequest : IUtf8JsonSerializable +internal partial class CreateFileRequest : IUtf8JsonSerializable { /* * CUSTOM CODE DESCRIPTION: diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/Assistant.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/Assistant.Serialization.cs index 3244fd411502..df949caa73bf 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/Assistant.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/Assistant.Serialization.cs @@ -30,7 +30,7 @@ internal static Assistant DeserializeAssistant(JsonElement element) string instructions = default; IReadOnlyList tools = default; IReadOnlyList fileIds = default; - Optional> metadata = default; + IReadOnlyDictionary metadata = default; foreach (var property in element.EnumerateObject()) { if (property.NameEquals("id"u8)) @@ -107,6 +107,7 @@ internal static Assistant DeserializeAssistant(JsonElement element) { if (property.Value.ValueKind == JsonValueKind.Null) { + metadata = new ChangeTrackingDictionary(); continue; } Dictionary dictionary = new Dictionary(); @@ -118,7 +119,7 @@ internal static Assistant DeserializeAssistant(JsonElement element) continue; } } - return new Assistant(id, @object, createdAt, name, description, model, instructions, tools, fileIds, Optional.ToDictionary(metadata)); + return new Assistant(id, @object, createdAt, name, description, model, instructions, tools, fileIds, metadata); } /// Deserializes the model from a raw response. diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/Assistant.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/Assistant.cs index aaa2fb2cc2bd..59023860a3dd 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/Assistant.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/Assistant.cs @@ -24,8 +24,9 @@ public partial class Assistant /// The system instructions for the assistant to use. /// The collection of tools enabled for the assistant. /// A list of attached file IDs, ordered by creation date in ascending order. + /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. /// , , or is null. - internal Assistant(string id, DateTimeOffset createdAt, string name, string description, string model, string instructions, IEnumerable tools, IEnumerable fileIds) + internal Assistant(string id, DateTimeOffset createdAt, string name, string description, string model, string instructions, IEnumerable tools, IEnumerable fileIds, IReadOnlyDictionary metadata) { Argument.AssertNotNull(id, nameof(id)); Argument.AssertNotNull(model, nameof(model)); @@ -40,7 +41,7 @@ internal Assistant(string id, DateTimeOffset createdAt, string name, string desc Instructions = instructions; Tools = tools.ToList(); FileIds = fileIds.ToList(); - Metadata = new ChangeTrackingDictionary(); + Metadata = metadata; } /// Initializes a new instance of . diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantCreationOptions.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantCreationOptions.Serialization.cs index b604cbd3d676..d6257f00c532 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantCreationOptions.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantCreationOptions.Serialization.cs @@ -19,18 +19,39 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) writer.WriteStringValue(Model); if (Optional.IsDefined(Name)) { - writer.WritePropertyName("name"u8); - writer.WriteStringValue(Name); + if (Name != null) + { + writer.WritePropertyName("name"u8); + writer.WriteStringValue(Name); + } + else + { + writer.WriteNull("name"); + } } if (Optional.IsDefined(Description)) { - writer.WritePropertyName("description"u8); - writer.WriteStringValue(Description); + if (Description != null) + { + writer.WritePropertyName("description"u8); + writer.WriteStringValue(Description); + } + else + { + writer.WriteNull("description"); + } } if (Optional.IsDefined(Instructions)) { - writer.WritePropertyName("instructions"u8); - writer.WriteStringValue(Instructions); + if (Instructions != null) + { + writer.WritePropertyName("instructions"u8); + writer.WriteStringValue(Instructions); + } + else + { + writer.WriteNull("instructions"); + } } if (Optional.IsCollectionDefined(Tools)) { @@ -54,14 +75,21 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) } if (Optional.IsCollectionDefined(Metadata)) { - writer.WritePropertyName("metadata"u8); - writer.WriteStartObject(); - foreach (var item in Metadata) + if (Metadata != null) + { + writer.WritePropertyName("metadata"u8); + writer.WriteStartObject(); + foreach (var item in Metadata) + { + writer.WritePropertyName(item.Key); + writer.WriteStringValue(item.Value); + } + writer.WriteEndObject(); + } + else { - writer.WritePropertyName(item.Key); - writer.WriteStringValue(item.Value); + writer.WriteNull("metadata"); } - writer.WriteEndObject(); } writer.WriteEndObject(); } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantCreationOptions.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantCreationOptions.cs index f9c15db09c22..c8c897f61149 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantCreationOptions.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantCreationOptions.cs @@ -63,6 +63,6 @@ internal AssistantCreationOptions(string model, string name, string description, /// A list of previously uploaded file IDs to attach to the assistant. public IList FileIds { get; } /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. - public IDictionary Metadata { get; } + public IDictionary Metadata { get; set; } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantModificationOptions.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantModificationOptions.Serialization.cs index 1058c697c6c0..ea2c34413be0 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantModificationOptions.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantModificationOptions.Serialization.cs @@ -22,18 +22,39 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) } if (Optional.IsDefined(Name)) { - writer.WritePropertyName("name"u8); - writer.WriteStringValue(Name); + if (Name != null) + { + writer.WritePropertyName("name"u8); + writer.WriteStringValue(Name); + } + else + { + writer.WriteNull("name"); + } } if (Optional.IsDefined(Description)) { - writer.WritePropertyName("description"u8); - writer.WriteStringValue(Description); + if (Description != null) + { + writer.WritePropertyName("description"u8); + writer.WriteStringValue(Description); + } + else + { + writer.WriteNull("description"); + } } if (Optional.IsDefined(Instructions)) { - writer.WritePropertyName("instructions"u8); - writer.WriteStringValue(Instructions); + if (Instructions != null) + { + writer.WritePropertyName("instructions"u8); + writer.WriteStringValue(Instructions); + } + else + { + writer.WriteNull("instructions"); + } } if (Optional.IsCollectionDefined(Tools)) { @@ -57,14 +78,21 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) } if (Optional.IsCollectionDefined(Metadata)) { - writer.WritePropertyName("metadata"u8); - writer.WriteStartObject(); - foreach (var item in Metadata) + if (Metadata != null) + { + writer.WritePropertyName("metadata"u8); + writer.WriteStartObject(); + foreach (var item in Metadata) + { + writer.WritePropertyName(item.Key); + writer.WriteStringValue(item.Value); + } + writer.WriteEndObject(); + } + else { - writer.WritePropertyName(item.Key); - writer.WriteStringValue(item.Value); + writer.WriteNull("metadata"); } - writer.WriteEndObject(); } writer.WriteEndObject(); } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantModificationOptions.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantModificationOptions.cs index f04d34a95ec5..976809cab927 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantModificationOptions.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantModificationOptions.cs @@ -57,6 +57,6 @@ internal AssistantModificationOptions(string model, string name, string descript /// The modified list of previously uploaded fileIDs to attach to the assistant. public IList FileIds { get; } /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. - public IDictionary Metadata { get; } + public IDictionary Metadata { get; set; } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantThread.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantThread.Serialization.cs index 5d56d9c5129d..a3e279d9cc72 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantThread.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantThread.Serialization.cs @@ -24,7 +24,7 @@ internal static AssistantThread DeserializeAssistantThread(JsonElement element) string id = default; string @object = default; DateTimeOffset createdAt = default; - Optional> metadata = default; + IReadOnlyDictionary metadata = default; foreach (var property in element.EnumerateObject()) { if (property.NameEquals("id"u8)) @@ -46,6 +46,7 @@ internal static AssistantThread DeserializeAssistantThread(JsonElement element) { if (property.Value.ValueKind == JsonValueKind.Null) { + metadata = new ChangeTrackingDictionary(); continue; } Dictionary dictionary = new Dictionary(); @@ -57,7 +58,7 @@ internal static AssistantThread DeserializeAssistantThread(JsonElement element) continue; } } - return new AssistantThread(id, @object, createdAt, Optional.ToDictionary(metadata)); + return new AssistantThread(id, @object, createdAt, metadata); } /// Deserializes the model from a raw response. diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantThread.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantThread.cs index d4d3b9eb86ca..3ced3d2241cb 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantThread.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantThread.cs @@ -17,14 +17,15 @@ public partial class AssistantThread /// Initializes a new instance of . /// The identifier, which can be referenced in API endpoints. /// The Unix timestamp, in seconds, representing when this object was created. + /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. /// is null. - internal AssistantThread(string id, DateTimeOffset createdAt) + internal AssistantThread(string id, DateTimeOffset createdAt, IReadOnlyDictionary metadata) { Argument.AssertNotNull(id, nameof(id)); Id = id; CreatedAt = createdAt; - Metadata = new ChangeTrackingDictionary(); + Metadata = metadata; } /// Initializes a new instance of . diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantThreadCreationOptions.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantThreadCreationOptions.Serialization.cs index 90cec5f52808..7e3f83fccc99 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantThreadCreationOptions.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantThreadCreationOptions.Serialization.cs @@ -27,14 +27,21 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) } if (Optional.IsCollectionDefined(Metadata)) { - writer.WritePropertyName("metadata"u8); - writer.WriteStartObject(); - foreach (var item in Metadata) + if (Metadata != null) { - writer.WritePropertyName(item.Key); - writer.WriteStringValue(item.Value); + writer.WritePropertyName("metadata"u8); + writer.WriteStartObject(); + foreach (var item in Metadata) + { + writer.WritePropertyName(item.Key); + writer.WriteStringValue(item.Value); + } + writer.WriteEndObject(); + } + else + { + writer.WriteNull("metadata"); } - writer.WriteEndObject(); } writer.WriteEndObject(); } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantThreadCreationOptions.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantThreadCreationOptions.cs index 60ec09eb6b42..4fb725ab6135 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantThreadCreationOptions.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantThreadCreationOptions.cs @@ -32,6 +32,6 @@ internal AssistantThreadCreationOptions(IList messages, IDictiona /// The messages to associate with the new thread. public IList Messages { get; } /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. - public IDictionary Metadata { get; } + public IDictionary Metadata { get; set; } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsClient.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsClient.cs index 64452f9d2878..c23ba4eb4b21 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsClient.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsClient.cs @@ -17,7 +17,7 @@ namespace Azure.AI.OpenAI.Assistants { // Data plane generated client. - /// The Assistants service client. + /// Azure OpenAI APIs for Assistants. public partial class AssistantsClient { private const string AuthorizationHeader = "api-key"; @@ -26,7 +26,6 @@ public partial class AssistantsClient private readonly TokenCredential _tokenCredential; private readonly HttpPipeline _pipeline; private readonly Uri _endpoint; - private readonly string _apiVersion; /// The ClientDiagnostics is used to provide tracing support for the client library. internal ClientDiagnostics ClientDiagnostics { get; } @@ -240,12 +239,12 @@ internal virtual Response InternalGetAssistants(int? limit, string order, string /// The cancellation token to use. /// is null. /// is an empty string, and was expected to be non-empty. - public virtual async Task> RetrieveAssistantAsync(string assistantId, CancellationToken cancellationToken = default) + public virtual async Task> GetAssistantAsync(string assistantId, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId)); RequestContext context = FromCancellationToken(cancellationToken); - Response response = await RetrieveAssistantAsync(assistantId, context).ConfigureAwait(false); + Response response = await GetAssistantAsync(assistantId, context).ConfigureAwait(false); return Response.FromValue(Assistant.FromResponse(response), response); } @@ -254,12 +253,12 @@ public virtual async Task> RetrieveAssistantAsync(string ass /// The cancellation token to use. /// is null. /// is an empty string, and was expected to be non-empty. - public virtual Response RetrieveAssistant(string assistantId, CancellationToken cancellationToken = default) + public virtual Response GetAssistant(string assistantId, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId)); RequestContext context = FromCancellationToken(cancellationToken); - Response response = RetrieveAssistant(assistantId, context); + Response response = GetAssistant(assistantId, context); return Response.FromValue(Assistant.FromResponse(response), response); } @@ -279,15 +278,15 @@ public virtual Response RetrieveAssistant(string assistantId, Cancell /// is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual async Task RetrieveAssistantAsync(string assistantId, RequestContext context) + internal virtual async Task GetAssistantAsync(string assistantId, RequestContext context) { Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId)); - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.RetrieveAssistant"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.GetAssistant"); scope.Start(); try { - using HttpMessage message = CreateRetrieveAssistantRequest(assistantId, context); + using HttpMessage message = CreateGetAssistantRequest(assistantId, context); return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); } catch (Exception e) @@ -313,15 +312,15 @@ internal virtual async Task RetrieveAssistantAsync(string assistantId, /// is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual Response RetrieveAssistant(string assistantId, RequestContext context) + internal virtual Response GetAssistant(string assistantId, RequestContext context) { Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId)); - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.RetrieveAssistant"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.GetAssistant"); scope.Start(); try { - using HttpMessage message = CreateRetrieveAssistantRequest(assistantId, context); + using HttpMessage message = CreateGetAssistantRequest(assistantId, context); return _pipeline.ProcessMessage(message, context); } catch (Exception e) @@ -777,13 +776,13 @@ internal virtual Response InternalGetAssistantFiles(string assistantId, int? lim /// The cancellation token to use. /// or is null. /// or is an empty string, and was expected to be non-empty. - public virtual async Task> RetrieveAssistantFileAsync(string assistantId, string fileId, CancellationToken cancellationToken = default) + public virtual async Task> GetAssistantFileAsync(string assistantId, string fileId, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId)); Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); RequestContext context = FromCancellationToken(cancellationToken); - Response response = await RetrieveAssistantFileAsync(assistantId, fileId, context).ConfigureAwait(false); + Response response = await GetAssistantFileAsync(assistantId, fileId, context).ConfigureAwait(false); return Response.FromValue(AssistantFile.FromResponse(response), response); } @@ -793,13 +792,13 @@ public virtual async Task> RetrieveAssistantFileAsync(st /// The cancellation token to use. /// or is null. /// or is an empty string, and was expected to be non-empty. - public virtual Response RetrieveAssistantFile(string assistantId, string fileId, CancellationToken cancellationToken = default) + public virtual Response GetAssistantFile(string assistantId, string fileId, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId)); Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); RequestContext context = FromCancellationToken(cancellationToken); - Response response = RetrieveAssistantFile(assistantId, fileId, context); + Response response = GetAssistantFile(assistantId, fileId, context); return Response.FromValue(AssistantFile.FromResponse(response), response); } @@ -820,16 +819,16 @@ public virtual Response RetrieveAssistantFile(string assistantId, /// or is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual async Task RetrieveAssistantFileAsync(string assistantId, string fileId, RequestContext context) + internal virtual async Task GetAssistantFileAsync(string assistantId, string fileId, RequestContext context) { Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId)); Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.RetrieveAssistantFile"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.GetAssistantFile"); scope.Start(); try { - using HttpMessage message = CreateRetrieveAssistantFileRequest(assistantId, fileId, context); + using HttpMessage message = CreateGetAssistantFileRequest(assistantId, fileId, context); return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); } catch (Exception e) @@ -856,16 +855,16 @@ internal virtual async Task RetrieveAssistantFileAsync(string assistan /// or is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual Response RetrieveAssistantFile(string assistantId, string fileId, RequestContext context) + internal virtual Response GetAssistantFile(string assistantId, string fileId, RequestContext context) { Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId)); Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.RetrieveAssistantFile"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.GetAssistantFile"); scope.Start(); try { - using HttpMessage message = CreateRetrieveAssistantFileRequest(assistantId, fileId, context); + using HttpMessage message = CreateGetAssistantFileRequest(assistantId, fileId, context); return _pipeline.ProcessMessage(message, context); } catch (Exception e) @@ -1096,12 +1095,12 @@ internal virtual Response CreateThread(RequestContent content, RequestContext co /// The cancellation token to use. /// is null. /// is an empty string, and was expected to be non-empty. - public virtual async Task> RetrieveThreadAsync(string threadId, CancellationToken cancellationToken = default) + public virtual async Task> GetThreadAsync(string threadId, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); RequestContext context = FromCancellationToken(cancellationToken); - Response response = await RetrieveThreadAsync(threadId, context).ConfigureAwait(false); + Response response = await GetThreadAsync(threadId, context).ConfigureAwait(false); return Response.FromValue(AssistantThread.FromResponse(response), response); } @@ -1110,12 +1109,12 @@ public virtual async Task> RetrieveThreadAsync(string /// The cancellation token to use. /// is null. /// is an empty string, and was expected to be non-empty. - public virtual Response RetrieveThread(string threadId, CancellationToken cancellationToken = default) + public virtual Response GetThread(string threadId, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); RequestContext context = FromCancellationToken(cancellationToken); - Response response = RetrieveThread(threadId, context); + Response response = GetThread(threadId, context); return Response.FromValue(AssistantThread.FromResponse(response), response); } @@ -1135,15 +1134,15 @@ public virtual Response RetrieveThread(string threadId, Cancell /// is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual async Task RetrieveThreadAsync(string threadId, RequestContext context) + internal virtual async Task GetThreadAsync(string threadId, RequestContext context) { Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.RetrieveThread"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.GetThread"); scope.Start(); try { - using HttpMessage message = CreateRetrieveThreadRequest(threadId, context); + using HttpMessage message = CreateGetThreadRequest(threadId, context); return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); } catch (Exception e) @@ -1169,15 +1168,15 @@ internal virtual async Task RetrieveThreadAsync(string threadId, Reque /// is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual Response RetrieveThread(string threadId, RequestContext context) + internal virtual Response GetThread(string threadId, RequestContext context) { Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.RetrieveThread"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.GetThread"); scope.Start(); try { - using HttpMessage message = CreateRetrieveThreadRequest(threadId, context); + using HttpMessage message = CreateGetThreadRequest(threadId, context); return _pipeline.ProcessMessage(message, context); } catch (Exception e) @@ -1198,16 +1197,11 @@ public virtual async Task> ModifyThreadAsync(string th Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); RequestContext context = FromCancellationToken(cancellationToken); - ModifyThreadRequest modifyThreadRequest = new ModifyThreadRequest(); - if (metadata != null) + ModifyThreadRequest modifyThreadRequest = new ModifyThreadRequest() { - foreach (var value in metadata) - { - modifyThreadRequest.Metadata.Add(value); - } - } - ModifyThreadRequest modifyThreadRequest0 = modifyThreadRequest; - Response response = await ModifyThreadAsync(threadId, modifyThreadRequest0.ToRequestContent(), context).ConfigureAwait(false); + Metadata = metadata + }; + Response response = await ModifyThreadAsync(threadId, modifyThreadRequest.ToRequestContent(), context).ConfigureAwait(false); return Response.FromValue(AssistantThread.FromResponse(response), response); } @@ -1222,16 +1216,11 @@ public virtual Response ModifyThread(string threadId, IDictiona Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); RequestContext context = FromCancellationToken(cancellationToken); - ModifyThreadRequest modifyThreadRequest = new ModifyThreadRequest(); - if (metadata != null) + ModifyThreadRequest modifyThreadRequest = new ModifyThreadRequest() { - foreach (var value in metadata) - { - modifyThreadRequest.Metadata.Add(value); - } - } - ModifyThreadRequest modifyThreadRequest0 = modifyThreadRequest; - Response response = ModifyThread(threadId, modifyThreadRequest0.ToRequestContent(), context); + Metadata = metadata + }; + Response response = ModifyThread(threadId, modifyThreadRequest.ToRequestContent(), context); return Response.FromValue(AssistantThread.FromResponse(response), response); } @@ -1428,7 +1417,10 @@ public virtual async Task> CreateMessageAsync(string thr Argument.AssertNotNull(content, nameof(content)); RequestContext context = FromCancellationToken(cancellationToken); - CreateMessageRequest createMessageRequest = new CreateMessageRequest(role, content); + CreateMessageRequest createMessageRequest = new CreateMessageRequest(role, content) + { + Metadata = metadata + }; if (fileIds != null) { foreach (var value in fileIds) @@ -1436,13 +1428,6 @@ public virtual async Task> CreateMessageAsync(string thr createMessageRequest.FileIds.Add(value); } } - if (metadata != null) - { - foreach (var value in metadata) - { - createMessageRequest.Metadata.Add(value); - } - } CreateMessageRequest createMessageRequest0 = createMessageRequest; Response response = await CreateMessageAsync(threadId, createMessageRequest0.ToRequestContent(), context).ConfigureAwait(false); return Response.FromValue(ThreadMessage.FromResponse(response), response); @@ -1463,7 +1448,10 @@ public virtual Response CreateMessage(string threadId, MessageRol Argument.AssertNotNull(content, nameof(content)); RequestContext context = FromCancellationToken(cancellationToken); - CreateMessageRequest createMessageRequest = new CreateMessageRequest(role, content); + CreateMessageRequest createMessageRequest = new CreateMessageRequest(role, content) + { + Metadata = metadata + }; if (fileIds != null) { foreach (var value in fileIds) @@ -1471,13 +1459,6 @@ public virtual Response CreateMessage(string threadId, MessageRol createMessageRequest.FileIds.Add(value); } } - if (metadata != null) - { - foreach (var value in metadata) - { - createMessageRequest.Metadata.Add(value); - } - } CreateMessageRequest createMessageRequest0 = createMessageRequest; Response response = CreateMessage(threadId, createMessageRequest0.ToRequestContent(), context); return Response.FromValue(ThreadMessage.FromResponse(response), response); @@ -1683,13 +1664,13 @@ internal virtual Response InternalGetMessages(string threadId, int? limit, strin /// The cancellation token to use. /// or is null. /// or is an empty string, and was expected to be non-empty. - public virtual async Task> RetrieveMessageAsync(string threadId, string messageId, CancellationToken cancellationToken = default) + public virtual async Task> GetMessageAsync(string threadId, string messageId, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); Argument.AssertNotNullOrEmpty(messageId, nameof(messageId)); RequestContext context = FromCancellationToken(cancellationToken); - Response response = await RetrieveMessageAsync(threadId, messageId, context).ConfigureAwait(false); + Response response = await GetMessageAsync(threadId, messageId, context).ConfigureAwait(false); return Response.FromValue(ThreadMessage.FromResponse(response), response); } @@ -1699,13 +1680,13 @@ public virtual async Task> RetrieveMessageAsync(string t /// The cancellation token to use. /// or is null. /// or is an empty string, and was expected to be non-empty. - public virtual Response RetrieveMessage(string threadId, string messageId, CancellationToken cancellationToken = default) + public virtual Response GetMessage(string threadId, string messageId, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); Argument.AssertNotNullOrEmpty(messageId, nameof(messageId)); RequestContext context = FromCancellationToken(cancellationToken); - Response response = RetrieveMessage(threadId, messageId, context); + Response response = GetMessage(threadId, messageId, context); return Response.FromValue(ThreadMessage.FromResponse(response), response); } @@ -1726,16 +1707,16 @@ public virtual Response RetrieveMessage(string threadId, string m /// or is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual async Task RetrieveMessageAsync(string threadId, string messageId, RequestContext context) + internal virtual async Task GetMessageAsync(string threadId, string messageId, RequestContext context) { Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); Argument.AssertNotNullOrEmpty(messageId, nameof(messageId)); - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.RetrieveMessage"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.GetMessage"); scope.Start(); try { - using HttpMessage message = CreateRetrieveMessageRequest(threadId, messageId, context); + using HttpMessage message = CreateGetMessageRequest(threadId, messageId, context); return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); } catch (Exception e) @@ -1762,16 +1743,16 @@ internal virtual async Task RetrieveMessageAsync(string threadId, stri /// or is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual Response RetrieveMessage(string threadId, string messageId, RequestContext context) + internal virtual Response GetMessage(string threadId, string messageId, RequestContext context) { Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); Argument.AssertNotNullOrEmpty(messageId, nameof(messageId)); - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.RetrieveMessage"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.GetMessage"); scope.Start(); try { - using HttpMessage message = CreateRetrieveMessageRequest(threadId, messageId, context); + using HttpMessage message = CreateGetMessageRequest(threadId, messageId, context); return _pipeline.ProcessMessage(message, context); } catch (Exception e) @@ -1794,16 +1775,11 @@ public virtual async Task> ModifyMessageAsync(string thr Argument.AssertNotNullOrEmpty(messageId, nameof(messageId)); RequestContext context = FromCancellationToken(cancellationToken); - ModifyMessageRequest modifyMessageRequest = new ModifyMessageRequest(); - if (metadata != null) + ModifyMessageRequest modifyMessageRequest = new ModifyMessageRequest() { - foreach (var value in metadata) - { - modifyMessageRequest.Metadata.Add(value); - } - } - ModifyMessageRequest modifyMessageRequest0 = modifyMessageRequest; - Response response = await ModifyMessageAsync(threadId, messageId, modifyMessageRequest0.ToRequestContent(), context).ConfigureAwait(false); + Metadata = metadata + }; + Response response = await ModifyMessageAsync(threadId, messageId, modifyMessageRequest.ToRequestContent(), context).ConfigureAwait(false); return Response.FromValue(ThreadMessage.FromResponse(response), response); } @@ -1820,16 +1796,11 @@ public virtual Response ModifyMessage(string threadId, string mes Argument.AssertNotNullOrEmpty(messageId, nameof(messageId)); RequestContext context = FromCancellationToken(cancellationToken); - ModifyMessageRequest modifyMessageRequest = new ModifyMessageRequest(); - if (metadata != null) + ModifyMessageRequest modifyMessageRequest = new ModifyMessageRequest() { - foreach (var value in metadata) - { - modifyMessageRequest.Metadata.Add(value); - } - } - ModifyMessageRequest modifyMessageRequest0 = modifyMessageRequest; - Response response = ModifyMessage(threadId, messageId, modifyMessageRequest0.ToRequestContent(), context); + Metadata = metadata + }; + Response response = ModifyMessage(threadId, messageId, modifyMessageRequest.ToRequestContent(), context); return Response.FromValue(ThreadMessage.FromResponse(response), response); } @@ -2046,14 +2017,14 @@ internal virtual Response InternalGetMessageFiles(string threadId, string messag /// The cancellation token to use. /// , or is null. /// , or is an empty string, and was expected to be non-empty. - public virtual async Task> RetrieveMessageFileAsync(string threadId, string messageId, string fileId, CancellationToken cancellationToken = default) + public virtual async Task> GetMessageFileAsync(string threadId, string messageId, string fileId, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); Argument.AssertNotNullOrEmpty(messageId, nameof(messageId)); Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); RequestContext context = FromCancellationToken(cancellationToken); - Response response = await RetrieveMessageFileAsync(threadId, messageId, fileId, context).ConfigureAwait(false); + Response response = await GetMessageFileAsync(threadId, messageId, fileId, context).ConfigureAwait(false); return Response.FromValue(MessageFile.FromResponse(response), response); } @@ -2064,14 +2035,14 @@ public virtual async Task> RetrieveMessageFileAsync(string /// The cancellation token to use. /// , or is null. /// , or is an empty string, and was expected to be non-empty. - public virtual Response RetrieveMessageFile(string threadId, string messageId, string fileId, CancellationToken cancellationToken = default) + public virtual Response GetMessageFile(string threadId, string messageId, string fileId, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); Argument.AssertNotNullOrEmpty(messageId, nameof(messageId)); Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); RequestContext context = FromCancellationToken(cancellationToken); - Response response = RetrieveMessageFile(threadId, messageId, fileId, context); + Response response = GetMessageFile(threadId, messageId, fileId, context); return Response.FromValue(MessageFile.FromResponse(response), response); } @@ -2093,17 +2064,17 @@ public virtual Response RetrieveMessageFile(string threadId, string /// , or is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual async Task RetrieveMessageFileAsync(string threadId, string messageId, string fileId, RequestContext context) + internal virtual async Task GetMessageFileAsync(string threadId, string messageId, string fileId, RequestContext context) { Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); Argument.AssertNotNullOrEmpty(messageId, nameof(messageId)); Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.RetrieveMessageFile"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.GetMessageFile"); scope.Start(); try { - using HttpMessage message = CreateRetrieveMessageFileRequest(threadId, messageId, fileId, context); + using HttpMessage message = CreateGetMessageFileRequest(threadId, messageId, fileId, context); return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); } catch (Exception e) @@ -2131,17 +2102,17 @@ internal virtual async Task RetrieveMessageFileAsync(string threadId, /// , or is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual Response RetrieveMessageFile(string threadId, string messageId, string fileId, RequestContext context) + internal virtual Response GetMessageFile(string threadId, string messageId, string fileId, RequestContext context) { Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); Argument.AssertNotNullOrEmpty(messageId, nameof(messageId)); Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.RetrieveMessageFile"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.GetMessageFile"); scope.Start(); try { - using HttpMessage message = CreateRetrieveMessageFileRequest(threadId, messageId, fileId, context); + using HttpMessage message = CreateGetMessageFileRequest(threadId, messageId, fileId, context); return _pipeline.ProcessMessage(message, context); } catch (Exception e) @@ -2154,7 +2125,7 @@ internal virtual Response RetrieveMessageFile(string threadId, string messageId, /// Creates a new run for an assistant thread. /// The ID of the thread to run. /// The ID of the assistant that should run the thread. - /// The overriden model name that the assistant should use to run the thread. + /// The overridden model name that the assistant should use to run the thread. /// The overridden system instructions that the assistant should use to run the thread. /// The overridden list of enabled tools that the assistant should use to run the thread. /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. @@ -2170,7 +2141,8 @@ public virtual async Task> CreateRunAsync(string threadId, s CreateRunRequest createRunRequest = new CreateRunRequest(assistantId) { OverrideModelName = overrideModelName, - OverrideInstructions = overrideInstructions + OverrideInstructions = overrideInstructions, + Metadata = metadata }; if (overrideTools != null) { @@ -2179,13 +2151,6 @@ public virtual async Task> CreateRunAsync(string threadId, s createRunRequest.OverrideTools.Add(value); } } - if (metadata != null) - { - foreach (var value in metadata) - { - createRunRequest.Metadata.Add(value); - } - } CreateRunRequest createRunRequest0 = createRunRequest; Response response = await CreateRunAsync(threadId, createRunRequest0.ToRequestContent(), context).ConfigureAwait(false); return Response.FromValue(ThreadRun.FromResponse(response), response); @@ -2194,7 +2159,7 @@ public virtual async Task> CreateRunAsync(string threadId, s /// Creates a new run for an assistant thread. /// The ID of the thread to run. /// The ID of the assistant that should run the thread. - /// The overriden model name that the assistant should use to run the thread. + /// The overridden model name that the assistant should use to run the thread. /// The overridden system instructions that the assistant should use to run the thread. /// The overridden list of enabled tools that the assistant should use to run the thread. /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. @@ -2210,7 +2175,8 @@ public virtual Response CreateRun(string threadId, string assistantId CreateRunRequest createRunRequest = new CreateRunRequest(assistantId) { OverrideModelName = overrideModelName, - OverrideInstructions = overrideInstructions + OverrideInstructions = overrideInstructions, + Metadata = metadata }; if (overrideTools != null) { @@ -2219,13 +2185,6 @@ public virtual Response CreateRun(string threadId, string assistantId createRunRequest.OverrideTools.Add(value); } } - if (metadata != null) - { - foreach (var value in metadata) - { - createRunRequest.Metadata.Add(value); - } - } CreateRunRequest createRunRequest0 = createRunRequest; Response response = CreateRun(threadId, createRunRequest0.ToRequestContent(), context); return Response.FromValue(ThreadRun.FromResponse(response), response); @@ -2431,13 +2390,13 @@ internal virtual Response InternalGetRuns(string threadId, int? limit, string or /// The cancellation token to use. /// or is null. /// or is an empty string, and was expected to be non-empty. - public virtual async Task> RetrieveRunAsync(string threadId, string runId, CancellationToken cancellationToken = default) + public virtual async Task> GetRunAsync(string threadId, string runId, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); Argument.AssertNotNullOrEmpty(runId, nameof(runId)); RequestContext context = FromCancellationToken(cancellationToken); - Response response = await RetrieveRunAsync(threadId, runId, context).ConfigureAwait(false); + Response response = await GetRunAsync(threadId, runId, context).ConfigureAwait(false); return Response.FromValue(ThreadRun.FromResponse(response), response); } @@ -2447,13 +2406,13 @@ public virtual async Task> RetrieveRunAsync(string threadId, /// The cancellation token to use. /// or is null. /// or is an empty string, and was expected to be non-empty. - public virtual Response RetrieveRun(string threadId, string runId, CancellationToken cancellationToken = default) + public virtual Response GetRun(string threadId, string runId, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); Argument.AssertNotNullOrEmpty(runId, nameof(runId)); RequestContext context = FromCancellationToken(cancellationToken); - Response response = RetrieveRun(threadId, runId, context); + Response response = GetRun(threadId, runId, context); return Response.FromValue(ThreadRun.FromResponse(response), response); } @@ -2474,16 +2433,16 @@ public virtual Response RetrieveRun(string threadId, string runId, Ca /// or is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual async Task RetrieveRunAsync(string threadId, string runId, RequestContext context) + internal virtual async Task GetRunAsync(string threadId, string runId, RequestContext context) { Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); Argument.AssertNotNullOrEmpty(runId, nameof(runId)); - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.RetrieveRun"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.GetRun"); scope.Start(); try { - using HttpMessage message = CreateRetrieveRunRequest(threadId, runId, context); + using HttpMessage message = CreateGetRunRequest(threadId, runId, context); return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); } catch (Exception e) @@ -2510,16 +2469,16 @@ internal virtual async Task RetrieveRunAsync(string threadId, string r /// or is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual Response RetrieveRun(string threadId, string runId, RequestContext context) + internal virtual Response GetRun(string threadId, string runId, RequestContext context) { Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); Argument.AssertNotNullOrEmpty(runId, nameof(runId)); - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.RetrieveRun"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.GetRun"); scope.Start(); try { - using HttpMessage message = CreateRetrieveRunRequest(threadId, runId, context); + using HttpMessage message = CreateGetRunRequest(threadId, runId, context); return _pipeline.ProcessMessage(message, context); } catch (Exception e) @@ -2542,16 +2501,11 @@ public virtual async Task> ModifyRunAsync(string threadId, s Argument.AssertNotNullOrEmpty(runId, nameof(runId)); RequestContext context = FromCancellationToken(cancellationToken); - ModifyRunRequest modifyRunRequest = new ModifyRunRequest(); - if (metadata != null) + ModifyRunRequest modifyRunRequest = new ModifyRunRequest() { - foreach (var value in metadata) - { - modifyRunRequest.Metadata.Add(value); - } - } - ModifyRunRequest modifyRunRequest0 = modifyRunRequest; - Response response = await ModifyRunAsync(threadId, runId, modifyRunRequest0.ToRequestContent(), context).ConfigureAwait(false); + Metadata = metadata + }; + Response response = await ModifyRunAsync(threadId, runId, modifyRunRequest.ToRequestContent(), context).ConfigureAwait(false); return Response.FromValue(ThreadRun.FromResponse(response), response); } @@ -2568,16 +2522,11 @@ public virtual Response ModifyRun(string threadId, string runId, IDic Argument.AssertNotNullOrEmpty(runId, nameof(runId)); RequestContext context = FromCancellationToken(cancellationToken); - ModifyRunRequest modifyRunRequest = new ModifyRunRequest(); - if (metadata != null) + ModifyRunRequest modifyRunRequest = new ModifyRunRequest() { - foreach (var value in metadata) - { - modifyRunRequest.Metadata.Add(value); - } - } - ModifyRunRequest modifyRunRequest0 = modifyRunRequest; - Response response = ModifyRun(threadId, runId, modifyRunRequest0.ToRequestContent(), context); + Metadata = metadata + }; + Response response = ModifyRun(threadId, runId, modifyRunRequest.ToRequestContent(), context); return Response.FromValue(ThreadRun.FromResponse(response), response); } @@ -2658,40 +2607,40 @@ internal virtual Response ModifyRun(string threadId, string runId, RequestConten } /// Submits outputs from tools as requested by tool calls in a run. Runs that need submitted tool outputs will have a status of 'requires_action' with a required_action.type of 'submit_tool_outputs'. - /// The ID of the the thread that was run. + /// The ID of the thread that was run. /// The ID of the run that requires tool outputs. /// The list of tool outputs requested by tool calls from the specified run. /// The cancellation token to use. /// , or is null. /// or is an empty string, and was expected to be non-empty. - public virtual async Task> SubmitRunToolOutputsAsync(string threadId, string runId, IEnumerable toolOutputs, CancellationToken cancellationToken = default) + public virtual async Task> SubmitToolOutputsToRunAsync(string threadId, string runId, IEnumerable toolOutputs, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); Argument.AssertNotNullOrEmpty(runId, nameof(runId)); Argument.AssertNotNull(toolOutputs, nameof(toolOutputs)); RequestContext context = FromCancellationToken(cancellationToken); - SubmitRunToolOutputsRequest submitRunToolOutputsRequest = new SubmitRunToolOutputsRequest(toolOutputs.ToList()); - Response response = await SubmitRunToolOutputsAsync(threadId, runId, submitRunToolOutputsRequest.ToRequestContent(), context).ConfigureAwait(false); + SubmitToolOutputsToRunRequest submitToolOutputsToRunRequest = new SubmitToolOutputsToRunRequest(toolOutputs.ToList()); + Response response = await SubmitToolOutputsToRunAsync(threadId, runId, submitToolOutputsToRunRequest.ToRequestContent(), context).ConfigureAwait(false); return Response.FromValue(ThreadRun.FromResponse(response), response); } /// Submits outputs from tools as requested by tool calls in a run. Runs that need submitted tool outputs will have a status of 'requires_action' with a required_action.type of 'submit_tool_outputs'. - /// The ID of the the thread that was run. + /// The ID of the thread that was run. /// The ID of the run that requires tool outputs. /// The list of tool outputs requested by tool calls from the specified run. /// The cancellation token to use. /// , or is null. /// or is an empty string, and was expected to be non-empty. - public virtual Response SubmitRunToolOutputs(string threadId, string runId, IEnumerable toolOutputs, CancellationToken cancellationToken = default) + public virtual Response SubmitToolOutputsToRun(string threadId, string runId, IEnumerable toolOutputs, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); Argument.AssertNotNullOrEmpty(runId, nameof(runId)); Argument.AssertNotNull(toolOutputs, nameof(toolOutputs)); RequestContext context = FromCancellationToken(cancellationToken); - SubmitRunToolOutputsRequest submitRunToolOutputsRequest = new SubmitRunToolOutputsRequest(toolOutputs.ToList()); - Response response = SubmitRunToolOutputs(threadId, runId, submitRunToolOutputsRequest.ToRequestContent(), context); + SubmitToolOutputsToRunRequest submitToolOutputsToRunRequest = new SubmitToolOutputsToRunRequest(toolOutputs.ToList()); + Response response = SubmitToolOutputsToRun(threadId, runId, submitToolOutputsToRunRequest.ToRequestContent(), context); return Response.FromValue(ThreadRun.FromResponse(response), response); } @@ -2705,7 +2654,7 @@ public virtual Response SubmitRunToolOutputs(string threadId, string /// /// /// - /// The ID of the the thread that was run. + /// The ID of the thread that was run. /// The ID of the run that requires tool outputs. /// The content to send as the body of the request. /// The request context, which can override default behaviors of the client pipeline on a per-call basis. @@ -2713,17 +2662,17 @@ public virtual Response SubmitRunToolOutputs(string threadId, string /// or is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual async Task SubmitRunToolOutputsAsync(string threadId, string runId, RequestContent content, RequestContext context = null) + internal virtual async Task SubmitToolOutputsToRunAsync(string threadId, string runId, RequestContent content, RequestContext context = null) { Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); Argument.AssertNotNullOrEmpty(runId, nameof(runId)); Argument.AssertNotNull(content, nameof(content)); - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.SubmitRunToolOutputs"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.SubmitToolOutputsToRun"); scope.Start(); try { - using HttpMessage message = CreateSubmitRunToolOutputsRequest(threadId, runId, content, context); + using HttpMessage message = CreateSubmitToolOutputsToRunRequest(threadId, runId, content, context); return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); } catch (Exception e) @@ -2743,7 +2692,7 @@ internal virtual async Task SubmitRunToolOutputsAsync(string threadId, /// /// /// - /// The ID of the the thread that was run. + /// The ID of the thread that was run. /// The ID of the run that requires tool outputs. /// The content to send as the body of the request. /// The request context, which can override default behaviors of the client pipeline on a per-call basis. @@ -2751,17 +2700,17 @@ internal virtual async Task SubmitRunToolOutputsAsync(string threadId, /// or is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual Response SubmitRunToolOutputs(string threadId, string runId, RequestContent content, RequestContext context = null) + internal virtual Response SubmitToolOutputsToRun(string threadId, string runId, RequestContent content, RequestContext context = null) { Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); Argument.AssertNotNullOrEmpty(runId, nameof(runId)); Argument.AssertNotNull(content, nameof(content)); - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.SubmitRunToolOutputs"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.SubmitToolOutputsToRun"); scope.Start(); try { - using HttpMessage message = CreateSubmitRunToolOutputsRequest(threadId, runId, content, context); + using HttpMessage message = CreateSubmitToolOutputsToRunRequest(threadId, runId, content, context); return _pipeline.ProcessMessage(message, context); } catch (Exception e) @@ -2771,7 +2720,7 @@ internal virtual Response SubmitRunToolOutputs(string threadId, string runId, Re } } - /// Cancels a thread run. + /// Cancels a run of an in progress thread. /// The ID of the thread being run. /// The ID of the run to cancel. /// The cancellation token to use. @@ -2787,7 +2736,7 @@ public virtual async Task> CancelRunAsync(string threadId, s return Response.FromValue(ThreadRun.FromResponse(response), response); } - /// Cancels a thread run. + /// Cancels a run of an in progress thread. /// The ID of the thread being run. /// The ID of the run to cancel. /// The cancellation token to use. @@ -2804,7 +2753,7 @@ public virtual Response CancelRun(string threadId, string runId, Canc } /// - /// [Protocol Method] Cancels a thread run. + /// [Protocol Method] Cancels a run of an in progress thread. /// /// /// @@ -2840,7 +2789,7 @@ internal virtual async Task CancelRunAsync(string threadId, string run } /// - /// [Protocol Method] Cancels a thread run. + /// [Protocol Method] Cancels a run of an in progress thread. /// /// /// @@ -2976,14 +2925,14 @@ internal virtual Response CreateThreadAndRun(RequestContent content, RequestCont /// The cancellation token to use. /// , or is null. /// , or is an empty string, and was expected to be non-empty. - public virtual async Task> RetrieveRunStepAsync(string threadId, string runId, string stepId, CancellationToken cancellationToken = default) + public virtual async Task> GetRunStepAsync(string threadId, string runId, string stepId, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); Argument.AssertNotNullOrEmpty(runId, nameof(runId)); Argument.AssertNotNullOrEmpty(stepId, nameof(stepId)); RequestContext context = FromCancellationToken(cancellationToken); - Response response = await RetrieveRunStepAsync(threadId, runId, stepId, context).ConfigureAwait(false); + Response response = await GetRunStepAsync(threadId, runId, stepId, context).ConfigureAwait(false); return Response.FromValue(RunStep.FromResponse(response), response); } @@ -2994,14 +2943,14 @@ public virtual async Task> RetrieveRunStepAsync(string threadI /// The cancellation token to use. /// , or is null. /// , or is an empty string, and was expected to be non-empty. - public virtual Response RetrieveRunStep(string threadId, string runId, string stepId, CancellationToken cancellationToken = default) + public virtual Response GetRunStep(string threadId, string runId, string stepId, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); Argument.AssertNotNullOrEmpty(runId, nameof(runId)); Argument.AssertNotNullOrEmpty(stepId, nameof(stepId)); RequestContext context = FromCancellationToken(cancellationToken); - Response response = RetrieveRunStep(threadId, runId, stepId, context); + Response response = GetRunStep(threadId, runId, stepId, context); return Response.FromValue(RunStep.FromResponse(response), response); } @@ -3023,17 +2972,17 @@ public virtual Response RetrieveRunStep(string threadId, string runId, /// , or is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual async Task RetrieveRunStepAsync(string threadId, string runId, string stepId, RequestContext context) + internal virtual async Task GetRunStepAsync(string threadId, string runId, string stepId, RequestContext context) { Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); Argument.AssertNotNullOrEmpty(runId, nameof(runId)); Argument.AssertNotNullOrEmpty(stepId, nameof(stepId)); - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.RetrieveRunStep"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.GetRunStep"); scope.Start(); try { - using HttpMessage message = CreateRetrieveRunStepRequest(threadId, runId, stepId, context); + using HttpMessage message = CreateGetRunStepRequest(threadId, runId, stepId, context); return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); } catch (Exception e) @@ -3061,17 +3010,17 @@ internal virtual async Task RetrieveRunStepAsync(string threadId, stri /// , or is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual Response RetrieveRunStep(string threadId, string runId, string stepId, RequestContext context) + internal virtual Response GetRunStep(string threadId, string runId, string stepId, RequestContext context) { Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); Argument.AssertNotNullOrEmpty(runId, nameof(runId)); Argument.AssertNotNullOrEmpty(stepId, nameof(stepId)); - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.RetrieveRunStep"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.GetRunStep"); scope.Start(); try { - using HttpMessage message = CreateRetrieveRunStepRequest(threadId, runId, stepId, context); + using HttpMessage message = CreateGetRunStepRequest(threadId, runId, stepId, context); return _pipeline.ProcessMessage(message, context); } catch (Exception e) @@ -3312,11 +3261,11 @@ public virtual async Task> UploadFileAsync(BinaryData data, Argument.AssertNotNull(data, nameof(data)); RequestContext context = FromCancellationToken(cancellationToken); - UploadFileRequest uploadFileRequest = new UploadFileRequest(data, purpose) + CreateFileRequest createFileRequest = new CreateFileRequest(data, purpose) { Filename = filename }; - Response response = await UploadFileAsync(uploadFileRequest.ToRequestContent(), context).ConfigureAwait(false); + Response response = await UploadFileAsync(createFileRequest.ToRequestContent(), context).ConfigureAwait(false); return Response.FromValue(OpenAIFile.FromResponse(response), response); } @@ -3331,11 +3280,11 @@ public virtual Response UploadFile(BinaryData data, OpenAIFilePurpos Argument.AssertNotNull(data, nameof(data)); RequestContext context = FromCancellationToken(cancellationToken); - UploadFileRequest uploadFileRequest = new UploadFileRequest(data, purpose) + CreateFileRequest createFileRequest = new CreateFileRequest(data, purpose) { Filename = filename }; - Response response = UploadFile(uploadFileRequest.ToRequestContent(), context); + Response response = UploadFile(createFileRequest.ToRequestContent(), context); return Response.FromValue(OpenAIFile.FromResponse(response), response); } @@ -3607,100 +3556,38 @@ internal virtual Response RetrieveFile(string fileId, RequestContext context) } } - /// Returns the contents of a specified file. - /// The ID of the file to retrieve the contents of. - /// The cancellation token to use. - /// is null. - /// is an empty string, and was expected to be non-empty. - public virtual async Task> RetrieveFileContentAsync(string fileId, CancellationToken cancellationToken = default) - { - Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); - - RequestContext context = FromCancellationToken(cancellationToken); - Response response = await RetrieveFileContentAsync(fileId, context).ConfigureAwait(false); - return Response.FromValue(response.Content, response); - } - - /// Returns the contents of a specified file. - /// The ID of the file to retrieve the contents of. - /// The cancellation token to use. - /// is null. - /// is an empty string, and was expected to be non-empty. - public virtual Response RetrieveFileContent(string fileId, CancellationToken cancellationToken = default) - { - Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); - - RequestContext context = FromCancellationToken(cancellationToken); - Response response = RetrieveFileContent(fileId, context); - return Response.FromValue(response.Content, response); - } - - /// - /// [Protocol Method] Returns the contents of a specified file. - /// - /// - /// - /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. - /// - /// - /// - /// - /// The ID of the file to retrieve the contents of. - /// The request context, which can override default behaviors of the client pipeline on a per-call basis. - /// is null. - /// is an empty string, and was expected to be non-empty. - /// Service returned a non-success status code. - /// The response returned from the service. - internal virtual async Task RetrieveFileContentAsync(string fileId, RequestContext context) + internal HttpMessage CreateSubmitToolOutputsToRunRequest(string threadId, string runId, RequestContent content, RequestContext context) { - Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); - - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.RetrieveFileContent"); - scope.Start(); - try - { - using HttpMessage message = CreateRetrieveFileContentRequest(fileId, context); - return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); - } - catch (Exception e) - { - scope.Failed(e); - throw; - } + var message = _pipeline.CreateMessage(context, ResponseClassifier200); + var request = message.Request; + request.Method = RequestMethod.Post; + var uri = new RawRequestUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/threads/", false); + uri.AppendPath(threadId, true); + uri.AppendPath("/runs/", false); + uri.AppendPath(runId, true); + uri.AppendPath("/submit_tool_outputs", false); + request.Uri = uri; + request.Headers.Add("Accept", "application/json"); + request.Headers.Add("Content-Type", "application/json"); + request.Content = content; + return message; } - /// - /// [Protocol Method] Returns the contents of a specified file. - /// - /// - /// - /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. - /// - /// - /// - /// - /// The ID of the file to retrieve the contents of. - /// The request context, which can override default behaviors of the client pipeline on a per-call basis. - /// is null. - /// is an empty string, and was expected to be non-empty. - /// Service returned a non-success status code. - /// The response returned from the service. - internal virtual Response RetrieveFileContent(string fileId, RequestContext context) + internal HttpMessage CreateUploadFileRequest(RequestContent content, RequestContext context) { - Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); - - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.RetrieveFileContent"); - scope.Start(); - try - { - using HttpMessage message = CreateRetrieveFileContentRequest(fileId, context); - return _pipeline.ProcessMessage(message, context); - } - catch (Exception e) - { - scope.Failed(e); - throw; - } + var message = _pipeline.CreateMessage(context, ResponseClassifier200); + var request = message.Request; + request.Method = RequestMethod.Post; + var uri = new RawRequestUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/files", false); + request.Uri = uri; + request.Headers.Add("Accept", "application/json"); + request.Headers.Add("content-type", "multipart/form-data"); + request.Content = content; + return message; } private static RequestContext DefaultRequestContext = new RequestContext(); diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsClientOptions.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsClientOptions.cs index 0808713f69a1..a847db2052bd 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsClientOptions.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsClientOptions.cs @@ -13,13 +13,13 @@ namespace Azure.AI.OpenAI.Assistants /// Client options for AssistantsClient. public partial class AssistantsClientOptions : ClientOptions { - private const ServiceVersion LatestVersion = ServiceVersion.V2023_11_06_Beta; + private const ServiceVersion LatestVersion = ServiceVersion.V2024_02_15_Preview; /// The version of the service to use. public enum ServiceVersion { - /// Service version "2023-11-06-beta". - V2023_11_06_Beta = 1, + /// Service version "2024-02-15-preview". + V2024_02_15_Preview = 1, } internal string Version { get; } @@ -29,7 +29,7 @@ public AssistantsClientOptions(ServiceVersion version = LatestVersion) { Version = version switch { - ServiceVersion.V2023_11_06_Beta => "2023-11-06-beta", + ServiceVersion.V2024_02_15_Preview => "2024-02-15-preview", _ => throw new NotSupportedException() }; } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateAndRunThreadOptions.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateAndRunThreadOptions.Serialization.cs index a9d7d6914d60..fa7217f816f9 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateAndRunThreadOptions.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateAndRunThreadOptions.Serialization.cs @@ -44,14 +44,21 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) } if (Optional.IsCollectionDefined(Metadata)) { - writer.WritePropertyName("metadata"u8); - writer.WriteStartObject(); - foreach (var item in Metadata) + if (Metadata != null) { - writer.WritePropertyName(item.Key); - writer.WriteStringValue(item.Value); + writer.WritePropertyName("metadata"u8); + writer.WriteStartObject(); + foreach (var item in Metadata) + { + writer.WritePropertyName(item.Key); + writer.WriteStringValue(item.Value); + } + writer.WriteEndObject(); + } + else + { + writer.WriteNull("metadata"); } - writer.WriteEndObject(); } writer.WriteEndObject(); } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateAndRunThreadOptions.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateAndRunThreadOptions.cs index 6aa505de4abe..d663adb7dde8 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateAndRunThreadOptions.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateAndRunThreadOptions.cs @@ -58,6 +58,6 @@ internal CreateAndRunThreadOptions(string assistantId, AssistantThreadCreationOp /// public IList OverrideTools { get; } /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. - public IDictionary Metadata { get; } + public IDictionary Metadata { get; set; } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UploadFileRequest.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateFileRequest.Serialization.cs similarity index 92% rename from sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UploadFileRequest.Serialization.cs rename to sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateFileRequest.Serialization.cs index 0206b80fb3ef..b06b7f4c2ee1 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UploadFileRequest.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateFileRequest.Serialization.cs @@ -10,7 +10,7 @@ namespace Azure.AI.OpenAI.Assistants { - internal partial class UploadFileRequest : IUtf8JsonSerializable + internal partial class CreateFileRequest : IUtf8JsonSerializable { void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) { diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UploadFileRequest.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateFileRequest.cs similarity index 81% rename from sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UploadFileRequest.cs rename to sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateFileRequest.cs index e276c52bea44..af2a52e84dd9 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UploadFileRequest.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateFileRequest.cs @@ -10,14 +10,14 @@ namespace Azure.AI.OpenAI.Assistants { - /// The UploadFileRequest. - internal partial class UploadFileRequest + /// The CreateFileRequest. + internal partial class CreateFileRequest { - /// Initializes a new instance of . + /// Initializes a new instance of . /// The file data (not filename) to upload. /// The intended purpose of the file. /// is null. - public UploadFileRequest(BinaryData data, OpenAIFilePurpose purpose) + public CreateFileRequest(BinaryData data, OpenAIFilePurpose purpose) { Argument.AssertNotNull(data, nameof(data)); @@ -25,11 +25,11 @@ public UploadFileRequest(BinaryData data, OpenAIFilePurpose purpose) Purpose = purpose; } - /// Initializes a new instance of . + /// Initializes a new instance of . /// The file data (not filename) to upload. /// The intended purpose of the file. /// A filename to associate with the uploaded data. - internal UploadFileRequest(BinaryData data, OpenAIFilePurpose purpose, string filename) + internal CreateFileRequest(BinaryData data, OpenAIFilePurpose purpose, string filename) { Data = data; Purpose = purpose; diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateMessageRequest.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateMessageRequest.Serialization.cs index 7db59b13eedb..14c7ce78000a 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateMessageRequest.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateMessageRequest.Serialization.cs @@ -31,14 +31,21 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) } if (Optional.IsCollectionDefined(Metadata)) { - writer.WritePropertyName("metadata"u8); - writer.WriteStartObject(); - foreach (var item in Metadata) + if (Metadata != null) { - writer.WritePropertyName(item.Key); - writer.WriteStringValue(item.Value); + writer.WritePropertyName("metadata"u8); + writer.WriteStartObject(); + foreach (var item in Metadata) + { + writer.WritePropertyName(item.Key); + writer.WriteStringValue(item.Value); + } + writer.WriteEndObject(); + } + else + { + writer.WriteNull("metadata"); } - writer.WriteEndObject(); } writer.WriteEndObject(); } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateMessageRequest.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateMessageRequest.cs index 5816540bf0c0..5104620eb279 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateMessageRequest.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateMessageRequest.cs @@ -48,6 +48,6 @@ internal CreateMessageRequest(MessageRole role, string content, IList fi /// A list of up to 10 file IDs to associate with the message, as used by tools like 'code_interpreter' or 'retrieval' that can read files. public IList FileIds { get; } /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. - public IDictionary Metadata { get; } + public IDictionary Metadata { get; set; } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateRunRequest.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateRunRequest.Serialization.cs index 267ef15e4207..efc7a9938301 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateRunRequest.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateRunRequest.Serialization.cs @@ -39,14 +39,21 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) } if (Optional.IsCollectionDefined(Metadata)) { - writer.WritePropertyName("metadata"u8); - writer.WriteStartObject(); - foreach (var item in Metadata) + if (Metadata != null) { - writer.WritePropertyName(item.Key); - writer.WriteStringValue(item.Value); + writer.WritePropertyName("metadata"u8); + writer.WriteStartObject(); + foreach (var item in Metadata) + { + writer.WritePropertyName(item.Key); + writer.WriteStringValue(item.Value); + } + writer.WriteEndObject(); + } + else + { + writer.WriteNull("metadata"); } - writer.WriteEndObject(); } writer.WriteEndObject(); } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateRunRequest.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateRunRequest.cs index 7704913f9bfd..62c1f406617c 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateRunRequest.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateRunRequest.cs @@ -28,7 +28,7 @@ public CreateRunRequest(string assistantId) /// Initializes a new instance of . /// The ID of the assistant that should run the thread. - /// The overriden model name that the assistant should use to run the thread. + /// The overridden model name that the assistant should use to run the thread. /// The overridden system instructions that the assistant should use to run the thread. /// The overridden list of enabled tools that the assistant should use to run the thread. /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. @@ -43,7 +43,7 @@ internal CreateRunRequest(string assistantId, string overrideModelName, string o /// The ID of the assistant that should run the thread. public string AssistantId { get; } - /// The overriden model name that the assistant should use to run the thread. + /// The overridden model name that the assistant should use to run the thread. public string OverrideModelName { get; set; } /// The overridden system instructions that the assistant should use to run the thread. public string OverrideInstructions { get; set; } @@ -54,6 +54,6 @@ internal CreateRunRequest(string assistantId, string overrideModelName, string o /// public IList OverrideTools { get; } /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. - public IDictionary Metadata { get; } + public IDictionary Metadata { get; set; } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalAssistantDeletionStatus.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalAssistantDeletionStatus.Serialization.cs index 0c0f7fd2d63c..bd41ced8d2ee 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalAssistantDeletionStatus.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalAssistantDeletionStatus.Serialization.cs @@ -18,13 +18,14 @@ internal static InternalAssistantDeletionStatus DeserializeInternalAssistantDele { return null; } - InternalAssistantDeletionStatusObject @object = default; + string id = default; bool deleted = default; + InternalAssistantDeletionStatusObject @object = default; foreach (var property in element.EnumerateObject()) { - if (property.NameEquals("object"u8)) + if (property.NameEquals("id"u8)) { - @object = new InternalAssistantDeletionStatusObject(property.Value.GetString()); + id = property.Value.GetString(); continue; } if (property.NameEquals("deleted"u8)) @@ -32,8 +33,13 @@ internal static InternalAssistantDeletionStatus DeserializeInternalAssistantDele deleted = property.Value.GetBoolean(); continue; } + if (property.NameEquals("object"u8)) + { + @object = new InternalAssistantDeletionStatusObject(property.Value.GetString()); + continue; + } } - return new InternalAssistantDeletionStatus(deleted, @object); + return new InternalAssistantDeletionStatus(id, deleted, @object); } /// Deserializes the model from a raw response. diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalAssistantDeletionStatus.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalAssistantDeletionStatus.cs index e7dcf0da2c00..7bca21ba1f4c 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalAssistantDeletionStatus.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalAssistantDeletionStatus.cs @@ -5,25 +5,41 @@ #nullable disable +using System; +using Azure.Core; + namespace Azure.AI.OpenAI.Assistants { /// The status of an assistant deletion operation. - internal partial class InternalAssistantDeletionStatus : InternalDeletionStatus + internal partial class InternalAssistantDeletionStatus { /// Initializes a new instance of . + /// The ID of the resource specified for deletion. /// A value indicating whether deletion was successful. - internal InternalAssistantDeletionStatus(bool deleted) : base(deleted) + /// is null. + internal InternalAssistantDeletionStatus(string id, bool deleted) { + Argument.AssertNotNull(id, nameof(id)); + + Id = id; + Deleted = deleted; } /// Initializes a new instance of . + /// The ID of the resource specified for deletion. /// A value indicating whether deletion was successful. /// The object type, which is always 'assistant.deleted'. - internal InternalAssistantDeletionStatus(bool deleted, InternalAssistantDeletionStatusObject @object) : base(deleted) + internal InternalAssistantDeletionStatus(string id, bool deleted, InternalAssistantDeletionStatusObject @object) { + Id = id; + Deleted = deleted; Object = @object; } + /// The ID of the resource specified for deletion. + public string Id { get; } + /// A value indicating whether deletion was successful. + public bool Deleted { get; } /// The object type, which is always 'assistant.deleted'. public InternalAssistantDeletionStatusObject Object { get; } = InternalAssistantDeletionStatusObject.AssistantDeleted; } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalAssistantFileDeletionStatus.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalAssistantFileDeletionStatus.Serialization.cs index d7367e77eea3..432a715fae3d 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalAssistantFileDeletionStatus.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalAssistantFileDeletionStatus.Serialization.cs @@ -18,13 +18,14 @@ internal static InternalAssistantFileDeletionStatus DeserializeInternalAssistant { return null; } - InternalAssistantFileDeletionStatusObject @object = default; + string id = default; bool deleted = default; + InternalAssistantFileDeletionStatusObject @object = default; foreach (var property in element.EnumerateObject()) { - if (property.NameEquals("object"u8)) + if (property.NameEquals("id"u8)) { - @object = new InternalAssistantFileDeletionStatusObject(property.Value.GetString()); + id = property.Value.GetString(); continue; } if (property.NameEquals("deleted"u8)) @@ -32,8 +33,13 @@ internal static InternalAssistantFileDeletionStatus DeserializeInternalAssistant deleted = property.Value.GetBoolean(); continue; } + if (property.NameEquals("object"u8)) + { + @object = new InternalAssistantFileDeletionStatusObject(property.Value.GetString()); + continue; + } } - return new InternalAssistantFileDeletionStatus(deleted, @object); + return new InternalAssistantFileDeletionStatus(id, deleted, @object); } /// Deserializes the model from a raw response. diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalAssistantFileDeletionStatus.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalAssistantFileDeletionStatus.cs index ad3c552bd138..709247cf8a33 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalAssistantFileDeletionStatus.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalAssistantFileDeletionStatus.cs @@ -5,25 +5,41 @@ #nullable disable +using System; +using Azure.Core; + namespace Azure.AI.OpenAI.Assistants { /// The status of an assistant file deletion operation. - internal partial class InternalAssistantFileDeletionStatus : InternalDeletionStatus + internal partial class InternalAssistantFileDeletionStatus { /// Initializes a new instance of . + /// The ID of the resource specified for deletion. /// A value indicating whether deletion was successful. - internal InternalAssistantFileDeletionStatus(bool deleted) : base(deleted) + /// is null. + internal InternalAssistantFileDeletionStatus(string id, bool deleted) { + Argument.AssertNotNull(id, nameof(id)); + + Id = id; + Deleted = deleted; } /// Initializes a new instance of . + /// The ID of the resource specified for deletion. /// A value indicating whether deletion was successful. /// The object type, which is always 'assistant.file.deleted'. - internal InternalAssistantFileDeletionStatus(bool deleted, InternalAssistantFileDeletionStatusObject @object) : base(deleted) + internal InternalAssistantFileDeletionStatus(string id, bool deleted, InternalAssistantFileDeletionStatusObject @object) { + Id = id; + Deleted = deleted; Object = @object; } + /// The ID of the resource specified for deletion. + public string Id { get; } + /// A value indicating whether deletion was successful. + public bool Deleted { get; } /// The object type, which is always 'assistant.file.deleted'. public InternalAssistantFileDeletionStatusObject Object { get; } = InternalAssistantFileDeletionStatusObject.AssistantFileDeleted; } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalDeletionStatus.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalDeletionStatus.cs deleted file mode 100644 index 6ef9d256b527..000000000000 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalDeletionStatus.cs +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -namespace Azure.AI.OpenAI.Assistants -{ - /// An abstract representation of an OpenAI deletion operation result status. - internal partial class InternalDeletionStatus - { - /// Initializes a new instance of . - /// A value indicating whether deletion was successful. - internal InternalDeletionStatus(bool deleted) - { - Deleted = deleted; - } - - /// A value indicating whether deletion was successful. - public bool Deleted { get; } - } -} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFileDeletionStatus.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFileDeletionStatus.Serialization.cs index 38b3bc738c01..334de061442a 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFileDeletionStatus.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFileDeletionStatus.Serialization.cs @@ -18,16 +18,11 @@ internal static InternalFileDeletionStatus DeserializeInternalFileDeletionStatus { return null; } - InternalFileDeletionStatusObject @object = default; string id = default; bool deleted = default; + InternalFileDeletionStatusObject @object = default; foreach (var property in element.EnumerateObject()) { - if (property.NameEquals("object"u8)) - { - @object = new InternalFileDeletionStatusObject(property.Value.GetString()); - continue; - } if (property.NameEquals("id"u8)) { id = property.Value.GetString(); @@ -38,8 +33,13 @@ internal static InternalFileDeletionStatus DeserializeInternalFileDeletionStatus deleted = property.Value.GetBoolean(); continue; } + if (property.NameEquals("object"u8)) + { + @object = new InternalFileDeletionStatusObject(property.Value.GetString()); + continue; + } } - return new InternalFileDeletionStatus(deleted, @object, id); + return new InternalFileDeletionStatus(id, deleted, @object); } /// Deserializes the model from a raw response. diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFileDeletionStatus.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFileDeletionStatus.cs index 765e44d5763b..4770a27ceda4 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFileDeletionStatus.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFileDeletionStatus.cs @@ -11,33 +11,36 @@ namespace Azure.AI.OpenAI.Assistants { /// A status response from a file deletion operation. - internal partial class InternalFileDeletionStatus : InternalDeletionStatus + internal partial class InternalFileDeletionStatus { /// Initializes a new instance of . + /// The ID of the resource specified for deletion. /// A value indicating whether deletion was successful. - /// The ID of the deleted file. /// is null. - internal InternalFileDeletionStatus(bool deleted, string id) : base(deleted) + internal InternalFileDeletionStatus(string id, bool deleted) { Argument.AssertNotNull(id, nameof(id)); Id = id; + Deleted = deleted; } /// Initializes a new instance of . + /// The ID of the resource specified for deletion. /// A value indicating whether deletion was successful. /// The object type, which is always 'file'. - /// The ID of the deleted file. - internal InternalFileDeletionStatus(bool deleted, InternalFileDeletionStatusObject @object, string id) : base(deleted) + internal InternalFileDeletionStatus(string id, bool deleted, InternalFileDeletionStatusObject @object) { - Object = @object; Id = id; + Deleted = deleted; + Object = @object; } + /// The ID of the resource specified for deletion. + public string Id { get; } + /// A value indicating whether deletion was successful. + public bool Deleted { get; } /// The object type, which is always 'file'. public InternalFileDeletionStatusObject Object { get; } = InternalFileDeletionStatusObject.File; - - /// The ID of the deleted file. - public string Id { get; } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFunctionDefinition.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFunctionDefinition.Serialization.cs index 11a35348bb0a..4e6e43d5897f 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFunctionDefinition.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFunctionDefinition.Serialization.cs @@ -19,8 +19,11 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) writer.WriteStartObject(); writer.WritePropertyName("name"u8); writer.WriteStringValue(Name); - writer.WritePropertyName("description"u8); - writer.WriteStringValue(Description); + if (Optional.IsDefined(Description)) + { + writer.WritePropertyName("description"u8); + writer.WriteStringValue(Description); + } writer.WritePropertyName("parameters"u8); #if NET6_0_OR_GREATER writer.WriteRawValue(Parameters); @@ -40,7 +43,7 @@ internal static InternalFunctionDefinition DeserializeInternalFunctionDefinition return null; } string name = default; - string description = default; + Optional description = default; BinaryData parameters = default; foreach (var property in element.EnumerateObject()) { @@ -60,7 +63,7 @@ internal static InternalFunctionDefinition DeserializeInternalFunctionDefinition continue; } } - return new InternalFunctionDefinition(name, description, parameters); + return new InternalFunctionDefinition(name, description.Value, parameters); } /// Deserializes the model from a raw response. diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFunctionDefinition.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFunctionDefinition.cs index dcd47a942e97..9202e6a4df87 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFunctionDefinition.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFunctionDefinition.cs @@ -15,15 +15,23 @@ internal partial class InternalFunctionDefinition { /// Initializes a new instance of . /// The name of the function to be called. - /// A description of what the function does, used by the model to choose when and how to call the function. /// The parameters the functions accepts, described as a JSON Schema object. - /// , or is null. - public InternalFunctionDefinition(string name, string description, BinaryData parameters) + /// or is null. + public InternalFunctionDefinition(string name, BinaryData parameters) { Argument.AssertNotNull(name, nameof(name)); - Argument.AssertNotNull(description, nameof(description)); Argument.AssertNotNull(parameters, nameof(parameters)); + Name = name; + Parameters = parameters; + } + + /// Initializes a new instance of . + /// The name of the function to be called. + /// A description of what the function does, used by the model to choose when and how to call the function. + /// The parameters the functions accepts, described as a JSON Schema object. + internal InternalFunctionDefinition(string name, string description, BinaryData parameters) + { Name = name; Description = description; Parameters = parameters; diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFunctionToolCallDetails.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFunctionToolCallDetails.Serialization.cs index 4b2bfb1e5743..7215403be309 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFunctionToolCallDetails.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFunctionToolCallDetails.Serialization.cs @@ -7,7 +7,6 @@ using System.Text.Json; using Azure; -using Azure.Core; namespace Azure.AI.OpenAI.Assistants { @@ -21,7 +20,7 @@ internal static InternalFunctionToolCallDetails DeserializeInternalFunctionToolC } string name = default; string arguments = default; - Optional output = default; + string output = default; foreach (var property in element.EnumerateObject()) { if (property.NameEquals("name"u8)) @@ -45,7 +44,7 @@ internal static InternalFunctionToolCallDetails DeserializeInternalFunctionToolC continue; } } - return new InternalFunctionToolCallDetails(name, arguments, output.Value); + return new InternalFunctionToolCallDetails(name, arguments, output); } /// Deserializes the model from a raw response. diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFunctionToolCallDetails.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFunctionToolCallDetails.cs index 1fb8fec11e3c..ae250e18735a 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFunctionToolCallDetails.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFunctionToolCallDetails.cs @@ -16,24 +16,15 @@ internal partial class InternalFunctionToolCallDetails /// Initializes a new instance of . /// The name of the function. /// The arguments that the model requires are provided to the named function. + /// The output of the function, only populated for function calls that have already have had their outputs submitted. /// or is null. - internal InternalFunctionToolCallDetails(string name, string arguments) + internal InternalFunctionToolCallDetails(string name, string arguments, string output) { Argument.AssertNotNull(name, nameof(name)); Argument.AssertNotNull(arguments, nameof(arguments)); Name = name; Arguments = arguments; - } - - /// Initializes a new instance of . - /// The name of the function. - /// The arguments that the model requires are provided to the named function. - /// The output of the function, only populated for function calls that have already have had their outputs submitted. - internal InternalFunctionToolCallDetails(string name, string arguments, string output) - { - Name = name; - Arguments = arguments; Output = output; } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ModifyMessageRequest.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ModifyMessageRequest.Serialization.cs index 29b24626f995..e4560cc47ead 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ModifyMessageRequest.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ModifyMessageRequest.Serialization.cs @@ -17,14 +17,21 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) writer.WriteStartObject(); if (Optional.IsCollectionDefined(Metadata)) { - writer.WritePropertyName("metadata"u8); - writer.WriteStartObject(); - foreach (var item in Metadata) + if (Metadata != null) { - writer.WritePropertyName(item.Key); - writer.WriteStringValue(item.Value); + writer.WritePropertyName("metadata"u8); + writer.WriteStartObject(); + foreach (var item in Metadata) + { + writer.WritePropertyName(item.Key); + writer.WriteStringValue(item.Value); + } + writer.WriteEndObject(); + } + else + { + writer.WriteNull("metadata"); } - writer.WriteEndObject(); } writer.WriteEndObject(); } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ModifyMessageRequest.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ModifyMessageRequest.cs index 148e4f317cf9..eb58a3742ceb 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ModifyMessageRequest.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ModifyMessageRequest.cs @@ -27,6 +27,6 @@ internal ModifyMessageRequest(IDictionary metadata) } /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. - public IDictionary Metadata { get; } + public IDictionary Metadata { get; set; } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ModifyRunRequest.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ModifyRunRequest.Serialization.cs index 5510dc7b6854..1153d53c570e 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ModifyRunRequest.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ModifyRunRequest.Serialization.cs @@ -17,14 +17,21 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) writer.WriteStartObject(); if (Optional.IsCollectionDefined(Metadata)) { - writer.WritePropertyName("metadata"u8); - writer.WriteStartObject(); - foreach (var item in Metadata) + if (Metadata != null) { - writer.WritePropertyName(item.Key); - writer.WriteStringValue(item.Value); + writer.WritePropertyName("metadata"u8); + writer.WriteStartObject(); + foreach (var item in Metadata) + { + writer.WritePropertyName(item.Key); + writer.WriteStringValue(item.Value); + } + writer.WriteEndObject(); + } + else + { + writer.WriteNull("metadata"); } - writer.WriteEndObject(); } writer.WriteEndObject(); } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ModifyRunRequest.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ModifyRunRequest.cs index b19db8333b70..dafa9161c384 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ModifyRunRequest.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ModifyRunRequest.cs @@ -27,6 +27,6 @@ internal ModifyRunRequest(IDictionary metadata) } /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. - public IDictionary Metadata { get; } + public IDictionary Metadata { get; set; } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ModifyThreadRequest.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ModifyThreadRequest.Serialization.cs index a650610cfdb9..b3bb6ec74101 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ModifyThreadRequest.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ModifyThreadRequest.Serialization.cs @@ -17,14 +17,21 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) writer.WriteStartObject(); if (Optional.IsCollectionDefined(Metadata)) { - writer.WritePropertyName("metadata"u8); - writer.WriteStartObject(); - foreach (var item in Metadata) + if (Metadata != null) { - writer.WritePropertyName(item.Key); - writer.WriteStringValue(item.Value); + writer.WritePropertyName("metadata"u8); + writer.WriteStartObject(); + foreach (var item in Metadata) + { + writer.WritePropertyName(item.Key); + writer.WriteStringValue(item.Value); + } + writer.WriteEndObject(); + } + else + { + writer.WriteNull("metadata"); } - writer.WriteEndObject(); } writer.WriteEndObject(); } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ModifyThreadRequest.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ModifyThreadRequest.cs index 63a52be45415..f5aec238ed54 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ModifyThreadRequest.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ModifyThreadRequest.cs @@ -27,6 +27,6 @@ internal ModifyThreadRequest(IDictionary metadata) } /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. - public IDictionary Metadata { get; } + public IDictionary Metadata { get; set; } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStep.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStep.Serialization.cs index a57e579382eb..ad34cf9cb5e1 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStep.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStep.Serialization.cs @@ -35,7 +35,7 @@ internal static RunStep DeserializeRunStep(JsonElement element) DateTimeOffset? completedAt = default; DateTimeOffset? cancelledAt = default; DateTimeOffset? failedAt = default; - Optional> metadata = default; + IReadOnlyDictionary metadata = default; foreach (var property in element.EnumerateObject()) { if (property.NameEquals("id"u8)) @@ -117,6 +117,7 @@ internal static RunStep DeserializeRunStep(JsonElement element) { if (property.Value.ValueKind == JsonValueKind.Null) { + metadata = new ChangeTrackingDictionary(); continue; } Dictionary dictionary = new Dictionary(); @@ -128,7 +129,7 @@ internal static RunStep DeserializeRunStep(JsonElement element) continue; } } - return new RunStep(id, @object, type, assistantId, threadId, runId, status, stepDetails, lastError, createdAt, expiredAt, completedAt, cancelledAt, failedAt, Optional.ToDictionary(metadata)); + return new RunStep(id, @object, type, assistantId, threadId, runId, status, stepDetails, lastError, createdAt, expiredAt, completedAt, cancelledAt, failedAt, metadata); } /// Deserializes the model from a raw response. diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStep.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStep.cs index 352aa566ae40..c6476b44a586 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStep.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStep.cs @@ -28,8 +28,9 @@ public partial class RunStep /// The Unix timestamp, in seconds, representing when this completed. /// The Unix timestamp, in seconds, representing when this was cancelled. /// The Unix timestamp, in seconds, representing when this failed. + /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. /// , , , or is null. - internal RunStep(string id, RunStepType type, string assistantId, string threadId, string runId, RunStepStatus status, RunStepDetails stepDetails, RunStepError lastError, DateTimeOffset createdAt, DateTimeOffset? expiredAt, DateTimeOffset? completedAt, DateTimeOffset? cancelledAt, DateTimeOffset? failedAt) + internal RunStep(string id, RunStepType type, string assistantId, string threadId, string runId, RunStepStatus status, RunStepDetails stepDetails, RunStepError lastError, DateTimeOffset createdAt, DateTimeOffset? expiredAt, DateTimeOffset? completedAt, DateTimeOffset? cancelledAt, DateTimeOffset? failedAt, IReadOnlyDictionary metadata) { Argument.AssertNotNull(id, nameof(id)); Argument.AssertNotNull(assistantId, nameof(assistantId)); @@ -50,7 +51,7 @@ internal RunStep(string id, RunStepType type, string assistantId, string threadI CompletedAt = completedAt; CancelledAt = cancelledAt; FailedAt = failedAt; - Metadata = new ChangeTrackingDictionary(); + Metadata = metadata; } /// Initializes a new instance of . diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/SubmitRunToolOutputsRequest.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/SubmitToolOutputsToRunRequest.Serialization.cs similarity index 92% rename from sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/SubmitRunToolOutputsRequest.Serialization.cs rename to sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/SubmitToolOutputsToRunRequest.Serialization.cs index 009950b7223b..d6db7a7e06ed 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/SubmitRunToolOutputsRequest.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/SubmitToolOutputsToRunRequest.Serialization.cs @@ -10,7 +10,7 @@ namespace Azure.AI.OpenAI.Assistants { - internal partial class SubmitRunToolOutputsRequest : IUtf8JsonSerializable + internal partial class SubmitToolOutputsToRunRequest : IUtf8JsonSerializable { void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) { diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/SubmitRunToolOutputsRequest.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/SubmitToolOutputsToRunRequest.cs similarity index 75% rename from sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/SubmitRunToolOutputsRequest.cs rename to sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/SubmitToolOutputsToRunRequest.cs index 70cc463b347f..45e5cd8b047c 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/SubmitRunToolOutputsRequest.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/SubmitToolOutputsToRunRequest.cs @@ -12,22 +12,22 @@ namespace Azure.AI.OpenAI.Assistants { - /// The SubmitRunToolOutputsRequest. - internal partial class SubmitRunToolOutputsRequest + /// The SubmitToolOutputsToRunRequest. + internal partial class SubmitToolOutputsToRunRequest { - /// Initializes a new instance of . + /// Initializes a new instance of . /// The list of tool outputs requested by tool calls from the specified run. /// is null. - public SubmitRunToolOutputsRequest(IEnumerable toolOutputs) + public SubmitToolOutputsToRunRequest(IEnumerable toolOutputs) { Argument.AssertNotNull(toolOutputs, nameof(toolOutputs)); ToolOutputs = toolOutputs.ToList(); } - /// Initializes a new instance of . + /// Initializes a new instance of . /// The list of tool outputs requested by tool calls from the specified run. - internal SubmitRunToolOutputsRequest(IList toolOutputs) + internal SubmitToolOutputsToRunRequest(IList toolOutputs) { ToolOutputs = toolOutputs; } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadDeletionStatus.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadDeletionStatus.Serialization.cs index 06416e70637a..ba0871f60dc1 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadDeletionStatus.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadDeletionStatus.Serialization.cs @@ -18,13 +18,14 @@ internal static ThreadDeletionStatus DeserializeThreadDeletionStatus(JsonElement { return null; } - ThreadDeletionStatusObject @object = default; + string id = default; bool deleted = default; + ThreadDeletionStatusObject @object = default; foreach (var property in element.EnumerateObject()) { - if (property.NameEquals("object"u8)) + if (property.NameEquals("id"u8)) { - @object = new ThreadDeletionStatusObject(property.Value.GetString()); + id = property.Value.GetString(); continue; } if (property.NameEquals("deleted"u8)) @@ -32,8 +33,13 @@ internal static ThreadDeletionStatus DeserializeThreadDeletionStatus(JsonElement deleted = property.Value.GetBoolean(); continue; } + if (property.NameEquals("object"u8)) + { + @object = new ThreadDeletionStatusObject(property.Value.GetString()); + continue; + } } - return new ThreadDeletionStatus(deleted, @object); + return new ThreadDeletionStatus(id, deleted, @object); } /// Deserializes the model from a raw response. diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadDeletionStatus.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadDeletionStatus.cs index 1fbeebd9489c..b75cd3499f16 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadDeletionStatus.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadDeletionStatus.cs @@ -5,25 +5,41 @@ #nullable disable +using System; +using Azure.Core; + namespace Azure.AI.OpenAI.Assistants { /// The status of a thread deletion operation. - internal partial class ThreadDeletionStatus : InternalDeletionStatus + internal partial class ThreadDeletionStatus { /// Initializes a new instance of . + /// The ID of the resource specified for deletion. /// A value indicating whether deletion was successful. - internal ThreadDeletionStatus(bool deleted) : base(deleted) + /// is null. + internal ThreadDeletionStatus(string id, bool deleted) { + Argument.AssertNotNull(id, nameof(id)); + + Id = id; + Deleted = deleted; } /// Initializes a new instance of . + /// The ID of the resource specified for deletion. /// A value indicating whether deletion was successful. /// The object type, which is always 'thread.deleted'. - internal ThreadDeletionStatus(bool deleted, ThreadDeletionStatusObject @object) : base(deleted) + internal ThreadDeletionStatus(string id, bool deleted, ThreadDeletionStatusObject @object) { + Id = id; + Deleted = deleted; Object = @object; } + /// The ID of the resource specified for deletion. + public string Id { get; } + /// A value indicating whether deletion was successful. + public bool Deleted { get; } /// The object type, which is always 'thread.deleted'. public ThreadDeletionStatusObject Object { get; } = ThreadDeletionStatusObject.ThreadDeleted; } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadMessage.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadMessage.Serialization.cs index f180c703bb2b..6e44b0b5c8b7 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadMessage.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadMessage.Serialization.cs @@ -52,7 +52,7 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) writer.WriteStringValue(item); } writer.WriteEndArray(); - if (Optional.IsCollectionDefined(Metadata)) + if (Metadata != null && Optional.IsCollectionDefined(Metadata)) { writer.WritePropertyName("metadata"u8); writer.WriteStartObject(); @@ -63,6 +63,10 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) } writer.WriteEndObject(); } + else + { + writer.WriteNull("metadata"); + } writer.WriteEndObject(); } @@ -81,7 +85,7 @@ internal static ThreadMessage DeserializeThreadMessage(JsonElement element) Optional assistantId = default; Optional runId = default; IList fileIds = default; - Optional> metadata = default; + IDictionary metadata = default; foreach (var property in element.EnumerateObject()) { if (property.NameEquals("id"u8)) @@ -143,6 +147,7 @@ internal static ThreadMessage DeserializeThreadMessage(JsonElement element) { if (property.Value.ValueKind == JsonValueKind.Null) { + metadata = new ChangeTrackingDictionary(); continue; } Dictionary dictionary = new Dictionary(); @@ -154,7 +159,7 @@ internal static ThreadMessage DeserializeThreadMessage(JsonElement element) continue; } } - return new ThreadMessage(id, @object, createdAt, threadId, role, content, assistantId.Value, runId.Value, fileIds, Optional.ToDictionary(metadata)); + return new ThreadMessage(id, @object, createdAt, threadId, role, content, assistantId.Value, runId.Value, fileIds, metadata); } /// Deserializes the model from a raw response. diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadMessage.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadMessage.cs index d65e66effcbe..c2e6b7f2e929 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadMessage.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadMessage.cs @@ -25,8 +25,9 @@ public partial class ThreadMessage /// A list of file IDs that the assistant should use. Useful for tools like retrieval and code_interpreter that can /// access files. /// + /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. /// , , or is null. - public ThreadMessage(string id, DateTimeOffset createdAt, string threadId, MessageRole role, IEnumerable contentItems, IEnumerable fileIds) + public ThreadMessage(string id, DateTimeOffset createdAt, string threadId, MessageRole role, IEnumerable contentItems, IEnumerable fileIds, IDictionary metadata) { Argument.AssertNotNull(id, nameof(id)); Argument.AssertNotNull(threadId, nameof(threadId)); @@ -39,7 +40,7 @@ public ThreadMessage(string id, DateTimeOffset createdAt, string threadId, Messa Role = role; ContentItems = contentItems.ToList(); FileIds = fileIds.ToList(); - Metadata = new ChangeTrackingDictionary(); + Metadata = metadata; } /// Initializes a new instance of . @@ -95,6 +96,6 @@ internal ThreadMessage(string id, string @object, DateTimeOffset createdAt, stri /// public IList FileIds { get; } /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. - public IDictionary Metadata { get; } + public IDictionary Metadata { get; set; } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadRun.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadRun.Serialization.cs index 57bfbea090bf..35c0283a6e32 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadRun.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadRun.Serialization.cs @@ -38,7 +38,7 @@ internal static ThreadRun DeserializeThreadRun(JsonElement element) DateTimeOffset? completedAt = default; DateTimeOffset? cancelledAt = default; DateTimeOffset? failedAt = default; - Optional> metadata = default; + IReadOnlyDictionary metadata = default; foreach (var property in element.EnumerateObject()) { if (property.NameEquals("id"u8)) @@ -150,6 +150,7 @@ internal static ThreadRun DeserializeThreadRun(JsonElement element) { if (property.Value.ValueKind == JsonValueKind.Null) { + metadata = new ChangeTrackingDictionary(); continue; } Dictionary dictionary = new Dictionary(); @@ -161,7 +162,7 @@ internal static ThreadRun DeserializeThreadRun(JsonElement element) continue; } } - return new ThreadRun(id, @object, threadId, assistantId, status, requiredAction.Value, lastError, model, instructions, tools, fileIds, createdAt, expiresAt, startedAt, completedAt, cancelledAt, failedAt, Optional.ToDictionary(metadata)); + return new ThreadRun(id, @object, threadId, assistantId, status, requiredAction.Value, lastError, model, instructions, tools, fileIds, createdAt, expiresAt, startedAt, completedAt, cancelledAt, failedAt, metadata); } /// Deserializes the model from a raw response. diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadRun.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadRun.cs index 2c8f3ab85bd7..bc2175644c1a 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadRun.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadRun.cs @@ -31,8 +31,9 @@ public partial class ThreadRun /// The Unix timestamp, in seconds, representing when this completed. /// The Unix timestamp, in seconds, representing when this was cancelled. /// The Unix timestamp, in seconds, representing when this failed. + /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. /// , , , , , or is null. - internal ThreadRun(string id, string threadId, string assistantId, RunStatus status, RunError lastError, string model, string instructions, IEnumerable tools, IEnumerable fileIds, DateTimeOffset createdAt, DateTimeOffset? expiresAt, DateTimeOffset? startedAt, DateTimeOffset? completedAt, DateTimeOffset? cancelledAt, DateTimeOffset? failedAt) + internal ThreadRun(string id, string threadId, string assistantId, RunStatus status, RunError lastError, string model, string instructions, IEnumerable tools, IEnumerable fileIds, DateTimeOffset createdAt, DateTimeOffset? expiresAt, DateTimeOffset? startedAt, DateTimeOffset? completedAt, DateTimeOffset? cancelledAt, DateTimeOffset? failedAt, IReadOnlyDictionary metadata) { Argument.AssertNotNull(id, nameof(id)); Argument.AssertNotNull(threadId, nameof(threadId)); @@ -57,7 +58,7 @@ internal ThreadRun(string id, string threadId, string assistantId, RunStatus sta CompletedAt = completedAt; CancelledAt = cancelledAt; FailedAt = failedAt; - Metadata = new ChangeTrackingDictionary(); + Metadata = metadata; } /// Initializes a new instance of . diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/tests/AssistantsTests.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/tests/AssistantsTests.cs index 797aeeaad2ca..cf8574a6c824 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/tests/AssistantsTests.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/tests/AssistantsTests.cs @@ -54,7 +54,7 @@ Response assistantCreationResponse // Retrieve the assistant we just created to ensure it's the same Response retrievalResponse - = await client.RetrieveAssistantAsync(assistantCreationResponse.Value.Id); + = await client.GetAssistantAsync(assistantCreationResponse.Value.Id); AssertSuccessfulResponse(retrievalResponse); Assert.That(retrievalResponse.Value.Id, Is.EqualTo(assistantCreationResponse.Value.Id)); @@ -109,7 +109,7 @@ Response threadCreationResponse EnsuredThreadDeletions.Add((client, thread.Id)); Assert.That(thread.Metadata.Contains(TestMetadataPair)); - Response retrievalResponse = await client.RetrieveThreadAsync(thread.Id); + Response retrievalResponse = await client.GetThreadAsync(thread.Id); AssertSuccessfulResponse(retrievalResponse); Assert.That(retrievalResponse.Value.Id, Is.EqualTo(thread.Id)); @@ -142,7 +142,7 @@ Response threadCreationResponse AssertSuccessfulResponse(messageCreationResponse); Response retrievalResponse - = await client.RetrieveMessageAsync( + = await client.GetMessageAsync( threadCreationResponse.Value.Id, messageCreationResponse.Value.Id); AssertSuccessfulResponse(retrievalResponse); @@ -160,7 +160,7 @@ Response modificationResponse }); AssertSuccessfulResponse(modificationResponse); - retrievalResponse = await client.RetrieveMessageAsync( + retrievalResponse = await client.GetMessageAsync( threadCreationResponse.Value.Id, messageCreationResponse.Value.Id); AssertSuccessfulResponse(retrievalResponse); @@ -225,7 +225,7 @@ Response threadCreationResponse do { await Task.Delay(500); - Response runRetrievalResponse = await client.RetrieveRunAsync(thread.Id, run.Id); + Response runRetrievalResponse = await client.GetRunAsync(thread.Id, run.Id); AssertSuccessfulResponse(runRetrievalResponse); run = runRetrievalResponse.Value; } @@ -282,7 +282,7 @@ Response threadCreationResponse Assert.That(stepDetails.MessageCreation.MessageId, Is.EqualTo(messages[0].Id)); // Check that we can retrieve the same run step - Response runStepRetrievalResponse = await client.RetrieveRunStepAsync(thread.Id, run.Id, runSteps[0].Id); + Response runStepRetrievalResponse = await client.GetRunStepAsync(thread.Id, run.Id, runSteps[0].Id); AssertSuccessfulResponse(runStepRetrievalResponse); // Delete the assistant we created diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/tests/FunctionsTests.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/tests/FunctionsTests.cs index f7a0b29588f4..614275e11052 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/tests/FunctionsTests.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/tests/FunctionsTests.cs @@ -117,7 +117,7 @@ Response threadCreationResponse do { await Task.Delay(500); - Response runRetrievalResponse = await client.RetrieveRunAsync(thread.Id, run.Id); + Response runRetrievalResponse = await client.GetRunAsync(thread.Id, run.Id); AssertSuccessfulResponse(runRetrievalResponse); run = runRetrievalResponse.Value; } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/tests/Samples/Samples_AssistantsClient.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/tests/Samples/Samples_AssistantsClient.cs index a0684a021f8a..0fde8cbf9b6b 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/tests/Samples/Samples_AssistantsClient.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/tests/Samples/Samples_AssistantsClient.cs @@ -82,7 +82,7 @@ public async Task OverviewSample() do { await Task.Delay(TimeSpan.FromMilliseconds(500)); - runResponse = await client.RetrieveRunAsync(thread.Id, runResponse.Value.Id); + runResponse = await client.GetRunAsync(thread.Id, runResponse.Value.Id); } while (runResponse.Value.Status == RunStatus.Queued || runResponse.Value.Status == RunStatus.InProgress); diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/tests/Samples/Samples_Functions.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/tests/Samples/Samples_Functions.cs index ce17482ad444..92c9af5b3c94 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/tests/Samples/Samples_Functions.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/tests/Samples/Samples_Functions.cs @@ -151,17 +151,17 @@ ToolOutput GetResolvedToolOutput(ToolCall toolCall) do { await Task.Delay(TimeSpan.FromMilliseconds(500)); - runResponse = await client.RetrieveRunAsync(thread.Id, runResponse.Value.Id); + runResponse = await client.GetRunAsync(thread.Id, runResponse.Value.Id); if (runResponse.Value.Status == RunStatus.RequiresAction && runResponse.Value.RequiredAction is SubmitToolOutputsAction submitToolOutputsAction) { List toolOutputs = new(); - foreach (var toolCall in submitToolOutputsAction.ToolCalls) + foreach (ToolCall toolCall in submitToolOutputsAction.ToolCalls) { toolOutputs.Add(GetResolvedToolOutput(toolCall)); } - runResponse = await client.SubmitRunToolOutputsAsync(runResponse.Value, toolOutputs); + runResponse = await client.SubmitToolOutputsToRunAsync(runResponse.Value, toolOutputs); } } while (runResponse.Value.Status == RunStatus.Queued diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/tests/Samples/Samples_Retrieval.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/tests/Samples/Samples_Retrieval.cs index 02eead7efd54..e764dae4fa46 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/tests/Samples/Samples_Retrieval.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/tests/Samples/Samples_Retrieval.cs @@ -66,7 +66,7 @@ public async Task AssistantsWithFilesSample() do { await Task.Delay(TimeSpan.FromMilliseconds(500)); - runResponse = await client.RetrieveRunAsync(thread.Id, runResponse.Value.Id); + runResponse = await client.GetRunAsync(thread.Id, runResponse.Value.Id); } while (runResponse.Value.Status == RunStatus.Queued || runResponse.Value.Status == RunStatus.InProgress); diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/tsp-location.yaml b/sdk/openai/Azure.AI.OpenAI.Assistants/tsp-location.yaml index 0381021233a2..2a94050c8d5f 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/tsp-location.yaml +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/tsp-location.yaml @@ -1,3 +1,3 @@ directory: specification/ai/OpenAI.Assistants -commit: 7b3bafb8c3220e9873e341b1a70abd57ef69b656 +commit: 84706e624d4949548865f965378052578f011b77 repo: Azure/azure-rest-api-specs From f427cd94635e9fb9f4c1ba128ebca5b2827ca76f Mon Sep 17 00:00:00 2001 From: Travis Wilson <35748617+trrwilson@users.noreply.github.com> Date: Fri, 12 Jan 2024 14:44:12 -0800 Subject: [PATCH 05/15] update for assets.json test automation --- sdk/openai/Azure.AI.OpenAI.Assistants/assets.json | 6 ++++++ .../src/Custom/AssistantsClient.cs | 2 +- .../src/Generated/AssistantsClient.cs | 15 --------------- .../tests/TestHelpers.cs | 2 +- 4 files changed, 8 insertions(+), 17 deletions(-) create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/assets.json diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/assets.json b/sdk/openai/Azure.AI.OpenAI.Assistants/assets.json new file mode 100644 index 000000000000..10e44a447c43 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/assets.json @@ -0,0 +1,6 @@ +{ + "AssetsRepo": "Azure/azure-sdk-assets", + "AssetsRepoPrefixPath": "net", + "TagPrefix": "net/openai/Azure.AI.OpenAI.Assistants", + "Tag": "net/openai/Azure.AI.OpenAI.Assistants_da262989c8" +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/AssistantsClient.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/AssistantsClient.cs index fa04e57c24d9..53367a7557d9 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/AssistantsClient.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/AssistantsClient.cs @@ -757,7 +757,7 @@ internal HttpMessage CreateInternalGetRunStepsRequest(string threadId, string ru internal HttpMessage CreateInternalListFilesRequest(string purpose, RequestContext context) => CreateRequestMessage("/files", content: null, context, RequestMethod.Get, ("purpose", purpose)); - internal HttpMessage CreateCreateFileRequest(RequestContent content, RequestContext context) + internal HttpMessage CreateUploadFileRequest(RequestContent content, RequestContext context) { HttpMessage message = CreateRequestMessage("/files", content, context, RequestMethod.Post); (content as Azure.Core.MultipartFormDataContent).ApplyToRequest(message.Request); diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsClient.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsClient.cs index c23ba4eb4b21..80b6f39f8aaa 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsClient.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsClient.cs @@ -3575,21 +3575,6 @@ internal HttpMessage CreateSubmitToolOutputsToRunRequest(string threadId, string return message; } - internal HttpMessage CreateUploadFileRequest(RequestContent content, RequestContext context) - { - var message = _pipeline.CreateMessage(context, ResponseClassifier200); - var request = message.Request; - request.Method = RequestMethod.Post; - var uri = new RawRequestUriBuilder(); - uri.Reset(_endpoint); - uri.AppendPath("/files", false); - request.Uri = uri; - request.Headers.Add("Accept", "application/json"); - request.Headers.Add("content-type", "multipart/form-data"); - request.Content = content; - return message; - } - private static RequestContext DefaultRequestContext = new RequestContext(); internal static RequestContext FromCancellationToken(CancellationToken cancellationToken = default) { diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/tests/TestHelpers.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/tests/TestHelpers.cs index 6f38c889bf28..77154cef2025 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/tests/TestHelpers.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/tests/TestHelpers.cs @@ -61,7 +61,7 @@ private AssistantsClientOptions GetInstrumentedClientOptions( protected string GetDeploymentOrModelName(OpenAIClientServiceTarget target) => target switch { - OpenAIClientServiceTarget.Azure => "gpt-4-1106", + OpenAIClientServiceTarget.Azure => "gpt-4-1106-preview", OpenAIClientServiceTarget.NonAzure => "gpt-4-1106-preview", _ => throw new NotImplementedException(), }; From 3e229358ee37c917a87b82b0790f7d9ae5fb5193 Mon Sep 17 00:00:00 2001 From: Travis Wilson <35748617+trrwilson@users.noreply.github.com> Date: Fri, 12 Jan 2024 15:22:24 -0800 Subject: [PATCH 06/15] test/CI updates for pipeline runs --- .../Azure.AI.OpenAI.Assistants/assets.json | 2 +- .../tests/AssistantsTestBase.cs | 21 +++++++++++++++++++ .../tests/TestHelpers.cs | 10 ++------- sdk/openai/ci.yml | 2 ++ 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/assets.json b/sdk/openai/Azure.AI.OpenAI.Assistants/assets.json index 10e44a447c43..b570300d37da 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/assets.json +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/assets.json @@ -2,5 +2,5 @@ "AssetsRepo": "Azure/azure-sdk-assets", "AssetsRepoPrefixPath": "net", "TagPrefix": "net/openai/Azure.AI.OpenAI.Assistants", - "Tag": "net/openai/Azure.AI.OpenAI.Assistants_da262989c8" + "Tag": "net/openai/Azure.AI.OpenAI.Assistants_4d3c57d995" } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/tests/AssistantsTestBase.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/tests/AssistantsTestBase.cs index ea57ee2f720f..f562fccbe434 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/tests/AssistantsTestBase.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/tests/AssistantsTestBase.cs @@ -20,6 +20,13 @@ protected string TestMetadataValue => Recording?.Mode == RecordedTestMode.Playback ? "RecordedMetadataValue" : s_testMetadataValue; protected KeyValuePair TestMetadataPair => new(s_testMetadataKey, TestMetadataValue); + private static readonly string s_placeholderAzureResourceUrl = "https://my-resource.openai.azure.com"; + protected readonly string _azureResourceUrl; + + private static readonly string s_placeholderApiKey = "placeholder"; + protected readonly string _nonAzureApiKey; + protected readonly AzureKeyCredential _azureApiKeyCredential; + public List<(AssistantsClient, string)> EnsuredFileDeletions = new(); public List<(AssistantsClient, string)> EnsuredThreadDeletions = new(); @@ -31,6 +38,20 @@ protected AssistantsTestBase(bool isAsync, RecordedTestMode? mode = null) : base HeaderRegexSanitizers.Add(new HeaderRegexSanitizer("api-key", "***********")); UriRegexSanitizers.Add(new UriRegexSanitizer("sig=[^\"]*", "sig=Sanitized")); SanitizedQueryParameters.Add("sig"); + + if (mode == RecordedTestMode.Playback) + { + _nonAzureApiKey = s_placeholderApiKey; + _azureResourceUrl = s_placeholderAzureResourceUrl; + _azureApiKeyCredential = new(s_placeholderApiKey); + } + else + { + _nonAzureApiKey = TestEnvironment.NonAzureOpenAIApiKey; + _azureResourceUrl = TestEnvironment.AzureOpenAIResourceUri; + _azureApiKeyCredential = new(TestEnvironment.AzureOpenAIApiKey); + UriRegexSanitizers.Add(new(_azureResourceUrl, s_placeholderAzureResourceUrl)); + } } [OneTimeTearDown] diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/tests/TestHelpers.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/tests/TestHelpers.cs index 77154cef2025..4c4e188a74e4 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/tests/TestHelpers.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/tests/TestHelpers.cs @@ -38,16 +38,10 @@ public AssistantsClient GetTestClient(OpenAIClientServiceTarget target) => GetTestClient(target, OpenAIClientAuthenticationType.ApiKey); protected AssistantsClient GetNonAzureClientWithKey() => InstrumentClient( - new AssistantsClient(GetNonAzureApiKey(), GetInstrumentedClientOptions())); + new AssistantsClient(_nonAzureApiKey, GetInstrumentedClientOptions())); protected AssistantsClient GetAzureClientWithKey() => InstrumentClient( - new AssistantsClient(GetAzureResourceUri(), new AzureKeyCredential(GetAzureApiKey()), GetInstrumentedClientOptions())); - - protected string GetNonAzureApiKey() => TestEnvironment.NonAzureOpenAIApiKey; - - protected Uri GetAzureResourceUri() => new(TestEnvironment.AzureOpenAIResourceUri); - - protected string GetAzureApiKey() => TestEnvironment.AzureOpenAIApiKey; + new AssistantsClient(new(_azureResourceUrl), _azureApiKeyCredential, GetInstrumentedClientOptions())); private AssistantsClientOptions GetInstrumentedClientOptions( AssistantsClientOptions.ServiceVersion? azureServiceVersionOverride = null) diff --git a/sdk/openai/ci.yml b/sdk/openai/ci.yml index f9da5c08c37f..8c8f55805cd8 100644 --- a/sdk/openai/ci.yml +++ b/sdk/openai/ci.yml @@ -11,6 +11,7 @@ trigger: - sdk/openai - sdk/openai/ci.yml - sdk/openai/Azure.AI.OpenAI + - sdk/openai/Azure.AI.OpenAI.Assistants pr: branches: @@ -24,6 +25,7 @@ pr: - sdk/openai - sdk/openai/ci.yml - sdk/openai/Azure.AI.OpenAI + - sdk/openai/Azure.AI.OpenAI.Assistants extends: template: /eng/pipelines/templates/stages/archetype-sdk-client.yml From c530ee766d2d587ef48a4e9f6efbee44ca4b5229 Mon Sep 17 00:00:00 2001 From: Travis Wilson <35748617+trrwilson@users.noreply.github.com> Date: Fri, 12 Jan 2024 15:35:42 -0800 Subject: [PATCH 07/15] one more recording logic flip for pipeline tests --- .../tests/AssistantsTestBase.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/tests/AssistantsTestBase.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/tests/AssistantsTestBase.cs index f562fccbe434..5ec0cae2479f 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/tests/AssistantsTestBase.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/tests/AssistantsTestBase.cs @@ -39,19 +39,19 @@ protected AssistantsTestBase(bool isAsync, RecordedTestMode? mode = null) : base UriRegexSanitizers.Add(new UriRegexSanitizer("sig=[^\"]*", "sig=Sanitized")); SanitizedQueryParameters.Add("sig"); - if (mode == RecordedTestMode.Playback) - { - _nonAzureApiKey = s_placeholderApiKey; - _azureResourceUrl = s_placeholderAzureResourceUrl; - _azureApiKeyCredential = new(s_placeholderApiKey); - } - else + if (mode == RecordedTestMode.Record || mode == RecordedTestMode.Live) { _nonAzureApiKey = TestEnvironment.NonAzureOpenAIApiKey; _azureResourceUrl = TestEnvironment.AzureOpenAIResourceUri; _azureApiKeyCredential = new(TestEnvironment.AzureOpenAIApiKey); UriRegexSanitizers.Add(new(_azureResourceUrl, s_placeholderAzureResourceUrl)); } + else + { + _nonAzureApiKey = s_placeholderApiKey; + _azureResourceUrl = s_placeholderAzureResourceUrl; + _azureApiKeyCredential = new(s_placeholderApiKey); + } } [OneTimeTearDown] From 46c6a4f9b08be4d98005cc10581774d5ba5ac083 Mon Sep 17 00:00:00 2001 From: Travis Wilson <35748617+trrwilson@users.noreply.github.com> Date: Fri, 12 Jan 2024 15:55:50 -0800 Subject: [PATCH 08/15] remove extra READMEs for process compliance --- .../src/Convenience/README.md | 4 ---- .../Azure.AI.OpenAI.Assistants/src/Custom/README.md | 3 --- sdk/openai/Azure.AI.OpenAI.Assistants/src/README.md | 13 ------------- 3 files changed, 20 deletions(-) delete mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Convenience/README.md delete mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/README.md delete mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/README.md diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Convenience/README.md b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Convenience/README.md deleted file mode 100644 index 9a982be09a65..000000000000 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Convenience/README.md +++ /dev/null @@ -1,4 +0,0 @@ -## Convenience additions - -This folder contains additional functionality for library types that does not modify or impact the behavior of generated -code. diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/README.md b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/README.md deleted file mode 100644 index 9663cdd42c9d..000000000000 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/README.md +++ /dev/null @@ -1,3 +0,0 @@ -## Customized code - -This folder contains code that replaces or modifies the behavior of generated code. diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/README.md b/sdk/openai/Azure.AI.OpenAI.Assistants/src/README.md deleted file mode 100644 index aa977ecb4375..000000000000 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/README.md +++ /dev/null @@ -1,13 +0,0 @@ -## Azure.AI.OpenAI.Assistants library source code - -**IMPORTANT**: this project is based on generated code from a common specification and changes either originate from or interact with the specification source. - -You can find the specification project for `OpenAI.Assistants` in the `azure-rest-api-specs` repository: https://github.com/Azure/azure-rest-api-specs/tree/main/specification/ai - -| Folder | Description | -|--|--| -| [/generated](/generated) | Purely generated code based on the specification commit tag described in [../tsp-location.yaml](../tsp-location.yaml) and influenced by the contents of files in [/custom](/custom). | -| [/custom](/custom) | Hand-written code that mutually informs code generation output by redefining types, structure, and other behavior. | -| [/convenience](/convenience) | Hand-written code to add or improve additional capabilities that bears no direction interaction with generated source. | - -To populate the generated code portion, use the appropriate build target via `dotnet build /t:GenerateCode`. From 11e205006608545f213157d65242f4880f00c0be Mon Sep 17 00:00:00 2001 From: Travis Wilson <35748617+trrwilson@users.noreply.github.com> Date: Fri, 12 Jan 2024 16:17:55 -0800 Subject: [PATCH 09/15] readme adjustments for doc-warden --- .../Azure.AI.OpenAI.Assistants/README.md | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/README.md b/sdk/openai/Azure.AI.OpenAI.Assistants/README.md index 92dcdfb70165..3a41c1e52d16 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/README.md +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/README.md @@ -1,4 +1,4 @@ -# OpenAI Assistants: Azure's client library for .NET +# Azure OpenAI: OpenAI Assistants client library for .NET > **NOTE**: This is a preview version of the Azure SDK library for OpenAI Assistants. The Azure OpenAI service does not yet include Assistants features and this project is thus currently for sole use with OpenAI's `api.openai.com` endpoints. [OpenAI's Assistants API](https://platform.openai.com/docs/api-reference/assistants) is tagged as beta and both the API surface as well as this library's representation are subject to change. @@ -29,9 +29,7 @@ Install the client library for .NET with [NuGet](https://www.nuget.org/ ): dotnet add package Azure.AI.OpenAI.Assistants --prerelease ``` -## Usage - -### Overview +### Authenticate the client See [OpenAI's "how assistants work"](https://platform.openai.com/docs/assistants/how-it-works) documentation for an overview of the concepts and relationships used with assistants. This overview closely follows @@ -45,7 +43,18 @@ AssistantsClient client = isAzureOpenAI : new AssistantsClient(nonAzureApiKey); ``` -With a client, an assistant can then be created: +## Key concepts + +### Overview + +For an overview of Assistants and the pertinent key concepts like Threads, Messages, Runs, and Tools, please see +[OpenAI's Assistants API overview](https://platform.openai.com/docs/assistants/overview). + +## Usage + +### Examples + +With an authenticated client, an assistant can be created: ```C# Snippet:OverviewCreateAssistant Response assistantResponse = await client.CreateAssistantAsync( new AssistantCreationOptions("gpt-4-1106-preview") From 4556890e3f6e9be06dc4f39b30f3be3bb499a229 Mon Sep 17 00:00:00 2001 From: Travis Wilson Date: Tue, 16 Jan 2024 14:49:43 -0800 Subject: [PATCH 10/15] tsp snap, basic retrieval test with one-shot thread creation --- ...ure.AI.OpenAI.Assistants.netstandard2.0.cs | 37 ++++--- .../Azure.AI.OpenAI.Assistants/assets.json | 2 +- .../src/Custom/AssistantsModelFactory.cs | 2 +- .../AssistantThreadCreationOptions.cs | 10 +- .../src/Generated/AssistantsModelFactory.cs | 11 ++ ...nalMessageFilePathDetails.Serialization.cs | 19 +--- .../InternalMessageFilePathDetails.cs | 4 +- ...alMessageImageFileDetails.Serialization.cs | 19 +--- .../InternalMessageImageFileDetails.cs | 4 +- ...MessageImageFileIdDetails.Serialization.cs | 19 +--- .../InternalMessageImageFileIdDetails.cs | 4 +- ...nternalMessageTextDetails.Serialization.cs | 28 +---- .../Generated/InternalMessageTextDetails.cs | 8 +- ...geTextFileCitationDetails.Serialization.cs | 21 +--- .../InternalMessageTextFileCitationDetails.cs | 6 +- .../Generated/MessageContent.Serialization.cs | 19 +--- .../MessageTextAnnotation.Serialization.cs | 25 +---- .../src/Generated/MessageTextAnnotation.cs | 6 +- ...readInitializationMessage.Serialization.cs | 61 +++++++++++ .../Generated/ThreadInitializationMessage.cs | 59 ++++++++++ .../Generated/ThreadMessage.Serialization.cs | 71 +----------- .../src/Generated/ThreadMessage.cs | 24 ++--- .../tests/AssistantsTests.cs | 2 +- .../tests/RetrievalTests.cs | 101 ++++++++++++++++++ .../tsp-location.yaml | 2 +- 25 files changed, 304 insertions(+), 260 deletions(-) create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadInitializationMessage.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadInitializationMessage.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/tests/RetrievalTests.cs diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/api/Azure.AI.OpenAI.Assistants.netstandard2.0.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/api/Azure.AI.OpenAI.Assistants.netstandard2.0.cs index b993898b8cdf..14645c0e16ee 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/api/Azure.AI.OpenAI.Assistants.netstandard2.0.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/api/Azure.AI.OpenAI.Assistants.netstandard2.0.cs @@ -147,6 +147,7 @@ public static partial class AssistantsModelFactory public static Azure.AI.OpenAI.Assistants.MessageFileCitationTextAnnotation MessageFileCitationTextAnnotation(string text, int startIndex, int endIndex, string fileId, string quote) { throw null; } public static Azure.AI.OpenAI.Assistants.MessageFilePathTextAnnotation MessageFilePathTextAnnotation(string text, int startIndex, int endIndex, string fileId) { throw null; } public static Azure.AI.OpenAI.Assistants.MessageImageFileContent MessageImageFileContent(string fileId) { throw null; } + public static Azure.AI.OpenAI.Assistants.MessageTextAnnotation MessageTextAnnotation(string type = null, string text = null, int startIndex = 0, int endIndex = 0) { throw null; } public static Azure.AI.OpenAI.Assistants.MessageTextContent MessageTextContent(string text, System.Collections.Generic.IEnumerable annotations) { throw null; } public static Azure.AI.OpenAI.Assistants.OpenAIFile OpenAIFile(string id = null, int size = 0, string filename = null, System.DateTimeOffset createdAt = default(System.DateTimeOffset), Azure.AI.OpenAI.Assistants.OpenAIFilePurpose purpose = default(Azure.AI.OpenAI.Assistants.OpenAIFilePurpose)) { throw null; } public static Azure.AI.OpenAI.Assistants.PageableList PageableList(System.Collections.Generic.IReadOnlyList data, string firstId, string lastId, bool hasMore) { throw null; } @@ -158,7 +159,7 @@ public static partial class AssistantsModelFactory public static Azure.AI.OpenAI.Assistants.RunStepMessageCreationReference RunStepMessageCreationReference(string messageId = null) { throw null; } public static Azure.AI.OpenAI.Assistants.RunStepToolCallDetails RunStepToolCallDetails(System.Collections.Generic.IEnumerable toolCalls = null) { throw null; } public static Azure.AI.OpenAI.Assistants.SubmitToolOutputsAction SubmitToolOutputsAction(System.Collections.Generic.IEnumerable toolCalls) { throw null; } - public static Azure.AI.OpenAI.Assistants.ThreadMessage ThreadMessage(string id = null, System.DateTimeOffset createdAt = default(System.DateTimeOffset), string threadId = null, Azure.AI.OpenAI.Assistants.MessageRole role = default(Azure.AI.OpenAI.Assistants.MessageRole), System.Collections.Generic.IEnumerable contentItems = null, string assistantId = null, string runId = null, System.Collections.Generic.IEnumerable fileIds = null, System.Collections.Generic.IDictionary metadata = null) { throw null; } + public static Azure.AI.OpenAI.Assistants.ThreadMessage ThreadMessage(string id = null, System.DateTimeOffset createdAt = default(System.DateTimeOffset), string threadId = null, Azure.AI.OpenAI.Assistants.MessageRole role = default(Azure.AI.OpenAI.Assistants.MessageRole), System.Collections.Generic.IEnumerable contentItems = null, string assistantId = null, string runId = null, System.Collections.Generic.IEnumerable fileIds = null, System.Collections.Generic.IReadOnlyDictionary metadata = null) { throw null; } public static Azure.AI.OpenAI.Assistants.ThreadRun ThreadRun(string id = null, string threadId = null, string assistantId = null, Azure.AI.OpenAI.Assistants.RunStatus status = default(Azure.AI.OpenAI.Assistants.RunStatus), Azure.AI.OpenAI.Assistants.RequiredAction requiredAction = null, Azure.AI.OpenAI.Assistants.RunError lastError = null, string model = null, string instructions = null, System.Collections.Generic.IEnumerable tools = null, System.Collections.Generic.IEnumerable fileIds = null, System.DateTimeOffset createdAt = default(System.DateTimeOffset), System.DateTimeOffset? expiresAt = default(System.DateTimeOffset?), System.DateTimeOffset? startedAt = default(System.DateTimeOffset?), System.DateTimeOffset? completedAt = default(System.DateTimeOffset?), System.DateTimeOffset? cancelledAt = default(System.DateTimeOffset?), System.DateTimeOffset? failedAt = default(System.DateTimeOffset?), System.Collections.Generic.IReadOnlyDictionary metadata = null) { throw null; } public static Azure.AI.OpenAI.Assistants.ToolCall ToolCall(string type = null, string id = null) { throw null; } } @@ -172,7 +173,7 @@ internal AssistantThread() { } public partial class AssistantThreadCreationOptions { public AssistantThreadCreationOptions() { } - public System.Collections.Generic.IList Messages { get { throw null; } } + public System.Collections.Generic.IList Messages { get { throw null; } } public System.Collections.Generic.IDictionary Metadata { get { throw null; } set { } } } public partial class CodeInterpreterImageOutput : Azure.AI.OpenAI.Assistants.CodeInterpreterToolCallOutput @@ -301,9 +302,9 @@ internal MessageImageFileContent() { } public abstract partial class MessageTextAnnotation { protected MessageTextAnnotation(string text, int startIndex, int endIndex) { } - public int EndIndex { get { throw null; } set { } } - public int StartIndex { get { throw null; } set { } } - public string Text { get { throw null; } set { } } + public int EndIndex { get { throw null; } } + public int StartIndex { get { throw null; } } + public string Text { get { throw null; } } } public partial class MessageTextContent : Azure.AI.OpenAI.Assistants.MessageContent { @@ -499,18 +500,26 @@ public partial class SubmitToolOutputsAction : Azure.AI.OpenAI.Assistants.Requir internal SubmitToolOutputsAction() { } public System.Collections.Generic.IReadOnlyList ToolCalls { get { throw null; } } } - public partial class ThreadMessage + public partial class ThreadInitializationMessage { - public ThreadMessage(string id, System.DateTimeOffset createdAt, string threadId, Azure.AI.OpenAI.Assistants.MessageRole role, System.Collections.Generic.IEnumerable contentItems, System.Collections.Generic.IEnumerable fileIds, System.Collections.Generic.IDictionary metadata) { } - public string AssistantId { get { throw null; } set { } } - public System.Collections.Generic.IList ContentItems { get { throw null; } } - public System.DateTimeOffset CreatedAt { get { throw null; } set { } } + public ThreadInitializationMessage(Azure.AI.OpenAI.Assistants.MessageRole role, string content) { } + public string Content { get { throw null; } } public System.Collections.Generic.IList FileIds { get { throw null; } } - public string Id { get { throw null; } set { } } public System.Collections.Generic.IDictionary Metadata { get { throw null; } set { } } - public Azure.AI.OpenAI.Assistants.MessageRole Role { get { throw null; } set { } } - public string RunId { get { throw null; } set { } } - public string ThreadId { get { throw null; } set { } } + public Azure.AI.OpenAI.Assistants.MessageRole Role { get { throw null; } } + } + public partial class ThreadMessage + { + internal ThreadMessage() { } + public string AssistantId { get { throw null; } } + public System.Collections.Generic.IReadOnlyList ContentItems { get { throw null; } } + public System.DateTimeOffset CreatedAt { get { throw null; } } + public System.Collections.Generic.IReadOnlyList FileIds { get { throw null; } } + public string Id { get { throw null; } } + public System.Collections.Generic.IReadOnlyDictionary Metadata { get { throw null; } } + public Azure.AI.OpenAI.Assistants.MessageRole Role { get { throw null; } } + public string RunId { get { throw null; } } + public string ThreadId { get { throw null; } } } public partial class ThreadRun { diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/assets.json b/sdk/openai/Azure.AI.OpenAI.Assistants/assets.json index b570300d37da..f2109759f373 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/assets.json +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/assets.json @@ -2,5 +2,5 @@ "AssetsRepo": "Azure/azure-sdk-assets", "AssetsRepoPrefixPath": "net", "TagPrefix": "net/openai/Azure.AI.OpenAI.Assistants", - "Tag": "net/openai/Azure.AI.OpenAI.Assistants_4d3c57d995" + "Tag": "net/openai/Azure.AI.OpenAI.Assistants_ef4bb9efe2" } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/AssistantsModelFactory.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/AssistantsModelFactory.cs index dd99669d3dfb..bad458d25844 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/AssistantsModelFactory.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/AssistantsModelFactory.cs @@ -149,7 +149,7 @@ public static RunStep RunStep(string id = null, RunStepType type = default, stri /// /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. /// A new instance for mocking. - public static ThreadMessage ThreadMessage(string id = null, DateTimeOffset createdAt = default, string threadId = null, MessageRole role = default, IEnumerable contentItems = null, string assistantId = null, string runId = null, IEnumerable fileIds = null, IDictionary metadata = null) + public static ThreadMessage ThreadMessage(string id = null, DateTimeOffset createdAt = default, string threadId = null, MessageRole role = default, IEnumerable contentItems = null, string assistantId = null, string runId = null, IEnumerable fileIds = null, IReadOnlyDictionary metadata = null) { contentItems ??= new List(); fileIds ??= new List(); diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantThreadCreationOptions.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantThreadCreationOptions.cs index 4fb725ab6135..67912f83c9f4 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantThreadCreationOptions.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantThreadCreationOptions.cs @@ -16,21 +16,21 @@ public partial class AssistantThreadCreationOptions /// Initializes a new instance of . public AssistantThreadCreationOptions() { - Messages = new ChangeTrackingList(); + Messages = new ChangeTrackingList(); Metadata = new ChangeTrackingDictionary(); } /// Initializes a new instance of . - /// The messages to associate with the new thread. + /// The initial messages to associate with the new thread. /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. - internal AssistantThreadCreationOptions(IList messages, IDictionary metadata) + internal AssistantThreadCreationOptions(IList messages, IDictionary metadata) { Messages = messages; Metadata = metadata; } - /// The messages to associate with the new thread. - public IList Messages { get; } + /// The initial messages to associate with the new thread. + public IList Messages { get; } /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. public IDictionary Metadata { get; set; } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsModelFactory.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsModelFactory.cs index 18b27830a1d7..36856e6eb73c 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsModelFactory.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsModelFactory.cs @@ -98,6 +98,17 @@ public static CodeInterpreterImageReference CodeInterpreterImageReference(string return new CodeInterpreterImageReference(fileId); } + /// Initializes a new instance of . + /// The object type. + /// The textual content associated with this text annotation item. + /// The first text index associated with this text annotation. + /// The last text index associated with this text annotation. + /// A new instance for mocking. + public static MessageTextAnnotation MessageTextAnnotation(string type = null, string text = null, int startIndex = default, int endIndex = default) + { + return new UnknownMessageTextAnnotation(type, text, startIndex, endIndex); + } + /// Initializes a new instance of . /// Information about the message creation associated with this run step. /// A new instance for mocking. diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageFilePathDetails.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageFilePathDetails.Serialization.cs index 69246f5698a3..112309e1c25b 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageFilePathDetails.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageFilePathDetails.Serialization.cs @@ -7,20 +7,11 @@ using System.Text.Json; using Azure; -using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - internal partial class InternalMessageFilePathDetails : IUtf8JsonSerializable + internal partial class InternalMessageFilePathDetails { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) - { - writer.WriteStartObject(); - writer.WritePropertyName("file_id"u8); - writer.WriteStringValue(FileId); - writer.WriteEndObject(); - } - internal static InternalMessageFilePathDetails DeserializeInternalMessageFilePathDetails(JsonElement element) { if (element.ValueKind == JsonValueKind.Null) @@ -46,13 +37,5 @@ internal static InternalMessageFilePathDetails FromResponse(Response response) using var document = JsonDocument.Parse(response.Content); return DeserializeInternalMessageFilePathDetails(document.RootElement); } - - /// Convert into a Utf8JsonRequestContent. - internal virtual RequestContent ToRequestContent() - { - var content = new Utf8JsonRequestContent(); - content.JsonWriter.WriteObjectValue(this); - return content; - } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageFilePathDetails.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageFilePathDetails.cs index 5ac8e1d63285..be82f0e885fb 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageFilePathDetails.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageFilePathDetails.cs @@ -16,7 +16,7 @@ internal partial class InternalMessageFilePathDetails /// Initializes a new instance of . /// The ID of the specific file that the citation is from. /// is null. - public InternalMessageFilePathDetails(string fileId) + internal InternalMessageFilePathDetails(string fileId) { Argument.AssertNotNull(fileId, nameof(fileId)); @@ -24,6 +24,6 @@ public InternalMessageFilePathDetails(string fileId) } /// The ID of the specific file that the citation is from. - public string FileId { get; set; } + public string FileId { get; } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageImageFileDetails.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageImageFileDetails.Serialization.cs index f889ce642105..a03d109c7b5a 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageImageFileDetails.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageImageFileDetails.Serialization.cs @@ -7,20 +7,11 @@ using System.Text.Json; using Azure; -using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - internal partial class InternalMessageImageFileDetails : IUtf8JsonSerializable + internal partial class InternalMessageImageFileDetails { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) - { - writer.WriteStartObject(); - writer.WritePropertyName("file_id"u8); - writer.WriteObjectValue(InternalDetails); - writer.WriteEndObject(); - } - internal static InternalMessageImageFileDetails DeserializeInternalMessageImageFileDetails(JsonElement element) { if (element.ValueKind == JsonValueKind.Null) @@ -46,13 +37,5 @@ internal static InternalMessageImageFileDetails FromResponse(Response response) using var document = JsonDocument.Parse(response.Content); return DeserializeInternalMessageImageFileDetails(document.RootElement); } - - /// Convert into a Utf8JsonRequestContent. - internal virtual RequestContent ToRequestContent() - { - var content = new Utf8JsonRequestContent(); - content.JsonWriter.WriteObjectValue(this); - return content; - } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageImageFileDetails.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageImageFileDetails.cs index e5e421864ee0..42c7412fcd4e 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageImageFileDetails.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageImageFileDetails.cs @@ -16,7 +16,7 @@ internal partial class InternalMessageImageFileDetails /// Initializes a new instance of . /// The ID for the file associated with this image. /// is null. - public InternalMessageImageFileDetails(InternalMessageImageFileIdDetails internalDetails) + internal InternalMessageImageFileDetails(InternalMessageImageFileIdDetails internalDetails) { Argument.AssertNotNull(internalDetails, nameof(internalDetails)); @@ -24,6 +24,6 @@ public InternalMessageImageFileDetails(InternalMessageImageFileIdDetails interna } /// The ID for the file associated with this image. - public InternalMessageImageFileIdDetails InternalDetails { get; set; } + public InternalMessageImageFileIdDetails InternalDetails { get; } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageImageFileIdDetails.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageImageFileIdDetails.Serialization.cs index 2e55a4f2306c..6a8e7b8e4065 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageImageFileIdDetails.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageImageFileIdDetails.Serialization.cs @@ -7,20 +7,11 @@ using System.Text.Json; using Azure; -using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - internal partial class InternalMessageImageFileIdDetails : IUtf8JsonSerializable + internal partial class InternalMessageImageFileIdDetails { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) - { - writer.WriteStartObject(); - writer.WritePropertyName("file_id"u8); - writer.WriteStringValue(FileId); - writer.WriteEndObject(); - } - internal static InternalMessageImageFileIdDetails DeserializeInternalMessageImageFileIdDetails(JsonElement element) { if (element.ValueKind == JsonValueKind.Null) @@ -46,13 +37,5 @@ internal static InternalMessageImageFileIdDetails FromResponse(Response response using var document = JsonDocument.Parse(response.Content); return DeserializeInternalMessageImageFileIdDetails(document.RootElement); } - - /// Convert into a Utf8JsonRequestContent. - internal virtual RequestContent ToRequestContent() - { - var content = new Utf8JsonRequestContent(); - content.JsonWriter.WriteObjectValue(this); - return content; - } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageImageFileIdDetails.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageImageFileIdDetails.cs index 456283136a29..f69325bb0542 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageImageFileIdDetails.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageImageFileIdDetails.cs @@ -16,7 +16,7 @@ internal partial class InternalMessageImageFileIdDetails /// Initializes a new instance of . /// The ID of the specific image file. /// is null. - public InternalMessageImageFileIdDetails(string fileId) + internal InternalMessageImageFileIdDetails(string fileId) { Argument.AssertNotNull(fileId, nameof(fileId)); @@ -24,6 +24,6 @@ public InternalMessageImageFileIdDetails(string fileId) } /// The ID of the specific image file. - public string FileId { get; set; } + public string FileId { get; } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextDetails.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextDetails.Serialization.cs index 0344e871c7c6..4107400831b8 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextDetails.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextDetails.Serialization.cs @@ -8,27 +8,11 @@ using System.Collections.Generic; using System.Text.Json; using Azure; -using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - internal partial class InternalMessageTextDetails : IUtf8JsonSerializable + internal partial class InternalMessageTextDetails { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) - { - writer.WriteStartObject(); - writer.WritePropertyName("value"u8); - writer.WriteStringValue(Text); - writer.WritePropertyName("annotations"u8); - writer.WriteStartArray(); - foreach (var item in Annotations) - { - writer.WriteObjectValue(item); - } - writer.WriteEndArray(); - writer.WriteEndObject(); - } - internal static InternalMessageTextDetails DeserializeInternalMessageTextDetails(JsonElement element) { if (element.ValueKind == JsonValueKind.Null) @@ -36,7 +20,7 @@ internal static InternalMessageTextDetails DeserializeInternalMessageTextDetails return null; } string value = default; - IList annotations = default; + IReadOnlyList annotations = default; foreach (var property in element.EnumerateObject()) { if (property.NameEquals("value"u8)) @@ -65,13 +49,5 @@ internal static InternalMessageTextDetails FromResponse(Response response) using var document = JsonDocument.Parse(response.Content); return DeserializeInternalMessageTextDetails(document.RootElement); } - - /// Convert into a Utf8JsonRequestContent. - internal virtual RequestContent ToRequestContent() - { - var content = new Utf8JsonRequestContent(); - content.JsonWriter.WriteObjectValue(this); - return content; - } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextDetails.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextDetails.cs index b3bb32d0f9b9..0242076ac8d2 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextDetails.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextDetails.cs @@ -19,7 +19,7 @@ internal partial class InternalMessageTextDetails /// The text data. /// A list of annotations associated with this text. /// or is null. - public InternalMessageTextDetails(string text, IEnumerable annotations) + internal InternalMessageTextDetails(string text, IEnumerable annotations) { Argument.AssertNotNull(text, nameof(text)); Argument.AssertNotNull(annotations, nameof(annotations)); @@ -31,19 +31,19 @@ public InternalMessageTextDetails(string text, IEnumerable Initializes a new instance of . /// The text data. /// A list of annotations associated with this text. - internal InternalMessageTextDetails(string text, IList annotations) + internal InternalMessageTextDetails(string text, IReadOnlyList annotations) { Text = text; Annotations = annotations; } /// The text data. - public string Text { get; set; } + public string Text { get; } /// /// A list of annotations associated with this text. /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. /// The available derived classes include and . /// - public IList Annotations { get; } + public IReadOnlyList Annotations { get; } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextFileCitationDetails.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextFileCitationDetails.Serialization.cs index 3b15e9ec02c5..21da36cc3673 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextFileCitationDetails.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextFileCitationDetails.Serialization.cs @@ -7,22 +7,11 @@ using System.Text.Json; using Azure; -using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - internal partial class InternalMessageTextFileCitationDetails : IUtf8JsonSerializable + internal partial class InternalMessageTextFileCitationDetails { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) - { - writer.WriteStartObject(); - writer.WritePropertyName("file_id"u8); - writer.WriteStringValue(FileId); - writer.WritePropertyName("quote"u8); - writer.WriteStringValue(Quote); - writer.WriteEndObject(); - } - internal static InternalMessageTextFileCitationDetails DeserializeInternalMessageTextFileCitationDetails(JsonElement element) { if (element.ValueKind == JsonValueKind.Null) @@ -54,13 +43,5 @@ internal static InternalMessageTextFileCitationDetails FromResponse(Response res using var document = JsonDocument.Parse(response.Content); return DeserializeInternalMessageTextFileCitationDetails(document.RootElement); } - - /// Convert into a Utf8JsonRequestContent. - internal virtual RequestContent ToRequestContent() - { - var content = new Utf8JsonRequestContent(); - content.JsonWriter.WriteObjectValue(this); - return content; - } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextFileCitationDetails.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextFileCitationDetails.cs index 410c68d3d12d..ea056e46c5d1 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextFileCitationDetails.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextFileCitationDetails.cs @@ -17,7 +17,7 @@ internal partial class InternalMessageTextFileCitationDetails /// The ID of the file associated with this citation. /// The specific quote cited in the associated file. /// or is null. - public InternalMessageTextFileCitationDetails(string fileId, string quote) + internal InternalMessageTextFileCitationDetails(string fileId, string quote) { Argument.AssertNotNull(fileId, nameof(fileId)); Argument.AssertNotNull(quote, nameof(quote)); @@ -27,8 +27,8 @@ public InternalMessageTextFileCitationDetails(string fileId, string quote) } /// The ID of the file associated with this citation. - public string FileId { get; set; } + public string FileId { get; } /// The specific quote cited in the associated file. - public string Quote { get; set; } + public string Quote { get; } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageContent.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageContent.Serialization.cs index c872d474934c..b4bea2abb9b6 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageContent.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageContent.Serialization.cs @@ -7,20 +7,11 @@ using System.Text.Json; using Azure; -using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - public partial class MessageContent : IUtf8JsonSerializable + public partial class MessageContent { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) - { - writer.WriteStartObject(); - writer.WritePropertyName("type"u8); - writer.WriteStringValue(Type); - writer.WriteEndObject(); - } - internal static MessageContent DeserializeMessageContent(JsonElement element) { if (element.ValueKind == JsonValueKind.Null) @@ -45,13 +36,5 @@ internal static MessageContent FromResponse(Response response) using var document = JsonDocument.Parse(response.Content); return DeserializeMessageContent(document.RootElement); } - - /// Convert into a Utf8JsonRequestContent. - internal virtual RequestContent ToRequestContent() - { - var content = new Utf8JsonRequestContent(); - content.JsonWriter.WriteObjectValue(this); - return content; - } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextAnnotation.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextAnnotation.Serialization.cs index 63de96c5b711..2308595f17eb 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextAnnotation.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextAnnotation.Serialization.cs @@ -7,26 +7,11 @@ using System.Text.Json; using Azure; -using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - public partial class MessageTextAnnotation : IUtf8JsonSerializable + public partial class MessageTextAnnotation { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) - { - writer.WriteStartObject(); - writer.WritePropertyName("type"u8); - writer.WriteStringValue(Type); - writer.WritePropertyName("text"u8); - writer.WriteStringValue(Text); - writer.WritePropertyName("start_index"u8); - writer.WriteNumberValue(StartIndex); - writer.WritePropertyName("end_index"u8); - writer.WriteNumberValue(EndIndex); - writer.WriteEndObject(); - } - internal static MessageTextAnnotation DeserializeMessageTextAnnotation(JsonElement element) { if (element.ValueKind == JsonValueKind.Null) @@ -51,13 +36,5 @@ internal static MessageTextAnnotation FromResponse(Response response) using var document = JsonDocument.Parse(response.Content); return DeserializeMessageTextAnnotation(document.RootElement); } - - /// Convert into a Utf8JsonRequestContent. - internal virtual RequestContent ToRequestContent() - { - var content = new Utf8JsonRequestContent(); - content.JsonWriter.WriteObjectValue(this); - return content; - } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextAnnotation.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextAnnotation.cs index 3ce8b24bfc54..4b53462a01ec 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextAnnotation.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextAnnotation.cs @@ -47,10 +47,10 @@ internal MessageTextAnnotation(string type, string text, int startIndex, int end /// The object type. internal string Type { get; set; } /// The textual content associated with this text annotation item. - public string Text { get; set; } + public string Text { get; } /// The first text index associated with this text annotation. - public int StartIndex { get; set; } + public int StartIndex { get; } /// The last text index associated with this text annotation. - public int EndIndex { get; set; } + public int EndIndex { get; } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadInitializationMessage.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadInitializationMessage.Serialization.cs new file mode 100644 index 000000000000..df66a59a730d --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadInitializationMessage.Serialization.cs @@ -0,0 +1,61 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class ThreadInitializationMessage : IUtf8JsonSerializable + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + { + writer.WriteStartObject(); + writer.WritePropertyName("role"u8); + writer.WriteStringValue(Role.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(Content); + if (Optional.IsCollectionDefined(FileIds)) + { + writer.WritePropertyName("file_ids"u8); + writer.WriteStartArray(); + foreach (var item in FileIds) + { + writer.WriteStringValue(item); + } + writer.WriteEndArray(); + } + if (Optional.IsCollectionDefined(Metadata)) + { + if (Metadata != null) + { + writer.WritePropertyName("metadata"u8); + writer.WriteStartObject(); + foreach (var item in Metadata) + { + writer.WritePropertyName(item.Key); + writer.WriteStringValue(item.Value); + } + writer.WriteEndObject(); + } + else + { + writer.WriteNull("metadata"); + } + } + writer.WriteEndObject(); + } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadInitializationMessage.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadInitializationMessage.cs new file mode 100644 index 000000000000..abf26ec513ec --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadInitializationMessage.cs @@ -0,0 +1,59 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + /// A single message within an assistant thread, as provided during that thread's creation for its initial state. + public partial class ThreadInitializationMessage + { + /// Initializes a new instance of . + /// The role associated with the assistant thread message. Currently, only 'user' is supported when providing initial messages to a new thread. + /// The textual content of the initial message. Currently, robust input including images and annotated text may only be provided via a separate call to the create message API. + /// is null. + public ThreadInitializationMessage(MessageRole role, string content) + { + Argument.AssertNotNull(content, nameof(content)); + + Role = role; + Content = content; + FileIds = new ChangeTrackingList(); + Metadata = new ChangeTrackingDictionary(); + } + + /// Initializes a new instance of . + /// The role associated with the assistant thread message. Currently, only 'user' is supported when providing initial messages to a new thread. + /// The textual content of the initial message. Currently, robust input including images and annotated text may only be provided via a separate call to the create message API. + /// + /// A list of file IDs that the assistant should use. Useful for tools like retrieval and code_interpreter that can + /// access files. + /// + /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. + internal ThreadInitializationMessage(MessageRole role, string content, IList fileIds, IDictionary metadata) + { + Role = role; + Content = content; + FileIds = fileIds; + Metadata = metadata; + } + + /// The role associated with the assistant thread message. Currently, only 'user' is supported when providing initial messages to a new thread. + public MessageRole Role { get; } + /// The textual content of the initial message. Currently, robust input including images and annotated text may only be provided via a separate call to the create message API. + public string Content { get; } + /// + /// A list of file IDs that the assistant should use. Useful for tools like retrieval and code_interpreter that can + /// access files. + /// + public IList FileIds { get; } + /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. + public IDictionary Metadata { get; set; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadMessage.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadMessage.Serialization.cs index 6e44b0b5c8b7..49e54a54d6e7 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadMessage.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadMessage.Serialization.cs @@ -13,63 +13,8 @@ namespace Azure.AI.OpenAI.Assistants { - public partial class ThreadMessage : IUtf8JsonSerializable + public partial class ThreadMessage { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) - { - writer.WriteStartObject(); - writer.WritePropertyName("id"u8); - writer.WriteStringValue(Id); - writer.WritePropertyName("object"u8); - writer.WriteStringValue(Object); - writer.WritePropertyName("created_at"u8); - writer.WriteNumberValue(CreatedAt, "U"); - writer.WritePropertyName("thread_id"u8); - writer.WriteStringValue(ThreadId); - writer.WritePropertyName("role"u8); - writer.WriteStringValue(Role.ToString()); - writer.WritePropertyName("content"u8); - writer.WriteStartArray(); - foreach (var item in ContentItems) - { - writer.WriteObjectValue(item); - } - writer.WriteEndArray(); - if (Optional.IsDefined(AssistantId)) - { - writer.WritePropertyName("assistant_id"u8); - writer.WriteStringValue(AssistantId); - } - if (Optional.IsDefined(RunId)) - { - writer.WritePropertyName("run_id"u8); - writer.WriteStringValue(RunId); - } - writer.WritePropertyName("file_ids"u8); - writer.WriteStartArray(); - foreach (var item in FileIds) - { - writer.WriteStringValue(item); - } - writer.WriteEndArray(); - if (Metadata != null && Optional.IsCollectionDefined(Metadata)) - { - writer.WritePropertyName("metadata"u8); - writer.WriteStartObject(); - foreach (var item in Metadata) - { - writer.WritePropertyName(item.Key); - writer.WriteStringValue(item.Value); - } - writer.WriteEndObject(); - } - else - { - writer.WriteNull("metadata"); - } - writer.WriteEndObject(); - } - internal static ThreadMessage DeserializeThreadMessage(JsonElement element) { if (element.ValueKind == JsonValueKind.Null) @@ -81,11 +26,11 @@ internal static ThreadMessage DeserializeThreadMessage(JsonElement element) DateTimeOffset createdAt = default; string threadId = default; MessageRole role = default; - IList content = default; + IReadOnlyList content = default; Optional assistantId = default; Optional runId = default; - IList fileIds = default; - IDictionary metadata = default; + IReadOnlyList fileIds = default; + IReadOnlyDictionary metadata = default; foreach (var property in element.EnumerateObject()) { if (property.NameEquals("id"u8)) @@ -169,13 +114,5 @@ internal static ThreadMessage FromResponse(Response response) using var document = JsonDocument.Parse(response.Content); return DeserializeThreadMessage(document.RootElement); } - - /// Convert into a Utf8JsonRequestContent. - internal virtual RequestContent ToRequestContent() - { - var content = new Utf8JsonRequestContent(); - content.JsonWriter.WriteObjectValue(this); - return content; - } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadMessage.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadMessage.cs index c2e6b7f2e929..a318019f31f6 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadMessage.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadMessage.cs @@ -12,7 +12,7 @@ namespace Azure.AI.OpenAI.Assistants { - /// A single message within an assistant thread. + /// A single, existing message within an assistant thread. public partial class ThreadMessage { /// Initializes a new instance of . @@ -27,7 +27,7 @@ public partial class ThreadMessage /// /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. /// , , or is null. - public ThreadMessage(string id, DateTimeOffset createdAt, string threadId, MessageRole role, IEnumerable contentItems, IEnumerable fileIds, IDictionary metadata) + internal ThreadMessage(string id, DateTimeOffset createdAt, string threadId, MessageRole role, IEnumerable contentItems, IEnumerable fileIds, IReadOnlyDictionary metadata) { Argument.AssertNotNull(id, nameof(id)); Argument.AssertNotNull(threadId, nameof(threadId)); @@ -57,7 +57,7 @@ public ThreadMessage(string id, DateTimeOffset createdAt, string threadId, Messa /// access files. /// /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. - internal ThreadMessage(string id, string @object, DateTimeOffset createdAt, string threadId, MessageRole role, IList contentItems, string assistantId, string runId, IList fileIds, IDictionary metadata) + internal ThreadMessage(string id, string @object, DateTimeOffset createdAt, string threadId, MessageRole role, IReadOnlyList contentItems, string assistantId, string runId, IReadOnlyList fileIds, IReadOnlyDictionary metadata) { Id = id; Object = @object; @@ -72,30 +72,30 @@ internal ThreadMessage(string id, string @object, DateTimeOffset createdAt, stri } /// The identifier, which can be referenced in API endpoints. - public string Id { get; set; } + public string Id { get; } /// The Unix timestamp, in seconds, representing when this object was created. - public DateTimeOffset CreatedAt { get; set; } + public DateTimeOffset CreatedAt { get; } /// The ID of the thread that this message belongs to. - public string ThreadId { get; set; } + public string ThreadId { get; } /// The role associated with the assistant thread message. - public MessageRole Role { get; set; } + public MessageRole Role { get; } /// /// The list of content items associated with the assistant thread message. /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. /// The available derived classes include and . /// - public IList ContentItems { get; } + public IReadOnlyList ContentItems { get; } /// If applicable, the ID of the assistant that authored this message. - public string AssistantId { get; set; } + public string AssistantId { get; } /// If applicable, the ID of the run associated with the authoring of this message. - public string RunId { get; set; } + public string RunId { get; } /// /// A list of file IDs that the assistant should use. Useful for tools like retrieval and code_interpreter that can /// access files. /// - public IList FileIds { get; } + public IReadOnlyList FileIds { get; } /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. - public IDictionary Metadata { get; set; } + public IReadOnlyDictionary Metadata { get; } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/tests/AssistantsTests.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/tests/AssistantsTests.cs index cf8574a6c824..a9934faa7482 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/tests/AssistantsTests.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/tests/AssistantsTests.cs @@ -46,7 +46,7 @@ Response assistantCreationResponse { Name = "AOAI SDK Test Assistant - Delete Me", Description = "Created by automated tests to exercise the API; should not be used", - Tools = { new CodeInterpreterToolDefinition() }, + Tools = { new RetrievalToolDefinition() }, Instructions = "You are a very generic assistant.", Metadata = { TestMetadataPair }, }); diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/tests/RetrievalTests.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/tests/RetrievalTests.cs new file mode 100644 index 000000000000..f1f1081fba0e --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/tests/RetrievalTests.cs @@ -0,0 +1,101 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Azure.Core.TestFramework; +using NUnit.Framework; + +namespace Azure.AI.OpenAI.Assistants.Tests; + +public class RetrievalTests : AssistantsTestBase +{ + public RetrievalTests(bool isAsync) + : base(isAsync) // , RecordedTestMode.Live) + { + } + + [RecordedTest] + [TestCase(OpenAIClientServiceTarget.NonAzure)] + [TestCase(OpenAIClientServiceTarget.Azure)] + public async Task BasicRetrievalWorks(OpenAIClientServiceTarget target) + { + AssistantsClient client = GetTestClient(target); + string deloymentOrModelName = GetDeploymentOrModelName(target); + + OpenAIFile uploadedFile = null; + using (TestRecording.DisableRecordingScope disableBodyRecordingScope = Recording.DisableRequestBodyRecording()) + { + Response uploadFileResponse = await client.UploadFileAsync( + BinaryData.FromString("The number for the color 'red' is 1. The number for the color 'blue' is 2. The number for the color 'green' is 4."), + OpenAIFilePurpose.Assistants); + AssertSuccessfulResponse(uploadFileResponse); + EnsuredFileDeletions.Add((client, uploadFileResponse.Value.Id)); + uploadedFile = uploadFileResponse.Value; + } + + Response assistantCreationResponse + = await client.CreateAssistantAsync(new AssistantCreationOptions(deloymentOrModelName) + { + Name = "AOAI SDK Test Assistant - Delete Me", + Description = "Created by automated tests to exercise the API; should not be used", + Instructions = "You are a very generic assistant.", + Tools = { new RetrievalToolDefinition() }, + FileIds = { uploadedFile.Id }, + Metadata = { TestMetadataPair }, + }); + AssertSuccessfulResponse(assistantCreationResponse); + Assistant assistant = assistantCreationResponse.Value; + + Response runCreationResponse = await client.CreateThreadAndRunAsync( + new CreateAndRunThreadOptions(assistantCreationResponse.Value.Id) + { + Metadata = { TestMetadataPair }, + Thread = new AssistantThreadCreationOptions() + { + Metadata = { TestMetadataPair }, + Messages = + { + new ThreadInitializationMessage( + MessageRole.User, + "Hello, assistant! What's the mathematical product of the numbers for the colors blue and green?") + { + Metadata = { TestMetadataPair }, + } + }, + }, + }); + AssertSuccessfulResponse(runCreationResponse); + ThreadRun run = runCreationResponse.Value; + + // Repeatedly retrieve the run (polling) until it's done + do + { + await Task.Delay(500); + Response runRetrievalResponse = await client.GetRunAsync(run.ThreadId, run.Id); + AssertSuccessfulResponse(runRetrievalResponse); + run = runRetrievalResponse.Value; + } + while (run.Status == RunStatus.Queued || run.Status == RunStatus.InProgress); + + Assert.That(run.Status, Is.EqualTo(RunStatus.Completed)); + Assert.That(run.AssistantId, Is.EqualTo(assistant.Id)); + + // List the messages on the thread, now updated from the completed run + Response> messageListResponse = await client.GetMessagesAsync(run.ThreadId); + AssertSuccessfulResponse(messageListResponse); + IReadOnlyList messages = messageListResponse.Value.Data; + Assert.That(messages.Count, Is.EqualTo(2)); + + // Messages are most recent first in the list + ThreadMessage latestMessage = messages[0]; + + Assert.That(latestMessage.Role, Is.EqualTo(MessageRole.Assistant)); + Assert.That(latestMessage.ContentItems, Is.Not.Null.Or.Empty); + MessageTextContent textContent = latestMessage.ContentItems[0] as MessageTextContent; + Assert.That(textContent, Is.Not.Null); + Assert.That(textContent.Text.Contains('8')); + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/tsp-location.yaml b/sdk/openai/Azure.AI.OpenAI.Assistants/tsp-location.yaml index 2a94050c8d5f..9da95eab6549 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/tsp-location.yaml +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/tsp-location.yaml @@ -1,3 +1,3 @@ directory: specification/ai/OpenAI.Assistants -commit: 84706e624d4949548865f965378052578f011b77 +commit: cdb2544bd7879936b89433e7d63c7b7e6f55308c repo: Azure/azure-rest-api-specs From 41061ac915415c8d7a75fddd4203562407d797f8 Mon Sep 17 00:00:00 2001 From: Travis Wilson Date: Tue, 23 Jan 2024 19:09:51 -0800 Subject: [PATCH 11/15] .tsp update --- .../Azure.AI.OpenAI.Assistants/README.md | 14 +- ...ure.AI.OpenAI.Assistants.netstandard2.0.cs | 105 +++++---- .../Azure.AI.OpenAI.Assistants/assets.json | 2 +- .../src/Convenience/AssistantsClient.cs | 31 +++ .../src/Custom/AssistantsClient.cs | 16 +- .../src/Custom/AssistantsModelFactory.cs | 15 +- ...s => MessageTextFileCitationAnnotation.cs} | 2 +- ...on.cs => MessageTextFilePathAnnotation.cs} | 6 +- .../src/Custom/OpenAIFile.cs | 35 +++ .../src/Custom/RequiredFunctionToolCall.cs | 26 +++ .../src/Custom/SubmitToolOutputsAction.cs | 2 +- .../src/Custom/ToolOutput.cs | 4 +- ....cs => UploadFileRequest.Serialization.cs} | 14 +- .../src/Custom/Visibility/ListSortOrder.cs | 15 -- .../src/Generated/AssistantsClient.cs | 213 +++++++----------- .../src/Generated/AssistantsModelFactory.cs | 11 +- .../src/Generated/CodeInterpreterToolCall.cs | 4 +- ...n.cs => CreateRunOptions.Serialization.cs} | 53 ++++- ...reateRunRequest.cs => CreateRunOptions.cs} | 24 +- .../src/Generated/FunctionToolCall.cs | 4 +- .../Generated/InternalMessageTextDetails.cs | 2 +- ...ssageTextFilePathDetails.Serialization.cs} | 10 +- ... => InternalMessageTextFilePathDetails.cs} | 6 +- ...lSubmitToolOutputsDetails.Serialization.cs | 6 +- .../InternalSubmitToolOutputsDetails.cs | 10 +- .../MessageTextAnnotation.Serialization.cs | 4 +- .../src/Generated/MessageTextAnnotation.cs | 2 +- ...xtFileCitationAnnotation.Serialization.cs} | 10 +- ...s => MessageTextFileCitationAnnotation.cs} | 10 +- ...geTextFilePathAnnotation.Serialization.cs} | 14 +- ...on.cs => MessageTextFilePathAnnotation.cs} | 10 +- .../src/Generated/OpenAIFile.Serialization.cs | 2 +- .../src/Generated/OpenAIFile.cs | 2 - .../RequiredFunctionToolCall.Serialization.cs | 53 +++++ .../src/Generated/RequiredFunctionToolCall.cs | 38 ++++ .../RequiredToolCall.Serialization.cs | 39 ++++ .../src/Generated/RequiredToolCall.cs | 44 ++++ .../src/Generated/RetrievalToolCall.cs | 4 +- .../src/Generated/RunStepToolCallDetails.cs | 6 +- .../src/Generated/ToolCall.cs | 3 +- .../UnknownRequiredToolCall.Serialization.cs | 47 ++++ .../src/Generated/UnknownRequiredToolCall.cs | 31 +++ ...> UpdateAssistantOptions.Serialization.cs} | 2 +- ...onOptions.cs => UpdateAssistantOptions.cs} | 10 +- ... => UpdateMessageRequest.Serialization.cs} | 2 +- ...sageRequest.cs => UpdateMessageRequest.cs} | 12 +- ...n.cs => UpdateRunRequest.Serialization.cs} | 2 +- ...odifyRunRequest.cs => UpdateRunRequest.cs} | 12 +- ...s => UpdateThreadRequest.Serialization.cs} | 2 +- ...hreadRequest.cs => UpdateThreadRequest.cs} | 12 +- ....cs => UploadFileRequest.Serialization.cs} | 2 +- ...ateFileRequest.cs => UploadFileRequest.cs} | 12 +- .../tests/AssistantsModelFactoryTests.cs | 4 +- .../tests/AssistantsTestBase.cs | 30 ++- .../tests/AssistantsTests.cs | 13 +- .../tests/FilesTests.cs | 2 +- .../tests/FunctionsTests.cs | 9 +- .../tests/RetrievalTests.cs | 2 +- .../tests/Samples/Samples_AssistantsClient.cs | 6 +- .../tests/Samples/Samples_Functions.cs | 10 +- .../tests/Samples/Samples_Retrieval.cs | 2 +- .../tests/TestHelpers.cs | 4 +- .../tsp-location.yaml | 2 +- 63 files changed, 729 insertions(+), 372 deletions(-) rename sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/{MessageFileCitationTextAnnotation.cs => MessageTextFileCitationAnnotation.cs} (93%) rename sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/{MessageFilePathTextAnnotation.cs => MessageTextFilePathAnnotation.cs} (69%) create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/OpenAIFile.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/RequiredFunctionToolCall.cs rename sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/{CreateFileRequest.Serialization.cs => UploadFileRequest.Serialization.cs} (58%) delete mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/Visibility/ListSortOrder.cs rename sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/{CreateRunRequest.Serialization.cs => CreateRunOptions.Serialization.cs} (51%) rename sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/{CreateRunRequest.cs => CreateRunOptions.cs} (73%) rename sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/{InternalMessageFilePathDetails.Serialization.cs => InternalMessageTextFilePathDetails.Serialization.cs} (68%) rename sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/{InternalMessageFilePathDetails.cs => InternalMessageTextFilePathDetails.cs} (82%) rename sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/{MessageFileCitationTextAnnotation.Serialization.cs => MessageTextFileCitationAnnotation.Serialization.cs} (84%) rename sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/{MessageFileCitationTextAnnotation.cs => MessageTextFileCitationAnnotation.cs} (89%) rename sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/{MessageFilePathTextAnnotation.Serialization.cs => MessageTextFilePathAnnotation.Serialization.cs} (75%) rename sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/{MessageFilePathTextAnnotation.cs => MessageTextFilePathAnnotation.cs} (78%) create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RequiredFunctionToolCall.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RequiredFunctionToolCall.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RequiredToolCall.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RequiredToolCall.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownRequiredToolCall.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownRequiredToolCall.cs rename sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/{AssistantModificationOptions.Serialization.cs => UpdateAssistantOptions.Serialization.cs} (97%) rename sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/{AssistantModificationOptions.cs => UpdateAssistantOptions.cs} (86%) rename sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/{ModifyMessageRequest.Serialization.cs => UpdateMessageRequest.Serialization.cs} (95%) rename sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/{ModifyMessageRequest.cs => UpdateMessageRequest.cs} (71%) rename sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/{ModifyRunRequest.Serialization.cs => UpdateRunRequest.Serialization.cs} (95%) rename sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/{ModifyRunRequest.cs => UpdateRunRequest.cs} (72%) rename sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/{ModifyThreadRequest.Serialization.cs => UpdateThreadRequest.Serialization.cs} (95%) rename sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/{ModifyThreadRequest.cs => UpdateThreadRequest.cs} (72%) rename sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/{CreateFileRequest.Serialization.cs => UploadFileRequest.Serialization.cs} (92%) rename sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/{CreateFileRequest.cs => UploadFileRequest.cs} (81%) diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/README.md b/sdk/openai/Azure.AI.OpenAI.Assistants/README.md index 3a41c1e52d16..afcf3df4424e 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/README.md +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/README.md @@ -85,8 +85,10 @@ A run can then be started that evaluates the thread against an assistant: ```C# Snippet:OverviewCreateRun Response runResponse = await client.CreateRunAsync( thread.Id, - assistant.Id, - overrideInstructions: "Please address the user as Jane Doe. The user has a premium account."); + new CreateRunOptions(assistant.Id) + { + AdditionalInstructions = "Please address the user as Jane Doe. The user has a premium account.", + }); ThreadRun run = runResponse.Value; ``` @@ -263,15 +265,15 @@ If the assistant calls tools, the calling code will need to resolve `ToolCall` i `ToolOutput` instances. For convenience, a basic example is extracted here: ```C# Snippet:FunctionsHandleFunctionCalls -ToolOutput GetResolvedToolOutput(ToolCall toolCall) +ToolOutput GetResolvedToolOutput(RequiredToolCall toolCall) { - if (toolCall is FunctionToolCall functionToolCall) + if (toolCall is RequiredFunctionToolCall functionToolCall) { if (functionToolCall.Name == getUserFavoriteCityTool.Name) { return new ToolOutput(toolCall, GetUserFavoriteCity()); } - using JsonDocument argumentsJson = JsonDocument.Parse(functionToolCall.Arguments); + using JsonDocument argumentsJson = JsonDocument.Parse(functionToolCall.Parameters); if (functionToolCall.Name == getCityNicknameTool.Name) { string locationArgument = argumentsJson.RootElement.GetProperty("location").GetString(); @@ -307,7 +309,7 @@ do && runResponse.Value.RequiredAction is SubmitToolOutputsAction submitToolOutputsAction) { List toolOutputs = new(); - foreach (ToolCall toolCall in submitToolOutputsAction.ToolCalls) + foreach (RequiredToolCall toolCall in submitToolOutputsAction.ToolCalls) { toolOutputs.Add(GetResolvedToolOutput(toolCall)); } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/api/Azure.AI.OpenAI.Assistants.netstandard2.0.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/api/Azure.AI.OpenAI.Assistants.netstandard2.0.cs index 14645c0e16ee..8d1c5b9cd3fe 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/api/Azure.AI.OpenAI.Assistants.netstandard2.0.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/api/Azure.AI.OpenAI.Assistants.netstandard2.0.cs @@ -31,17 +31,6 @@ internal AssistantFile() { } public System.DateTimeOffset CreatedAt { get { throw null; } } public string Id { get { throw null; } } } - public partial class AssistantModificationOptions - { - public AssistantModificationOptions() { } - public string Description { get { throw null; } set { } } - public System.Collections.Generic.IList FileIds { get { throw null; } } - public string Instructions { get { throw null; } set { } } - public System.Collections.Generic.IDictionary Metadata { get { throw null; } set { } } - public string Model { get { throw null; } set { } } - public string Name { get { throw null; } set { } } - public System.Collections.Generic.IList Tools { get { throw null; } } - } public partial class AssistantsClient { protected AssistantsClient() { } @@ -58,8 +47,10 @@ public AssistantsClient(System.Uri endpoint, Azure.Core.TokenCredential tokenCre public virtual System.Threading.Tasks.Task> CreateAssistantAsync(Azure.AI.OpenAI.Assistants.AssistantCreationOptions assistantCreationOptions, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Response CreateMessage(string threadId, Azure.AI.OpenAI.Assistants.MessageRole role, string content, System.Collections.Generic.IEnumerable fileIds = null, System.Collections.Generic.IDictionary metadata = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task> CreateMessageAsync(string threadId, Azure.AI.OpenAI.Assistants.MessageRole role, string content, System.Collections.Generic.IEnumerable fileIds = null, System.Collections.Generic.IDictionary metadata = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual Azure.Response CreateRun(string threadId, string assistantId, string overrideModelName = null, string overrideInstructions = null, System.Collections.Generic.IEnumerable overrideTools = null, System.Collections.Generic.IDictionary metadata = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task> CreateRunAsync(string threadId, string assistantId, string overrideModelName = null, string overrideInstructions = null, System.Collections.Generic.IEnumerable overrideTools = null, System.Collections.Generic.IDictionary metadata = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response CreateRun(Azure.AI.OpenAI.Assistants.AssistantThread thread, Azure.AI.OpenAI.Assistants.Assistant assistant, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response CreateRun(string threadId, Azure.AI.OpenAI.Assistants.CreateRunOptions createRunOptions, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> CreateRunAsync(Azure.AI.OpenAI.Assistants.AssistantThread thread, Azure.AI.OpenAI.Assistants.Assistant assistant, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> CreateRunAsync(string threadId, Azure.AI.OpenAI.Assistants.CreateRunOptions createRunOptions, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Response CreateThread(Azure.AI.OpenAI.Assistants.AssistantThreadCreationOptions assistantThreadCreationOptions, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Response CreateThread(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Response CreateThreadAndRun(Azure.AI.OpenAI.Assistants.CreateAndRunThreadOptions createAndRunThreadOptions, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } @@ -80,6 +71,8 @@ public AssistantsClient(System.Uri endpoint, Azure.Core.TokenCredential tokenCre public virtual System.Threading.Tasks.Task>> GetAssistantFilesAsync(string assistantId, int? limit = default(int?), Azure.AI.OpenAI.Assistants.ListSortOrder? order = default(Azure.AI.OpenAI.Assistants.ListSortOrder?), string after = null, string before = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Response> GetAssistants(int? limit = default(int?), Azure.AI.OpenAI.Assistants.ListSortOrder? order = default(Azure.AI.OpenAI.Assistants.ListSortOrder?), string after = null, string before = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task>> GetAssistantsAsync(int? limit = default(int?), Azure.AI.OpenAI.Assistants.ListSortOrder? order = default(Azure.AI.OpenAI.Assistants.ListSortOrder?), string after = null, string before = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response GetFile(string fileId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> GetFileAsync(string fileId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Response> GetFiles(Azure.AI.OpenAI.Assistants.OpenAIFilePurpose? purpose = default(Azure.AI.OpenAI.Assistants.OpenAIFilePurpose?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task>> GetFilesAsync(Azure.AI.OpenAI.Assistants.OpenAIFilePurpose? purpose = default(Azure.AI.OpenAI.Assistants.OpenAIFilePurpose?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Response GetMessage(string threadId, string messageId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } @@ -104,22 +97,20 @@ public AssistantsClient(System.Uri endpoint, Azure.Core.TokenCredential tokenCre public virtual System.Threading.Tasks.Task> GetThreadAsync(string threadId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Response LinkAssistantFile(string assistantId, string fileId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task> LinkAssistantFileAsync(string assistantId, string fileId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual Azure.Response ModifyAssistant(string assistantId, Azure.AI.OpenAI.Assistants.AssistantModificationOptions modificationOptions, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task> ModifyAssistantAsync(string assistantId, Azure.AI.OpenAI.Assistants.AssistantModificationOptions modificationOptions, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual Azure.Response ModifyMessage(string threadId, string messageId, System.Collections.Generic.IDictionary metadata = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task> ModifyMessageAsync(string threadId, string messageId, System.Collections.Generic.IDictionary metadata = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual Azure.Response ModifyRun(string threadId, string runId, System.Collections.Generic.IDictionary metadata = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task> ModifyRunAsync(string threadId, string runId, System.Collections.Generic.IDictionary metadata = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual Azure.Response ModifyThread(string threadId, System.Collections.Generic.IDictionary metadata = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task> ModifyThreadAsync(string threadId, System.Collections.Generic.IDictionary metadata = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual Azure.Response RetrieveFile(string fileId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task> RetrieveFileAsync(string fileId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Response SubmitToolOutputsToRun(Azure.AI.OpenAI.Assistants.ThreadRun run, System.Collections.Generic.IEnumerable toolOutputs, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Response SubmitToolOutputsToRun(string threadId, string runId, System.Collections.Generic.IEnumerable toolOutputs, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task> SubmitToolOutputsToRunAsync(Azure.AI.OpenAI.Assistants.ThreadRun run, System.Collections.Generic.IEnumerable toolOutputs, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task> SubmitToolOutputsToRunAsync(string threadId, string runId, System.Collections.Generic.IEnumerable toolOutputs, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Response UnlinkAssistantFile(string assistantId, string fileId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task> UnlinkAssistantFileAsync(string assistantId, string fileId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response UpdateAssistant(string assistantId, Azure.AI.OpenAI.Assistants.UpdateAssistantOptions updateAssistantOptions, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> UpdateAssistantAsync(string assistantId, Azure.AI.OpenAI.Assistants.UpdateAssistantOptions updateAssistantOptions, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response UpdateMessage(string threadId, string messageId, System.Collections.Generic.IDictionary metadata = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> UpdateMessageAsync(string threadId, string messageId, System.Collections.Generic.IDictionary metadata = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response UpdateRun(string threadId, string runId, System.Collections.Generic.IDictionary metadata = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> UpdateRunAsync(string threadId, string runId, System.Collections.Generic.IDictionary metadata = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response UpdateThread(string threadId, System.Collections.Generic.IDictionary metadata = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> UpdateThreadAsync(string threadId, System.Collections.Generic.IDictionary metadata = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Response UploadFile(System.BinaryData data, Azure.AI.OpenAI.Assistants.OpenAIFilePurpose purpose, string filename = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Response UploadFile(string localFilePath, Azure.AI.OpenAI.Assistants.OpenAIFilePurpose purpose, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task> UploadFileAsync(System.BinaryData data, Azure.AI.OpenAI.Assistants.OpenAIFilePurpose purpose, string filename = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } @@ -144,13 +135,15 @@ public static partial class AssistantsModelFactory public static Azure.AI.OpenAI.Assistants.CodeInterpreterToolCall CodeInterpreterToolCall(string id, string input, System.Collections.Generic.IReadOnlyList outputs) { throw null; } public static Azure.AI.OpenAI.Assistants.FunctionToolCall FunctionToolCall(string id, string name, string arguments, string output) { throw null; } public static Azure.AI.OpenAI.Assistants.MessageFile MessageFile(string id = null, System.DateTimeOffset createdAt = default(System.DateTimeOffset), string messageId = null) { throw null; } - public static Azure.AI.OpenAI.Assistants.MessageFileCitationTextAnnotation MessageFileCitationTextAnnotation(string text, int startIndex, int endIndex, string fileId, string quote) { throw null; } - public static Azure.AI.OpenAI.Assistants.MessageFilePathTextAnnotation MessageFilePathTextAnnotation(string text, int startIndex, int endIndex, string fileId) { throw null; } + public static Azure.AI.OpenAI.Assistants.MessageTextFileCitationAnnotation MessageFileCitationTextAnnotation(string text, int startIndex, int endIndex, string fileId, string quote) { throw null; } + public static Azure.AI.OpenAI.Assistants.MessageTextFilePathAnnotation MessageFilePathTextAnnotation(string text, int startIndex, int endIndex, string fileId) { throw null; } public static Azure.AI.OpenAI.Assistants.MessageImageFileContent MessageImageFileContent(string fileId) { throw null; } public static Azure.AI.OpenAI.Assistants.MessageTextAnnotation MessageTextAnnotation(string type = null, string text = null, int startIndex = 0, int endIndex = 0) { throw null; } public static Azure.AI.OpenAI.Assistants.MessageTextContent MessageTextContent(string text, System.Collections.Generic.IEnumerable annotations) { throw null; } public static Azure.AI.OpenAI.Assistants.OpenAIFile OpenAIFile(string id = null, int size = 0, string filename = null, System.DateTimeOffset createdAt = default(System.DateTimeOffset), Azure.AI.OpenAI.Assistants.OpenAIFilePurpose purpose = default(Azure.AI.OpenAI.Assistants.OpenAIFilePurpose)) { throw null; } public static Azure.AI.OpenAI.Assistants.PageableList PageableList(System.Collections.Generic.IReadOnlyList data, string firstId, string lastId, bool hasMore) { throw null; } + public static Azure.AI.OpenAI.Assistants.RequiredFunctionToolCall RequiredFunctionToolCall(string toolCallId, string functionName, System.BinaryData functionParameters) { throw null; } + public static Azure.AI.OpenAI.Assistants.RequiredToolCall RequiredToolCall(string type = null, string id = null) { throw null; } public static Azure.AI.OpenAI.Assistants.RetrievalToolCall RetrievalToolCall(string id = null, System.Collections.Generic.IReadOnlyDictionary retrieval = null) { throw null; } public static Azure.AI.OpenAI.Assistants.RunError RunError(string code = null, string message = null) { throw null; } public static Azure.AI.OpenAI.Assistants.RunStep RunStep(string id = null, Azure.AI.OpenAI.Assistants.RunStepType type = default(Azure.AI.OpenAI.Assistants.RunStepType), string assistantId = null, string threadId = null, string runId = null, Azure.AI.OpenAI.Assistants.RunStepStatus status = default(Azure.AI.OpenAI.Assistants.RunStepStatus), Azure.AI.OpenAI.Assistants.RunStepDetails stepDetails = null, Azure.AI.OpenAI.Assistants.RunStepError lastError = null, System.DateTimeOffset createdAt = default(System.DateTimeOffset), System.DateTimeOffset? expiredAt = default(System.DateTimeOffset?), System.DateTimeOffset? completedAt = default(System.DateTimeOffset?), System.DateTimeOffset? cancelledAt = default(System.DateTimeOffset?), System.DateTimeOffset? failedAt = default(System.DateTimeOffset?), System.Collections.Generic.IReadOnlyDictionary metadata = null) { throw null; } @@ -158,7 +151,7 @@ public static partial class AssistantsModelFactory public static Azure.AI.OpenAI.Assistants.RunStepMessageCreationDetails RunStepMessageCreationDetails(Azure.AI.OpenAI.Assistants.RunStepMessageCreationReference messageCreation = null) { throw null; } public static Azure.AI.OpenAI.Assistants.RunStepMessageCreationReference RunStepMessageCreationReference(string messageId = null) { throw null; } public static Azure.AI.OpenAI.Assistants.RunStepToolCallDetails RunStepToolCallDetails(System.Collections.Generic.IEnumerable toolCalls = null) { throw null; } - public static Azure.AI.OpenAI.Assistants.SubmitToolOutputsAction SubmitToolOutputsAction(System.Collections.Generic.IEnumerable toolCalls) { throw null; } + public static Azure.AI.OpenAI.Assistants.SubmitToolOutputsAction SubmitToolOutputsAction(System.Collections.Generic.IEnumerable toolCalls) { throw null; } public static Azure.AI.OpenAI.Assistants.ThreadMessage ThreadMessage(string id = null, System.DateTimeOffset createdAt = default(System.DateTimeOffset), string threadId = null, Azure.AI.OpenAI.Assistants.MessageRole role = default(Azure.AI.OpenAI.Assistants.MessageRole), System.Collections.Generic.IEnumerable contentItems = null, string assistantId = null, string runId = null, System.Collections.Generic.IEnumerable fileIds = null, System.Collections.Generic.IReadOnlyDictionary metadata = null) { throw null; } public static Azure.AI.OpenAI.Assistants.ThreadRun ThreadRun(string id = null, string threadId = null, string assistantId = null, Azure.AI.OpenAI.Assistants.RunStatus status = default(Azure.AI.OpenAI.Assistants.RunStatus), Azure.AI.OpenAI.Assistants.RequiredAction requiredAction = null, Azure.AI.OpenAI.Assistants.RunError lastError = null, string model = null, string instructions = null, System.Collections.Generic.IEnumerable tools = null, System.Collections.Generic.IEnumerable fileIds = null, System.DateTimeOffset createdAt = default(System.DateTimeOffset), System.DateTimeOffset? expiresAt = default(System.DateTimeOffset?), System.DateTimeOffset? startedAt = default(System.DateTimeOffset?), System.DateTimeOffset? completedAt = default(System.DateTimeOffset?), System.DateTimeOffset? cancelledAt = default(System.DateTimeOffset?), System.DateTimeOffset? failedAt = default(System.DateTimeOffset?), System.Collections.Generic.IReadOnlyDictionary metadata = null) { throw null; } public static Azure.AI.OpenAI.Assistants.ToolCall ToolCall(string type = null, string id = null) { throw null; } @@ -215,6 +208,16 @@ public CreateAndRunThreadOptions(string assistantId) { } public System.Collections.Generic.IList OverrideTools { get { throw null; } } public Azure.AI.OpenAI.Assistants.AssistantThreadCreationOptions Thread { get { throw null; } set { } } } + public partial class CreateRunOptions + { + public CreateRunOptions(string assistantId) { } + public string AdditionalInstructions { get { throw null; } set { } } + public string AssistantId { get { throw null; } } + public System.Collections.Generic.IDictionary Metadata { get { throw null; } set { } } + public string OverrideInstructions { get { throw null; } set { } } + public string OverrideModelName { get { throw null; } set { } } + public System.Collections.Generic.IList OverrideTools { get { throw null; } set { } } + } public partial class FunctionToolCall : Azure.AI.OpenAI.Assistants.ToolCall { internal FunctionToolCall() : base (default(string)) { } @@ -265,17 +268,6 @@ internal MessageFile() { } public string Id { get { throw null; } } public string MessageId { get { throw null; } } } - public partial class MessageFileCitationTextAnnotation : Azure.AI.OpenAI.Assistants.MessageTextAnnotation - { - internal MessageFileCitationTextAnnotation() : base (default(string), default(int), default(int)) { } - public string FileId { get { throw null; } } - public string Quote { get { throw null; } } - } - public partial class MessageFilePathTextAnnotation : Azure.AI.OpenAI.Assistants.MessageTextAnnotation - { - internal MessageFilePathTextAnnotation() : base (default(string), default(int), default(int)) { } - public string FileId { get { throw null; } } - } public partial class MessageImageFileContent : Azure.AI.OpenAI.Assistants.MessageContent { internal MessageImageFileContent() { } @@ -312,6 +304,17 @@ internal MessageTextContent() { } public System.Collections.Generic.IReadOnlyList Annotations { get { throw null; } } public string Text { get { throw null; } } } + public partial class MessageTextFileCitationAnnotation : Azure.AI.OpenAI.Assistants.MessageTextAnnotation + { + internal MessageTextFileCitationAnnotation() : base (default(string), default(int), default(int)) { } + public string FileId { get { throw null; } } + public string Quote { get { throw null; } } + } + public partial class MessageTextFilePathAnnotation : Azure.AI.OpenAI.Assistants.MessageTextAnnotation + { + internal MessageTextFilePathAnnotation() : base (default(string), default(int), default(int)) { } + public string FileId { get { throw null; } } + } public partial class OpenAIFile { internal OpenAIFile() { } @@ -356,6 +359,17 @@ public abstract partial class RequiredAction { protected RequiredAction() { } } + public partial class RequiredFunctionToolCall : Azure.AI.OpenAI.Assistants.RequiredToolCall + { + internal RequiredFunctionToolCall() : base (default(string)) { } + public string Name { get { throw null; } } + public System.BinaryData Parameters { get { throw null; } } + } + public abstract partial class RequiredToolCall + { + protected RequiredToolCall(string id) { } + public string Id { get { throw null; } } + } public partial class RetrievalToolCall : Azure.AI.OpenAI.Assistants.ToolCall { internal RetrievalToolCall() : base (default(string)) { } @@ -498,7 +512,7 @@ internal RunStepToolCallDetails() { } public partial class SubmitToolOutputsAction : Azure.AI.OpenAI.Assistants.RequiredAction { internal SubmitToolOutputsAction() { } - public System.Collections.Generic.IReadOnlyList ToolCalls { get { throw null; } } + public System.Collections.Generic.IReadOnlyList ToolCalls { get { throw null; } } } public partial class ThreadInitializationMessage { @@ -554,13 +568,24 @@ protected ToolDefinition() { } public partial class ToolOutput { public ToolOutput() { } - public ToolOutput(Azure.AI.OpenAI.Assistants.ToolCall toolCall) { } - public ToolOutput(Azure.AI.OpenAI.Assistants.ToolCall toolCall, string output) { } + public ToolOutput(Azure.AI.OpenAI.Assistants.RequiredToolCall toolCall) { } + public ToolOutput(Azure.AI.OpenAI.Assistants.RequiredToolCall toolCall, string output) { } public ToolOutput(string toolCallId) { } public ToolOutput(string toolCallId, string output) { } public string Output { get { throw null; } set { } } public string ToolCallId { get { throw null; } set { } } } + public partial class UpdateAssistantOptions + { + public UpdateAssistantOptions() { } + public string Description { get { throw null; } set { } } + public System.Collections.Generic.IList FileIds { get { throw null; } } + public string Instructions { get { throw null; } set { } } + public System.Collections.Generic.IDictionary Metadata { get { throw null; } set { } } + public string Model { get { throw null; } set { } } + public string Name { get { throw null; } set { } } + public System.Collections.Generic.IList Tools { get { throw null; } } + } } namespace Microsoft.Extensions.Azure { diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/assets.json b/sdk/openai/Azure.AI.OpenAI.Assistants/assets.json index f2109759f373..b3135940ce57 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/assets.json +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/assets.json @@ -2,5 +2,5 @@ "AssetsRepo": "Azure/azure-sdk-assets", "AssetsRepoPrefixPath": "net", "TagPrefix": "net/openai/Azure.AI.OpenAI.Assistants", - "Tag": "net/openai/Azure.AI.OpenAI.Assistants_ef4bb9efe2" + "Tag": "net/openai/Azure.AI.OpenAI.Assistants_62ebf0102d" } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Convenience/AssistantsClient.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Convenience/AssistantsClient.cs index e8a972d8bb9e..1aeea8531813 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Convenience/AssistantsClient.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Convenience/AssistantsClient.cs @@ -39,6 +39,37 @@ public virtual Task> CreateThreadAsync( CancellationToken cancellationToken = default) => CreateThreadAsync(new AssistantThreadCreationOptions(), cancellationToken); + /// + /// Creates a new run of the specified thread using a specified assistant. + /// + /// + /// This method will create the run with default configuration. + /// To customize the run, use . + /// + /// The thread that should be run. + /// The assistant that should run the thread. + /// The cancellation token to use. + /// A new instance. + public virtual Response CreateRun(AssistantThread thread, Assistant assistant, CancellationToken cancellationToken = default) + => CreateRun(thread.Id, new CreateRunOptions(assistant.Id), cancellationToken); + + /// + /// Creates a new run of the specified thread using a specified assistant. + /// + /// + /// This method will create the run with default configuration. + /// To customize the run, use . + /// + /// The thread that should be run. + /// The assistant that should run the thread. + /// The cancellation token to use. + /// A new instance. + public virtual Task> CreateRunAsync( + AssistantThread thread, + Assistant assistant, + CancellationToken cancellationToken = default) + => CreateRunAsync(thread.Id, new CreateRunOptions(assistant.Id), cancellationToken); + /// Returns a list of run steps associated an assistant thread run. /// The instance from which run steps should be listed. /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/AssistantsClient.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/AssistantsClient.cs index 53367a7557d9..a5d4c16330de 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/AssistantsClient.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/AssistantsClient.cs @@ -583,10 +583,6 @@ internal HttpMessage CreateRequestMessage( if (_isConfiguredForAzure) { uri.AppendPath("openai"); - if (operationPath.ToLowerInvariant().StartsWith("/files")) - { - uri.AppendPath("/beta", escape: false); - } uri.AppendPath(operationPath, escape: false); uri.AppendQuery("api-version", _apiVersion, true); } @@ -629,7 +625,7 @@ internal HttpMessage CreateCreateAssistantRequest(RequestContent content, Reques internal HttpMessage CreateGetAssistantRequest(string assistantId, RequestContext context) => CreateRequestMessage($"/assistants/{assistantId}", content: null, context, RequestMethod.Get); - internal HttpMessage CreateModifyAssistantRequest(string assistantId, RequestContent content, RequestContext context) + internal HttpMessage CreateUpdateAssistantRequest(string assistantId, RequestContent content, RequestContext context) => CreateRequestMessage($"/assistants/{assistantId}", content, context, RequestMethod.Post); internal HttpMessage CreateInternalDeleteAssistantRequest(string assistantId, RequestContext context) @@ -662,7 +658,7 @@ internal HttpMessage CreateCreateThreadRequest(RequestContent content, RequestCo internal HttpMessage CreateGetThreadRequest(string threadId, RequestContext context) => CreateRequestMessage($"/threads/{threadId}", content: null, context, RequestMethod.Get); - internal HttpMessage CreateModifyThreadRequest(string threadId, RequestContent content, RequestContext context) + internal HttpMessage CreateUpdateThreadRequest(string threadId, RequestContent content, RequestContext context) => CreateRequestMessage($"/threads/{threadId}", content, context, RequestMethod.Post); internal HttpMessage CreateInternalDeleteThreadRequest(string threadId, RequestContext context) => CreateRequestMessage($"/threads/{threadId}", content: null, context, RequestMethod.Delete); @@ -684,7 +680,7 @@ internal HttpMessage CreateInternalGetMessagesRequest(string threadId, int? limi internal HttpMessage CreateGetMessageRequest(string threadId, string messageId, RequestContext context) => CreateRequestMessage($"/threads/{threadId}/messages/{messageId}", content: null, context, RequestMethod.Get); - internal HttpMessage CreateModifyMessageRequest(string threadId, string messageId, RequestContent content, RequestContext context) + internal HttpMessage CreateUpdateMessageRequest(string threadId, string messageId, RequestContent content, RequestContext context) => CreateRequestMessage($"/threads/{threadId}/messages/{messageId}", content, context, RequestMethod.Post); internal HttpMessage CreateInternalGetMessageFilesRequest(string threadId, string messageId, int? limit, string order, string after, string before, RequestContext context) => CreateRequestMessage( @@ -721,9 +717,9 @@ internal HttpMessage CreateInternalGetRunsRequest(string threadId, int? limit, s internal HttpMessage CreateGetRunRequest(string threadId, string runId, RequestContext context) => CreateRequestMessage($"/threads/{threadId}/runs/{runId}", content: null, context, RequestMethod.Get); - internal HttpMessage CreateModifyRunRequest(string threadId, string runId, RequestContent content, RequestContext context) + internal HttpMessage CreateUpdateRunRequest(string threadId, string runId, RequestContent content, RequestContext context) => CreateRequestMessage($"/threads/{threadId}/runs/{runId}", content, context, RequestMethod.Post); - internal HttpMessage CreateSubmitToolOuputsToRunRequest(string threadId, string runId, RequestContent content, RequestContext context) + internal HttpMessage CreateSubmitToolOutputsToRunRequest(string threadId, string runId, RequestContent content, RequestContext context) => CreateRequestMessage( $"/threads/{threadId}/runs/{runId}/submit_tool_outputs", content, @@ -767,7 +763,7 @@ internal HttpMessage CreateUploadFileRequest(RequestContent content, RequestCont internal HttpMessage CreateInternalDeleteFileRequest(string fileId, RequestContext context) => CreateRequestMessage($"/files/{fileId}", content: null, context, RequestMethod.Delete); - internal HttpMessage CreateRetrieveFileRequest(string fileId, RequestContext context) + internal HttpMessage CreateGetFileRequest(string fileId, RequestContext context) => CreateRequestMessage($"/files/{fileId}", content: null, context, RequestMethod.Get); private static TokenCredential CreateDelegatedToken(string token) diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/AssistantsModelFactory.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/AssistantsModelFactory.cs index bad458d25844..1b2e878a4d0f 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/AssistantsModelFactory.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/AssistantsModelFactory.cs @@ -158,6 +158,11 @@ public static ThreadMessage ThreadMessage(string id = null, DateTimeOffset creat return new ThreadMessage(id, @object: null, createdAt, threadId, role, contentItems?.ToList(), assistantId, runId, fileIds?.ToList(), metadata); } + public static RequiredFunctionToolCall RequiredFunctionToolCall(string toolCallId, string functionName, BinaryData functionParameters) + { + return new RequiredFunctionToolCall(toolCallId, new InternalFunctionDefinition(functionName, functionParameters)); + } + public static FunctionToolCall FunctionToolCall(string id, string name, string arguments, string output) { return new FunctionToolCall(id, new InternalFunctionToolCallDetails(name, arguments, output)); @@ -173,7 +178,7 @@ public static CodeInterpreterToolCall CodeInterpreterToolCall(string id, string /// /// The tool calls to include in the mocked action. /// A new instance of SubmitToolOutputsAction. - public static SubmitToolOutputsAction SubmitToolOutputsAction(IEnumerable toolCalls) + public static SubmitToolOutputsAction SubmitToolOutputsAction(IEnumerable toolCalls) { return new SubmitToolOutputsAction(new InternalSubmitToolOutputsDetails(toolCalls)); } @@ -208,9 +213,9 @@ public static MessageImageFileContent MessageImageFileContent(string fileId) /// The file ID for the citation. /// The quote for the citation. /// A new instance of MessageFileCitationTextAnnotation. - public static MessageFileCitationTextAnnotation MessageFileCitationTextAnnotation(string text, int startIndex, int endIndex, string fileId, string quote) + public static MessageTextFileCitationAnnotation MessageFileCitationTextAnnotation(string text, int startIndex, int endIndex, string fileId, string quote) { - return new MessageFileCitationTextAnnotation(text, startIndex, endIndex, new InternalMessageTextFileCitationDetails(fileId, quote)); + return new MessageTextFileCitationAnnotation(text, startIndex, endIndex, new InternalMessageTextFileCitationDetails(fileId, quote)); } /// @@ -221,9 +226,9 @@ public static MessageFileCitationTextAnnotation MessageFileCitationTextAnnotatio /// The end index for the annotation. /// The file ID for the annotation. /// A new instance of MessageFilePathTextAnnotation. - public static MessageFilePathTextAnnotation MessageFilePathTextAnnotation(string text, int startIndex, int endIndex, string fileId) + public static MessageTextFilePathAnnotation MessageFilePathTextAnnotation(string text, int startIndex, int endIndex, string fileId) { - return new MessageFilePathTextAnnotation(text, startIndex, endIndex, new InternalMessageFilePathDetails(fileId)); + return new MessageTextFilePathAnnotation(text, startIndex, endIndex, new InternalMessageTextFilePathDetails(fileId)); } /// diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/MessageFileCitationTextAnnotation.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/MessageTextFileCitationAnnotation.cs similarity index 93% rename from sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/MessageFileCitationTextAnnotation.cs rename to sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/MessageTextFileCitationAnnotation.cs index aa2fa86ce3bb..1f607f3d4720 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/MessageFileCitationTextAnnotation.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/MessageTextFileCitationAnnotation.cs @@ -12,7 +12,7 @@ namespace Azure.AI.OpenAI.Assistants; * is to avoid having types that contain nothing meaningful beyond a property to another type. */ -public partial class MessageFileCitationTextAnnotation +public partial class MessageTextFileCitationAnnotation { /// public string FileId => InternalDetails.FileId; diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/MessageFilePathTextAnnotation.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/MessageTextFilePathAnnotation.cs similarity index 69% rename from sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/MessageFilePathTextAnnotation.cs rename to sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/MessageTextFilePathAnnotation.cs index 99d3678e63ed..42af631294e5 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/MessageFilePathTextAnnotation.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/MessageTextFilePathAnnotation.cs @@ -12,10 +12,10 @@ namespace Azure.AI.OpenAI.Assistants; * is to avoid having types that contain nothing meaningful beyond a property to another type. */ -public partial class MessageFilePathTextAnnotation : MessageTextAnnotation +public partial class MessageTextFilePathAnnotation : MessageTextAnnotation { - /// + /// public string FileId => InternalDetails.FileId; - internal InternalMessageFilePathDetails InternalDetails { get; } + internal InternalMessageTextFilePathDetails InternalDetails { get; } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/OpenAIFile.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/OpenAIFile.cs new file mode 100644 index 000000000000..3c3ff9e9af7c --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/OpenAIFile.cs @@ -0,0 +1,35 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +#nullable disable + +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants; + +/* + * CUSTOM CODE DESCRIPTION: + * + * This is a short-term workaround for an observed parity issue with Azure OpenAI's treatment of 'bytes' on files as + * a nullable integer. + */ + +public partial class OpenAIFile +{ + /// The size of the file, in bytes. + [CodeGenMemberSerializationHooks(DeserializationValueHook = nameof(DeserializeNullableSize))] + public int Size { get; } + + private static void DeserializeNullableSize(JsonProperty property, ref int size) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + size = 0; + } + else + { + size = property.Value.GetInt32(); + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/RequiredFunctionToolCall.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/RequiredFunctionToolCall.cs new file mode 100644 index 000000000000..ab9963d7d322 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/RequiredFunctionToolCall.cs @@ -0,0 +1,26 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +#nullable disable + +using System; + +namespace Azure.AI.OpenAI.Assistants; + +/* + * CUSTOM CODE DESCRIPTION: + * + * These changes facilitate the merging of superficial types introduced by the underlying REST wire format. The goal + * is to avoid having types that contain nothing meaningful beyond a property to another type. + */ + +public partial class RequiredFunctionToolCall +{ + /// + public string Name => InternalFunctionDefinition.Name; + + /// + public BinaryData Parameters => InternalFunctionDefinition.Parameters; + + internal InternalFunctionDefinition InternalFunctionDefinition { get; } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/SubmitToolOutputsAction.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/SubmitToolOutputsAction.cs index 12ac6ba63aa3..79ea9510a62a 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/SubmitToolOutputsAction.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/SubmitToolOutputsAction.cs @@ -18,7 +18,7 @@ public partial class SubmitToolOutputsAction : RequiredAction */ /// - public IReadOnlyList ToolCalls => InternalDetails.ToolCalls; + public IReadOnlyList ToolCalls => InternalDetails.ToolCalls; /// The details describing tools that should be called to submit tool outputs. internal InternalSubmitToolOutputsDetails InternalDetails { get; } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/ToolOutput.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/ToolOutput.cs index 89a3a37e54c9..a8d5f5a79ea3 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/ToolOutput.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/ToolOutput.cs @@ -37,7 +37,7 @@ public ToolOutput(string toolCallId, string output) /// /// When using this constructor, the property should be set prior to submission. /// - public ToolOutput(ToolCall toolCall) + public ToolOutput(RequiredToolCall toolCall) { ToolCallId = toolCall.Id; } @@ -48,7 +48,7 @@ public ToolOutput(ToolCall toolCall) /// /// When using this constructor, the property should be set prior to submission. /// - public ToolOutput(ToolCall toolCall, string output) + public ToolOutput(RequiredToolCall toolCall, string output) { ToolCallId = toolCall.Id; Output = output; diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/CreateFileRequest.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/UploadFileRequest.Serialization.cs similarity index 58% rename from sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/CreateFileRequest.Serialization.cs rename to sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/UploadFileRequest.Serialization.cs index 9e95deaf8bcc..2de2df660139 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/CreateFileRequest.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/UploadFileRequest.Serialization.cs @@ -8,7 +8,7 @@ namespace Azure.AI.OpenAI.Assistants; -internal partial class CreateFileRequest : IUtf8JsonSerializable +internal partial class UploadFileRequest : IUtf8JsonSerializable { /* * CUSTOM CODE DESCRIPTION: @@ -21,12 +21,12 @@ internal virtual RequestContent ToRequestContent() { MultipartFormDataContent content = new(); - content.Add(MultipartContent.Create(Purpose.ToString()), "purpose", new Dictionary()); - content.Add(MultipartContent.Create(Data), new Dictionary() - { - ["Content-Disposition"] = $"form-data; name=file; filename={(string.IsNullOrEmpty(Filename) ? "file" : Filename)}", - ["Content-Type"] = "text/plain", - }); + content.Add(MultipartContent.Create(Purpose.ToString()), "\"purpose\"", new Dictionary()); + content.Add( + MultipartContent.Create(Data), + name: "file", + fileName: string.IsNullOrEmpty(Filename) ? "file" : Filename, + headers: new Dictionary()); return content; } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/Visibility/ListSortOrder.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/Visibility/ListSortOrder.cs deleted file mode 100644 index d7f3aa8e526f..000000000000 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/Visibility/ListSortOrder.cs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#nullable disable - -namespace Azure.AI.OpenAI.Assistants; - -/* - * CUSTOM CODE DESCRIPTION: - * - * Public visibility. @@access decorators don't currently restore this visibility when the consuming methods are - * internalized. - */ - -public readonly partial struct ListSortOrder { } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsClient.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsClient.cs index 80b6f39f8aaa..2c897a420a3b 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsClient.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsClient.cs @@ -332,35 +332,35 @@ internal virtual Response GetAssistant(string assistantId, RequestContext contex /// Modifies an existing assistant. /// The ID of the assistant to modify. - /// The details of the modification to perform on the specified assistant. + /// The request details to use when modifying an existing assistant. /// The cancellation token to use. - /// or is null. + /// or is null. /// is an empty string, and was expected to be non-empty. - public virtual async Task> ModifyAssistantAsync(string assistantId, AssistantModificationOptions modificationOptions, CancellationToken cancellationToken = default) + public virtual async Task> UpdateAssistantAsync(string assistantId, UpdateAssistantOptions updateAssistantOptions, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId)); - Argument.AssertNotNull(modificationOptions, nameof(modificationOptions)); + Argument.AssertNotNull(updateAssistantOptions, nameof(updateAssistantOptions)); RequestContext context = FromCancellationToken(cancellationToken); - using RequestContent content = modificationOptions.ToRequestContent(); - Response response = await ModifyAssistantAsync(assistantId, content, context).ConfigureAwait(false); + using RequestContent content = updateAssistantOptions.ToRequestContent(); + Response response = await UpdateAssistantAsync(assistantId, content, context).ConfigureAwait(false); return Response.FromValue(Assistant.FromResponse(response), response); } /// Modifies an existing assistant. /// The ID of the assistant to modify. - /// The details of the modification to perform on the specified assistant. + /// The request details to use when modifying an existing assistant. /// The cancellation token to use. - /// or is null. + /// or is null. /// is an empty string, and was expected to be non-empty. - public virtual Response ModifyAssistant(string assistantId, AssistantModificationOptions modificationOptions, CancellationToken cancellationToken = default) + public virtual Response UpdateAssistant(string assistantId, UpdateAssistantOptions updateAssistantOptions, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId)); - Argument.AssertNotNull(modificationOptions, nameof(modificationOptions)); + Argument.AssertNotNull(updateAssistantOptions, nameof(updateAssistantOptions)); RequestContext context = FromCancellationToken(cancellationToken); - using RequestContent content = modificationOptions.ToRequestContent(); - Response response = ModifyAssistant(assistantId, content, context); + using RequestContent content = updateAssistantOptions.ToRequestContent(); + Response response = UpdateAssistant(assistantId, content, context); return Response.FromValue(Assistant.FromResponse(response), response); } @@ -381,16 +381,16 @@ public virtual Response ModifyAssistant(string assistantId, Assistant /// is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual async Task ModifyAssistantAsync(string assistantId, RequestContent content, RequestContext context = null) + internal virtual async Task UpdateAssistantAsync(string assistantId, RequestContent content, RequestContext context = null) { Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId)); Argument.AssertNotNull(content, nameof(content)); - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.ModifyAssistant"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.UpdateAssistant"); scope.Start(); try { - using HttpMessage message = CreateModifyAssistantRequest(assistantId, content, context); + using HttpMessage message = CreateUpdateAssistantRequest(assistantId, content, context); return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); } catch (Exception e) @@ -417,16 +417,16 @@ internal virtual async Task ModifyAssistantAsync(string assistantId, R /// is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual Response ModifyAssistant(string assistantId, RequestContent content, RequestContext context = null) + internal virtual Response UpdateAssistant(string assistantId, RequestContent content, RequestContext context = null) { Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId)); Argument.AssertNotNull(content, nameof(content)); - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.ModifyAssistant"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.UpdateAssistant"); scope.Start(); try { - using HttpMessage message = CreateModifyAssistantRequest(assistantId, content, context); + using HttpMessage message = CreateUpdateAssistantRequest(assistantId, content, context); return _pipeline.ProcessMessage(message, context); } catch (Exception e) @@ -1192,16 +1192,16 @@ internal virtual Response GetThread(string threadId, RequestContext context) /// The cancellation token to use. /// is null. /// is an empty string, and was expected to be non-empty. - public virtual async Task> ModifyThreadAsync(string threadId, IDictionary metadata = null, CancellationToken cancellationToken = default) + public virtual async Task> UpdateThreadAsync(string threadId, IDictionary metadata = null, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); RequestContext context = FromCancellationToken(cancellationToken); - ModifyThreadRequest modifyThreadRequest = new ModifyThreadRequest() + UpdateThreadRequest updateThreadRequest = new UpdateThreadRequest() { Metadata = metadata }; - Response response = await ModifyThreadAsync(threadId, modifyThreadRequest.ToRequestContent(), context).ConfigureAwait(false); + Response response = await UpdateThreadAsync(threadId, updateThreadRequest.ToRequestContent(), context).ConfigureAwait(false); return Response.FromValue(AssistantThread.FromResponse(response), response); } @@ -1211,16 +1211,16 @@ public virtual async Task> ModifyThreadAsync(string th /// The cancellation token to use. /// is null. /// is an empty string, and was expected to be non-empty. - public virtual Response ModifyThread(string threadId, IDictionary metadata = null, CancellationToken cancellationToken = default) + public virtual Response UpdateThread(string threadId, IDictionary metadata = null, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); RequestContext context = FromCancellationToken(cancellationToken); - ModifyThreadRequest modifyThreadRequest = new ModifyThreadRequest() + UpdateThreadRequest updateThreadRequest = new UpdateThreadRequest() { Metadata = metadata }; - Response response = ModifyThread(threadId, modifyThreadRequest.ToRequestContent(), context); + Response response = UpdateThread(threadId, updateThreadRequest.ToRequestContent(), context); return Response.FromValue(AssistantThread.FromResponse(response), response); } @@ -1241,16 +1241,16 @@ public virtual Response ModifyThread(string threadId, IDictiona /// is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual async Task ModifyThreadAsync(string threadId, RequestContent content, RequestContext context = null) + internal virtual async Task UpdateThreadAsync(string threadId, RequestContent content, RequestContext context = null) { Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); Argument.AssertNotNull(content, nameof(content)); - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.ModifyThread"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.UpdateThread"); scope.Start(); try { - using HttpMessage message = CreateModifyThreadRequest(threadId, content, context); + using HttpMessage message = CreateUpdateThreadRequest(threadId, content, context); return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); } catch (Exception e) @@ -1277,16 +1277,16 @@ internal virtual async Task ModifyThreadAsync(string threadId, Request /// is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual Response ModifyThread(string threadId, RequestContent content, RequestContext context = null) + internal virtual Response UpdateThread(string threadId, RequestContent content, RequestContext context = null) { Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); Argument.AssertNotNull(content, nameof(content)); - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.ModifyThread"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.UpdateThread"); scope.Start(); try { - using HttpMessage message = CreateModifyThreadRequest(threadId, content, context); + using HttpMessage message = CreateUpdateThreadRequest(threadId, content, context); return _pipeline.ProcessMessage(message, context); } catch (Exception e) @@ -1769,17 +1769,17 @@ internal virtual Response GetMessage(string threadId, string messageId, RequestC /// The cancellation token to use. /// or is null. /// or is an empty string, and was expected to be non-empty. - public virtual async Task> ModifyMessageAsync(string threadId, string messageId, IDictionary metadata = null, CancellationToken cancellationToken = default) + public virtual async Task> UpdateMessageAsync(string threadId, string messageId, IDictionary metadata = null, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); Argument.AssertNotNullOrEmpty(messageId, nameof(messageId)); RequestContext context = FromCancellationToken(cancellationToken); - ModifyMessageRequest modifyMessageRequest = new ModifyMessageRequest() + UpdateMessageRequest updateMessageRequest = new UpdateMessageRequest() { Metadata = metadata }; - Response response = await ModifyMessageAsync(threadId, messageId, modifyMessageRequest.ToRequestContent(), context).ConfigureAwait(false); + Response response = await UpdateMessageAsync(threadId, messageId, updateMessageRequest.ToRequestContent(), context).ConfigureAwait(false); return Response.FromValue(ThreadMessage.FromResponse(response), response); } @@ -1790,17 +1790,17 @@ public virtual async Task> ModifyMessageAsync(string thr /// The cancellation token to use. /// or is null. /// or is an empty string, and was expected to be non-empty. - public virtual Response ModifyMessage(string threadId, string messageId, IDictionary metadata = null, CancellationToken cancellationToken = default) + public virtual Response UpdateMessage(string threadId, string messageId, IDictionary metadata = null, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); Argument.AssertNotNullOrEmpty(messageId, nameof(messageId)); RequestContext context = FromCancellationToken(cancellationToken); - ModifyMessageRequest modifyMessageRequest = new ModifyMessageRequest() + UpdateMessageRequest updateMessageRequest = new UpdateMessageRequest() { Metadata = metadata }; - Response response = ModifyMessage(threadId, messageId, modifyMessageRequest.ToRequestContent(), context); + Response response = UpdateMessage(threadId, messageId, updateMessageRequest.ToRequestContent(), context); return Response.FromValue(ThreadMessage.FromResponse(response), response); } @@ -1822,17 +1822,17 @@ public virtual Response ModifyMessage(string threadId, string mes /// or is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual async Task ModifyMessageAsync(string threadId, string messageId, RequestContent content, RequestContext context = null) + internal virtual async Task UpdateMessageAsync(string threadId, string messageId, RequestContent content, RequestContext context = null) { Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); Argument.AssertNotNullOrEmpty(messageId, nameof(messageId)); Argument.AssertNotNull(content, nameof(content)); - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.ModifyMessage"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.UpdateMessage"); scope.Start(); try { - using HttpMessage message = CreateModifyMessageRequest(threadId, messageId, content, context); + using HttpMessage message = CreateUpdateMessageRequest(threadId, messageId, content, context); return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); } catch (Exception e) @@ -1860,17 +1860,17 @@ internal virtual async Task ModifyMessageAsync(string threadId, string /// or is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual Response ModifyMessage(string threadId, string messageId, RequestContent content, RequestContext context = null) + internal virtual Response UpdateMessage(string threadId, string messageId, RequestContent content, RequestContext context = null) { Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); Argument.AssertNotNullOrEmpty(messageId, nameof(messageId)); Argument.AssertNotNull(content, nameof(content)); - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.ModifyMessage"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.UpdateMessage"); scope.Start(); try { - using HttpMessage message = CreateModifyMessageRequest(threadId, messageId, content, context); + using HttpMessage message = CreateUpdateMessageRequest(threadId, messageId, content, context); return _pipeline.ProcessMessage(message, context); } catch (Exception e) @@ -2124,69 +2124,35 @@ internal virtual Response GetMessageFile(string threadId, string messageId, stri /// Creates a new run for an assistant thread. /// The ID of the thread to run. - /// The ID of the assistant that should run the thread. - /// The overridden model name that the assistant should use to run the thread. - /// The overridden system instructions that the assistant should use to run the thread. - /// The overridden list of enabled tools that the assistant should use to run the thread. - /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. + /// The details for the run to create. /// The cancellation token to use. - /// or is null. + /// or is null. /// is an empty string, and was expected to be non-empty. - public virtual async Task> CreateRunAsync(string threadId, string assistantId, string overrideModelName = null, string overrideInstructions = null, IEnumerable overrideTools = null, IDictionary metadata = null, CancellationToken cancellationToken = default) + public virtual async Task> CreateRunAsync(string threadId, CreateRunOptions createRunOptions, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); - Argument.AssertNotNull(assistantId, nameof(assistantId)); + Argument.AssertNotNull(createRunOptions, nameof(createRunOptions)); RequestContext context = FromCancellationToken(cancellationToken); - CreateRunRequest createRunRequest = new CreateRunRequest(assistantId) - { - OverrideModelName = overrideModelName, - OverrideInstructions = overrideInstructions, - Metadata = metadata - }; - if (overrideTools != null) - { - foreach (var value in overrideTools) - { - createRunRequest.OverrideTools.Add(value); - } - } - CreateRunRequest createRunRequest0 = createRunRequest; - Response response = await CreateRunAsync(threadId, createRunRequest0.ToRequestContent(), context).ConfigureAwait(false); + using RequestContent content = createRunOptions.ToRequestContent(); + Response response = await CreateRunAsync(threadId, content, context).ConfigureAwait(false); return Response.FromValue(ThreadRun.FromResponse(response), response); } /// Creates a new run for an assistant thread. /// The ID of the thread to run. - /// The ID of the assistant that should run the thread. - /// The overridden model name that the assistant should use to run the thread. - /// The overridden system instructions that the assistant should use to run the thread. - /// The overridden list of enabled tools that the assistant should use to run the thread. - /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. + /// The details for the run to create. /// The cancellation token to use. - /// or is null. + /// or is null. /// is an empty string, and was expected to be non-empty. - public virtual Response CreateRun(string threadId, string assistantId, string overrideModelName = null, string overrideInstructions = null, IEnumerable overrideTools = null, IDictionary metadata = null, CancellationToken cancellationToken = default) + public virtual Response CreateRun(string threadId, CreateRunOptions createRunOptions, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); - Argument.AssertNotNull(assistantId, nameof(assistantId)); + Argument.AssertNotNull(createRunOptions, nameof(createRunOptions)); RequestContext context = FromCancellationToken(cancellationToken); - CreateRunRequest createRunRequest = new CreateRunRequest(assistantId) - { - OverrideModelName = overrideModelName, - OverrideInstructions = overrideInstructions, - Metadata = metadata - }; - if (overrideTools != null) - { - foreach (var value in overrideTools) - { - createRunRequest.OverrideTools.Add(value); - } - } - CreateRunRequest createRunRequest0 = createRunRequest; - Response response = CreateRun(threadId, createRunRequest0.ToRequestContent(), context); + using RequestContent content = createRunOptions.ToRequestContent(); + Response response = CreateRun(threadId, content, context); return Response.FromValue(ThreadRun.FromResponse(response), response); } @@ -2495,17 +2461,17 @@ internal virtual Response GetRun(string threadId, string runId, RequestContext c /// The cancellation token to use. /// or is null. /// or is an empty string, and was expected to be non-empty. - public virtual async Task> ModifyRunAsync(string threadId, string runId, IDictionary metadata = null, CancellationToken cancellationToken = default) + public virtual async Task> UpdateRunAsync(string threadId, string runId, IDictionary metadata = null, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); Argument.AssertNotNullOrEmpty(runId, nameof(runId)); RequestContext context = FromCancellationToken(cancellationToken); - ModifyRunRequest modifyRunRequest = new ModifyRunRequest() + UpdateRunRequest updateRunRequest = new UpdateRunRequest() { Metadata = metadata }; - Response response = await ModifyRunAsync(threadId, runId, modifyRunRequest.ToRequestContent(), context).ConfigureAwait(false); + Response response = await UpdateRunAsync(threadId, runId, updateRunRequest.ToRequestContent(), context).ConfigureAwait(false); return Response.FromValue(ThreadRun.FromResponse(response), response); } @@ -2516,17 +2482,17 @@ public virtual async Task> ModifyRunAsync(string threadId, s /// The cancellation token to use. /// or is null. /// or is an empty string, and was expected to be non-empty. - public virtual Response ModifyRun(string threadId, string runId, IDictionary metadata = null, CancellationToken cancellationToken = default) + public virtual Response UpdateRun(string threadId, string runId, IDictionary metadata = null, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); Argument.AssertNotNullOrEmpty(runId, nameof(runId)); RequestContext context = FromCancellationToken(cancellationToken); - ModifyRunRequest modifyRunRequest = new ModifyRunRequest() + UpdateRunRequest updateRunRequest = new UpdateRunRequest() { Metadata = metadata }; - Response response = ModifyRun(threadId, runId, modifyRunRequest.ToRequestContent(), context); + Response response = UpdateRun(threadId, runId, updateRunRequest.ToRequestContent(), context); return Response.FromValue(ThreadRun.FromResponse(response), response); } @@ -2548,17 +2514,17 @@ public virtual Response ModifyRun(string threadId, string runId, IDic /// or is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual async Task ModifyRunAsync(string threadId, string runId, RequestContent content, RequestContext context = null) + internal virtual async Task UpdateRunAsync(string threadId, string runId, RequestContent content, RequestContext context = null) { Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); Argument.AssertNotNullOrEmpty(runId, nameof(runId)); Argument.AssertNotNull(content, nameof(content)); - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.ModifyRun"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.UpdateRun"); scope.Start(); try { - using HttpMessage message = CreateModifyRunRequest(threadId, runId, content, context); + using HttpMessage message = CreateUpdateRunRequest(threadId, runId, content, context); return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); } catch (Exception e) @@ -2586,17 +2552,17 @@ internal virtual async Task ModifyRunAsync(string threadId, string run /// or is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual Response ModifyRun(string threadId, string runId, RequestContent content, RequestContext context = null) + internal virtual Response UpdateRun(string threadId, string runId, RequestContent content, RequestContext context = null) { Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); Argument.AssertNotNullOrEmpty(runId, nameof(runId)); Argument.AssertNotNull(content, nameof(content)); - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.ModifyRun"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.UpdateRun"); scope.Start(); try { - using HttpMessage message = CreateModifyRunRequest(threadId, runId, content, context); + using HttpMessage message = CreateUpdateRunRequest(threadId, runId, content, context); return _pipeline.ProcessMessage(message, context); } catch (Exception e) @@ -3261,11 +3227,11 @@ public virtual async Task> UploadFileAsync(BinaryData data, Argument.AssertNotNull(data, nameof(data)); RequestContext context = FromCancellationToken(cancellationToken); - CreateFileRequest createFileRequest = new CreateFileRequest(data, purpose) + UploadFileRequest uploadFileRequest = new UploadFileRequest(data, purpose) { Filename = filename }; - Response response = await UploadFileAsync(createFileRequest.ToRequestContent(), context).ConfigureAwait(false); + Response response = await UploadFileAsync(uploadFileRequest.ToRequestContent(), context).ConfigureAwait(false); return Response.FromValue(OpenAIFile.FromResponse(response), response); } @@ -3280,11 +3246,11 @@ public virtual Response UploadFile(BinaryData data, OpenAIFilePurpos Argument.AssertNotNull(data, nameof(data)); RequestContext context = FromCancellationToken(cancellationToken); - CreateFileRequest createFileRequest = new CreateFileRequest(data, purpose) + UploadFileRequest uploadFileRequest = new UploadFileRequest(data, purpose) { Filename = filename }; - Response response = UploadFile(createFileRequest.ToRequestContent(), context); + Response response = UploadFile(uploadFileRequest.ToRequestContent(), context); return Response.FromValue(OpenAIFile.FromResponse(response), response); } @@ -3465,12 +3431,12 @@ internal virtual Response InternalDeleteFile(string fileId, RequestContext conte /// The cancellation token to use. /// is null. /// is an empty string, and was expected to be non-empty. - public virtual async Task> RetrieveFileAsync(string fileId, CancellationToken cancellationToken = default) + public virtual async Task> GetFileAsync(string fileId, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); RequestContext context = FromCancellationToken(cancellationToken); - Response response = await RetrieveFileAsync(fileId, context).ConfigureAwait(false); + Response response = await GetFileAsync(fileId, context).ConfigureAwait(false); return Response.FromValue(OpenAIFile.FromResponse(response), response); } @@ -3479,12 +3445,12 @@ public virtual async Task> RetrieveFileAsync(string fileId, /// The cancellation token to use. /// is null. /// is an empty string, and was expected to be non-empty. - public virtual Response RetrieveFile(string fileId, CancellationToken cancellationToken = default) + public virtual Response GetFile(string fileId, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); RequestContext context = FromCancellationToken(cancellationToken); - Response response = RetrieveFile(fileId, context); + Response response = GetFile(fileId, context); return Response.FromValue(OpenAIFile.FromResponse(response), response); } @@ -3504,15 +3470,15 @@ public virtual Response RetrieveFile(string fileId, CancellationToke /// is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual async Task RetrieveFileAsync(string fileId, RequestContext context) + internal virtual async Task GetFileAsync(string fileId, RequestContext context) { Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.RetrieveFile"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.GetFile"); scope.Start(); try { - using HttpMessage message = CreateRetrieveFileRequest(fileId, context); + using HttpMessage message = CreateGetFileRequest(fileId, context); return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); } catch (Exception e) @@ -3538,15 +3504,15 @@ internal virtual async Task RetrieveFileAsync(string fileId, RequestCo /// is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual Response RetrieveFile(string fileId, RequestContext context) + internal virtual Response GetFile(string fileId, RequestContext context) { Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.RetrieveFile"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.GetFile"); scope.Start(); try { - using HttpMessage message = CreateRetrieveFileRequest(fileId, context); + using HttpMessage message = CreateGetFileRequest(fileId, context); return _pipeline.ProcessMessage(message, context); } catch (Exception e) @@ -3556,25 +3522,6 @@ internal virtual Response RetrieveFile(string fileId, RequestContext context) } } - internal HttpMessage CreateSubmitToolOutputsToRunRequest(string threadId, string runId, RequestContent content, RequestContext context) - { - var message = _pipeline.CreateMessage(context, ResponseClassifier200); - var request = message.Request; - request.Method = RequestMethod.Post; - var uri = new RawRequestUriBuilder(); - uri.Reset(_endpoint); - uri.AppendPath("/threads/", false); - uri.AppendPath(threadId, true); - uri.AppendPath("/runs/", false); - uri.AppendPath(runId, true); - uri.AppendPath("/submit_tool_outputs", false); - request.Uri = uri; - request.Headers.Add("Accept", "application/json"); - request.Headers.Add("Content-Type", "application/json"); - request.Content = content; - return message; - } - private static RequestContext DefaultRequestContext = new RequestContext(); internal static RequestContext FromCancellationToken(CancellationToken cancellationToken = default) { diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsModelFactory.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsModelFactory.cs index 36856e6eb73c..5e35bab278ec 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsModelFactory.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsModelFactory.cs @@ -48,6 +48,15 @@ public static RunStepError RunStepError(RunStepErrorCode code = default, string return new RunStepError(code, message); } + /// Initializes a new instance of . + /// The object type for the required tool call. + /// The ID of the tool call. This ID must be referenced when submitting tool outputs. + /// A new instance for mocking. + public static RequiredToolCall RequiredToolCall(string type = null, string id = null) + { + return new UnknownRequiredToolCall(type, id); + } + /// Initializes a new instance of . /// The object type. /// The ID of the tool call. This ID must be referenced when you submit tool outputs. @@ -132,7 +141,7 @@ public static RunStepMessageCreationReference RunStepMessageCreationReference(st } /// Initializes a new instance of . - /// A list tool call details for this run step. + /// A list of tool call details for this run step. /// A new instance for mocking. public static RunStepToolCallDetails RunStepToolCallDetails(IEnumerable toolCalls = null) { diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterToolCall.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterToolCall.cs index 5e63c73fd8c2..7ff205504495 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterToolCall.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterToolCall.cs @@ -11,8 +11,8 @@ namespace Azure.AI.OpenAI.Assistants { /// - /// A tool call to a code interpreter tool, issued by the model in evaluation of a configured code interpreter tool, that - /// represents submitted output needed or already fulfilled by the tool for the model to continue. + /// A record of a call to a code interpreter tool, issued by the model in evaluation of a defined tool, that + /// represents inputs and outputs consumed and emitted by the code interpreter. /// public partial class CodeInterpreterToolCall : ToolCall { diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateRunRequest.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateRunOptions.Serialization.cs similarity index 51% rename from sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateRunRequest.Serialization.cs rename to sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateRunOptions.Serialization.cs index efc7a9938301..53e2bc6d2984 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateRunRequest.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateRunOptions.Serialization.cs @@ -10,7 +10,7 @@ namespace Azure.AI.OpenAI.Assistants { - internal partial class CreateRunRequest : IUtf8JsonSerializable + public partial class CreateRunOptions : IUtf8JsonSerializable { void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) { @@ -19,23 +19,56 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) writer.WriteStringValue(AssistantId); if (Optional.IsDefined(OverrideModelName)) { - writer.WritePropertyName("model"u8); - writer.WriteStringValue(OverrideModelName); + if (OverrideModelName != null) + { + writer.WritePropertyName("model"u8); + writer.WriteStringValue(OverrideModelName); + } + else + { + writer.WriteNull("model"); + } } if (Optional.IsDefined(OverrideInstructions)) { - writer.WritePropertyName("instructions"u8); - writer.WriteStringValue(OverrideInstructions); + if (OverrideInstructions != null) + { + writer.WritePropertyName("instructions"u8); + writer.WriteStringValue(OverrideInstructions); + } + else + { + writer.WriteNull("instructions"); + } + } + if (Optional.IsDefined(AdditionalInstructions)) + { + if (AdditionalInstructions != null) + { + writer.WritePropertyName("additional_instructions"u8); + writer.WriteStringValue(AdditionalInstructions); + } + else + { + writer.WriteNull("additional_instructions"); + } } if (Optional.IsCollectionDefined(OverrideTools)) { - writer.WritePropertyName("tools"u8); - writer.WriteStartArray(); - foreach (var item in OverrideTools) + if (OverrideTools != null) + { + writer.WritePropertyName("tools"u8); + writer.WriteStartArray(); + foreach (var item in OverrideTools) + { + writer.WriteObjectValue(item); + } + writer.WriteEndArray(); + } + else { - writer.WriteObjectValue(item); + writer.WriteNull("tools"); } - writer.WriteEndArray(); } if (Optional.IsCollectionDefined(Metadata)) { diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateRunRequest.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateRunOptions.cs similarity index 73% rename from sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateRunRequest.cs rename to sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateRunOptions.cs index 62c1f406617c..2a667424102e 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateRunRequest.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateRunOptions.cs @@ -11,13 +11,13 @@ namespace Azure.AI.OpenAI.Assistants { - /// The CreateRunRequest. - internal partial class CreateRunRequest + /// The details used when creating a new run of an assistant thread. + public partial class CreateRunOptions { - /// Initializes a new instance of . + /// Initializes a new instance of . /// The ID of the assistant that should run the thread. /// is null. - public CreateRunRequest(string assistantId) + public CreateRunOptions(string assistantId) { Argument.AssertNotNull(assistantId, nameof(assistantId)); @@ -26,17 +26,22 @@ public CreateRunRequest(string assistantId) Metadata = new ChangeTrackingDictionary(); } - /// Initializes a new instance of . + /// Initializes a new instance of . /// The ID of the assistant that should run the thread. /// The overridden model name that the assistant should use to run the thread. /// The overridden system instructions that the assistant should use to run the thread. + /// + /// Additional instructions to append at the end of the instructions for the run. This is useful for modifying the behavior + /// on a per-run basis without overriding other instructions. + /// /// The overridden list of enabled tools that the assistant should use to run the thread. /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. - internal CreateRunRequest(string assistantId, string overrideModelName, string overrideInstructions, IList overrideTools, IDictionary metadata) + internal CreateRunOptions(string assistantId, string overrideModelName, string overrideInstructions, string additionalInstructions, IList overrideTools, IDictionary metadata) { AssistantId = assistantId; OverrideModelName = overrideModelName; OverrideInstructions = overrideInstructions; + AdditionalInstructions = additionalInstructions; OverrideTools = overrideTools; Metadata = metadata; } @@ -48,11 +53,16 @@ internal CreateRunRequest(string assistantId, string overrideModelName, string o /// The overridden system instructions that the assistant should use to run the thread. public string OverrideInstructions { get; set; } /// + /// Additional instructions to append at the end of the instructions for the run. This is useful for modifying the behavior + /// on a per-run basis without overriding other instructions. + /// + public string AdditionalInstructions { get; set; } + /// /// The overridden list of enabled tools that the assistant should use to run the thread. /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. /// The available derived classes include , and . /// - public IList OverrideTools { get; } + public IList OverrideTools { get; set; } /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. public IDictionary Metadata { get; set; } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/FunctionToolCall.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/FunctionToolCall.cs index 4db7d3b5dc4e..839e92631519 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/FunctionToolCall.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/FunctionToolCall.cs @@ -11,8 +11,8 @@ namespace Azure.AI.OpenAI.Assistants { /// - /// A tool call to a function tool, issued by the model in evaluation of a configured function tool, that represents - /// given function inputs and submitted function outputs needed or already fulfilled by the tool for the model to continue. + /// A record of a call to a function tool, issued by the model in evaluation of a defined tool, that represents the inputs + /// and output consumed and emitted by the specified function. /// public partial class FunctionToolCall : ToolCall { diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextDetails.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextDetails.cs index 0242076ac8d2..84f5a03f57ce 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextDetails.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextDetails.cs @@ -42,7 +42,7 @@ internal InternalMessageTextDetails(string text, IReadOnlyList /// A list of annotations associated with this text. /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. - /// The available derived classes include and . + /// The available derived classes include and . /// public IReadOnlyList Annotations { get; } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageFilePathDetails.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextFilePathDetails.Serialization.cs similarity index 68% rename from sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageFilePathDetails.Serialization.cs rename to sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextFilePathDetails.Serialization.cs index 112309e1c25b..569554542dc4 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageFilePathDetails.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextFilePathDetails.Serialization.cs @@ -10,9 +10,9 @@ namespace Azure.AI.OpenAI.Assistants { - internal partial class InternalMessageFilePathDetails + internal partial class InternalMessageTextFilePathDetails { - internal static InternalMessageFilePathDetails DeserializeInternalMessageFilePathDetails(JsonElement element) + internal static InternalMessageTextFilePathDetails DeserializeInternalMessageTextFilePathDetails(JsonElement element) { if (element.ValueKind == JsonValueKind.Null) { @@ -27,15 +27,15 @@ internal static InternalMessageFilePathDetails DeserializeInternalMessageFilePat continue; } } - return new InternalMessageFilePathDetails(fileId); + return new InternalMessageTextFilePathDetails(fileId); } /// Deserializes the model from a raw response. /// The response to deserialize the model from. - internal static InternalMessageFilePathDetails FromResponse(Response response) + internal static InternalMessageTextFilePathDetails FromResponse(Response response) { using var document = JsonDocument.Parse(response.Content); - return DeserializeInternalMessageFilePathDetails(document.RootElement); + return DeserializeInternalMessageTextFilePathDetails(document.RootElement); } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageFilePathDetails.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextFilePathDetails.cs similarity index 82% rename from sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageFilePathDetails.cs rename to sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextFilePathDetails.cs index be82f0e885fb..60dc0f0b42e6 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageFilePathDetails.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextFilePathDetails.cs @@ -11,12 +11,12 @@ namespace Azure.AI.OpenAI.Assistants { /// An encapsulation of an image file ID, as used by message image content. - internal partial class InternalMessageFilePathDetails + internal partial class InternalMessageTextFilePathDetails { - /// Initializes a new instance of . + /// Initializes a new instance of . /// The ID of the specific file that the citation is from. /// is null. - internal InternalMessageFilePathDetails(string fileId) + internal InternalMessageTextFilePathDetails(string fileId) { Argument.AssertNotNull(fileId, nameof(fileId)); diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalSubmitToolOutputsDetails.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalSubmitToolOutputsDetails.Serialization.cs index 46bd3aab4aeb..ba3ba9a78e57 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalSubmitToolOutputsDetails.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalSubmitToolOutputsDetails.Serialization.cs @@ -19,15 +19,15 @@ internal static InternalSubmitToolOutputsDetails DeserializeInternalSubmitToolOu { return null; } - IReadOnlyList toolCalls = default; + IReadOnlyList toolCalls = default; foreach (var property in element.EnumerateObject()) { if (property.NameEquals("tool_calls"u8)) { - List array = new List(); + List array = new List(); foreach (var item in property.Value.EnumerateArray()) { - array.Add(ToolCall.DeserializeToolCall(item)); + array.Add(RequiredToolCall.DeserializeRequiredToolCall(item)); } toolCalls = array; continue; diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalSubmitToolOutputsDetails.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalSubmitToolOutputsDetails.cs index d12cae50c58a..60d6550f38d2 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalSubmitToolOutputsDetails.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalSubmitToolOutputsDetails.cs @@ -18,7 +18,7 @@ internal partial class InternalSubmitToolOutputsDetails /// Initializes a new instance of . /// The list of tool calls that must be resolved for the assistant thread run to continue. /// is null. - internal InternalSubmitToolOutputsDetails(IEnumerable toolCalls) + internal InternalSubmitToolOutputsDetails(IEnumerable toolCalls) { Argument.AssertNotNull(toolCalls, nameof(toolCalls)); @@ -27,16 +27,16 @@ internal InternalSubmitToolOutputsDetails(IEnumerable toolCalls) /// Initializes a new instance of . /// The list of tool calls that must be resolved for the assistant thread run to continue. - internal InternalSubmitToolOutputsDetails(IReadOnlyList toolCalls) + internal InternalSubmitToolOutputsDetails(IReadOnlyList toolCalls) { ToolCalls = toolCalls; } /// /// The list of tool calls that must be resolved for the assistant thread run to continue. - /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. - /// The available derived classes include , and . + /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. + /// The available derived classes include . /// - public IReadOnlyList ToolCalls { get; } + public IReadOnlyList ToolCalls { get; } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextAnnotation.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextAnnotation.Serialization.cs index 2308595f17eb..168e5a35e517 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextAnnotation.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextAnnotation.Serialization.cs @@ -22,8 +22,8 @@ internal static MessageTextAnnotation DeserializeMessageTextAnnotation(JsonEleme { switch (discriminator.GetString()) { - case "file_citation": return MessageFileCitationTextAnnotation.DeserializeMessageFileCitationTextAnnotation(element); - case "file_path": return MessageFilePathTextAnnotation.DeserializeMessageFilePathTextAnnotation(element); + case "file_citation": return MessageTextFileCitationAnnotation.DeserializeMessageTextFileCitationAnnotation(element); + case "file_path": return MessageTextFilePathAnnotation.DeserializeMessageTextFilePathAnnotation(element); } } return UnknownMessageTextAnnotation.DeserializeUnknownMessageTextAnnotation(element); diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextAnnotation.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextAnnotation.cs index 4b53462a01ec..f602b67aee86 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextAnnotation.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextAnnotation.cs @@ -13,7 +13,7 @@ namespace Azure.AI.OpenAI.Assistants /// /// An abstract representation of an annotation to text thread message content. /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. - /// The available derived classes include and . + /// The available derived classes include and . /// public abstract partial class MessageTextAnnotation { diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageFileCitationTextAnnotation.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextFileCitationAnnotation.Serialization.cs similarity index 84% rename from sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageFileCitationTextAnnotation.Serialization.cs rename to sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextFileCitationAnnotation.Serialization.cs index 5e614af621a9..8993420f138a 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageFileCitationTextAnnotation.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextFileCitationAnnotation.Serialization.cs @@ -10,9 +10,9 @@ namespace Azure.AI.OpenAI.Assistants { - public partial class MessageFileCitationTextAnnotation + public partial class MessageTextFileCitationAnnotation { - internal static MessageFileCitationTextAnnotation DeserializeMessageFileCitationTextAnnotation(JsonElement element) + internal static MessageTextFileCitationAnnotation DeserializeMessageTextFileCitationAnnotation(JsonElement element) { if (element.ValueKind == JsonValueKind.Null) { @@ -51,15 +51,15 @@ internal static MessageFileCitationTextAnnotation DeserializeMessageFileCitation continue; } } - return new MessageFileCitationTextAnnotation(type, text, startIndex, endIndex, fileCitation); + return new MessageTextFileCitationAnnotation(type, text, startIndex, endIndex, fileCitation); } /// Deserializes the model from a raw response. /// The response to deserialize the model from. - internal static new MessageFileCitationTextAnnotation FromResponse(Response response) + internal static new MessageTextFileCitationAnnotation FromResponse(Response response) { using var document = JsonDocument.Parse(response.Content); - return DeserializeMessageFileCitationTextAnnotation(document.RootElement); + return DeserializeMessageTextFileCitationAnnotation(document.RootElement); } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageFileCitationTextAnnotation.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextFileCitationAnnotation.cs similarity index 89% rename from sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageFileCitationTextAnnotation.cs rename to sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextFileCitationAnnotation.cs index 362ca9826473..beb3871fd74b 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageFileCitationTextAnnotation.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextFileCitationAnnotation.cs @@ -11,9 +11,9 @@ namespace Azure.AI.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 'retrieval' tool to search files. - public partial class MessageFileCitationTextAnnotation : MessageTextAnnotation + public partial class MessageTextFileCitationAnnotation : MessageTextAnnotation { - /// Initializes a new instance of . + /// Initializes a new instance of . /// The textual content associated with this text annotation item. /// The first text index associated with this text annotation. /// The last text index associated with this text annotation. @@ -22,7 +22,7 @@ public partial class MessageFileCitationTextAnnotation : MessageTextAnnotation /// Generated when the assistant uses the "retrieval" tool to search files. /// /// or is null. - internal MessageFileCitationTextAnnotation(string text, int startIndex, int endIndex, InternalMessageTextFileCitationDetails internalDetails) : base(text, startIndex, endIndex) + internal MessageTextFileCitationAnnotation(string text, int startIndex, int endIndex, InternalMessageTextFileCitationDetails internalDetails) : base(text, startIndex, endIndex) { Argument.AssertNotNull(text, nameof(text)); Argument.AssertNotNull(internalDetails, nameof(internalDetails)); @@ -31,7 +31,7 @@ internal MessageFileCitationTextAnnotation(string text, int startIndex, int endI InternalDetails = internalDetails; } - /// Initializes a new instance of . + /// Initializes a new instance of . /// The object type. /// The textual content associated with this text annotation item. /// The first text index associated with this text annotation. @@ -40,7 +40,7 @@ internal MessageFileCitationTextAnnotation(string text, int startIndex, int endI /// A citation within the message that points to a specific quote from a specific file. /// Generated when the assistant uses the "retrieval" tool to search files. /// - internal MessageFileCitationTextAnnotation(string type, string text, int startIndex, int endIndex, InternalMessageTextFileCitationDetails internalDetails) : base(type, text, startIndex, endIndex) + internal MessageTextFileCitationAnnotation(string type, string text, int startIndex, int endIndex, InternalMessageTextFileCitationDetails internalDetails) : base(type, text, startIndex, endIndex) { InternalDetails = internalDetails; } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageFilePathTextAnnotation.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextFilePathAnnotation.Serialization.cs similarity index 75% rename from sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageFilePathTextAnnotation.Serialization.cs rename to sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextFilePathAnnotation.Serialization.cs index 1a56fe587326..e0dddab8f430 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageFilePathTextAnnotation.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextFilePathAnnotation.Serialization.cs @@ -10,15 +10,15 @@ namespace Azure.AI.OpenAI.Assistants { - public partial class MessageFilePathTextAnnotation + public partial class MessageTextFilePathAnnotation { - internal static MessageFilePathTextAnnotation DeserializeMessageFilePathTextAnnotation(JsonElement element) + internal static MessageTextFilePathAnnotation DeserializeMessageTextFilePathAnnotation(JsonElement element) { if (element.ValueKind == JsonValueKind.Null) { return null; } - InternalMessageFilePathDetails filePath = default; + InternalMessageTextFilePathDetails filePath = default; string type = default; string text = default; int startIndex = default; @@ -27,7 +27,7 @@ internal static MessageFilePathTextAnnotation DeserializeMessageFilePathTextAnno { if (property.NameEquals("file_path"u8)) { - filePath = InternalMessageFilePathDetails.DeserializeInternalMessageFilePathDetails(property.Value); + filePath = InternalMessageTextFilePathDetails.DeserializeInternalMessageTextFilePathDetails(property.Value); continue; } if (property.NameEquals("type"u8)) @@ -51,15 +51,15 @@ internal static MessageFilePathTextAnnotation DeserializeMessageFilePathTextAnno continue; } } - return new MessageFilePathTextAnnotation(type, text, startIndex, endIndex, filePath); + return new MessageTextFilePathAnnotation(type, text, startIndex, endIndex, filePath); } /// Deserializes the model from a raw response. /// The response to deserialize the model from. - internal static new MessageFilePathTextAnnotation FromResponse(Response response) + internal static new MessageTextFilePathAnnotation FromResponse(Response response) { using var document = JsonDocument.Parse(response.Content); - return DeserializeMessageFilePathTextAnnotation(document.RootElement); + return DeserializeMessageTextFilePathAnnotation(document.RootElement); } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageFilePathTextAnnotation.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextFilePathAnnotation.cs similarity index 78% rename from sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageFilePathTextAnnotation.cs rename to sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextFilePathAnnotation.cs index a2aa3413b979..840d0f1625d6 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageFilePathTextAnnotation.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextFilePathAnnotation.cs @@ -11,15 +11,15 @@ namespace Azure.AI.OpenAI.Assistants { /// A citation within the message that points to a file located at a specific path. - public partial class MessageFilePathTextAnnotation : MessageTextAnnotation + public partial class MessageTextFilePathAnnotation : MessageTextAnnotation { - /// Initializes a new instance of . + /// Initializes a new instance of . /// The textual content associated with this text annotation item. /// The first text index associated with this text annotation. /// The last text index associated with this text annotation. /// A URL for the file that's generated when the assistant used the code_interpreter tool to generate a file. /// or is null. - internal MessageFilePathTextAnnotation(string text, int startIndex, int endIndex, InternalMessageFilePathDetails internalDetails) : base(text, startIndex, endIndex) + internal MessageTextFilePathAnnotation(string text, int startIndex, int endIndex, InternalMessageTextFilePathDetails internalDetails) : base(text, startIndex, endIndex) { Argument.AssertNotNull(text, nameof(text)); Argument.AssertNotNull(internalDetails, nameof(internalDetails)); @@ -28,13 +28,13 @@ internal MessageFilePathTextAnnotation(string text, int startIndex, int endIndex InternalDetails = internalDetails; } - /// Initializes a new instance of . + /// Initializes a new instance of . /// The object type. /// The textual content associated with this text annotation item. /// The first text index associated with this text annotation. /// The last text index associated with this text annotation. /// A URL for the file that's generated when the assistant used the code_interpreter tool to generate a file. - internal MessageFilePathTextAnnotation(string type, string text, int startIndex, int endIndex, InternalMessageFilePathDetails internalDetails) : base(type, text, startIndex, endIndex) + internal MessageTextFilePathAnnotation(string type, string text, int startIndex, int endIndex, InternalMessageTextFilePathDetails internalDetails) : base(type, text, startIndex, endIndex) { InternalDetails = internalDetails; } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIFile.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIFile.Serialization.cs index 297a60918822..8069a695b136 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIFile.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIFile.Serialization.cs @@ -39,7 +39,7 @@ internal static OpenAIFile DeserializeOpenAIFile(JsonElement element) } if (property.NameEquals("bytes"u8)) { - bytes = property.Value.GetInt32(); + DeserializeNullableSize(property, ref bytes); continue; } if (property.NameEquals("filename"u8)) diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIFile.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIFile.cs index aca056a49a99..4d7f08dd0c9c 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIFile.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIFile.cs @@ -51,8 +51,6 @@ internal OpenAIFile(string @object, string id, int size, string filename, DateTi /// The identifier, which can be referenced in API endpoints. public string Id { get; } - /// The size of the file, in bytes. - public int Size { get; } /// The name of the file. public string Filename { get; } /// The Unix timestamp, in seconds, representing when this object was created. diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RequiredFunctionToolCall.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RequiredFunctionToolCall.Serialization.cs new file mode 100644 index 000000000000..569f9dde89cf --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RequiredFunctionToolCall.Serialization.cs @@ -0,0 +1,53 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class RequiredFunctionToolCall + { + internal static RequiredFunctionToolCall DeserializeRequiredFunctionToolCall(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + InternalFunctionDefinition function = default; + string type = default; + string id = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("function"u8)) + { + function = Assistants.InternalFunctionDefinition.DeserializeInternalFunctionDefinition(property.Value); + continue; + } + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString(); + continue; + } + if (property.NameEquals("id"u8)) + { + id = property.Value.GetString(); + continue; + } + } + return new RequiredFunctionToolCall(type, id, function); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new RequiredFunctionToolCall FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeRequiredFunctionToolCall(document.RootElement); + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RequiredFunctionToolCall.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RequiredFunctionToolCall.cs new file mode 100644 index 000000000000..2ed873ffb523 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RequiredFunctionToolCall.cs @@ -0,0 +1,38 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + /// A representation of a requested call to a function tool, needed by the model to continue evaluation of a run. + public partial class RequiredFunctionToolCall : RequiredToolCall + { + /// Initializes a new instance of . + /// The ID of the tool call. This ID must be referenced when submitting tool outputs. + /// Detailed information about the function to be executed by the tool that includes name and arguments. + /// or is null. + internal RequiredFunctionToolCall(string id, InternalFunctionDefinition internalFunctionDefinition) : base(id) + { + Argument.AssertNotNull(id, nameof(id)); + Argument.AssertNotNull(internalFunctionDefinition, nameof(internalFunctionDefinition)); + + Type = "function"; + InternalFunctionDefinition = internalFunctionDefinition; + } + + /// Initializes a new instance of . + /// The object type for the required tool call. + /// The ID of the tool call. This ID must be referenced when submitting tool outputs. + /// Detailed information about the function to be executed by the tool that includes name and arguments. + internal RequiredFunctionToolCall(string type, string id, InternalFunctionDefinition internalFunctionDefinition) : base(type, id) + { + InternalFunctionDefinition = internalFunctionDefinition; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RequiredToolCall.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RequiredToolCall.Serialization.cs new file mode 100644 index 000000000000..5d0b6e5f3773 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RequiredToolCall.Serialization.cs @@ -0,0 +1,39 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class RequiredToolCall + { + internal static RequiredToolCall DeserializeRequiredToolCall(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + if (element.TryGetProperty("type", out JsonElement discriminator)) + { + switch (discriminator.GetString()) + { + case "function": return RequiredFunctionToolCall.DeserializeRequiredFunctionToolCall(element); + } + } + return UnknownRequiredToolCall.DeserializeUnknownRequiredToolCall(element); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static RequiredToolCall FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeRequiredToolCall(document.RootElement); + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RequiredToolCall.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RequiredToolCall.cs new file mode 100644 index 000000000000..9bc55d38e1d0 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RequiredToolCall.cs @@ -0,0 +1,44 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + /// + /// An abstract representation a a tool invocation needed by the model to continue a run. + /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. + /// The available derived classes include . + /// + public abstract partial class RequiredToolCall + { + /// Initializes a new instance of . + /// The ID of the tool call. This ID must be referenced when submitting tool outputs. + /// is null. + protected RequiredToolCall(string id) + { + Argument.AssertNotNull(id, nameof(id)); + + Id = id; + } + + /// Initializes a new instance of . + /// The object type for the required tool call. + /// The ID of the tool call. This ID must be referenced when submitting tool outputs. + internal RequiredToolCall(string type, string id) + { + Type = type; + Id = id; + } + + /// The object type for the required tool call. + internal string Type { get; set; } + /// The ID of the tool call. This ID must be referenced when submitting tool outputs. + public string Id { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RetrievalToolCall.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RetrievalToolCall.cs index f4d7e1f8b222..ac46f2942ab8 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RetrievalToolCall.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RetrievalToolCall.cs @@ -12,8 +12,8 @@ namespace Azure.AI.OpenAI.Assistants { /// - /// A tool call to a retrieval tool, issued by the model in evaluation of a configured retrieval tool, that represents - /// submitted output needed or already fulfilled by the tool for the model to continue. + /// A record of a call to a retrieval tool, issued by the model in evaluation of a defined tool, that represents + /// executed retrieval actions. /// public partial class RetrievalToolCall : ToolCall { diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepToolCallDetails.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepToolCallDetails.cs index 1e26eb6240c7..7b6b186a8e19 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepToolCallDetails.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepToolCallDetails.cs @@ -16,7 +16,7 @@ namespace Azure.AI.OpenAI.Assistants public partial class RunStepToolCallDetails : RunStepDetails { /// Initializes a new instance of . - /// A list tool call details for this run step. + /// A list of tool call details for this run step. /// is null. internal RunStepToolCallDetails(IEnumerable toolCalls) { @@ -28,14 +28,14 @@ internal RunStepToolCallDetails(IEnumerable toolCalls) /// Initializes a new instance of . /// The object type. - /// A list tool call details for this run step. + /// A list of tool call details for this run step. internal RunStepToolCallDetails(RunStepType type, IReadOnlyList toolCalls) : base(type) { ToolCalls = toolCalls; } /// - /// A list tool call details for this run step. + /// A list of tool call details for this run step. /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. /// The available derived classes include , and . /// diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ToolCall.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ToolCall.cs index 783c92c7119b..3fb7c57e56a4 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ToolCall.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ToolCall.cs @@ -11,8 +11,7 @@ namespace Azure.AI.OpenAI.Assistants { /// - /// An abstract representation a tool call, issued by the model in evaluation of a configured tool definition, that must - /// be fulfilled and have its outputs submitted before the model can continue. + /// An abstract representation of a detailed tool call as recorded within a run step for an existing run. /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. /// The available derived classes include , and . /// diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownRequiredToolCall.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownRequiredToolCall.Serialization.cs new file mode 100644 index 000000000000..18b96e83ca6e --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownRequiredToolCall.Serialization.cs @@ -0,0 +1,47 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure; + +namespace Azure.AI.OpenAI.Assistants +{ + internal partial class UnknownRequiredToolCall + { + internal static UnknownRequiredToolCall DeserializeUnknownRequiredToolCall(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string type = "Unknown"; + string id = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString(); + continue; + } + if (property.NameEquals("id"u8)) + { + id = property.Value.GetString(); + continue; + } + } + return new UnknownRequiredToolCall(type, id); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new UnknownRequiredToolCall FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeUnknownRequiredToolCall(document.RootElement); + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownRequiredToolCall.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownRequiredToolCall.cs new file mode 100644 index 000000000000..f7002d4c3d7c --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownRequiredToolCall.cs @@ -0,0 +1,31 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + /// Unknown version of RequiredToolCall. + internal partial class UnknownRequiredToolCall : RequiredToolCall + { + /// Initializes a new instance of . + /// The ID of the tool call. This ID must be referenced when submitting tool outputs. + /// is null. + internal UnknownRequiredToolCall(string id) : base(id) + { + Argument.AssertNotNull(id, nameof(id)); + } + + /// Initializes a new instance of . + /// The object type for the required tool call. + /// The ID of the tool call. This ID must be referenced when submitting tool outputs. + internal UnknownRequiredToolCall(string type, string id) : base(type, id) + { + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantModificationOptions.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateAssistantOptions.Serialization.cs similarity index 97% rename from sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantModificationOptions.Serialization.cs rename to sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateAssistantOptions.Serialization.cs index ea2c34413be0..f34faaa5e02f 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantModificationOptions.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateAssistantOptions.Serialization.cs @@ -10,7 +10,7 @@ namespace Azure.AI.OpenAI.Assistants { - public partial class AssistantModificationOptions : IUtf8JsonSerializable + public partial class UpdateAssistantOptions : IUtf8JsonSerializable { void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) { diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantModificationOptions.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateAssistantOptions.cs similarity index 86% rename from sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantModificationOptions.cs rename to sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateAssistantOptions.cs index 976809cab927..3d300ca50e04 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantModificationOptions.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateAssistantOptions.cs @@ -11,17 +11,17 @@ namespace Azure.AI.OpenAI.Assistants { /// The request details to use when modifying an existing assistant. - public partial class AssistantModificationOptions + public partial class UpdateAssistantOptions { - /// Initializes a new instance of . - public AssistantModificationOptions() + /// Initializes a new instance of . + public UpdateAssistantOptions() { Tools = new ChangeTrackingList(); FileIds = new ChangeTrackingList(); Metadata = new ChangeTrackingDictionary(); } - /// Initializes a new instance of . + /// Initializes a new instance of . /// The ID of the model to use. /// The modified name for the assistant to use. /// The modified description for the assistant to use. @@ -29,7 +29,7 @@ public AssistantModificationOptions() /// The modified collection of tools to enable for the assistant. /// The modified list of previously uploaded fileIDs to attach to the assistant. /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. - internal AssistantModificationOptions(string model, string name, string description, string instructions, IList tools, IList fileIds, IDictionary metadata) + internal UpdateAssistantOptions(string model, string name, string description, string instructions, IList tools, IList fileIds, IDictionary metadata) { Model = model; Name = name; diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ModifyMessageRequest.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateMessageRequest.Serialization.cs similarity index 95% rename from sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ModifyMessageRequest.Serialization.cs rename to sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateMessageRequest.Serialization.cs index e4560cc47ead..87c5f61ca88f 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ModifyMessageRequest.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateMessageRequest.Serialization.cs @@ -10,7 +10,7 @@ namespace Azure.AI.OpenAI.Assistants { - internal partial class ModifyMessageRequest : IUtf8JsonSerializable + internal partial class UpdateMessageRequest : IUtf8JsonSerializable { void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) { diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ModifyMessageRequest.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateMessageRequest.cs similarity index 71% rename from sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ModifyMessageRequest.cs rename to sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateMessageRequest.cs index eb58a3742ceb..6a666c7f4f67 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ModifyMessageRequest.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateMessageRequest.cs @@ -10,18 +10,18 @@ namespace Azure.AI.OpenAI.Assistants { - /// The ModifyMessageRequest. - internal partial class ModifyMessageRequest + /// The UpdateMessageRequest. + internal partial class UpdateMessageRequest { - /// Initializes a new instance of . - public ModifyMessageRequest() + /// Initializes a new instance of . + public UpdateMessageRequest() { Metadata = new ChangeTrackingDictionary(); } - /// Initializes a new instance of . + /// Initializes a new instance of . /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. - internal ModifyMessageRequest(IDictionary metadata) + internal UpdateMessageRequest(IDictionary metadata) { Metadata = metadata; } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ModifyRunRequest.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateRunRequest.Serialization.cs similarity index 95% rename from sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ModifyRunRequest.Serialization.cs rename to sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateRunRequest.Serialization.cs index 1153d53c570e..403a81afc374 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ModifyRunRequest.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateRunRequest.Serialization.cs @@ -10,7 +10,7 @@ namespace Azure.AI.OpenAI.Assistants { - internal partial class ModifyRunRequest : IUtf8JsonSerializable + internal partial class UpdateRunRequest : IUtf8JsonSerializable { void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) { diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ModifyRunRequest.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateRunRequest.cs similarity index 72% rename from sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ModifyRunRequest.cs rename to sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateRunRequest.cs index dafa9161c384..fff7fc1dde7d 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ModifyRunRequest.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateRunRequest.cs @@ -10,18 +10,18 @@ namespace Azure.AI.OpenAI.Assistants { - /// The ModifyRunRequest. - internal partial class ModifyRunRequest + /// The UpdateRunRequest. + internal partial class UpdateRunRequest { - /// Initializes a new instance of . - public ModifyRunRequest() + /// Initializes a new instance of . + public UpdateRunRequest() { Metadata = new ChangeTrackingDictionary(); } - /// Initializes a new instance of . + /// Initializes a new instance of . /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. - internal ModifyRunRequest(IDictionary metadata) + internal UpdateRunRequest(IDictionary metadata) { Metadata = metadata; } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ModifyThreadRequest.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateThreadRequest.Serialization.cs similarity index 95% rename from sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ModifyThreadRequest.Serialization.cs rename to sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateThreadRequest.Serialization.cs index b3bb6ec74101..1152d8d9b446 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ModifyThreadRequest.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateThreadRequest.Serialization.cs @@ -10,7 +10,7 @@ namespace Azure.AI.OpenAI.Assistants { - internal partial class ModifyThreadRequest : IUtf8JsonSerializable + internal partial class UpdateThreadRequest : IUtf8JsonSerializable { void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) { diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ModifyThreadRequest.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateThreadRequest.cs similarity index 72% rename from sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ModifyThreadRequest.cs rename to sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateThreadRequest.cs index f5aec238ed54..1932f7fe6e88 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ModifyThreadRequest.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateThreadRequest.cs @@ -10,18 +10,18 @@ namespace Azure.AI.OpenAI.Assistants { - /// The ModifyThreadRequest. - internal partial class ModifyThreadRequest + /// The UpdateThreadRequest. + internal partial class UpdateThreadRequest { - /// Initializes a new instance of . - public ModifyThreadRequest() + /// Initializes a new instance of . + public UpdateThreadRequest() { Metadata = new ChangeTrackingDictionary(); } - /// Initializes a new instance of . + /// Initializes a new instance of . /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. - internal ModifyThreadRequest(IDictionary metadata) + internal UpdateThreadRequest(IDictionary metadata) { Metadata = metadata; } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateFileRequest.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UploadFileRequest.Serialization.cs similarity index 92% rename from sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateFileRequest.Serialization.cs rename to sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UploadFileRequest.Serialization.cs index b06b7f4c2ee1..0206b80fb3ef 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateFileRequest.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UploadFileRequest.Serialization.cs @@ -10,7 +10,7 @@ namespace Azure.AI.OpenAI.Assistants { - internal partial class CreateFileRequest : IUtf8JsonSerializable + internal partial class UploadFileRequest : IUtf8JsonSerializable { void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) { diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateFileRequest.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UploadFileRequest.cs similarity index 81% rename from sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateFileRequest.cs rename to sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UploadFileRequest.cs index af2a52e84dd9..e276c52bea44 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateFileRequest.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UploadFileRequest.cs @@ -10,14 +10,14 @@ namespace Azure.AI.OpenAI.Assistants { - /// The CreateFileRequest. - internal partial class CreateFileRequest + /// The UploadFileRequest. + internal partial class UploadFileRequest { - /// Initializes a new instance of . + /// Initializes a new instance of . /// The file data (not filename) to upload. /// The intended purpose of the file. /// is null. - public CreateFileRequest(BinaryData data, OpenAIFilePurpose purpose) + public UploadFileRequest(BinaryData data, OpenAIFilePurpose purpose) { Argument.AssertNotNull(data, nameof(data)); @@ -25,11 +25,11 @@ public CreateFileRequest(BinaryData data, OpenAIFilePurpose purpose) Purpose = purpose; } - /// Initializes a new instance of . + /// Initializes a new instance of . /// The file data (not filename) to upload. /// The intended purpose of the file. /// A filename to associate with the uploaded data. - internal CreateFileRequest(BinaryData data, OpenAIFilePurpose purpose, string filename) + internal UploadFileRequest(BinaryData data, OpenAIFilePurpose purpose, string filename) { Data = data; Purpose = purpose; diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/tests/AssistantsModelFactoryTests.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/tests/AssistantsModelFactoryTests.cs index d55b1c05d4bd..3f113f8155fc 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/tests/AssistantsModelFactoryTests.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/tests/AssistantsModelFactoryTests.cs @@ -296,9 +296,9 @@ public void CanInstantiateTypes() "assistantId", RunStatus.Completed, AssistantsModelFactory.SubmitToolOutputsAction( - new ToolCall[] + new RequiredToolCall[] { - AssistantsModelFactory.FunctionToolCall("id", "name", "arguments", "output"), + AssistantsModelFactory.RequiredFunctionToolCall("id", "name", BinaryData.FromString("parameters")), }), mockRunError, "model", diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/tests/AssistantsTestBase.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/tests/AssistantsTestBase.cs index 5ec0cae2479f..1c34391358c1 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/tests/AssistantsTestBase.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/tests/AssistantsTestBase.cs @@ -21,11 +21,20 @@ protected string TestMetadataValue protected KeyValuePair TestMetadataPair => new(s_testMetadataKey, TestMetadataValue); private static readonly string s_placeholderAzureResourceUrl = "https://my-resource.openai.azure.com"; - protected readonly string _azureResourceUrl; + protected string AzureResourceUrl + => Recording?.Mode == RecordedTestMode.Record || Recording?.Mode == RecordedTestMode.Live + ? TestEnvironment.AzureOpenAIResourceUri + : s_placeholderAzureResourceUrl; private static readonly string s_placeholderApiKey = "placeholder"; - protected readonly string _nonAzureApiKey; - protected readonly AzureKeyCredential _azureApiKeyCredential; + protected string NonAzureApiKey + => Recording?.Mode == RecordedTestMode.Record || Recording?.Mode == RecordedTestMode.Live + ? TestEnvironment.NonAzureOpenAIApiKey + : s_placeholderApiKey; + protected AzureKeyCredential AzureApiKeyCredential + => Recording?.Mode == RecordedTestMode.Record || Recording?.Mode == RecordedTestMode.Live + ? new(TestEnvironment.AzureOpenAIApiKey) + : new(s_placeholderApiKey); public List<(AssistantsClient, string)> EnsuredFileDeletions = new(); public List<(AssistantsClient, string)> EnsuredThreadDeletions = new(); @@ -37,21 +46,8 @@ protected AssistantsTestBase(bool isAsync, RecordedTestMode? mode = null) : base BodyRegexSanitizers.Add(new BodyRegexSanitizer("(\"key\" *: *\")[^ \n\"]*(\")", "$1placeholder$2")); HeaderRegexSanitizers.Add(new HeaderRegexSanitizer("api-key", "***********")); UriRegexSanitizers.Add(new UriRegexSanitizer("sig=[^\"]*", "sig=Sanitized")); + UriRegexSanitizers.Add(new(TestEnvironment.AzureOpenAIResourceUri ?? s_placeholderAzureResourceUrl, s_placeholderAzureResourceUrl)); SanitizedQueryParameters.Add("sig"); - - if (mode == RecordedTestMode.Record || mode == RecordedTestMode.Live) - { - _nonAzureApiKey = TestEnvironment.NonAzureOpenAIApiKey; - _azureResourceUrl = TestEnvironment.AzureOpenAIResourceUri; - _azureApiKeyCredential = new(TestEnvironment.AzureOpenAIApiKey); - UriRegexSanitizers.Add(new(_azureResourceUrl, s_placeholderAzureResourceUrl)); - } - else - { - _nonAzureApiKey = s_placeholderApiKey; - _azureResourceUrl = s_placeholderAzureResourceUrl; - _azureApiKeyCredential = new(s_placeholderApiKey); - } } [OneTimeTearDown] diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/tests/AssistantsTests.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/tests/AssistantsTests.cs index a9934faa7482..2d19cf967539 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/tests/AssistantsTests.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/tests/AssistantsTests.cs @@ -69,9 +69,9 @@ Response retrievalResponse Assert.That(retrievalResponse.Value.Metadata.ContainsKey("modification_key"), Is.False); // Now modify the assistant by adding a k/v - Response modificationResponse = await client.ModifyAssistantAsync( + Response modificationResponse = await client.UpdateAssistantAsync( assistantCreationResponse.Value.Id, - new AssistantModificationOptions() + new UpdateAssistantOptions() { Model = deploymentName, Metadata = @@ -150,7 +150,7 @@ Response retrievalResponse Assert.That(retrievalResponse.Value.Metadata.ContainsKey("test_modification_key"), Is.False); Response modificationResponse - = await client.ModifyMessageAsync( + = await client.UpdateMessageAsync( threadCreationResponse.Value.Id, messageCreationResponse.Value.Id, new Dictionary @@ -216,8 +216,11 @@ Response threadCreationResponse // Create a run of the thread Response runCreationResponse = await client.CreateRunAsync( thread.Id, - assistant.Id, - metadata: new Dictionary { [s_testMetadataKey] = TestMetadataValue }); + new CreateRunOptions(assistant.Id) + { + Metadata = new Dictionary { [s_testMetadataKey] = TestMetadataValue }, + }); + AssertSuccessfulResponse(runCreationResponse); ThreadRun run = runCreationResponse.Value; diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/tests/FilesTests.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/tests/FilesTests.cs index 6c49d64c061f..d036df83d3d4 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/tests/FilesTests.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/tests/FilesTests.cs @@ -63,7 +63,7 @@ Response> listNotMatchingPurposeFilesResponse } // Retrieving file information should work - Response retrieveFileResponse = await client.RetrieveFileAsync(uploadedFile.Id); + Response retrieveFileResponse = await client.GetFileAsync(uploadedFile.Id); AssertSuccessfulResponse(retrieveFileResponse); OpenAIFile retrievedFile = retrieveFileResponse.Value; Assert.That(retrievedFile.Id, Is.EqualTo(uploadedFile.Id)); diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/tests/FunctionsTests.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/tests/FunctionsTests.cs index 614275e11052..6f10a4a6df15 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/tests/FunctionsTests.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/tests/FunctionsTests.cs @@ -108,8 +108,11 @@ Response threadCreationResponse // Create a run of the thread Response runCreationResponse = await client.CreateRunAsync( thread.Id, - assistant.Id, - metadata: new Dictionary { [s_testMetadataKey] = TestMetadataValue }); + new CreateRunOptions(assistant.Id) + { + Metadata = new Dictionary { [s_testMetadataKey] = TestMetadataValue }, + }); + AssertSuccessfulResponse(runCreationResponse); ThreadRun run = runCreationResponse.Value; @@ -127,7 +130,7 @@ Response threadCreationResponse SubmitToolOutputsAction outputsAction = run.RequiredAction as SubmitToolOutputsAction; Assert.That(outputsAction, Is.Not.Null); Assert.That(outputsAction.ToolCalls, Is.Not.Null.Or.Empty); - FunctionToolCall functionCall = outputsAction.ToolCalls[0] as FunctionToolCall; + RequiredFunctionToolCall functionCall = outputsAction.ToolCalls[0] as RequiredFunctionToolCall; Assert.That(functionCall, Is.Not.Null); Response> listRunStepResponse = await client.GetRunStepsAsync(run); diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/tests/RetrievalTests.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/tests/RetrievalTests.cs index f1f1081fba0e..f37f5adb01ff 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/tests/RetrievalTests.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/tests/RetrievalTests.cs @@ -13,7 +13,7 @@ namespace Azure.AI.OpenAI.Assistants.Tests; public class RetrievalTests : AssistantsTestBase { public RetrievalTests(bool isAsync) - : base(isAsync) // , RecordedTestMode.Live) + : base(isAsync) // RecordedTestMode.Live) { } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/tests/Samples/Samples_AssistantsClient.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/tests/Samples/Samples_AssistantsClient.cs index 0fde8cbf9b6b..b3cfb97b601d 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/tests/Samples/Samples_AssistantsClient.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/tests/Samples/Samples_AssistantsClient.cs @@ -73,8 +73,10 @@ public async Task OverviewSample() #region Snippet:OverviewCreateRun Response runResponse = await client.CreateRunAsync( thread.Id, - assistant.Id, - overrideInstructions: "Please address the user as Jane Doe. The user has a premium account."); + new CreateRunOptions(assistant.Id) + { + AdditionalInstructions = "Please address the user as Jane Doe. The user has a premium account.", + }); ThreadRun run = runResponse.Value; #endregion diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/tests/Samples/Samples_Functions.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/tests/Samples/Samples_Functions.cs index 92c9af5b3c94..6fe9fd2e8ad4 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/tests/Samples/Samples_Functions.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/tests/Samples/Samples_Functions.cs @@ -88,15 +88,15 @@ public async Task FunctionCallingExample() #endregion #region Snippet:FunctionsHandleFunctionCalls - ToolOutput GetResolvedToolOutput(ToolCall toolCall) + ToolOutput GetResolvedToolOutput(RequiredToolCall toolCall) { - if (toolCall is FunctionToolCall functionToolCall) + if (toolCall is RequiredFunctionToolCall functionToolCall) { if (functionToolCall.Name == getUserFavoriteCityTool.Name) { return new ToolOutput(toolCall, GetUserFavoriteCity()); } - using JsonDocument argumentsJson = JsonDocument.Parse(functionToolCall.Arguments); + using JsonDocument argumentsJson = JsonDocument.Parse(functionToolCall.Parameters); if (functionToolCall.Name == getCityNicknameTool.Name) { string locationArgument = argumentsJson.RootElement.GetProperty("location").GetString(); @@ -145,7 +145,7 @@ ToolOutput GetResolvedToolOutput(ToolCall toolCall) "What's the weather like in my favorite city?"); ThreadMessage message = messageResponse.Value; - Response runResponse = await client.CreateRunAsync(thread.Id, assistant.Id); + Response runResponse = await client.CreateRunAsync(thread, assistant); #region Snippet:FunctionsHandlePollingWithRequiredAction do @@ -157,7 +157,7 @@ ToolOutput GetResolvedToolOutput(ToolCall toolCall) && runResponse.Value.RequiredAction is SubmitToolOutputsAction submitToolOutputsAction) { List toolOutputs = new(); - foreach (ToolCall toolCall in submitToolOutputsAction.ToolCalls) + foreach (RequiredToolCall toolCall in submitToolOutputsAction.ToolCalls) { toolOutputs.Add(GetResolvedToolOutput(toolCall)); } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/tests/Samples/Samples_Retrieval.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/tests/Samples/Samples_Retrieval.cs index e764dae4fa46..3c97304ba6aa 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/tests/Samples/Samples_Retrieval.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/tests/Samples/Samples_Retrieval.cs @@ -61,7 +61,7 @@ public async Task AssistantsWithFilesSample() "Can you give me the documented codes for 'banana' and 'orange'?"); ThreadMessage message = messageResponse.Value; - Response runResponse = await client.CreateRunAsync(thread.Id, assistant.Id); + Response runResponse = await client.CreateRunAsync(thread, assistant); do { diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/tests/TestHelpers.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/tests/TestHelpers.cs index 4c4e188a74e4..fe2f5c3cad02 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/tests/TestHelpers.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/tests/TestHelpers.cs @@ -38,10 +38,10 @@ public AssistantsClient GetTestClient(OpenAIClientServiceTarget target) => GetTestClient(target, OpenAIClientAuthenticationType.ApiKey); protected AssistantsClient GetNonAzureClientWithKey() => InstrumentClient( - new AssistantsClient(_nonAzureApiKey, GetInstrumentedClientOptions())); + new AssistantsClient(NonAzureApiKey, GetInstrumentedClientOptions())); protected AssistantsClient GetAzureClientWithKey() => InstrumentClient( - new AssistantsClient(new(_azureResourceUrl), _azureApiKeyCredential, GetInstrumentedClientOptions())); + new AssistantsClient(new(AzureResourceUrl), AzureApiKeyCredential, GetInstrumentedClientOptions())); private AssistantsClientOptions GetInstrumentedClientOptions( AssistantsClientOptions.ServiceVersion? azureServiceVersionOverride = null) diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/tsp-location.yaml b/sdk/openai/Azure.AI.OpenAI.Assistants/tsp-location.yaml index 9da95eab6549..867841ef36ac 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/tsp-location.yaml +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/tsp-location.yaml @@ -1,3 +1,3 @@ directory: specification/ai/OpenAI.Assistants -commit: cdb2544bd7879936b89433e7d63c7b7e6f55308c +commit: cacb3dc095486d8691c47dea944fc9ed0f4d0e32 repo: Azure/azure-rest-api-specs From 918f7b28b779a8d9c4218fb28404902da0c6ffb9 Mon Sep 17 00:00:00 2001 From: Travis Wilson <35748617+trrwilson@users.noreply.github.com> Date: Thu, 25 Jan 2024 15:44:36 -0800 Subject: [PATCH 12/15] swap to 02-15 label and fix playback run polling --- .../src/Custom/AssistantsClient.cs | 10 +--------- .../tests/AssistantsTestBase.cs | 4 ++++ .../tests/AssistantsTests.cs | 2 +- .../Azure.AI.OpenAI.Assistants/tests/FunctionsTests.cs | 4 +--- .../Azure.AI.OpenAI.Assistants/tests/RetrievalTests.cs | 6 +++--- 5 files changed, 10 insertions(+), 16 deletions(-) diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/AssistantsClient.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/AssistantsClient.cs index a5d4c16330de..9f6529076b51 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/AssistantsClient.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/AssistantsClient.cs @@ -57,15 +57,7 @@ public AssistantsClient(Uri endpoint, AzureKeyCredential keyCredential, Assistan }, new ResponseClassifier()); _endpoint = endpoint; - if (options.Version == "2024-02-15-preview") - { - // Temporary redirection pending Azure versioning finalization - _apiVersion = "2024-01-01-preview"; - } - else - { - _apiVersion = options.Version; - } + _apiVersion = options.Version; } /// diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/tests/AssistantsTestBase.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/tests/AssistantsTestBase.cs index 1c34391358c1..f50e3d87c689 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/tests/AssistantsTestBase.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/tests/AssistantsTestBase.cs @@ -35,6 +35,10 @@ protected AzureKeyCredential AzureApiKeyCredential => Recording?.Mode == RecordedTestMode.Record || Recording?.Mode == RecordedTestMode.Live ? new(TestEnvironment.AzureOpenAIApiKey) : new(s_placeholderApiKey); + protected TimeSpan RunPollingInterval + => Recording?.Mode == RecordedTestMode.Playback + ? TimeSpan.FromMilliseconds(10) + : TimeSpan.FromMilliseconds(500); public List<(AssistantsClient, string)> EnsuredFileDeletions = new(); public List<(AssistantsClient, string)> EnsuredThreadDeletions = new(); diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/tests/AssistantsTests.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/tests/AssistantsTests.cs index 2d19cf967539..0d08e982b1d9 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/tests/AssistantsTests.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/tests/AssistantsTests.cs @@ -227,7 +227,7 @@ Response threadCreationResponse // Repeatedly retrieve the run (polling) until it's done do { - await Task.Delay(500); + await Task.Delay(RunPollingInterval); Response runRetrievalResponse = await client.GetRunAsync(thread.Id, run.Id); AssertSuccessfulResponse(runRetrievalResponse); run = runRetrievalResponse.Value; diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/tests/FunctionsTests.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/tests/FunctionsTests.cs index 6f10a4a6df15..c92feddb825d 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/tests/FunctionsTests.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/tests/FunctionsTests.cs @@ -119,7 +119,7 @@ Response threadCreationResponse // Repeatedly retrieve the run (polling) until it's done do { - await Task.Delay(500); + await Task.Delay(RunPollingInterval); Response runRetrievalResponse = await client.GetRunAsync(thread.Id, run.Id); AssertSuccessfulResponse(runRetrievalResponse); run = runRetrievalResponse.Value; @@ -140,7 +140,5 @@ Response threadCreationResponse RunStepToolCallDetails runStepToolCallDetails = runSteps[0].StepDetails as RunStepToolCallDetails; Assert.That(runStepToolCallDetails, Is.Not.Null); - - await Task.Delay(0); } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/tests/RetrievalTests.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/tests/RetrievalTests.cs index f37f5adb01ff..46091cc3d73c 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/tests/RetrievalTests.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/tests/RetrievalTests.cs @@ -23,7 +23,7 @@ public RetrievalTests(bool isAsync) public async Task BasicRetrievalWorks(OpenAIClientServiceTarget target) { AssistantsClient client = GetTestClient(target); - string deloymentOrModelName = GetDeploymentOrModelName(target); + string deploymentOrModelName = GetDeploymentOrModelName(target); OpenAIFile uploadedFile = null; using (TestRecording.DisableRecordingScope disableBodyRecordingScope = Recording.DisableRequestBodyRecording()) @@ -37,7 +37,7 @@ public async Task BasicRetrievalWorks(OpenAIClientServiceTarget target) } Response assistantCreationResponse - = await client.CreateAssistantAsync(new AssistantCreationOptions(deloymentOrModelName) + = await client.CreateAssistantAsync(new AssistantCreationOptions(deploymentOrModelName) { Name = "AOAI SDK Test Assistant - Delete Me", Description = "Created by automated tests to exercise the API; should not be used", @@ -73,7 +73,7 @@ Response assistantCreationResponse // Repeatedly retrieve the run (polling) until it's done do { - await Task.Delay(500); + await Task.Delay(RunPollingInterval); Response runRetrievalResponse = await client.GetRunAsync(run.ThreadId, run.Id); AssertSuccessfulResponse(runRetrievalResponse); run = runRetrievalResponse.Value; From b4d65176af018402715e7d5b74ca3e4f42a7772c Mon Sep 17 00:00:00 2001 From: Travis Wilson <35748617+trrwilson@users.noreply.github.com> Date: Thu, 25 Jan 2024 16:01:39 -0800 Subject: [PATCH 13/15] merge and assets.json test update --- sdk/openai/Azure.AI.OpenAI.Assistants/assets.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/assets.json b/sdk/openai/Azure.AI.OpenAI.Assistants/assets.json index b3135940ce57..b1497a32fb0e 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/assets.json +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/assets.json @@ -2,5 +2,5 @@ "AssetsRepo": "Azure/azure-sdk-assets", "AssetsRepoPrefixPath": "net", "TagPrefix": "net/openai/Azure.AI.OpenAI.Assistants", - "Tag": "net/openai/Azure.AI.OpenAI.Assistants_62ebf0102d" + "Tag": "net/openai/Azure.AI.OpenAI.Assistants_1c6609d664" } From b51996f50c38f31084ebebcb15cedd9362bc27cb Mon Sep 17 00:00:00 2001 From: Travis Wilson <35748617+trrwilson@users.noreply.github.com> Date: Thu, 25 Jan 2024 16:39:13 -0800 Subject: [PATCH 14/15] post-merge generated code update --- .../UnknownCodeInterpreterToolCallOutput.cs | 5 ----- .../src/Generated/UnknownMessageContent.cs | 5 ----- .../src/Generated/UnknownMessageTextAnnotation.cs | 13 ------------- .../src/Generated/UnknownRequiredAction.cs | 5 ----- .../src/Generated/UnknownRequiredToolCall.cs | 11 ----------- .../src/Generated/UnknownRunStepDetails.cs | 5 ----- .../src/Generated/UnknownToolCall.cs | 11 ----------- .../src/Generated/UnknownToolDefinition.cs | 5 ----- 8 files changed, 60 deletions(-) diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownCodeInterpreterToolCallOutput.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownCodeInterpreterToolCallOutput.cs index 9c5bc46d4108..956c72b0c974 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownCodeInterpreterToolCallOutput.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownCodeInterpreterToolCallOutput.cs @@ -10,11 +10,6 @@ namespace Azure.AI.OpenAI.Assistants /// Unknown version of CodeInterpreterToolCallOutput. internal partial class UnknownCodeInterpreterToolCallOutput : CodeInterpreterToolCallOutput { - /// Initializes a new instance of . - internal UnknownCodeInterpreterToolCallOutput() - { - } - /// Initializes a new instance of . /// The object type. internal UnknownCodeInterpreterToolCallOutput(string type) : base(type) diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownMessageContent.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownMessageContent.cs index ec5d8306d117..c99054419730 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownMessageContent.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownMessageContent.cs @@ -10,11 +10,6 @@ namespace Azure.AI.OpenAI.Assistants /// Unknown version of MessageContent. internal partial class UnknownMessageContent : MessageContent { - /// Initializes a new instance of . - internal UnknownMessageContent() - { - } - /// Initializes a new instance of . /// The object type. internal UnknownMessageContent(string type) : base(type) diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownMessageTextAnnotation.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownMessageTextAnnotation.cs index 6fbd1ac1d9ab..dfe14d871079 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownMessageTextAnnotation.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownMessageTextAnnotation.cs @@ -5,24 +5,11 @@ #nullable disable -using System; -using Azure.Core; - namespace Azure.AI.OpenAI.Assistants { /// Unknown version of MessageTextAnnotation. internal partial class UnknownMessageTextAnnotation : MessageTextAnnotation { - /// Initializes a new instance of . - /// The textual content associated with this text annotation item. - /// The first text index associated with this text annotation. - /// The last text index associated with this text annotation. - /// is null. - internal UnknownMessageTextAnnotation(string text, int startIndex, int endIndex) : base(text, startIndex, endIndex) - { - Argument.AssertNotNull(text, nameof(text)); - } - /// Initializes a new instance of . /// The object type. /// The textual content associated with this text annotation item. diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownRequiredAction.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownRequiredAction.cs index c0eaa5d12b84..c8e25ca01bd8 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownRequiredAction.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownRequiredAction.cs @@ -10,11 +10,6 @@ namespace Azure.AI.OpenAI.Assistants /// Unknown version of RequiredAction. internal partial class UnknownRequiredAction : RequiredAction { - /// Initializes a new instance of . - internal UnknownRequiredAction() - { - } - /// Initializes a new instance of . /// The object type. internal UnknownRequiredAction(string type) : base(type) diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownRequiredToolCall.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownRequiredToolCall.cs index f7002d4c3d7c..c9b4ade3898b 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownRequiredToolCall.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownRequiredToolCall.cs @@ -5,22 +5,11 @@ #nullable disable -using System; -using Azure.Core; - namespace Azure.AI.OpenAI.Assistants { /// Unknown version of RequiredToolCall. internal partial class UnknownRequiredToolCall : RequiredToolCall { - /// Initializes a new instance of . - /// The ID of the tool call. This ID must be referenced when submitting tool outputs. - /// is null. - internal UnknownRequiredToolCall(string id) : base(id) - { - Argument.AssertNotNull(id, nameof(id)); - } - /// Initializes a new instance of . /// The object type for the required tool call. /// The ID of the tool call. This ID must be referenced when submitting tool outputs. diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownRunStepDetails.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownRunStepDetails.cs index 7899ded79513..023e9b33a506 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownRunStepDetails.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownRunStepDetails.cs @@ -10,11 +10,6 @@ namespace Azure.AI.OpenAI.Assistants /// Unknown version of RunStepDetails. internal partial class UnknownRunStepDetails : RunStepDetails { - /// Initializes a new instance of . - internal UnknownRunStepDetails() - { - } - /// Initializes a new instance of . /// The object type. internal UnknownRunStepDetails(RunStepType type) : base(type) diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownToolCall.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownToolCall.cs index 905ac16f3ce7..4db2276f6d45 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownToolCall.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownToolCall.cs @@ -5,22 +5,11 @@ #nullable disable -using System; -using Azure.Core; - namespace Azure.AI.OpenAI.Assistants { /// Unknown version of ToolCall. internal partial class UnknownToolCall : ToolCall { - /// Initializes a new instance of . - /// The ID of the tool call. This ID must be referenced when you submit tool outputs. - /// is null. - internal UnknownToolCall(string id) : base(id) - { - Argument.AssertNotNull(id, nameof(id)); - } - /// Initializes a new instance of . /// The object type. /// The ID of the tool call. This ID must be referenced when you submit tool outputs. diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownToolDefinition.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownToolDefinition.cs index 5b92f0688764..6c06da69d2e3 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownToolDefinition.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownToolDefinition.cs @@ -10,11 +10,6 @@ namespace Azure.AI.OpenAI.Assistants /// Unknown version of ToolDefinition. internal partial class UnknownToolDefinition : ToolDefinition { - /// Initializes a new instance of . - internal UnknownToolDefinition() - { - } - /// Initializes a new instance of . /// The object type. internal UnknownToolDefinition(string type) : base(type) From ed4f99af598f398b6cf81b863021f8c641f89544 Mon Sep 17 00:00:00 2001 From: Travis Wilson Date: Tue, 30 Jan 2024 11:42:25 -0800 Subject: [PATCH 15/15] merge and merged TypeSpec update, including Azure.Core update --- ...ure.AI.OpenAI.Assistants.netstandard2.0.cs | 305 +++++++++++++++--- .../src/Azure.AI.OpenAI.Assistants.csproj | 1 + .../src/Custom/AssistantsModelFactory.cs | 20 +- .../src/Custom/FunctionToolDefinition.cs | 2 +- .../src/Generated/Assistant.Serialization.cs | 160 ++++++++- .../src/Generated/Assistant.cs | 41 ++- .../AssistantCreationOptions.Serialization.cs | 187 ++++++++++- .../src/Generated/AssistantCreationOptions.cs | 41 ++- .../Generated/AssistantFile.Serialization.cs | 106 +++++- .../src/Generated/AssistantFile.cs | 42 ++- .../AssistantThread.Serialization.cs | 117 ++++++- .../src/Generated/AssistantThread.cs | 41 ++- ...tantThreadCreationOptions.Serialization.cs | 133 +++++++- .../AssistantThreadCreationOptions.cs | 37 ++- .../src/Generated/AssistantsModelFactory.cs | 121 ++++--- ...odeInterpreterImageOutput.Serialization.cs | 103 +++++- .../Generated/CodeInterpreterImageOutput.cs | 9 +- ...InterpreterImageReference.Serialization.cs | 101 +++++- .../CodeInterpreterImageReference.cs | 47 +++ .../CodeInterpreterLogOutput.Serialization.cs | 103 +++++- .../src/Generated/CodeInterpreterLogOutput.cs | 9 +- .../CodeInterpreterToolCall.Serialization.cs | 105 +++++- .../src/Generated/CodeInterpreterToolCall.cs | 9 +- ...InterpreterToolCallOutput.Serialization.cs | 92 +++++- .../CodeInterpreterToolCallOutput.cs | 39 ++- ...InterpreterToolDefinition.Serialization.cs | 86 ++++- .../CodeInterpreterToolDefinition.cs | 6 +- ...CreateAndRunThreadOptions.Serialization.cs | 161 ++++++++- .../Generated/CreateAndRunThreadOptions.cs | 41 ++- ...reateAssistantFileRequest.Serialization.cs | 109 ++++++- .../Generated/CreateAssistantFileRequest.cs | 47 +++ .../CreateMessageRequest.Serialization.cs | 145 ++++++++- .../src/Generated/CreateMessageRequest.cs | 41 ++- .../CreateRunOptions.Serialization.cs | 172 +++++++++- .../src/Generated/CreateRunOptions.cs | 41 ++- .../FunctionToolCall.Serialization.cs | 105 +++++- .../src/Generated/FunctionToolCall.cs | 9 +- .../FunctionToolDefinition.Serialization.cs | 86 ++++- .../src/Generated/FunctionToolDefinition.cs | 9 +- ...alAssistantDeletionStatus.Serialization.cs | 105 +++++- .../InternalAssistantDeletionStatus.cs | 42 ++- ...sistantFileDeletionStatus.Serialization.cs | 105 +++++- .../InternalAssistantFileDeletionStatus.cs | 42 ++- ...nterpreterToolCallDetails.Serialization.cs | 107 +++++- .../InternalCodeInterpreterToolCallDetails.cs | 41 ++- ...nternalFileDeletionStatus.Serialization.cs | 105 +++++- .../Generated/InternalFileDeletionStatus.cs | 42 ++- .../InternalFileListResponse.Serialization.cs | 107 +++++- .../src/Generated/InternalFileListResponse.cs | 41 ++- ...nternalFunctionDefinition.Serialization.cs | 85 ++++- .../Generated/InternalFunctionDefinition.cs | 42 ++- ...alFunctionToolCallDetails.Serialization.cs | 112 ++++++- .../InternalFunctionToolCallDetails.cs | 51 +++ ...alMessageImageFileDetails.Serialization.cs | 101 +++++- .../InternalMessageImageFileDetails.cs | 47 +++ ...MessageImageFileIdDetails.Serialization.cs | 101 +++++- .../InternalMessageImageFileIdDetails.cs | 47 +++ ...nternalMessageTextDetails.Serialization.cs | 107 +++++- .../Generated/InternalMessageTextDetails.cs | 41 ++- ...geTextFileCitationDetails.Serialization.cs | 103 +++++- .../InternalMessageTextFileCitationDetails.cs | 49 +++ ...essageTextFilePathDetails.Serialization.cs | 101 +++++- .../InternalMessageTextFilePathDetails.cs | 47 +++ ...AIPageableListOfAssistant.Serialization.cs | 113 ++++++- .../InternalOpenAIPageableListOfAssistant.cs | 41 ++- ...geableListOfAssistantFile.Serialization.cs | 113 ++++++- ...ternalOpenAIPageableListOfAssistantFile.cs | 41 ++- ...PageableListOfMessageFile.Serialization.cs | 113 ++++++- ...InternalOpenAIPageableListOfMessageFile.cs | 41 ++- ...enAIPageableListOfRunStep.Serialization.cs | 113 ++++++- .../InternalOpenAIPageableListOfRunStep.cs | 41 ++- ...geableListOfThreadMessage.Serialization.cs | 113 ++++++- ...ternalOpenAIPageableListOfThreadMessage.cs | 41 ++- ...AIPageableListOfThreadRun.Serialization.cs | 113 ++++++- .../InternalOpenAIPageableListOfThreadRun.cs | 41 ++- ...lSubmitToolOutputsDetails.Serialization.cs | 105 +++++- .../InternalSubmitToolOutputsDetails.cs | 41 ++- .../Generated/MessageContent.Serialization.cs | 92 +++++- .../src/Generated/MessageContent.cs | 39 ++- .../Generated/MessageFile.Serialization.cs | 106 +++++- .../src/Generated/MessageFile.cs | 42 ++- .../MessageImageFileContent.Serialization.cs | 103 +++++- .../src/Generated/MessageImageFileContent.cs | 9 +- .../MessageTextAnnotation.Serialization.cs | 98 +++++- .../src/Generated/MessageTextAnnotation.cs | 42 ++- .../MessageTextContent.Serialization.cs | 103 +++++- .../src/Generated/MessageTextContent.cs | 9 +- ...extFileCitationAnnotation.Serialization.cs | 109 ++++++- .../MessageTextFileCitationAnnotation.cs | 9 +- ...ageTextFilePathAnnotation.Serialization.cs | 109 ++++++- .../MessageTextFilePathAnnotation.cs | 9 +- .../src/Generated/OpenAIFile.Serialization.cs | 110 ++++++- .../src/Generated/OpenAIFile.cs | 42 ++- .../Generated/RequiredAction.Serialization.cs | 92 +++++- .../src/Generated/RequiredAction.cs | 39 ++- .../RequiredFunctionToolCall.Serialization.cs | 105 +++++- .../src/Generated/RequiredFunctionToolCall.cs | 9 +- .../RequiredToolCall.Serialization.cs | 94 +++++- .../src/Generated/RequiredToolCall.cs | 42 ++- .../RetrievalToolCall.Serialization.cs | 110 ++++++- .../src/Generated/RetrievalToolCall.cs | 8 +- .../RetrievalToolDefinition.Serialization.cs | 86 ++++- .../src/Generated/RetrievalToolDefinition.cs | 6 +- .../src/Generated/RunError.Serialization.cs | 103 +++++- .../src/Generated/RunError.cs | 49 +++ .../src/Generated/RunStep.Serialization.cs | 174 +++++++++- .../src/Generated/RunStep.cs | 41 ++- .../Generated/RunStepDetails.Serialization.cs | 92 +++++- .../src/Generated/RunStepDetails.cs | 39 ++- .../Generated/RunStepError.Serialization.cs | 103 +++++- .../src/Generated/RunStepError.cs | 49 +++ ...tepMessageCreationDetails.Serialization.cs | 103 +++++- .../RunStepMessageCreationDetails.cs | 9 +- ...pMessageCreationReference.Serialization.cs | 101 +++++- .../RunStepMessageCreationReference.cs | 47 +++ .../RunStepToolCallDetails.Serialization.cs | 107 +++++- .../src/Generated/RunStepToolCallDetails.cs | 8 +- .../SubmitToolOutputsAction.Serialization.cs | 103 +++++- .../src/Generated/SubmitToolOutputsAction.cs | 9 +- ...itToolOutputsToRunRequest.Serialization.cs | 114 ++++++- .../SubmitToolOutputsToRunRequest.cs | 41 ++- .../ThreadDeletionStatus.Serialization.cs | 105 +++++- .../src/Generated/ThreadDeletionStatus.cs | 42 ++- ...readInitializationMessage.Serialization.cs | 145 ++++++++- .../Generated/ThreadInitializationMessage.cs | 41 ++- .../Generated/ThreadMessage.Serialization.cs | 145 ++++++++- .../src/Generated/ThreadMessage.cs | 41 ++- .../src/Generated/ThreadRun.Serialization.cs | 207 +++++++++++- .../src/Generated/ThreadRun.cs | 41 ++- .../src/Generated/ToolCall.Serialization.cs | 94 +++++- .../src/Generated/ToolCall.cs | 42 ++- .../Generated/ToolDefinition.Serialization.cs | 77 ++++- .../src/Generated/ToolDefinition.cs | 39 ++- .../src/Generated/ToolOutput.Serialization.cs | 115 ++++++- .../src/Generated/ToolOutput.cs | 46 +++ ...InterpreterToolCallOutput.Serialization.cs | 101 +++++- .../UnknownCodeInterpreterToolCallOutput.cs | 11 +- .../UnknownMessageContent.Serialization.cs | 101 +++++- .../src/Generated/UnknownMessageContent.cs | 11 +- ...nownMessageTextAnnotation.Serialization.cs | 107 +++++- .../Generated/UnknownMessageTextAnnotation.cs | 11 +- .../UnknownRequiredAction.Serialization.cs | 101 +++++- .../src/Generated/UnknownRequiredAction.cs | 11 +- .../UnknownRequiredToolCall.Serialization.cs | 103 +++++- .../src/Generated/UnknownRequiredToolCall.cs | 11 +- .../UnknownRunStepDetails.Serialization.cs | 101 +++++- .../src/Generated/UnknownRunStepDetails.cs | 11 +- .../UnknownToolCall.Serialization.cs | 103 +++++- .../src/Generated/UnknownToolCall.cs | 11 +- .../UnknownToolDefinition.Serialization.cs | 101 +++++- .../src/Generated/UnknownToolDefinition.cs | 11 +- .../UpdateAssistantOptions.Serialization.cs | 187 ++++++++++- .../src/Generated/UpdateAssistantOptions.cs | 37 ++- .../UpdateMessageRequest.Serialization.cs | 118 ++++++- .../src/Generated/UpdateMessageRequest.cs | 37 ++- .../UpdateRunRequest.Serialization.cs | 118 ++++++- .../src/Generated/UpdateRunRequest.cs | 37 ++- .../UpdateThreadRequest.Serialization.cs | 118 ++++++- .../src/Generated/UpdateThreadRequest.cs | 37 ++- .../UploadFileRequest.Serialization.cs | 121 ++++++- .../src/Generated/UploadFileRequest.cs | 42 ++- .../tsp-location.yaml | 2 +- 162 files changed, 11350 insertions(+), 374 deletions(-) diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/api/Azure.AI.OpenAI.Assistants.netstandard2.0.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/api/Azure.AI.OpenAI.Assistants.netstandard2.0.cs index 8d1c5b9cd3fe..2d2baa467e96 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/api/Azure.AI.OpenAI.Assistants.netstandard2.0.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/api/Azure.AI.OpenAI.Assistants.netstandard2.0.cs @@ -1,6 +1,6 @@ namespace Azure.AI.OpenAI.Assistants { - public partial class Assistant + public partial class Assistant : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel { internal Assistant() { } public System.DateTimeOffset CreatedAt { get { throw null; } } @@ -12,8 +12,13 @@ internal Assistant() { } public string Model { get { throw null; } } public string Name { get { throw null; } } public System.Collections.Generic.IReadOnlyList Tools { get { throw null; } } + Azure.AI.OpenAI.Assistants.Assistant System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.AI.OpenAI.Assistants.Assistant System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } } - public partial class AssistantCreationOptions + public partial class AssistantCreationOptions : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel { public AssistantCreationOptions(string model) { } public string Description { get { throw null; } set { } } @@ -23,13 +28,23 @@ public AssistantCreationOptions(string model) { } public string Model { get { throw null; } } public string Name { get { throw null; } set { } } public System.Collections.Generic.IList Tools { get { throw null; } } + Azure.AI.OpenAI.Assistants.AssistantCreationOptions System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.AI.OpenAI.Assistants.AssistantCreationOptions System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } } - public partial class AssistantFile + public partial class AssistantFile : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel { internal AssistantFile() { } public string AssistantId { get { throw null; } } public System.DateTimeOffset CreatedAt { get { throw null; } } public string Id { get { throw null; } } + Azure.AI.OpenAI.Assistants.AssistantFile System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.AI.OpenAI.Assistants.AssistantFile System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } } public partial class AssistantsClient { @@ -127,12 +142,15 @@ public enum ServiceVersion public static partial class AssistantsModelFactory { public static Azure.AI.OpenAI.Assistants.Assistant Assistant(string id = null, System.DateTimeOffset createdAt = default(System.DateTimeOffset), string name = null, string description = null, string model = null, string instructions = null, System.Collections.Generic.IEnumerable tools = null, System.Collections.Generic.IEnumerable fileIds = null, System.Collections.Generic.IReadOnlyDictionary metadata = null) { throw null; } + public static Azure.AI.OpenAI.Assistants.AssistantCreationOptions AssistantCreationOptions(string model = null, string name = null, string description = null, string instructions = null, System.Collections.Generic.IEnumerable tools = null, System.Collections.Generic.IEnumerable fileIds = null, System.Collections.Generic.IDictionary metadata = null) { throw null; } public static Azure.AI.OpenAI.Assistants.AssistantFile AssistantFile(string id = null, System.DateTimeOffset createdAt = default(System.DateTimeOffset), string assistantId = null) { throw null; } public static Azure.AI.OpenAI.Assistants.AssistantThread AssistantThread(string id = null, System.DateTimeOffset createdAt = default(System.DateTimeOffset), System.Collections.Generic.IReadOnlyDictionary metadata = null) { throw null; } public static Azure.AI.OpenAI.Assistants.CodeInterpreterImageOutput CodeInterpreterImageOutput(Azure.AI.OpenAI.Assistants.CodeInterpreterImageReference image = null) { throw null; } public static Azure.AI.OpenAI.Assistants.CodeInterpreterImageReference CodeInterpreterImageReference(string fileId = null) { throw null; } public static Azure.AI.OpenAI.Assistants.CodeInterpreterLogOutput CodeInterpreterLogOutput(string logs = null) { throw null; } public static Azure.AI.OpenAI.Assistants.CodeInterpreterToolCall CodeInterpreterToolCall(string id, string input, System.Collections.Generic.IReadOnlyList outputs) { throw null; } + public static Azure.AI.OpenAI.Assistants.CreateAndRunThreadOptions CreateAndRunThreadOptions(string assistantId = null, Azure.AI.OpenAI.Assistants.AssistantThreadCreationOptions thread = null, string overrideModelName = null, string overrideInstructions = null, System.Collections.Generic.IEnumerable overrideTools = null, System.Collections.Generic.IDictionary metadata = null) { throw null; } + public static Azure.AI.OpenAI.Assistants.CreateRunOptions CreateRunOptions(string assistantId = null, string overrideModelName = null, string overrideInstructions = null, string additionalInstructions = null, System.Collections.Generic.IEnumerable overrideTools = null, System.Collections.Generic.IDictionary metadata = null) { throw null; } public static Azure.AI.OpenAI.Assistants.FunctionToolCall FunctionToolCall(string id, string name, string arguments, string output) { throw null; } public static Azure.AI.OpenAI.Assistants.MessageFile MessageFile(string id = null, System.DateTimeOffset createdAt = default(System.DateTimeOffset), string messageId = null) { throw null; } public static Azure.AI.OpenAI.Assistants.MessageTextFileCitationAnnotation MessageFileCitationTextAnnotation(string text, int startIndex, int endIndex, string fileId, string quote) { throw null; } @@ -152,53 +170,94 @@ public static partial class AssistantsModelFactory public static Azure.AI.OpenAI.Assistants.RunStepMessageCreationReference RunStepMessageCreationReference(string messageId = null) { throw null; } public static Azure.AI.OpenAI.Assistants.RunStepToolCallDetails RunStepToolCallDetails(System.Collections.Generic.IEnumerable toolCalls = null) { throw null; } public static Azure.AI.OpenAI.Assistants.SubmitToolOutputsAction SubmitToolOutputsAction(System.Collections.Generic.IEnumerable toolCalls) { throw null; } + public static Azure.AI.OpenAI.Assistants.ThreadInitializationMessage ThreadInitializationMessage(Azure.AI.OpenAI.Assistants.MessageRole role = default(Azure.AI.OpenAI.Assistants.MessageRole), string content = null, System.Collections.Generic.IEnumerable fileIds = null, System.Collections.Generic.IDictionary metadata = null) { throw null; } public static Azure.AI.OpenAI.Assistants.ThreadMessage ThreadMessage(string id = null, System.DateTimeOffset createdAt = default(System.DateTimeOffset), string threadId = null, Azure.AI.OpenAI.Assistants.MessageRole role = default(Azure.AI.OpenAI.Assistants.MessageRole), System.Collections.Generic.IEnumerable contentItems = null, string assistantId = null, string runId = null, System.Collections.Generic.IEnumerable fileIds = null, System.Collections.Generic.IReadOnlyDictionary metadata = null) { throw null; } public static Azure.AI.OpenAI.Assistants.ThreadRun ThreadRun(string id = null, string threadId = null, string assistantId = null, Azure.AI.OpenAI.Assistants.RunStatus status = default(Azure.AI.OpenAI.Assistants.RunStatus), Azure.AI.OpenAI.Assistants.RequiredAction requiredAction = null, Azure.AI.OpenAI.Assistants.RunError lastError = null, string model = null, string instructions = null, System.Collections.Generic.IEnumerable tools = null, System.Collections.Generic.IEnumerable fileIds = null, System.DateTimeOffset createdAt = default(System.DateTimeOffset), System.DateTimeOffset? expiresAt = default(System.DateTimeOffset?), System.DateTimeOffset? startedAt = default(System.DateTimeOffset?), System.DateTimeOffset? completedAt = default(System.DateTimeOffset?), System.DateTimeOffset? cancelledAt = default(System.DateTimeOffset?), System.DateTimeOffset? failedAt = default(System.DateTimeOffset?), System.Collections.Generic.IReadOnlyDictionary metadata = null) { throw null; } public static Azure.AI.OpenAI.Assistants.ToolCall ToolCall(string type = null, string id = null) { throw null; } } - public partial class AssistantThread + public partial class AssistantThread : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel { internal AssistantThread() { } public System.DateTimeOffset CreatedAt { get { throw null; } } public string Id { get { throw null; } } public System.Collections.Generic.IReadOnlyDictionary Metadata { get { throw null; } } + Azure.AI.OpenAI.Assistants.AssistantThread System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.AI.OpenAI.Assistants.AssistantThread System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } } - public partial class AssistantThreadCreationOptions + public partial class AssistantThreadCreationOptions : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel { public AssistantThreadCreationOptions() { } public System.Collections.Generic.IList Messages { get { throw null; } } public System.Collections.Generic.IDictionary Metadata { get { throw null; } set { } } + Azure.AI.OpenAI.Assistants.AssistantThreadCreationOptions System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.AI.OpenAI.Assistants.AssistantThreadCreationOptions System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } } - public partial class CodeInterpreterImageOutput : Azure.AI.OpenAI.Assistants.CodeInterpreterToolCallOutput + public partial class CodeInterpreterImageOutput : Azure.AI.OpenAI.Assistants.CodeInterpreterToolCallOutput, System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel { internal CodeInterpreterImageOutput() { } public Azure.AI.OpenAI.Assistants.CodeInterpreterImageReference Image { get { throw null; } } + Azure.AI.OpenAI.Assistants.CodeInterpreterImageOutput System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.AI.OpenAI.Assistants.CodeInterpreterImageOutput System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } } - public partial class CodeInterpreterImageReference + public partial class CodeInterpreterImageReference : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel { internal CodeInterpreterImageReference() { } public string FileId { get { throw null; } } + Azure.AI.OpenAI.Assistants.CodeInterpreterImageReference System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.AI.OpenAI.Assistants.CodeInterpreterImageReference System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } } - public partial class CodeInterpreterLogOutput : Azure.AI.OpenAI.Assistants.CodeInterpreterToolCallOutput + public partial class CodeInterpreterLogOutput : Azure.AI.OpenAI.Assistants.CodeInterpreterToolCallOutput, System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel { internal CodeInterpreterLogOutput() { } public string Logs { get { throw null; } } + Azure.AI.OpenAI.Assistants.CodeInterpreterLogOutput System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.AI.OpenAI.Assistants.CodeInterpreterLogOutput System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } } - public partial class CodeInterpreterToolCall : Azure.AI.OpenAI.Assistants.ToolCall + public partial class CodeInterpreterToolCall : Azure.AI.OpenAI.Assistants.ToolCall, System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel { internal CodeInterpreterToolCall() : base (default(string)) { } public string Input { get { throw null; } } public System.Collections.Generic.IReadOnlyList Outputs { get { throw null; } } + Azure.AI.OpenAI.Assistants.CodeInterpreterToolCall System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.AI.OpenAI.Assistants.CodeInterpreterToolCall System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } } - public abstract partial class CodeInterpreterToolCallOutput + public abstract partial class CodeInterpreterToolCallOutput : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel { protected CodeInterpreterToolCallOutput() { } + Azure.AI.OpenAI.Assistants.CodeInterpreterToolCallOutput System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.AI.OpenAI.Assistants.CodeInterpreterToolCallOutput System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } } - public partial class CodeInterpreterToolDefinition : Azure.AI.OpenAI.Assistants.ToolDefinition + public partial class CodeInterpreterToolDefinition : Azure.AI.OpenAI.Assistants.ToolDefinition, System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel { public CodeInterpreterToolDefinition() { } + Azure.AI.OpenAI.Assistants.CodeInterpreterToolDefinition System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.AI.OpenAI.Assistants.CodeInterpreterToolDefinition System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } } - public partial class CreateAndRunThreadOptions + public partial class CreateAndRunThreadOptions : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel { public CreateAndRunThreadOptions(string assistantId) { } public string AssistantId { get { throw null; } } @@ -207,8 +266,13 @@ public CreateAndRunThreadOptions(string assistantId) { } public string OverrideModelName { get { throw null; } set { } } public System.Collections.Generic.IList OverrideTools { get { throw null; } } public Azure.AI.OpenAI.Assistants.AssistantThreadCreationOptions Thread { get { throw null; } set { } } + Azure.AI.OpenAI.Assistants.CreateAndRunThreadOptions System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.AI.OpenAI.Assistants.CreateAndRunThreadOptions System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } } - public partial class CreateRunOptions + public partial class CreateRunOptions : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel { public CreateRunOptions(string assistantId) { } public string AdditionalInstructions { get { throw null; } set { } } @@ -217,15 +281,25 @@ public CreateRunOptions(string assistantId) { } public string OverrideInstructions { get { throw null; } set { } } public string OverrideModelName { get { throw null; } set { } } public System.Collections.Generic.IList OverrideTools { get { throw null; } set { } } + Azure.AI.OpenAI.Assistants.CreateRunOptions System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.AI.OpenAI.Assistants.CreateRunOptions System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } } - public partial class FunctionToolCall : Azure.AI.OpenAI.Assistants.ToolCall + public partial class FunctionToolCall : Azure.AI.OpenAI.Assistants.ToolCall, System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel { internal FunctionToolCall() : base (default(string)) { } public string Arguments { get { throw null; } } public string Name { get { throw null; } } public string Output { get { throw null; } } + Azure.AI.OpenAI.Assistants.FunctionToolCall System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.AI.OpenAI.Assistants.FunctionToolCall System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } } - public partial class FunctionToolDefinition : Azure.AI.OpenAI.Assistants.ToolDefinition + public partial class FunctionToolDefinition : Azure.AI.OpenAI.Assistants.ToolDefinition, System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel { public FunctionToolDefinition(string name, string description) { } public FunctionToolDefinition(string name, string description, System.BinaryData parameters) { } @@ -238,6 +312,11 @@ public FunctionToolDefinition(string name, string description, System.BinaryData public static bool operator ==(Azure.AI.OpenAI.Assistants.FunctionToolDefinition functionToolDefinition, Azure.AI.OpenAI.Assistants.FunctionToolCall functionToolCall) { throw null; } public static bool operator !=(Azure.AI.OpenAI.Assistants.FunctionToolCall functionToolCall, Azure.AI.OpenAI.Assistants.FunctionToolDefinition functionToolDefinition) { throw null; } public static bool operator !=(Azure.AI.OpenAI.Assistants.FunctionToolDefinition functionToolDefinition, Azure.AI.OpenAI.Assistants.FunctionToolCall functionToolCall) { throw null; } + Azure.AI.OpenAI.Assistants.FunctionToolDefinition System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.AI.OpenAI.Assistants.FunctionToolDefinition System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } } [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] public readonly partial struct ListSortOrder : System.IEquatable @@ -257,21 +336,36 @@ public FunctionToolDefinition(string name, string description, System.BinaryData public static bool operator !=(Azure.AI.OpenAI.Assistants.ListSortOrder left, Azure.AI.OpenAI.Assistants.ListSortOrder right) { throw null; } public override string ToString() { throw null; } } - public abstract partial class MessageContent + public abstract partial class MessageContent : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel { protected MessageContent() { } + Azure.AI.OpenAI.Assistants.MessageContent System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.AI.OpenAI.Assistants.MessageContent System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } } - public partial class MessageFile + public partial class MessageFile : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel { internal MessageFile() { } public System.DateTimeOffset CreatedAt { get { throw null; } } public string Id { get { throw null; } } public string MessageId { get { throw null; } } + Azure.AI.OpenAI.Assistants.MessageFile System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.AI.OpenAI.Assistants.MessageFile System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } } - public partial class MessageImageFileContent : Azure.AI.OpenAI.Assistants.MessageContent + public partial class MessageImageFileContent : Azure.AI.OpenAI.Assistants.MessageContent, System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel { internal MessageImageFileContent() { } public string FileId { get { throw null; } } + Azure.AI.OpenAI.Assistants.MessageImageFileContent System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.AI.OpenAI.Assistants.MessageImageFileContent System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } } [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] public readonly partial struct MessageRole : System.IEquatable @@ -291,31 +385,51 @@ internal MessageImageFileContent() { } public static bool operator !=(Azure.AI.OpenAI.Assistants.MessageRole left, Azure.AI.OpenAI.Assistants.MessageRole right) { throw null; } public override string ToString() { throw null; } } - public abstract partial class MessageTextAnnotation + public abstract partial class MessageTextAnnotation : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel { protected MessageTextAnnotation(string text, int startIndex, int endIndex) { } public int EndIndex { get { throw null; } } public int StartIndex { get { throw null; } } public string Text { get { throw null; } } + Azure.AI.OpenAI.Assistants.MessageTextAnnotation System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.AI.OpenAI.Assistants.MessageTextAnnotation System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } } - public partial class MessageTextContent : Azure.AI.OpenAI.Assistants.MessageContent + public partial class MessageTextContent : Azure.AI.OpenAI.Assistants.MessageContent, System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel { internal MessageTextContent() { } public System.Collections.Generic.IReadOnlyList Annotations { get { throw null; } } public string Text { get { throw null; } } + Azure.AI.OpenAI.Assistants.MessageTextContent System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.AI.OpenAI.Assistants.MessageTextContent System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } } - public partial class MessageTextFileCitationAnnotation : Azure.AI.OpenAI.Assistants.MessageTextAnnotation + public partial class MessageTextFileCitationAnnotation : Azure.AI.OpenAI.Assistants.MessageTextAnnotation, System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel { internal MessageTextFileCitationAnnotation() : base (default(string), default(int), default(int)) { } public string FileId { get { throw null; } } public string Quote { get { throw null; } } + Azure.AI.OpenAI.Assistants.MessageTextFileCitationAnnotation System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.AI.OpenAI.Assistants.MessageTextFileCitationAnnotation System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } } - public partial class MessageTextFilePathAnnotation : Azure.AI.OpenAI.Assistants.MessageTextAnnotation + public partial class MessageTextFilePathAnnotation : Azure.AI.OpenAI.Assistants.MessageTextAnnotation, System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel { internal MessageTextFilePathAnnotation() : base (default(string), default(int), default(int)) { } public string FileId { get { throw null; } } + Azure.AI.OpenAI.Assistants.MessageTextFilePathAnnotation System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.AI.OpenAI.Assistants.MessageTextFilePathAnnotation System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } } - public partial class OpenAIFile + public partial class OpenAIFile : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel { internal OpenAIFile() { } public System.DateTimeOffset CreatedAt { get { throw null; } } @@ -323,6 +437,11 @@ internal OpenAIFile() { } public string Id { get { throw null; } } public Azure.AI.OpenAI.Assistants.OpenAIFilePurpose Purpose { get { throw null; } } public int Size { get { throw null; } } + Azure.AI.OpenAI.Assistants.OpenAIFile System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.AI.OpenAI.Assistants.OpenAIFile System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } } [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] public readonly partial struct OpenAIFilePurpose : System.IEquatable @@ -355,35 +474,65 @@ internal PageableList() { } public System.Collections.Generic.IEnumerator GetEnumerator() { throw null; } System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { throw null; } } - public abstract partial class RequiredAction + public abstract partial class RequiredAction : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel { protected RequiredAction() { } + Azure.AI.OpenAI.Assistants.RequiredAction System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.AI.OpenAI.Assistants.RequiredAction System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } } - public partial class RequiredFunctionToolCall : Azure.AI.OpenAI.Assistants.RequiredToolCall + public partial class RequiredFunctionToolCall : Azure.AI.OpenAI.Assistants.RequiredToolCall, System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel { internal RequiredFunctionToolCall() : base (default(string)) { } public string Name { get { throw null; } } public System.BinaryData Parameters { get { throw null; } } + Azure.AI.OpenAI.Assistants.RequiredFunctionToolCall System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.AI.OpenAI.Assistants.RequiredFunctionToolCall System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } } - public abstract partial class RequiredToolCall + public abstract partial class RequiredToolCall : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel { protected RequiredToolCall(string id) { } public string Id { get { throw null; } } + Azure.AI.OpenAI.Assistants.RequiredToolCall System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.AI.OpenAI.Assistants.RequiredToolCall System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } } - public partial class RetrievalToolCall : Azure.AI.OpenAI.Assistants.ToolCall + public partial class RetrievalToolCall : Azure.AI.OpenAI.Assistants.ToolCall, System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel { internal RetrievalToolCall() : base (default(string)) { } public System.Collections.Generic.IReadOnlyDictionary Retrieval { get { throw null; } } + Azure.AI.OpenAI.Assistants.RetrievalToolCall System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.AI.OpenAI.Assistants.RetrievalToolCall System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } } - public partial class RetrievalToolDefinition : Azure.AI.OpenAI.Assistants.ToolDefinition + public partial class RetrievalToolDefinition : Azure.AI.OpenAI.Assistants.ToolDefinition, System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel { public RetrievalToolDefinition() { } + Azure.AI.OpenAI.Assistants.RetrievalToolDefinition System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.AI.OpenAI.Assistants.RetrievalToolDefinition System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } } - public partial class RunError + public partial class RunError : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel { internal RunError() { } public string Code { get { throw null; } } public string Message { get { throw null; } } + Azure.AI.OpenAI.Assistants.RunError System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.AI.OpenAI.Assistants.RunError System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } } [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] public readonly partial struct RunStatus : System.IEquatable @@ -409,7 +558,7 @@ internal RunError() { } public static bool operator !=(Azure.AI.OpenAI.Assistants.RunStatus left, Azure.AI.OpenAI.Assistants.RunStatus right) { throw null; } public override string ToString() { throw null; } } - public partial class RunStep + public partial class RunStep : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel { internal RunStep() { } public string AssistantId { get { throw null; } } @@ -426,16 +575,31 @@ internal RunStep() { } public Azure.AI.OpenAI.Assistants.RunStepDetails StepDetails { get { throw null; } } public string ThreadId { get { throw null; } } public Azure.AI.OpenAI.Assistants.RunStepType Type { get { throw null; } } + Azure.AI.OpenAI.Assistants.RunStep System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.AI.OpenAI.Assistants.RunStep System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } } - public abstract partial class RunStepDetails + public abstract partial class RunStepDetails : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel { protected RunStepDetails() { } + Azure.AI.OpenAI.Assistants.RunStepDetails System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.AI.OpenAI.Assistants.RunStepDetails System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } } - public partial class RunStepError + public partial class RunStepError : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel { internal RunStepError() { } public Azure.AI.OpenAI.Assistants.RunStepErrorCode Code { get { throw null; } } public string Message { get { throw null; } } + Azure.AI.OpenAI.Assistants.RunStepError System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.AI.OpenAI.Assistants.RunStepError System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } } [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] public readonly partial struct RunStepErrorCode : System.IEquatable @@ -455,15 +619,25 @@ internal RunStepError() { } public static bool operator !=(Azure.AI.OpenAI.Assistants.RunStepErrorCode left, Azure.AI.OpenAI.Assistants.RunStepErrorCode right) { throw null; } public override string ToString() { throw null; } } - public partial class RunStepMessageCreationDetails : Azure.AI.OpenAI.Assistants.RunStepDetails + public partial class RunStepMessageCreationDetails : Azure.AI.OpenAI.Assistants.RunStepDetails, System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel { internal RunStepMessageCreationDetails() { } public Azure.AI.OpenAI.Assistants.RunStepMessageCreationReference MessageCreation { get { throw null; } } + Azure.AI.OpenAI.Assistants.RunStepMessageCreationDetails System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.AI.OpenAI.Assistants.RunStepMessageCreationDetails System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } } - public partial class RunStepMessageCreationReference + public partial class RunStepMessageCreationReference : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel { internal RunStepMessageCreationReference() { } public string MessageId { get { throw null; } } + Azure.AI.OpenAI.Assistants.RunStepMessageCreationReference System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.AI.OpenAI.Assistants.RunStepMessageCreationReference System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } } [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] public readonly partial struct RunStepStatus : System.IEquatable @@ -486,10 +660,15 @@ internal RunStepMessageCreationReference() { } public static bool operator !=(Azure.AI.OpenAI.Assistants.RunStepStatus left, Azure.AI.OpenAI.Assistants.RunStepStatus right) { throw null; } public override string ToString() { throw null; } } - public partial class RunStepToolCallDetails : Azure.AI.OpenAI.Assistants.RunStepDetails + public partial class RunStepToolCallDetails : Azure.AI.OpenAI.Assistants.RunStepDetails, System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel { internal RunStepToolCallDetails() { } public System.Collections.Generic.IReadOnlyList ToolCalls { get { throw null; } } + Azure.AI.OpenAI.Assistants.RunStepToolCallDetails System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.AI.OpenAI.Assistants.RunStepToolCallDetails System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } } [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] public readonly partial struct RunStepType : System.IEquatable @@ -509,20 +688,30 @@ internal RunStepToolCallDetails() { } public static bool operator !=(Azure.AI.OpenAI.Assistants.RunStepType left, Azure.AI.OpenAI.Assistants.RunStepType right) { throw null; } public override string ToString() { throw null; } } - public partial class SubmitToolOutputsAction : Azure.AI.OpenAI.Assistants.RequiredAction + public partial class SubmitToolOutputsAction : Azure.AI.OpenAI.Assistants.RequiredAction, System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel { internal SubmitToolOutputsAction() { } public System.Collections.Generic.IReadOnlyList ToolCalls { get { throw null; } } + Azure.AI.OpenAI.Assistants.SubmitToolOutputsAction System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.AI.OpenAI.Assistants.SubmitToolOutputsAction System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } } - public partial class ThreadInitializationMessage + public partial class ThreadInitializationMessage : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel { public ThreadInitializationMessage(Azure.AI.OpenAI.Assistants.MessageRole role, string content) { } public string Content { get { throw null; } } public System.Collections.Generic.IList FileIds { get { throw null; } } public System.Collections.Generic.IDictionary Metadata { get { throw null; } set { } } public Azure.AI.OpenAI.Assistants.MessageRole Role { get { throw null; } } + Azure.AI.OpenAI.Assistants.ThreadInitializationMessage System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.AI.OpenAI.Assistants.ThreadInitializationMessage System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } } - public partial class ThreadMessage + public partial class ThreadMessage : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel { internal ThreadMessage() { } public string AssistantId { get { throw null; } } @@ -534,8 +723,13 @@ internal ThreadMessage() { } public Azure.AI.OpenAI.Assistants.MessageRole Role { get { throw null; } } public string RunId { get { throw null; } } public string ThreadId { get { throw null; } } + Azure.AI.OpenAI.Assistants.ThreadMessage System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.AI.OpenAI.Assistants.ThreadMessage System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } } - public partial class ThreadRun + public partial class ThreadRun : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel { internal ThreadRun() { } public string AssistantId { get { throw null; } } @@ -555,17 +749,32 @@ internal ThreadRun() { } public Azure.AI.OpenAI.Assistants.RunStatus Status { get { throw null; } } public string ThreadId { get { throw null; } } public System.Collections.Generic.IReadOnlyList Tools { get { throw null; } } + Azure.AI.OpenAI.Assistants.ThreadRun System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.AI.OpenAI.Assistants.ThreadRun System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } } - public abstract partial class ToolCall + public abstract partial class ToolCall : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel { protected ToolCall(string id) { } public string Id { get { throw null; } } + Azure.AI.OpenAI.Assistants.ToolCall System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.AI.OpenAI.Assistants.ToolCall System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } } - public abstract partial class ToolDefinition + public abstract partial class ToolDefinition : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel { protected ToolDefinition() { } + Azure.AI.OpenAI.Assistants.ToolDefinition System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.AI.OpenAI.Assistants.ToolDefinition System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } } - public partial class ToolOutput + public partial class ToolOutput : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel { public ToolOutput() { } public ToolOutput(Azure.AI.OpenAI.Assistants.RequiredToolCall toolCall) { } @@ -574,8 +783,13 @@ public ToolOutput(string toolCallId) { } public ToolOutput(string toolCallId, string output) { } public string Output { get { throw null; } set { } } public string ToolCallId { get { throw null; } set { } } + Azure.AI.OpenAI.Assistants.ToolOutput System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.AI.OpenAI.Assistants.ToolOutput System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } } - public partial class UpdateAssistantOptions + public partial class UpdateAssistantOptions : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel { public UpdateAssistantOptions() { } public string Description { get { throw null; } set { } } @@ -585,6 +799,11 @@ public UpdateAssistantOptions() { } public string Model { get { throw null; } set { } } public string Name { get { throw null; } set { } } public System.Collections.Generic.IList Tools { get { throw null; } } + Azure.AI.OpenAI.Assistants.UpdateAssistantOptions System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.AI.OpenAI.Assistants.UpdateAssistantOptions System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } } } namespace Microsoft.Extensions.Azure diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Azure.AI.OpenAI.Assistants.csproj b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Azure.AI.OpenAI.Assistants.csproj index f4ec7c0c46c2..6d0629d413e4 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Azure.AI.OpenAI.Assistants.csproj +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Azure.AI.OpenAI.Assistants.csproj @@ -16,6 +16,7 @@ + diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/AssistantsModelFactory.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/AssistantsModelFactory.cs index 1b2e878a4d0f..81c036df8a06 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/AssistantsModelFactory.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/AssistantsModelFactory.cs @@ -37,7 +37,17 @@ public static Assistant Assistant(string id = null, DateTimeOffset createdAt = d fileIds ??= new List(); metadata ??= new Dictionary(); - return new Assistant(id, @object: null, createdAt, name, description, model, instructions, tools?.ToList(), fileIds?.ToList(), metadata); + return new Assistant( + id, + @object: null, + createdAt, + name, + description, + model, + instructions, tools?.ToList(), + fileIds?.ToList(), + metadata, + serializedAdditionalRawData: null); } /// Initializes a new instance of . @@ -59,7 +69,7 @@ public static AssistantThread AssistantThread(string id = null, DateTimeOffset c { metadata ??= new Dictionary(); - return new AssistantThread(id, @object: null, createdAt, metadata); + return new AssistantThread(id, @object: null, createdAt, metadata, serializedAdditionalRawData: null); } /// Initializes a new instance of . @@ -97,7 +107,7 @@ public static ThreadRun ThreadRun(string id = null, string threadId = null, stri fileIds ??= new List(); metadata ??= new Dictionary(); - return new ThreadRun(id, @object: null, threadId, assistantId, status, requiredAction, lastError, model, instructions, tools?.ToList(), fileIds?.ToList(), createdAt, expiresAt, startedAt, completedAt, cancelledAt, failedAt, metadata); + return new ThreadRun(id, @object: null, threadId, assistantId, status, requiredAction, lastError, model, instructions, tools?.ToList(), fileIds?.ToList(), createdAt, expiresAt, startedAt, completedAt, cancelledAt, failedAt, metadata, serializedAdditionalRawData: null); } /// Initializes a new instance of . @@ -132,7 +142,7 @@ public static RunStep RunStep(string id = null, RunStepType type = default, stri { metadata ??= new Dictionary(); - return new RunStep(id, @object: null, type, assistantId, threadId, runId, status, stepDetails, lastError, createdAt, expiredAt, completedAt, cancelledAt, failedAt, metadata); + return new RunStep(id, @object: null, type, assistantId, threadId, runId, status, stepDetails, lastError, createdAt, expiredAt, completedAt, cancelledAt, failedAt, metadata, serializedAdditionalRawData: null); } /// Initializes a new instance of . @@ -155,7 +165,7 @@ public static ThreadMessage ThreadMessage(string id = null, DateTimeOffset creat fileIds ??= new List(); metadata ??= new Dictionary(); - return new ThreadMessage(id, @object: null, createdAt, threadId, role, contentItems?.ToList(), assistantId, runId, fileIds?.ToList(), metadata); + return new ThreadMessage(id, @object: null, createdAt, threadId, role, contentItems?.ToList(), assistantId, runId, fileIds?.ToList(), metadata, serializedAdditionalRawData: null); } public static RequiredFunctionToolCall RequiredFunctionToolCall(string toolCallId, string functionName, BinaryData functionParameters) diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/FunctionToolDefinition.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/FunctionToolDefinition.cs index 69d753460552..ad230819be45 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/FunctionToolDefinition.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Custom/FunctionToolDefinition.cs @@ -41,7 +41,7 @@ public partial class FunctionToolDefinition /// The parameters the functions accepts, described as a JSON Schema object. /// , or is null. public FunctionToolDefinition(string name, string description, BinaryData parameters) - : this(type: "function", new InternalFunctionDefinition(name, description, parameters)) + : this(type: "function", serializedAdditionalRawData: null, new InternalFunctionDefinition(name, description, parameters, serializedAdditionalRawData: null)) { } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/Assistant.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/Assistant.Serialization.cs index df949caa73bf..c0cfd0a49047 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/Assistant.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/Assistant.Serialization.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.ClientModel.Primitives; using System.Collections.Generic; using System.Text.Json; using Azure; @@ -13,10 +14,117 @@ namespace Azure.AI.OpenAI.Assistants { - public partial class Assistant + public partial class Assistant : IUtf8JsonSerializable, IJsonModel { - internal static Assistant DeserializeAssistant(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(Assistant)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("id"u8); + writer.WriteStringValue(Id); + writer.WritePropertyName("object"u8); + writer.WriteStringValue(Object); + writer.WritePropertyName("created_at"u8); + writer.WriteNumberValue(CreatedAt, "U"); + if (Name != null) + { + writer.WritePropertyName("name"u8); + writer.WriteStringValue(Name); + } + else + { + writer.WriteNull("name"); + } + if (Description != null) + { + writer.WritePropertyName("description"u8); + writer.WriteStringValue(Description); + } + else + { + writer.WriteNull("description"); + } + writer.WritePropertyName("model"u8); + writer.WriteStringValue(Model); + if (Instructions != null) + { + writer.WritePropertyName("instructions"u8); + writer.WriteStringValue(Instructions); + } + else + { + writer.WriteNull("instructions"); + } + writer.WritePropertyName("tools"u8); + writer.WriteStartArray(); + foreach (var item in Tools) + { + writer.WriteObjectValue(item); + } + writer.WriteEndArray(); + writer.WritePropertyName("file_ids"u8); + writer.WriteStartArray(); + foreach (var item in FileIds) + { + writer.WriteStringValue(item); + } + writer.WriteEndArray(); + if (Metadata != null && Optional.IsCollectionDefined(Metadata)) + { + writer.WritePropertyName("metadata"u8); + writer.WriteStartObject(); + foreach (var item in Metadata) + { + writer.WritePropertyName(item.Key); + writer.WriteStringValue(item.Value); + } + writer.WriteEndObject(); + } + else + { + writer.WriteNull("metadata"); + } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + Assistant IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(Assistant)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeAssistant(document.RootElement, options); + } + + internal static Assistant DeserializeAssistant(JsonElement element, ModelReaderWriterOptions options = null) { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; @@ -31,6 +139,8 @@ internal static Assistant DeserializeAssistant(JsonElement element) IReadOnlyList tools = default; IReadOnlyList fileIds = default; IReadOnlyDictionary metadata = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("id"u8)) @@ -118,10 +228,46 @@ internal static Assistant DeserializeAssistant(JsonElement element) metadata = dictionary; continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } } - return new Assistant(id, @object, createdAt, name, description, model, instructions, tools, fileIds, metadata); + serializedAdditionalRawData = additionalPropertiesDictionary; + return new Assistant(id, @object, createdAt, name, description, model, instructions, tools, fileIds, metadata, serializedAdditionalRawData); } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(Assistant)} does not support '{options.Format}' format."); + } + } + + Assistant IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeAssistant(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(Assistant)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + /// Deserializes the model from a raw response. /// The response to deserialize the model from. internal static Assistant FromResponse(Response response) @@ -129,5 +275,13 @@ internal static Assistant FromResponse(Response response) using var document = JsonDocument.Parse(response.Content); return DeserializeAssistant(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/Assistant.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/Assistant.cs index 59023860a3dd..3a199c516d57 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/Assistant.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/Assistant.cs @@ -15,6 +15,38 @@ namespace Azure.AI.OpenAI.Assistants /// Represents an assistant that can call the model and use tools. public partial class Assistant { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . /// The identifier, which can be referenced in API endpoints. /// The Unix timestamp, in seconds, representing when this object was created. @@ -55,7 +87,8 @@ internal Assistant(string id, DateTimeOffset createdAt, string name, string desc /// The collection of tools enabled for the assistant. /// A list of attached file IDs, ordered by creation date in ascending order. /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. - internal Assistant(string id, string @object, DateTimeOffset createdAt, string name, string description, string model, string instructions, IReadOnlyList tools, IReadOnlyList fileIds, IReadOnlyDictionary metadata) + /// Keeps track of any properties unknown to the library. + internal Assistant(string id, string @object, DateTimeOffset createdAt, string name, string description, string model, string instructions, IReadOnlyList tools, IReadOnlyList fileIds, IReadOnlyDictionary metadata, IDictionary serializedAdditionalRawData) { Id = id; Object = @object; @@ -67,6 +100,12 @@ internal Assistant(string id, string @object, DateTimeOffset createdAt, string n Tools = tools; FileIds = fileIds; Metadata = metadata; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal Assistant() + { } /// The identifier, which can be referenced in API endpoints. diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantCreationOptions.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantCreationOptions.Serialization.cs index d6257f00c532..830e1a6c2f2c 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantCreationOptions.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantCreationOptions.Serialization.cs @@ -5,15 +5,27 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; +using Azure; using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - public partial class AssistantCreationOptions : IUtf8JsonSerializable + public partial class AssistantCreationOptions : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(AssistantCreationOptions)} does not support '{format}' format."); + } + writer.WriteStartObject(); writer.WritePropertyName("model"u8); writer.WriteStringValue(Model); @@ -91,9 +103,180 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) writer.WriteNull("metadata"); } } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } + AssistantCreationOptions IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(AssistantCreationOptions)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeAssistantCreationOptions(document.RootElement, options); + } + + internal static AssistantCreationOptions DeserializeAssistantCreationOptions(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string model = default; + Optional name = default; + Optional description = default; + Optional instructions = default; + Optional> tools = default; + Optional> fileIds = default; + Optional> metadata = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("model"u8)) + { + model = property.Value.GetString(); + continue; + } + if (property.NameEquals("name"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + name = null; + continue; + } + name = property.Value.GetString(); + continue; + } + if (property.NameEquals("description"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + description = null; + continue; + } + description = property.Value.GetString(); + continue; + } + if (property.NameEquals("instructions"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + instructions = null; + continue; + } + instructions = property.Value.GetString(); + continue; + } + if (property.NameEquals("tools"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(ToolDefinition.DeserializeToolDefinition(item)); + } + tools = array; + continue; + } + if (property.NameEquals("file_ids"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(item.GetString()); + } + fileIds = array; + continue; + } + if (property.NameEquals("metadata"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + Dictionary dictionary = new Dictionary(); + foreach (var property0 in property.Value.EnumerateObject()) + { + dictionary.Add(property0.Name, property0.Value.GetString()); + } + metadata = dictionary; + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new AssistantCreationOptions(model, name.Value, description.Value, instructions.Value, Optional.ToList(tools), Optional.ToList(fileIds), Optional.ToDictionary(metadata), serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(AssistantCreationOptions)} does not support '{options.Format}' format."); + } + } + + AssistantCreationOptions IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeAssistantCreationOptions(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(AssistantCreationOptions)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static AssistantCreationOptions FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeAssistantCreationOptions(document.RootElement); + } + /// Convert into a Utf8JsonRequestContent. internal virtual RequestContent ToRequestContent() { diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantCreationOptions.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantCreationOptions.cs index c8c897f61149..431717276aee 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantCreationOptions.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantCreationOptions.cs @@ -14,6 +14,38 @@ namespace Azure.AI.OpenAI.Assistants /// The request details to use when creating a new assistant. public partial class AssistantCreationOptions { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . /// The ID of the model to use. /// is null. @@ -35,7 +67,8 @@ public AssistantCreationOptions(string model) /// The collection of tools to enable for the new assistant. /// A list of previously uploaded file IDs to attach to the assistant. /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. - internal AssistantCreationOptions(string model, string name, string description, string instructions, IList tools, IList fileIds, IDictionary metadata) + /// Keeps track of any properties unknown to the library. + internal AssistantCreationOptions(string model, string name, string description, string instructions, IList tools, IList fileIds, IDictionary metadata, IDictionary serializedAdditionalRawData) { Model = model; Name = name; @@ -44,6 +77,12 @@ internal AssistantCreationOptions(string model, string name, string description, Tools = tools; FileIds = fileIds; Metadata = metadata; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal AssistantCreationOptions() + { } /// The ID of the model to use. diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantFile.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantFile.Serialization.cs index c431007e9da8..68dc7cf5e845 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantFile.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantFile.Serialization.cs @@ -6,15 +6,69 @@ #nullable disable using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - public partial class AssistantFile + public partial class AssistantFile : IUtf8JsonSerializable, IJsonModel { - internal static AssistantFile DeserializeAssistantFile(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(AssistantFile)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("id"u8); + writer.WriteStringValue(Id); + writer.WritePropertyName("object"u8); + writer.WriteStringValue(Object); + writer.WritePropertyName("created_at"u8); + writer.WriteNumberValue(CreatedAt, "U"); + writer.WritePropertyName("assistant_id"u8); + writer.WriteStringValue(AssistantId); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + AssistantFile IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(AssistantFile)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeAssistantFile(document.RootElement, options); + } + + internal static AssistantFile DeserializeAssistantFile(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; @@ -23,6 +77,8 @@ internal static AssistantFile DeserializeAssistantFile(JsonElement element) string @object = default; DateTimeOffset createdAt = default; string assistantId = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("id"u8)) @@ -45,10 +101,46 @@ internal static AssistantFile DeserializeAssistantFile(JsonElement element) assistantId = property.Value.GetString(); continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new AssistantFile(id, @object, createdAt, assistantId, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(AssistantFile)} does not support '{options.Format}' format."); + } + } + + AssistantFile IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeAssistantFile(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(AssistantFile)} does not support '{options.Format}' format."); } - return new AssistantFile(id, @object, createdAt, assistantId); } + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + /// Deserializes the model from a raw response. /// The response to deserialize the model from. internal static AssistantFile FromResponse(Response response) @@ -56,5 +148,13 @@ internal static AssistantFile FromResponse(Response response) using var document = JsonDocument.Parse(response.Content); return DeserializeAssistantFile(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantFile.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantFile.cs index 7b51df805c7c..5d7b6e6b035d 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantFile.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantFile.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.Collections.Generic; using Azure.Core; namespace Azure.AI.OpenAI.Assistants @@ -13,6 +14,38 @@ namespace Azure.AI.OpenAI.Assistants /// Information about a file attached to an assistant, as used by tools that can read files. public partial class AssistantFile { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . /// The identifier, which can be referenced in API endpoints. /// The Unix timestamp, in seconds, representing when this object was created. @@ -33,12 +66,19 @@ internal AssistantFile(string id, DateTimeOffset createdAt, string assistantId) /// The object type, which is always 'assistant.file'. /// The Unix timestamp, in seconds, representing when this object was created. /// The assistant ID that the file is attached to. - internal AssistantFile(string id, string @object, DateTimeOffset createdAt, string assistantId) + /// Keeps track of any properties unknown to the library. + internal AssistantFile(string id, string @object, DateTimeOffset createdAt, string assistantId, IDictionary serializedAdditionalRawData) { Id = id; Object = @object; CreatedAt = createdAt; AssistantId = assistantId; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal AssistantFile() + { } /// The identifier, which can be referenced in API endpoints. diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantThread.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantThread.Serialization.cs index a3e279d9cc72..ce3bf2311e79 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantThread.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantThread.Serialization.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.ClientModel.Primitives; using System.Collections.Generic; using System.Text.Json; using Azure; @@ -13,10 +14,74 @@ namespace Azure.AI.OpenAI.Assistants { - public partial class AssistantThread + public partial class AssistantThread : IUtf8JsonSerializable, IJsonModel { - internal static AssistantThread DeserializeAssistantThread(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(AssistantThread)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("id"u8); + writer.WriteStringValue(Id); + writer.WritePropertyName("object"u8); + writer.WriteStringValue(Object); + writer.WritePropertyName("created_at"u8); + writer.WriteNumberValue(CreatedAt, "U"); + if (Metadata != null && Optional.IsCollectionDefined(Metadata)) + { + writer.WritePropertyName("metadata"u8); + writer.WriteStartObject(); + foreach (var item in Metadata) + { + writer.WritePropertyName(item.Key); + writer.WriteStringValue(item.Value); + } + writer.WriteEndObject(); + } + else + { + writer.WriteNull("metadata"); + } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + AssistantThread IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(AssistantThread)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeAssistantThread(document.RootElement, options); + } + + internal static AssistantThread DeserializeAssistantThread(JsonElement element, ModelReaderWriterOptions options = null) { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; @@ -25,6 +90,8 @@ internal static AssistantThread DeserializeAssistantThread(JsonElement element) string @object = default; DateTimeOffset createdAt = default; IReadOnlyDictionary metadata = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("id"u8)) @@ -57,10 +124,46 @@ internal static AssistantThread DeserializeAssistantThread(JsonElement element) metadata = dictionary; continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new AssistantThread(id, @object, createdAt, metadata, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(AssistantThread)} does not support '{options.Format}' format."); } - return new AssistantThread(id, @object, createdAt, metadata); } + AssistantThread IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeAssistantThread(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(AssistantThread)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + /// Deserializes the model from a raw response. /// The response to deserialize the model from. internal static AssistantThread FromResponse(Response response) @@ -68,5 +171,13 @@ internal static AssistantThread FromResponse(Response response) using var document = JsonDocument.Parse(response.Content); return DeserializeAssistantThread(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantThread.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantThread.cs index 3ced3d2241cb..821189a4433e 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantThread.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantThread.cs @@ -14,6 +14,38 @@ namespace Azure.AI.OpenAI.Assistants /// Information about a single thread associated with an assistant. public partial class AssistantThread { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . /// The identifier, which can be referenced in API endpoints. /// The Unix timestamp, in seconds, representing when this object was created. @@ -33,12 +65,19 @@ internal AssistantThread(string id, DateTimeOffset createdAt, IReadOnlyDictionar /// The object type, which is always 'thread'. /// The Unix timestamp, in seconds, representing when this object was created. /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. - internal AssistantThread(string id, string @object, DateTimeOffset createdAt, IReadOnlyDictionary metadata) + /// Keeps track of any properties unknown to the library. + internal AssistantThread(string id, string @object, DateTimeOffset createdAt, IReadOnlyDictionary metadata, IDictionary serializedAdditionalRawData) { Id = id; Object = @object; CreatedAt = createdAt; Metadata = metadata; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal AssistantThread() + { } /// The identifier, which can be referenced in API endpoints. diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantThreadCreationOptions.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantThreadCreationOptions.Serialization.cs index 7e3f83fccc99..930ddd8e61fa 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantThreadCreationOptions.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantThreadCreationOptions.Serialization.cs @@ -5,15 +5,27 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; +using Azure; using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - public partial class AssistantThreadCreationOptions : IUtf8JsonSerializable + public partial class AssistantThreadCreationOptions : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(AssistantThreadCreationOptions)} does not support '{format}' format."); + } + writer.WriteStartObject(); if (Optional.IsCollectionDefined(Messages)) { @@ -43,9 +55,126 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) writer.WriteNull("metadata"); } } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } + AssistantThreadCreationOptions IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(AssistantThreadCreationOptions)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeAssistantThreadCreationOptions(document.RootElement, options); + } + + internal static AssistantThreadCreationOptions DeserializeAssistantThreadCreationOptions(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + Optional> messages = default; + Optional> metadata = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("messages"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(ThreadInitializationMessage.DeserializeThreadInitializationMessage(item)); + } + messages = array; + continue; + } + if (property.NameEquals("metadata"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + Dictionary dictionary = new Dictionary(); + foreach (var property0 in property.Value.EnumerateObject()) + { + dictionary.Add(property0.Name, property0.Value.GetString()); + } + metadata = dictionary; + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new AssistantThreadCreationOptions(Optional.ToList(messages), Optional.ToDictionary(metadata), serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(AssistantThreadCreationOptions)} does not support '{options.Format}' format."); + } + } + + AssistantThreadCreationOptions IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeAssistantThreadCreationOptions(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(AssistantThreadCreationOptions)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static AssistantThreadCreationOptions FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeAssistantThreadCreationOptions(document.RootElement); + } + /// Convert into a Utf8JsonRequestContent. internal virtual RequestContent ToRequestContent() { diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantThreadCreationOptions.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantThreadCreationOptions.cs index 67912f83c9f4..cb33ccd883ea 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantThreadCreationOptions.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantThreadCreationOptions.cs @@ -5,6 +5,7 @@ #nullable disable +using System; using System.Collections.Generic; using Azure.Core; @@ -13,6 +14,38 @@ namespace Azure.AI.OpenAI.Assistants /// The details used to create a new assistant thread. public partial class AssistantThreadCreationOptions { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . public AssistantThreadCreationOptions() { @@ -23,10 +56,12 @@ public AssistantThreadCreationOptions() /// Initializes a new instance of . /// The initial messages to associate with the new thread. /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. - internal AssistantThreadCreationOptions(IList messages, IDictionary metadata) + /// Keeps track of any properties unknown to the library. + internal AssistantThreadCreationOptions(IList messages, IDictionary metadata, IDictionary serializedAdditionalRawData) { Messages = messages; Metadata = metadata; + _serializedAdditionalRawData = serializedAdditionalRawData; } /// The initial messages to associate with the new thread. diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsModelFactory.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsModelFactory.cs index 5e35bab278ec..06671305c6c6 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsModelFactory.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsModelFactory.cs @@ -5,7 +5,6 @@ #nullable disable -using System; using System.Collections.Generic; using System.Linq; @@ -14,38 +13,92 @@ namespace Azure.AI.OpenAI.Assistants /// Model factory for models. public static partial class AssistantsModelFactory { + /// Initializes a new instance of . + /// The ID of the model to use. + /// The name of the new assistant. + /// The description of the new assistant. + /// The system instructions for the new assistant to use. + /// The collection of tools to enable for the new assistant. + /// A list of previously uploaded file IDs to attach to the assistant. + /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. + /// A new instance for mocking. + public static AssistantCreationOptions AssistantCreationOptions(string model = null, string name = null, string description = null, string instructions = null, IEnumerable tools = null, IEnumerable fileIds = null, IDictionary metadata = null) + { + tools ??= new List(); + fileIds ??= new List(); + metadata ??= new Dictionary(); + + return new AssistantCreationOptions(model, name, description, instructions, tools?.ToList(), fileIds?.ToList(), metadata, serializedAdditionalRawData: null); + } + + /// Initializes a new instance of . + /// The role associated with the assistant thread message. Currently, only 'user' is supported when providing initial messages to a new thread. + /// The textual content of the initial message. Currently, robust input including images and annotated text may only be provided via a separate call to the create message API. + /// + /// A list of file IDs that the assistant should use. Useful for tools like retrieval and code_interpreter that can + /// access files. + /// + /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. + /// A new instance for mocking. + public static ThreadInitializationMessage ThreadInitializationMessage(MessageRole role = default, string content = null, IEnumerable fileIds = null, IDictionary metadata = null) + { + fileIds ??= new List(); + metadata ??= new Dictionary(); + + return new ThreadInitializationMessage(role, content, fileIds?.ToList(), metadata, serializedAdditionalRawData: null); + } + + /// Initializes a new instance of . + /// The ID of the assistant that should run the thread. + /// The overridden model name that the assistant should use to run the thread. + /// The overridden system instructions that the assistant should use to run the thread. + /// + /// Additional instructions to append at the end of the instructions for the run. This is useful for modifying the behavior + /// on a per-run basis without overriding other instructions. + /// + /// The overridden list of enabled tools that the assistant should use to run the thread. + /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. + /// A new instance for mocking. + public static CreateRunOptions CreateRunOptions(string assistantId = null, string overrideModelName = null, string overrideInstructions = null, string additionalInstructions = null, IEnumerable overrideTools = null, IDictionary metadata = null) + { + overrideTools ??= new List(); + metadata ??= new Dictionary(); + + return new CreateRunOptions(assistantId, overrideModelName, overrideInstructions, additionalInstructions, overrideTools?.ToList(), metadata, serializedAdditionalRawData: null); + } + /// Initializes a new instance of . /// The status for the error. /// The human-readable text associated with the error. - /// or is null. /// A new instance for mocking. public static RunError RunError(string code = null, string message = null) { - if (code == null) - { - throw new ArgumentNullException(nameof(code)); - } - if (message == null) - { - throw new ArgumentNullException(nameof(message)); - } + return new RunError(code, message, serializedAdditionalRawData: null); + } - return new RunError(code, message); + /// Initializes a new instance of . + /// The ID of the assistant for which the thread should be created. + /// The details used to create the new thread. + /// The overridden model that the assistant should use to run the thread. + /// The overridden system instructions the assistant should use to run the thread. + /// The overridden list of enabled tools the assistant should use to run the thread. + /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. + /// A new instance for mocking. + public static CreateAndRunThreadOptions CreateAndRunThreadOptions(string assistantId = null, AssistantThreadCreationOptions thread = null, string overrideModelName = null, string overrideInstructions = null, IEnumerable overrideTools = null, IDictionary metadata = null) + { + overrideTools ??= new List(); + metadata ??= new Dictionary(); + + return new CreateAndRunThreadOptions(assistantId, thread, overrideModelName, overrideInstructions, overrideTools?.ToList(), metadata, serializedAdditionalRawData: null); } /// Initializes a new instance of . /// The error code for this error. /// The human-readable text associated with this error. - /// is null. /// A new instance for mocking. public static RunStepError RunStepError(RunStepErrorCode code = default, string message = null) { - if (message == null) - { - throw new ArgumentNullException(nameof(message)); - } - - return new RunStepError(code, message); + return new RunStepError(code, message, serializedAdditionalRawData: null); } /// Initializes a new instance of . @@ -54,7 +107,7 @@ public static RunStepError RunStepError(RunStepErrorCode code = default, string /// A new instance for mocking. public static RequiredToolCall RequiredToolCall(string type = null, string id = null) { - return new UnknownRequiredToolCall(type, id); + return new UnknownRequiredToolCall(type, id, serializedAdditionalRawData: null); } /// Initializes a new instance of . @@ -63,7 +116,7 @@ public static RequiredToolCall RequiredToolCall(string type = null, string id = /// A new instance for mocking. public static ToolCall ToolCall(string type = null, string id = null) { - return new UnknownToolCall(type, id); + return new UnknownToolCall(type, id, serializedAdditionalRawData: null); } /// Initializes a new instance of . @@ -74,7 +127,7 @@ public static RetrievalToolCall RetrievalToolCall(string id = null, IReadOnlyDic { retrieval ??= new Dictionary(); - return new RetrievalToolCall("retrieval", id, retrieval); + return new RetrievalToolCall("retrieval", id, serializedAdditionalRawData: null, retrieval); } /// Initializes a new instance of . @@ -82,7 +135,7 @@ public static RetrievalToolCall RetrievalToolCall(string id = null, IReadOnlyDic /// A new instance for mocking. public static CodeInterpreterLogOutput CodeInterpreterLogOutput(string logs = null) { - return new CodeInterpreterLogOutput("logs", logs); + return new CodeInterpreterLogOutput("logs", serializedAdditionalRawData: null, logs); } /// Initializes a new instance of . @@ -90,21 +143,15 @@ public static CodeInterpreterLogOutput CodeInterpreterLogOutput(string logs = nu /// A new instance for mocking. public static CodeInterpreterImageOutput CodeInterpreterImageOutput(CodeInterpreterImageReference image = null) { - return new CodeInterpreterImageOutput("image", image); + return new CodeInterpreterImageOutput("image", serializedAdditionalRawData: null, image); } /// Initializes a new instance of . /// The ID of the file associated with this image. - /// is null. /// A new instance for mocking. public static CodeInterpreterImageReference CodeInterpreterImageReference(string fileId = null) { - if (fileId == null) - { - throw new ArgumentNullException(nameof(fileId)); - } - - return new CodeInterpreterImageReference(fileId); + return new CodeInterpreterImageReference(fileId, serializedAdditionalRawData: null); } /// Initializes a new instance of . @@ -115,7 +162,7 @@ public static CodeInterpreterImageReference CodeInterpreterImageReference(string /// A new instance for mocking. public static MessageTextAnnotation MessageTextAnnotation(string type = null, string text = null, int startIndex = default, int endIndex = default) { - return new UnknownMessageTextAnnotation(type, text, startIndex, endIndex); + return new UnknownMessageTextAnnotation(type, text, startIndex, endIndex, serializedAdditionalRawData: null); } /// Initializes a new instance of . @@ -123,21 +170,15 @@ public static MessageTextAnnotation MessageTextAnnotation(string type = null, st /// A new instance for mocking. public static RunStepMessageCreationDetails RunStepMessageCreationDetails(RunStepMessageCreationReference messageCreation = null) { - return new RunStepMessageCreationDetails(RunStepType.MessageCreation, messageCreation); + return new RunStepMessageCreationDetails(RunStepType.MessageCreation, serializedAdditionalRawData: null, messageCreation); } /// Initializes a new instance of . /// The ID of the message created by this run step. - /// is null. /// A new instance for mocking. public static RunStepMessageCreationReference RunStepMessageCreationReference(string messageId = null) { - if (messageId == null) - { - throw new ArgumentNullException(nameof(messageId)); - } - - return new RunStepMessageCreationReference(messageId); + return new RunStepMessageCreationReference(messageId, serializedAdditionalRawData: null); } /// Initializes a new instance of . @@ -147,7 +188,7 @@ public static RunStepToolCallDetails RunStepToolCallDetails(IEnumerable(); - return new RunStepToolCallDetails(RunStepType.ToolCalls, toolCalls?.ToList()); + return new RunStepToolCallDetails(RunStepType.ToolCalls, serializedAdditionalRawData: null, toolCalls?.ToList()); } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterImageOutput.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterImageOutput.Serialization.cs index f6397375eca4..2a099191287f 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterImageOutput.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterImageOutput.Serialization.cs @@ -5,21 +5,74 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - public partial class CodeInterpreterImageOutput + public partial class CodeInterpreterImageOutput : IUtf8JsonSerializable, IJsonModel { - internal static CodeInterpreterImageOutput DeserializeCodeInterpreterImageOutput(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(CodeInterpreterImageOutput)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("image"u8); + writer.WriteObjectValue(Image); + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + CodeInterpreterImageOutput IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(CodeInterpreterImageOutput)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeCodeInterpreterImageOutput(document.RootElement, options); + } + + internal static CodeInterpreterImageOutput DeserializeCodeInterpreterImageOutput(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; } CodeInterpreterImageReference image = default; string type = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("image"u8)) @@ -32,10 +85,46 @@ internal static CodeInterpreterImageOutput DeserializeCodeInterpreterImageOutput type = property.Value.GetString(); continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new CodeInterpreterImageOutput(type, serializedAdditionalRawData, image); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(CodeInterpreterImageOutput)} does not support '{options.Format}' format."); + } + } + + CodeInterpreterImageOutput IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeCodeInterpreterImageOutput(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(CodeInterpreterImageOutput)} does not support '{options.Format}' format."); } - return new CodeInterpreterImageOutput(type, image); } + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + /// Deserializes the model from a raw response. /// The response to deserialize the model from. internal static new CodeInterpreterImageOutput FromResponse(Response response) @@ -43,5 +132,13 @@ internal static CodeInterpreterImageOutput DeserializeCodeInterpreterImageOutput using var document = JsonDocument.Parse(response.Content); return DeserializeCodeInterpreterImageOutput(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal override RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterImageOutput.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterImageOutput.cs index a29bd099f124..20cf2eb894c2 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterImageOutput.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterImageOutput.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.Collections.Generic; using Azure.Core; namespace Azure.AI.OpenAI.Assistants @@ -26,12 +27,18 @@ internal CodeInterpreterImageOutput(CodeInterpreterImageReference image) /// Initializes a new instance of . /// The object type. + /// Keeps track of any properties unknown to the library. /// Referential information for the image associated with this output. - internal CodeInterpreterImageOutput(string type, CodeInterpreterImageReference image) : base(type) + internal CodeInterpreterImageOutput(string type, IDictionary serializedAdditionalRawData, CodeInterpreterImageReference image) : base(type, serializedAdditionalRawData) { Image = image; } + /// Initializes a new instance of for deserialization. + internal CodeInterpreterImageOutput() + { + } + /// Referential information for the image associated with this output. public CodeInterpreterImageReference Image { get; } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterImageReference.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterImageReference.Serialization.cs index 32beec637f8f..fe4e73ddfbed 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterImageReference.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterImageReference.Serialization.cs @@ -5,20 +5,71 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - public partial class CodeInterpreterImageReference + public partial class CodeInterpreterImageReference : IUtf8JsonSerializable, IJsonModel { - internal static CodeInterpreterImageReference DeserializeCodeInterpreterImageReference(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(CodeInterpreterImageReference)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("file_id"u8); + writer.WriteStringValue(FileId); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + CodeInterpreterImageReference IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(CodeInterpreterImageReference)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeCodeInterpreterImageReference(document.RootElement, options); + } + + internal static CodeInterpreterImageReference DeserializeCodeInterpreterImageReference(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; } string fileId = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("file_id"u8)) @@ -26,10 +77,46 @@ internal static CodeInterpreterImageReference DeserializeCodeInterpreterImageRef fileId = property.Value.GetString(); continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new CodeInterpreterImageReference(fileId, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(CodeInterpreterImageReference)} does not support '{options.Format}' format."); + } + } + + CodeInterpreterImageReference IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeCodeInterpreterImageReference(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(CodeInterpreterImageReference)} does not support '{options.Format}' format."); } - return new CodeInterpreterImageReference(fileId); } + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + /// Deserializes the model from a raw response. /// The response to deserialize the model from. internal static CodeInterpreterImageReference FromResponse(Response response) @@ -37,5 +124,13 @@ internal static CodeInterpreterImageReference FromResponse(Response response) using var document = JsonDocument.Parse(response.Content); return DeserializeCodeInterpreterImageReference(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterImageReference.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterImageReference.cs index 3e291a443b24..87e833a302e1 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterImageReference.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterImageReference.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.Collections.Generic; using Azure.Core; namespace Azure.AI.OpenAI.Assistants @@ -13,6 +14,38 @@ namespace Azure.AI.OpenAI.Assistants /// An image reference emitted by a code interpreter tool in response to a tool call by the model. public partial class CodeInterpreterImageReference { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . /// The ID of the file associated with this image. /// is null. @@ -23,6 +56,20 @@ internal CodeInterpreterImageReference(string fileId) FileId = fileId; } + /// Initializes a new instance of . + /// The ID of the file associated with this image. + /// Keeps track of any properties unknown to the library. + internal CodeInterpreterImageReference(string fileId, IDictionary serializedAdditionalRawData) + { + FileId = fileId; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal CodeInterpreterImageReference() + { + } + /// The ID of the file associated with this image. public string FileId { get; } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterLogOutput.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterLogOutput.Serialization.cs index 258d3cbba965..15552d59b388 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterLogOutput.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterLogOutput.Serialization.cs @@ -5,21 +5,74 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - public partial class CodeInterpreterLogOutput + public partial class CodeInterpreterLogOutput : IUtf8JsonSerializable, IJsonModel { - internal static CodeInterpreterLogOutput DeserializeCodeInterpreterLogOutput(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(CodeInterpreterLogOutput)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("logs"u8); + writer.WriteStringValue(Logs); + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + CodeInterpreterLogOutput IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(CodeInterpreterLogOutput)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeCodeInterpreterLogOutput(document.RootElement, options); + } + + internal static CodeInterpreterLogOutput DeserializeCodeInterpreterLogOutput(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; } string logs = default; string type = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("logs"u8)) @@ -32,10 +85,46 @@ internal static CodeInterpreterLogOutput DeserializeCodeInterpreterLogOutput(Jso type = property.Value.GetString(); continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new CodeInterpreterLogOutput(type, serializedAdditionalRawData, logs); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(CodeInterpreterLogOutput)} does not support '{options.Format}' format."); + } + } + + CodeInterpreterLogOutput IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeCodeInterpreterLogOutput(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(CodeInterpreterLogOutput)} does not support '{options.Format}' format."); } - return new CodeInterpreterLogOutput(type, logs); } + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + /// Deserializes the model from a raw response. /// The response to deserialize the model from. internal static new CodeInterpreterLogOutput FromResponse(Response response) @@ -43,5 +132,13 @@ internal static CodeInterpreterLogOutput DeserializeCodeInterpreterLogOutput(Jso using var document = JsonDocument.Parse(response.Content); return DeserializeCodeInterpreterLogOutput(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal override RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterLogOutput.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterLogOutput.cs index a242df685458..a08680f45063 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterLogOutput.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterLogOutput.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.Collections.Generic; using Azure.Core; namespace Azure.AI.OpenAI.Assistants @@ -26,12 +27,18 @@ internal CodeInterpreterLogOutput(string logs) /// Initializes a new instance of . /// The object type. + /// Keeps track of any properties unknown to the library. /// The serialized log output emitted by the code interpreter. - internal CodeInterpreterLogOutput(string type, string logs) : base(type) + internal CodeInterpreterLogOutput(string type, IDictionary serializedAdditionalRawData, string logs) : base(type, serializedAdditionalRawData) { Logs = logs; } + /// Initializes a new instance of for deserialization. + internal CodeInterpreterLogOutput() + { + } + /// The serialized log output emitted by the code interpreter. public string Logs { get; } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterToolCall.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterToolCall.Serialization.cs index d80e710382f6..4e88efaa91a7 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterToolCall.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterToolCall.Serialization.cs @@ -5,15 +5,68 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - public partial class CodeInterpreterToolCall + public partial class CodeInterpreterToolCall : IUtf8JsonSerializable, IJsonModel { - internal static CodeInterpreterToolCall DeserializeCodeInterpreterToolCall(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(CodeInterpreterToolCall)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("code_interpreter"u8); + writer.WriteObjectValue(InternalDetails); + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type); + writer.WritePropertyName("id"u8); + writer.WriteStringValue(Id); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + CodeInterpreterToolCall IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(CodeInterpreterToolCall)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeCodeInterpreterToolCall(document.RootElement, options); + } + + internal static CodeInterpreterToolCall DeserializeCodeInterpreterToolCall(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; @@ -21,6 +74,8 @@ internal static CodeInterpreterToolCall DeserializeCodeInterpreterToolCall(JsonE InternalCodeInterpreterToolCallDetails codeInterpreter = default; string type = default; string id = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("code_interpreter"u8)) @@ -38,10 +93,46 @@ internal static CodeInterpreterToolCall DeserializeCodeInterpreterToolCall(JsonE id = property.Value.GetString(); continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new CodeInterpreterToolCall(type, id, serializedAdditionalRawData, codeInterpreter); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(CodeInterpreterToolCall)} does not support '{options.Format}' format."); + } + } + + CodeInterpreterToolCall IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeCodeInterpreterToolCall(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(CodeInterpreterToolCall)} does not support '{options.Format}' format."); } - return new CodeInterpreterToolCall(type, id, codeInterpreter); } + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + /// Deserializes the model from a raw response. /// The response to deserialize the model from. internal static new CodeInterpreterToolCall FromResponse(Response response) @@ -49,5 +140,13 @@ internal static CodeInterpreterToolCall DeserializeCodeInterpreterToolCall(JsonE using var document = JsonDocument.Parse(response.Content); return DeserializeCodeInterpreterToolCall(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal override RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterToolCall.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterToolCall.cs index 7ff205504495..ce67d06cc9ad 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterToolCall.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterToolCall.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.Collections.Generic; using Azure.Core; namespace Azure.AI.OpenAI.Assistants @@ -32,10 +33,16 @@ internal CodeInterpreterToolCall(string id, InternalCodeInterpreterToolCallDetai /// Initializes a new instance of . /// The object type. /// The ID of the tool call. This ID must be referenced when you submit tool outputs. + /// Keeps track of any properties unknown to the library. /// The details of the tool call to the code interpreter tool. - internal CodeInterpreterToolCall(string type, string id, InternalCodeInterpreterToolCallDetails internalDetails) : base(type, id) + internal CodeInterpreterToolCall(string type, string id, IDictionary serializedAdditionalRawData, InternalCodeInterpreterToolCallDetails internalDetails) : base(type, id, serializedAdditionalRawData) { InternalDetails = internalDetails; } + + /// Initializes a new instance of for deserialization. + internal CodeInterpreterToolCall() + { + } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterToolCallOutput.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterToolCallOutput.Serialization.cs index e4db8114844b..93fb158c0cb2 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterToolCallOutput.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterToolCallOutput.Serialization.cs @@ -5,15 +5,64 @@ #nullable disable +using System; +using System.ClientModel.Primitives; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - public partial class CodeInterpreterToolCallOutput + [PersistableModelProxy(typeof(UnknownCodeInterpreterToolCallOutput))] + public partial class CodeInterpreterToolCallOutput : IUtf8JsonSerializable, IJsonModel { - internal static CodeInterpreterToolCallOutput DeserializeCodeInterpreterToolCallOutput(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(CodeInterpreterToolCallOutput)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + CodeInterpreterToolCallOutput IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(CodeInterpreterToolCallOutput)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeCodeInterpreterToolCallOutput(document.RootElement, options); + } + + internal static CodeInterpreterToolCallOutput DeserializeCodeInterpreterToolCallOutput(JsonElement element, ModelReaderWriterOptions options = null) { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; @@ -29,6 +78,37 @@ internal static CodeInterpreterToolCallOutput DeserializeCodeInterpreterToolCall return UnknownCodeInterpreterToolCallOutput.DeserializeUnknownCodeInterpreterToolCallOutput(element); } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(CodeInterpreterToolCallOutput)} does not support '{options.Format}' format."); + } + } + + CodeInterpreterToolCallOutput IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeCodeInterpreterToolCallOutput(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(CodeInterpreterToolCallOutput)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + /// Deserializes the model from a raw response. /// The response to deserialize the model from. internal static CodeInterpreterToolCallOutput FromResponse(Response response) @@ -36,5 +116,13 @@ internal static CodeInterpreterToolCallOutput FromResponse(Response response) using var document = JsonDocument.Parse(response.Content); return DeserializeCodeInterpreterToolCallOutput(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterToolCallOutput.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterToolCallOutput.cs index 8409302c7373..faaacfcff1c1 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterToolCallOutput.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterToolCallOutput.cs @@ -5,6 +5,9 @@ #nullable disable +using System; +using System.Collections.Generic; + namespace Azure.AI.OpenAI.Assistants { /// @@ -14,6 +17,38 @@ namespace Azure.AI.OpenAI.Assistants /// public abstract partial class CodeInterpreterToolCallOutput { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private protected IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . protected CodeInterpreterToolCallOutput() { @@ -21,9 +56,11 @@ protected CodeInterpreterToolCallOutput() /// Initializes a new instance of . /// The object type. - internal CodeInterpreterToolCallOutput(string type) + /// Keeps track of any properties unknown to the library. + internal CodeInterpreterToolCallOutput(string type, IDictionary serializedAdditionalRawData) { Type = type; + _serializedAdditionalRawData = serializedAdditionalRawData; } /// The object type. diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterToolDefinition.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterToolDefinition.Serialization.cs index e86daf800d77..c3d274302d26 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterToolDefinition.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterToolDefinition.Serialization.cs @@ -5,29 +5,71 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; using Azure; using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - public partial class CodeInterpreterToolDefinition : IUtf8JsonSerializable + public partial class CodeInterpreterToolDefinition : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(CodeInterpreterToolDefinition)} does not support '{format}' format."); + } + writer.WriteStartObject(); writer.WritePropertyName("type"u8); writer.WriteStringValue(Type); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } - internal static CodeInterpreterToolDefinition DeserializeCodeInterpreterToolDefinition(JsonElement element) + CodeInterpreterToolDefinition IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(CodeInterpreterToolDefinition)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeCodeInterpreterToolDefinition(document.RootElement, options); + } + + internal static CodeInterpreterToolDefinition DeserializeCodeInterpreterToolDefinition(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; } string type = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("type"u8)) @@ -35,10 +77,46 @@ internal static CodeInterpreterToolDefinition DeserializeCodeInterpreterToolDefi type = property.Value.GetString(); continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new CodeInterpreterToolDefinition(type, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(CodeInterpreterToolDefinition)} does not support '{options.Format}' format."); } - return new CodeInterpreterToolDefinition(type); } + CodeInterpreterToolDefinition IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeCodeInterpreterToolDefinition(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(CodeInterpreterToolDefinition)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + /// Deserializes the model from a raw response. /// The response to deserialize the model from. internal static new CodeInterpreterToolDefinition FromResponse(Response response) diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterToolDefinition.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterToolDefinition.cs index a7109a1953fa..a057579590fc 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterToolDefinition.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterToolDefinition.cs @@ -5,6 +5,9 @@ #nullable disable +using System; +using System.Collections.Generic; + namespace Azure.AI.OpenAI.Assistants { /// The input definition information for a code interpreter tool as used to configure an assistant. @@ -18,7 +21,8 @@ public CodeInterpreterToolDefinition() /// Initializes a new instance of . /// The object type. - internal CodeInterpreterToolDefinition(string type) : base(type) + /// Keeps track of any properties unknown to the library. + internal CodeInterpreterToolDefinition(string type, IDictionary serializedAdditionalRawData) : base(type, serializedAdditionalRawData) { } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateAndRunThreadOptions.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateAndRunThreadOptions.Serialization.cs index fa7217f816f9..542a1976c8da 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateAndRunThreadOptions.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateAndRunThreadOptions.Serialization.cs @@ -5,15 +5,27 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; +using Azure; using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - public partial class CreateAndRunThreadOptions : IUtf8JsonSerializable + public partial class CreateAndRunThreadOptions : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(CreateAndRunThreadOptions)} does not support '{format}' format."); + } + writer.WriteStartObject(); writer.WritePropertyName("assistant_id"u8); writer.WriteStringValue(AssistantId); @@ -60,9 +72,154 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) writer.WriteNull("metadata"); } } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } + CreateAndRunThreadOptions IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(CreateAndRunThreadOptions)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeCreateAndRunThreadOptions(document.RootElement, options); + } + + internal static CreateAndRunThreadOptions DeserializeCreateAndRunThreadOptions(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string assistantId = default; + Optional thread = default; + Optional model = default; + Optional instructions = default; + Optional> tools = default; + Optional> metadata = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("assistant_id"u8)) + { + assistantId = property.Value.GetString(); + continue; + } + if (property.NameEquals("thread"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + thread = AssistantThreadCreationOptions.DeserializeAssistantThreadCreationOptions(property.Value); + continue; + } + if (property.NameEquals("model"u8)) + { + model = property.Value.GetString(); + continue; + } + if (property.NameEquals("instructions"u8)) + { + instructions = property.Value.GetString(); + continue; + } + if (property.NameEquals("tools"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(ToolDefinition.DeserializeToolDefinition(item)); + } + tools = array; + continue; + } + if (property.NameEquals("metadata"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + Dictionary dictionary = new Dictionary(); + foreach (var property0 in property.Value.EnumerateObject()) + { + dictionary.Add(property0.Name, property0.Value.GetString()); + } + metadata = dictionary; + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new CreateAndRunThreadOptions(assistantId, thread.Value, model.Value, instructions.Value, Optional.ToList(tools), Optional.ToDictionary(metadata), serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(CreateAndRunThreadOptions)} does not support '{options.Format}' format."); + } + } + + CreateAndRunThreadOptions IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeCreateAndRunThreadOptions(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(CreateAndRunThreadOptions)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static CreateAndRunThreadOptions FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeCreateAndRunThreadOptions(document.RootElement); + } + /// Convert into a Utf8JsonRequestContent. internal virtual RequestContent ToRequestContent() { diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateAndRunThreadOptions.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateAndRunThreadOptions.cs index d663adb7dde8..cbdc0d7202a3 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateAndRunThreadOptions.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateAndRunThreadOptions.cs @@ -14,6 +14,38 @@ namespace Azure.AI.OpenAI.Assistants /// The details used when creating and immediately running a new assistant thread. public partial class CreateAndRunThreadOptions { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . /// The ID of the assistant for which the thread should be created. /// is null. @@ -33,7 +65,8 @@ public CreateAndRunThreadOptions(string assistantId) /// The overridden system instructions the assistant should use to run the thread. /// The overridden list of enabled tools the assistant should use to run the thread. /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. - internal CreateAndRunThreadOptions(string assistantId, AssistantThreadCreationOptions thread, string overrideModelName, string overrideInstructions, IList overrideTools, IDictionary metadata) + /// Keeps track of any properties unknown to the library. + internal CreateAndRunThreadOptions(string assistantId, AssistantThreadCreationOptions thread, string overrideModelName, string overrideInstructions, IList overrideTools, IDictionary metadata, IDictionary serializedAdditionalRawData) { AssistantId = assistantId; Thread = thread; @@ -41,6 +74,12 @@ internal CreateAndRunThreadOptions(string assistantId, AssistantThreadCreationOp OverrideInstructions = overrideInstructions; OverrideTools = overrideTools; Metadata = metadata; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal CreateAndRunThreadOptions() + { } /// The ID of the assistant for which the thread should be created. diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateAssistantFileRequest.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateAssistantFileRequest.Serialization.cs index 16635b518b79..ea7bf80f524d 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateAssistantFileRequest.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateAssistantFileRequest.Serialization.cs @@ -5,21 +5,126 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; +using Azure; using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - internal partial class CreateAssistantFileRequest : IUtf8JsonSerializable + internal partial class CreateAssistantFileRequest : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(CreateAssistantFileRequest)} does not support '{format}' format."); + } + writer.WriteStartObject(); writer.WritePropertyName("file_id"u8); writer.WriteStringValue(FileId); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } + CreateAssistantFileRequest IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(CreateAssistantFileRequest)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeCreateAssistantFileRequest(document.RootElement, options); + } + + internal static CreateAssistantFileRequest DeserializeCreateAssistantFileRequest(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string fileId = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("file_id"u8)) + { + fileId = property.Value.GetString(); + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new CreateAssistantFileRequest(fileId, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(CreateAssistantFileRequest)} does not support '{options.Format}' format."); + } + } + + CreateAssistantFileRequest IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeCreateAssistantFileRequest(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(CreateAssistantFileRequest)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static CreateAssistantFileRequest FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeCreateAssistantFileRequest(document.RootElement); + } + /// Convert into a Utf8JsonRequestContent. internal virtual RequestContent ToRequestContent() { diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateAssistantFileRequest.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateAssistantFileRequest.cs index 762b79d212ed..f60662741a54 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateAssistantFileRequest.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateAssistantFileRequest.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.Collections.Generic; using Azure.Core; namespace Azure.AI.OpenAI.Assistants @@ -13,6 +14,38 @@ namespace Azure.AI.OpenAI.Assistants /// The CreateAssistantFileRequest. internal partial class CreateAssistantFileRequest { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . /// The ID of the previously uploaded file to attach. /// is null. @@ -23,6 +56,20 @@ public CreateAssistantFileRequest(string fileId) FileId = fileId; } + /// Initializes a new instance of . + /// The ID of the previously uploaded file to attach. + /// Keeps track of any properties unknown to the library. + internal CreateAssistantFileRequest(string fileId, IDictionary serializedAdditionalRawData) + { + FileId = fileId; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal CreateAssistantFileRequest() + { + } + /// The ID of the previously uploaded file to attach. public string FileId { get; } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateMessageRequest.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateMessageRequest.Serialization.cs index 14c7ce78000a..464fa3a2181a 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateMessageRequest.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateMessageRequest.Serialization.cs @@ -5,15 +5,27 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; +using Azure; using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - internal partial class CreateMessageRequest : IUtf8JsonSerializable + internal partial class CreateMessageRequest : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(CreateMessageRequest)} does not support '{format}' format."); + } + writer.WriteStartObject(); writer.WritePropertyName("role"u8); writer.WriteStringValue(Role.ToString()); @@ -47,9 +59,138 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) writer.WriteNull("metadata"); } } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } + CreateMessageRequest IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(CreateMessageRequest)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeCreateMessageRequest(document.RootElement, options); + } + + internal static CreateMessageRequest DeserializeCreateMessageRequest(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + MessageRole role = default; + string content = default; + Optional> fileIds = default; + Optional> metadata = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("role"u8)) + { + role = new MessageRole(property.Value.GetString()); + continue; + } + if (property.NameEquals("content"u8)) + { + content = property.Value.GetString(); + continue; + } + if (property.NameEquals("file_ids"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(item.GetString()); + } + fileIds = array; + continue; + } + if (property.NameEquals("metadata"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + Dictionary dictionary = new Dictionary(); + foreach (var property0 in property.Value.EnumerateObject()) + { + dictionary.Add(property0.Name, property0.Value.GetString()); + } + metadata = dictionary; + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new CreateMessageRequest(role, content, Optional.ToList(fileIds), Optional.ToDictionary(metadata), serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(CreateMessageRequest)} does not support '{options.Format}' format."); + } + } + + CreateMessageRequest IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeCreateMessageRequest(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(CreateMessageRequest)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static CreateMessageRequest FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeCreateMessageRequest(document.RootElement); + } + /// Convert into a Utf8JsonRequestContent. internal virtual RequestContent ToRequestContent() { diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateMessageRequest.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateMessageRequest.cs index 5104620eb279..63771aac904e 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateMessageRequest.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateMessageRequest.cs @@ -14,6 +14,38 @@ namespace Azure.AI.OpenAI.Assistants /// The CreateMessageRequest. internal partial class CreateMessageRequest { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . /// The role to associate with the new message. /// The textual content for the new message. @@ -33,12 +65,19 @@ public CreateMessageRequest(MessageRole role, string content) /// The textual content for the new message. /// A list of up to 10 file IDs to associate with the message, as used by tools like 'code_interpreter' or 'retrieval' that can read files. /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. - internal CreateMessageRequest(MessageRole role, string content, IList fileIds, IDictionary metadata) + /// Keeps track of any properties unknown to the library. + internal CreateMessageRequest(MessageRole role, string content, IList fileIds, IDictionary metadata, IDictionary serializedAdditionalRawData) { Role = role; Content = content; FileIds = fileIds; Metadata = metadata; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal CreateMessageRequest() + { } /// The role to associate with the new message. diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateRunOptions.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateRunOptions.Serialization.cs index 53e2bc6d2984..d4acb4b70756 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateRunOptions.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateRunOptions.Serialization.cs @@ -5,15 +5,27 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; +using Azure; using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - public partial class CreateRunOptions : IUtf8JsonSerializable + public partial class CreateRunOptions : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(CreateRunOptions)} does not support '{format}' format."); + } + writer.WriteStartObject(); writer.WritePropertyName("assistant_id"u8); writer.WriteStringValue(AssistantId); @@ -88,9 +100,165 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) writer.WriteNull("metadata"); } } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } + CreateRunOptions IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(CreateRunOptions)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeCreateRunOptions(document.RootElement, options); + } + + internal static CreateRunOptions DeserializeCreateRunOptions(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string assistantId = default; + Optional model = default; + Optional instructions = default; + Optional additionalInstructions = default; + Optional> tools = default; + Optional> metadata = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("assistant_id"u8)) + { + assistantId = property.Value.GetString(); + continue; + } + if (property.NameEquals("model"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + model = null; + continue; + } + model = property.Value.GetString(); + continue; + } + if (property.NameEquals("instructions"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + instructions = null; + continue; + } + instructions = property.Value.GetString(); + continue; + } + if (property.NameEquals("additional_instructions"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + additionalInstructions = null; + continue; + } + additionalInstructions = property.Value.GetString(); + continue; + } + if (property.NameEquals("tools"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(ToolDefinition.DeserializeToolDefinition(item)); + } + tools = array; + continue; + } + if (property.NameEquals("metadata"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + Dictionary dictionary = new Dictionary(); + foreach (var property0 in property.Value.EnumerateObject()) + { + dictionary.Add(property0.Name, property0.Value.GetString()); + } + metadata = dictionary; + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new CreateRunOptions(assistantId, model.Value, instructions.Value, additionalInstructions.Value, Optional.ToList(tools), Optional.ToDictionary(metadata), serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(CreateRunOptions)} does not support '{options.Format}' format."); + } + } + + CreateRunOptions IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeCreateRunOptions(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(CreateRunOptions)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static CreateRunOptions FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeCreateRunOptions(document.RootElement); + } + /// Convert into a Utf8JsonRequestContent. internal virtual RequestContent ToRequestContent() { diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateRunOptions.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateRunOptions.cs index 2a667424102e..b1cc3ee18151 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateRunOptions.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateRunOptions.cs @@ -14,6 +14,38 @@ namespace Azure.AI.OpenAI.Assistants /// The details used when creating a new run of an assistant thread. public partial class CreateRunOptions { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . /// The ID of the assistant that should run the thread. /// is null. @@ -36,7 +68,8 @@ public CreateRunOptions(string assistantId) /// /// The overridden list of enabled tools that the assistant should use to run the thread. /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. - internal CreateRunOptions(string assistantId, string overrideModelName, string overrideInstructions, string additionalInstructions, IList overrideTools, IDictionary metadata) + /// Keeps track of any properties unknown to the library. + internal CreateRunOptions(string assistantId, string overrideModelName, string overrideInstructions, string additionalInstructions, IList overrideTools, IDictionary metadata, IDictionary serializedAdditionalRawData) { AssistantId = assistantId; OverrideModelName = overrideModelName; @@ -44,6 +77,12 @@ internal CreateRunOptions(string assistantId, string overrideModelName, string o AdditionalInstructions = additionalInstructions; OverrideTools = overrideTools; Metadata = metadata; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal CreateRunOptions() + { } /// The ID of the assistant that should run the thread. diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/FunctionToolCall.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/FunctionToolCall.Serialization.cs index 2b7e33546f65..c66edb93672e 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/FunctionToolCall.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/FunctionToolCall.Serialization.cs @@ -5,15 +5,68 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - public partial class FunctionToolCall + public partial class FunctionToolCall : IUtf8JsonSerializable, IJsonModel { - internal static FunctionToolCall DeserializeFunctionToolCall(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(FunctionToolCall)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("function"u8); + writer.WriteObjectValue(InternalDetails); + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type); + writer.WritePropertyName("id"u8); + writer.WriteStringValue(Id); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + FunctionToolCall IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(FunctionToolCall)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeFunctionToolCall(document.RootElement, options); + } + + internal static FunctionToolCall DeserializeFunctionToolCall(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; @@ -21,6 +74,8 @@ internal static FunctionToolCall DeserializeFunctionToolCall(JsonElement element InternalFunctionToolCallDetails function = default; string type = default; string id = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("function"u8)) @@ -38,10 +93,46 @@ internal static FunctionToolCall DeserializeFunctionToolCall(JsonElement element id = property.Value.GetString(); continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new FunctionToolCall(type, id, serializedAdditionalRawData, function); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(FunctionToolCall)} does not support '{options.Format}' format."); + } + } + + FunctionToolCall IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeFunctionToolCall(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(FunctionToolCall)} does not support '{options.Format}' format."); } - return new FunctionToolCall(type, id, function); } + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + /// Deserializes the model from a raw response. /// The response to deserialize the model from. internal static new FunctionToolCall FromResponse(Response response) @@ -49,5 +140,13 @@ internal static FunctionToolCall DeserializeFunctionToolCall(JsonElement element using var document = JsonDocument.Parse(response.Content); return DeserializeFunctionToolCall(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal override RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/FunctionToolCall.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/FunctionToolCall.cs index 839e92631519..fd86f62f2063 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/FunctionToolCall.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/FunctionToolCall.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.Collections.Generic; using Azure.Core; namespace Azure.AI.OpenAI.Assistants @@ -32,10 +33,16 @@ internal FunctionToolCall(string id, InternalFunctionToolCallDetails internalDet /// Initializes a new instance of . /// The object type. /// The ID of the tool call. This ID must be referenced when you submit tool outputs. + /// Keeps track of any properties unknown to the library. /// The detailed information about the function called by the model. - internal FunctionToolCall(string type, string id, InternalFunctionToolCallDetails internalDetails) : base(type, id) + internal FunctionToolCall(string type, string id, IDictionary serializedAdditionalRawData, InternalFunctionToolCallDetails internalDetails) : base(type, id, serializedAdditionalRawData) { InternalDetails = internalDetails; } + + /// Initializes a new instance of for deserialization. + internal FunctionToolCall() + { + } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/FunctionToolDefinition.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/FunctionToolDefinition.Serialization.cs index b27e41a52a5f..838898bbf516 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/FunctionToolDefinition.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/FunctionToolDefinition.Serialization.cs @@ -5,32 +5,74 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; using Azure; using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - public partial class FunctionToolDefinition : IUtf8JsonSerializable + public partial class FunctionToolDefinition : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(FunctionToolDefinition)} does not support '{format}' format."); + } + writer.WriteStartObject(); writer.WritePropertyName("function"u8); writer.WriteObjectValue(InternalFunction); writer.WritePropertyName("type"u8); writer.WriteStringValue(Type); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } - internal static FunctionToolDefinition DeserializeFunctionToolDefinition(JsonElement element) + FunctionToolDefinition IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(FunctionToolDefinition)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeFunctionToolDefinition(document.RootElement, options); + } + + internal static FunctionToolDefinition DeserializeFunctionToolDefinition(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; } InternalFunctionDefinition function = default; string type = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("function"u8)) @@ -43,10 +85,46 @@ internal static FunctionToolDefinition DeserializeFunctionToolDefinition(JsonEle type = property.Value.GetString(); continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new FunctionToolDefinition(type, serializedAdditionalRawData, function); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(FunctionToolDefinition)} does not support '{options.Format}' format."); } - return new FunctionToolDefinition(type, function); } + FunctionToolDefinition IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeFunctionToolDefinition(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(FunctionToolDefinition)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + /// Deserializes the model from a raw response. /// The response to deserialize the model from. internal static new FunctionToolDefinition FromResponse(Response response) diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/FunctionToolDefinition.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/FunctionToolDefinition.cs index 2678baf741b0..fe7c807f7363 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/FunctionToolDefinition.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/FunctionToolDefinition.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.Collections.Generic; using Azure.Core; namespace Azure.AI.OpenAI.Assistants @@ -15,10 +16,16 @@ public partial class FunctionToolDefinition : ToolDefinition { /// Initializes a new instance of . /// The object type. + /// Keeps track of any properties unknown to the library. /// The definition of the concrete function that the function tool should call. - internal FunctionToolDefinition(string type, InternalFunctionDefinition internalFunction) : base(type) + internal FunctionToolDefinition(string type, IDictionary serializedAdditionalRawData, InternalFunctionDefinition internalFunction) : base(type, serializedAdditionalRawData) { InternalFunction = internalFunction; } + + /// Initializes a new instance of for deserialization. + internal FunctionToolDefinition() + { + } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalAssistantDeletionStatus.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalAssistantDeletionStatus.Serialization.cs index bd41ced8d2ee..87882d1e43fd 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalAssistantDeletionStatus.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalAssistantDeletionStatus.Serialization.cs @@ -5,15 +5,68 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - internal partial class InternalAssistantDeletionStatus + internal partial class InternalAssistantDeletionStatus : IUtf8JsonSerializable, IJsonModel { - internal static InternalAssistantDeletionStatus DeserializeInternalAssistantDeletionStatus(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalAssistantDeletionStatus)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("id"u8); + writer.WriteStringValue(Id); + writer.WritePropertyName("deleted"u8); + writer.WriteBooleanValue(Deleted); + writer.WritePropertyName("object"u8); + writer.WriteStringValue(Object.ToString()); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + InternalAssistantDeletionStatus IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalAssistantDeletionStatus)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInternalAssistantDeletionStatus(document.RootElement, options); + } + + internal static InternalAssistantDeletionStatus DeserializeInternalAssistantDeletionStatus(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; @@ -21,6 +74,8 @@ internal static InternalAssistantDeletionStatus DeserializeInternalAssistantDele string id = default; bool deleted = default; InternalAssistantDeletionStatusObject @object = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("id"u8)) @@ -38,10 +93,46 @@ internal static InternalAssistantDeletionStatus DeserializeInternalAssistantDele @object = new InternalAssistantDeletionStatusObject(property.Value.GetString()); continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new InternalAssistantDeletionStatus(id, deleted, @object, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(InternalAssistantDeletionStatus)} does not support '{options.Format}' format."); + } + } + + InternalAssistantDeletionStatus IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInternalAssistantDeletionStatus(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InternalAssistantDeletionStatus)} does not support '{options.Format}' format."); } - return new InternalAssistantDeletionStatus(id, deleted, @object); } + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + /// Deserializes the model from a raw response. /// The response to deserialize the model from. internal static InternalAssistantDeletionStatus FromResponse(Response response) @@ -49,5 +140,13 @@ internal static InternalAssistantDeletionStatus FromResponse(Response response) using var document = JsonDocument.Parse(response.Content); return DeserializeInternalAssistantDeletionStatus(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalAssistantDeletionStatus.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalAssistantDeletionStatus.cs index 7bca21ba1f4c..044de1fc40a5 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalAssistantDeletionStatus.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalAssistantDeletionStatus.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.Collections.Generic; using Azure.Core; namespace Azure.AI.OpenAI.Assistants @@ -13,6 +14,38 @@ namespace Azure.AI.OpenAI.Assistants /// The status of an assistant deletion operation. internal partial class InternalAssistantDeletionStatus { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . /// The ID of the resource specified for deletion. /// A value indicating whether deletion was successful. @@ -29,11 +62,18 @@ internal InternalAssistantDeletionStatus(string id, bool deleted) /// The ID of the resource specified for deletion. /// A value indicating whether deletion was successful. /// The object type, which is always 'assistant.deleted'. - internal InternalAssistantDeletionStatus(string id, bool deleted, InternalAssistantDeletionStatusObject @object) + /// Keeps track of any properties unknown to the library. + internal InternalAssistantDeletionStatus(string id, bool deleted, InternalAssistantDeletionStatusObject @object, IDictionary serializedAdditionalRawData) { Id = id; Deleted = deleted; Object = @object; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal InternalAssistantDeletionStatus() + { } /// The ID of the resource specified for deletion. diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalAssistantFileDeletionStatus.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalAssistantFileDeletionStatus.Serialization.cs index 432a715fae3d..1c6208425002 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalAssistantFileDeletionStatus.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalAssistantFileDeletionStatus.Serialization.cs @@ -5,15 +5,68 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - internal partial class InternalAssistantFileDeletionStatus + internal partial class InternalAssistantFileDeletionStatus : IUtf8JsonSerializable, IJsonModel { - internal static InternalAssistantFileDeletionStatus DeserializeInternalAssistantFileDeletionStatus(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalAssistantFileDeletionStatus)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("id"u8); + writer.WriteStringValue(Id); + writer.WritePropertyName("deleted"u8); + writer.WriteBooleanValue(Deleted); + writer.WritePropertyName("object"u8); + writer.WriteStringValue(Object.ToString()); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + InternalAssistantFileDeletionStatus IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalAssistantFileDeletionStatus)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInternalAssistantFileDeletionStatus(document.RootElement, options); + } + + internal static InternalAssistantFileDeletionStatus DeserializeInternalAssistantFileDeletionStatus(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; @@ -21,6 +74,8 @@ internal static InternalAssistantFileDeletionStatus DeserializeInternalAssistant string id = default; bool deleted = default; InternalAssistantFileDeletionStatusObject @object = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("id"u8)) @@ -38,10 +93,46 @@ internal static InternalAssistantFileDeletionStatus DeserializeInternalAssistant @object = new InternalAssistantFileDeletionStatusObject(property.Value.GetString()); continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new InternalAssistantFileDeletionStatus(id, deleted, @object, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(InternalAssistantFileDeletionStatus)} does not support '{options.Format}' format."); + } + } + + InternalAssistantFileDeletionStatus IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInternalAssistantFileDeletionStatus(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InternalAssistantFileDeletionStatus)} does not support '{options.Format}' format."); } - return new InternalAssistantFileDeletionStatus(id, deleted, @object); } + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + /// Deserializes the model from a raw response. /// The response to deserialize the model from. internal static InternalAssistantFileDeletionStatus FromResponse(Response response) @@ -49,5 +140,13 @@ internal static InternalAssistantFileDeletionStatus FromResponse(Response respon using var document = JsonDocument.Parse(response.Content); return DeserializeInternalAssistantFileDeletionStatus(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalAssistantFileDeletionStatus.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalAssistantFileDeletionStatus.cs index 709247cf8a33..beedfc174cb7 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalAssistantFileDeletionStatus.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalAssistantFileDeletionStatus.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.Collections.Generic; using Azure.Core; namespace Azure.AI.OpenAI.Assistants @@ -13,6 +14,38 @@ namespace Azure.AI.OpenAI.Assistants /// The status of an assistant file deletion operation. internal partial class InternalAssistantFileDeletionStatus { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . /// The ID of the resource specified for deletion. /// A value indicating whether deletion was successful. @@ -29,11 +62,18 @@ internal InternalAssistantFileDeletionStatus(string id, bool deleted) /// The ID of the resource specified for deletion. /// A value indicating whether deletion was successful. /// The object type, which is always 'assistant.file.deleted'. - internal InternalAssistantFileDeletionStatus(string id, bool deleted, InternalAssistantFileDeletionStatusObject @object) + /// Keeps track of any properties unknown to the library. + internal InternalAssistantFileDeletionStatus(string id, bool deleted, InternalAssistantFileDeletionStatusObject @object, IDictionary serializedAdditionalRawData) { Id = id; Deleted = deleted; Object = @object; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal InternalAssistantFileDeletionStatus() + { } /// The ID of the resource specified for deletion. diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalCodeInterpreterToolCallDetails.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalCodeInterpreterToolCallDetails.Serialization.cs index 961918d214b1..5223d1a4fcb9 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalCodeInterpreterToolCallDetails.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalCodeInterpreterToolCallDetails.Serialization.cs @@ -5,22 +5,79 @@ #nullable disable +using System; +using System.ClientModel.Primitives; using System.Collections.Generic; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - internal partial class InternalCodeInterpreterToolCallDetails + internal partial class InternalCodeInterpreterToolCallDetails : IUtf8JsonSerializable, IJsonModel { - internal static InternalCodeInterpreterToolCallDetails DeserializeInternalCodeInterpreterToolCallDetails(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalCodeInterpreterToolCallDetails)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("input"u8); + writer.WriteStringValue(Input); + writer.WritePropertyName("outputs"u8); + writer.WriteStartArray(); + foreach (var item in Outputs) + { + writer.WriteObjectValue(item); + } + writer.WriteEndArray(); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + InternalCodeInterpreterToolCallDetails IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalCodeInterpreterToolCallDetails)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInternalCodeInterpreterToolCallDetails(document.RootElement, options); + } + + internal static InternalCodeInterpreterToolCallDetails DeserializeInternalCodeInterpreterToolCallDetails(JsonElement element, ModelReaderWriterOptions options = null) { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; } string input = default; IReadOnlyList outputs = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("input"u8)) @@ -38,10 +95,46 @@ internal static InternalCodeInterpreterToolCallDetails DeserializeInternalCodeIn outputs = array; continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } } - return new InternalCodeInterpreterToolCallDetails(input, outputs); + serializedAdditionalRawData = additionalPropertiesDictionary; + return new InternalCodeInterpreterToolCallDetails(input, outputs, serializedAdditionalRawData); } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(InternalCodeInterpreterToolCallDetails)} does not support '{options.Format}' format."); + } + } + + InternalCodeInterpreterToolCallDetails IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInternalCodeInterpreterToolCallDetails(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InternalCodeInterpreterToolCallDetails)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + /// Deserializes the model from a raw response. /// The response to deserialize the model from. internal static InternalCodeInterpreterToolCallDetails FromResponse(Response response) @@ -49,5 +142,13 @@ internal static InternalCodeInterpreterToolCallDetails FromResponse(Response res using var document = JsonDocument.Parse(response.Content); return DeserializeInternalCodeInterpreterToolCallDetails(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalCodeInterpreterToolCallDetails.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalCodeInterpreterToolCallDetails.cs index 0ca3c2e9f672..64a78b0ec3c3 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalCodeInterpreterToolCallDetails.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalCodeInterpreterToolCallDetails.cs @@ -15,6 +15,38 @@ namespace Azure.AI.OpenAI.Assistants /// The detailed information about a code interpreter invocation by the model. internal partial class InternalCodeInterpreterToolCallDetails { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . /// The input provided by the model to the code interpreter tool. /// The outputs produced by the code interpreter tool back to the model in response to the tool call. @@ -31,10 +63,17 @@ internal InternalCodeInterpreterToolCallDetails(string input, IEnumerable Initializes a new instance of . /// The input provided by the model to the code interpreter tool. /// The outputs produced by the code interpreter tool back to the model in response to the tool call. - internal InternalCodeInterpreterToolCallDetails(string input, IReadOnlyList outputs) + /// Keeps track of any properties unknown to the library. + internal InternalCodeInterpreterToolCallDetails(string input, IReadOnlyList outputs, IDictionary serializedAdditionalRawData) { Input = input; Outputs = outputs; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal InternalCodeInterpreterToolCallDetails() + { } /// The input provided by the model to the code interpreter tool. diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFileDeletionStatus.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFileDeletionStatus.Serialization.cs index 334de061442a..1a3851d7c3d5 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFileDeletionStatus.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFileDeletionStatus.Serialization.cs @@ -5,15 +5,68 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - internal partial class InternalFileDeletionStatus + internal partial class InternalFileDeletionStatus : IUtf8JsonSerializable, IJsonModel { - internal static InternalFileDeletionStatus DeserializeInternalFileDeletionStatus(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalFileDeletionStatus)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("id"u8); + writer.WriteStringValue(Id); + writer.WritePropertyName("deleted"u8); + writer.WriteBooleanValue(Deleted); + writer.WritePropertyName("object"u8); + writer.WriteStringValue(Object.ToString()); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + InternalFileDeletionStatus IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalFileDeletionStatus)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInternalFileDeletionStatus(document.RootElement, options); + } + + internal static InternalFileDeletionStatus DeserializeInternalFileDeletionStatus(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; @@ -21,6 +74,8 @@ internal static InternalFileDeletionStatus DeserializeInternalFileDeletionStatus string id = default; bool deleted = default; InternalFileDeletionStatusObject @object = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("id"u8)) @@ -38,10 +93,46 @@ internal static InternalFileDeletionStatus DeserializeInternalFileDeletionStatus @object = new InternalFileDeletionStatusObject(property.Value.GetString()); continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new InternalFileDeletionStatus(id, deleted, @object, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(InternalFileDeletionStatus)} does not support '{options.Format}' format."); + } + } + + InternalFileDeletionStatus IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInternalFileDeletionStatus(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InternalFileDeletionStatus)} does not support '{options.Format}' format."); } - return new InternalFileDeletionStatus(id, deleted, @object); } + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + /// Deserializes the model from a raw response. /// The response to deserialize the model from. internal static InternalFileDeletionStatus FromResponse(Response response) @@ -49,5 +140,13 @@ internal static InternalFileDeletionStatus FromResponse(Response response) using var document = JsonDocument.Parse(response.Content); return DeserializeInternalFileDeletionStatus(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFileDeletionStatus.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFileDeletionStatus.cs index 4770a27ceda4..937617a1c5d8 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFileDeletionStatus.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFileDeletionStatus.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.Collections.Generic; using Azure.Core; namespace Azure.AI.OpenAI.Assistants @@ -13,6 +14,38 @@ namespace Azure.AI.OpenAI.Assistants /// A status response from a file deletion operation. internal partial class InternalFileDeletionStatus { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . /// The ID of the resource specified for deletion. /// A value indicating whether deletion was successful. @@ -29,11 +62,18 @@ internal InternalFileDeletionStatus(string id, bool deleted) /// The ID of the resource specified for deletion. /// A value indicating whether deletion was successful. /// The object type, which is always 'file'. - internal InternalFileDeletionStatus(string id, bool deleted, InternalFileDeletionStatusObject @object) + /// Keeps track of any properties unknown to the library. + internal InternalFileDeletionStatus(string id, bool deleted, InternalFileDeletionStatusObject @object, IDictionary serializedAdditionalRawData) { Id = id; Deleted = deleted; Object = @object; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal InternalFileDeletionStatus() + { } /// The ID of the resource specified for deletion. diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFileListResponse.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFileListResponse.Serialization.cs index 9a50ae200613..61ac8b856ea6 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFileListResponse.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFileListResponse.Serialization.cs @@ -5,22 +5,79 @@ #nullable disable +using System; +using System.ClientModel.Primitives; using System.Collections.Generic; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - internal partial class InternalFileListResponse + internal partial class InternalFileListResponse : IUtf8JsonSerializable, IJsonModel { - internal static InternalFileListResponse DeserializeInternalFileListResponse(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalFileListResponse)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("object"u8); + writer.WriteStringValue(Object.ToString()); + writer.WritePropertyName("data"u8); + writer.WriteStartArray(); + foreach (var item in Data) + { + writer.WriteObjectValue(item); + } + writer.WriteEndArray(); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + InternalFileListResponse IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalFileListResponse)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInternalFileListResponse(document.RootElement, options); + } + + internal static InternalFileListResponse DeserializeInternalFileListResponse(JsonElement element, ModelReaderWriterOptions options = null) { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; } InternalFileListResponseObject @object = default; IReadOnlyList data = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("object"u8)) @@ -38,10 +95,46 @@ internal static InternalFileListResponse DeserializeInternalFileListResponse(Jso data = array; continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } } - return new InternalFileListResponse(@object, data); + serializedAdditionalRawData = additionalPropertiesDictionary; + return new InternalFileListResponse(@object, data, serializedAdditionalRawData); } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(InternalFileListResponse)} does not support '{options.Format}' format."); + } + } + + InternalFileListResponse IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInternalFileListResponse(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InternalFileListResponse)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + /// Deserializes the model from a raw response. /// The response to deserialize the model from. internal static InternalFileListResponse FromResponse(Response response) @@ -49,5 +142,13 @@ internal static InternalFileListResponse FromResponse(Response response) using var document = JsonDocument.Parse(response.Content); return DeserializeInternalFileListResponse(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFileListResponse.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFileListResponse.cs index dfa3298d3ab3..7c106251212b 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFileListResponse.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFileListResponse.cs @@ -15,6 +15,38 @@ namespace Azure.AI.OpenAI.Assistants /// The response data from a file list operation. internal partial class InternalFileListResponse { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . /// The files returned for the request. /// is null. @@ -28,10 +60,17 @@ internal InternalFileListResponse(IEnumerable data) /// Initializes a new instance of . /// The object type, which is always 'list'. /// The files returned for the request. - internal InternalFileListResponse(InternalFileListResponseObject @object, IReadOnlyList data) + /// Keeps track of any properties unknown to the library. + internal InternalFileListResponse(InternalFileListResponseObject @object, IReadOnlyList data, IDictionary serializedAdditionalRawData) { Object = @object; Data = data; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal InternalFileListResponse() + { } /// The object type, which is always 'list'. diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFunctionDefinition.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFunctionDefinition.Serialization.cs index 4e6e43d5897f..7363c689c36e 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFunctionDefinition.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFunctionDefinition.Serialization.cs @@ -6,16 +6,26 @@ #nullable disable using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; using Azure; using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - internal partial class InternalFunctionDefinition : IUtf8JsonSerializable + internal partial class InternalFunctionDefinition : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalFunctionDefinition)} does not support '{format}' format."); + } + writer.WriteStartObject(); writer.WritePropertyName("name"u8); writer.WriteStringValue(Name); @@ -33,11 +43,40 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) JsonSerializer.Serialize(writer, document.RootElement); } #endif + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } - internal static InternalFunctionDefinition DeserializeInternalFunctionDefinition(JsonElement element) + InternalFunctionDefinition IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalFunctionDefinition)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInternalFunctionDefinition(document.RootElement, options); + } + + internal static InternalFunctionDefinition DeserializeInternalFunctionDefinition(JsonElement element, ModelReaderWriterOptions options = null) { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; @@ -45,6 +84,8 @@ internal static InternalFunctionDefinition DeserializeInternalFunctionDefinition string name = default; Optional description = default; BinaryData parameters = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("name"u8)) @@ -62,10 +103,46 @@ internal static InternalFunctionDefinition DeserializeInternalFunctionDefinition parameters = BinaryData.FromString(property.Value.GetRawText()); continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new InternalFunctionDefinition(name, description.Value, parameters, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(InternalFunctionDefinition)} does not support '{options.Format}' format."); + } + } + + InternalFunctionDefinition IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInternalFunctionDefinition(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InternalFunctionDefinition)} does not support '{options.Format}' format."); } - return new InternalFunctionDefinition(name, description.Value, parameters); } + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + /// Deserializes the model from a raw response. /// The response to deserialize the model from. internal static InternalFunctionDefinition FromResponse(Response response) diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFunctionDefinition.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFunctionDefinition.cs index 9202e6a4df87..5dc65ec4a2cb 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFunctionDefinition.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFunctionDefinition.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.Collections.Generic; using Azure.Core; namespace Azure.AI.OpenAI.Assistants @@ -13,6 +14,38 @@ namespace Azure.AI.OpenAI.Assistants /// The input definition information for a function. internal partial class InternalFunctionDefinition { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . /// The name of the function to be called. /// The parameters the functions accepts, described as a JSON Schema object. @@ -30,11 +63,18 @@ public InternalFunctionDefinition(string name, BinaryData parameters) /// The name of the function to be called. /// A description of what the function does, used by the model to choose when and how to call the function. /// The parameters the functions accepts, described as a JSON Schema object. - internal InternalFunctionDefinition(string name, string description, BinaryData parameters) + /// Keeps track of any properties unknown to the library. + internal InternalFunctionDefinition(string name, string description, BinaryData parameters, IDictionary serializedAdditionalRawData) { Name = name; Description = description; Parameters = parameters; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal InternalFunctionDefinition() + { } /// The name of the function to be called. diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFunctionToolCallDetails.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFunctionToolCallDetails.Serialization.cs index 7215403be309..b770c5a7488f 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFunctionToolCallDetails.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFunctionToolCallDetails.Serialization.cs @@ -5,15 +5,75 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - internal partial class InternalFunctionToolCallDetails + internal partial class InternalFunctionToolCallDetails : IUtf8JsonSerializable, IJsonModel { - internal static InternalFunctionToolCallDetails DeserializeInternalFunctionToolCallDetails(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalFunctionToolCallDetails)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(Name); + writer.WritePropertyName("arguments"u8); + writer.WriteStringValue(Arguments); + if (Output != null) + { + writer.WritePropertyName("output"u8); + writer.WriteStringValue(Output); + } + else + { + writer.WriteNull("output"); + } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + InternalFunctionToolCallDetails IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalFunctionToolCallDetails)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInternalFunctionToolCallDetails(document.RootElement, options); + } + + internal static InternalFunctionToolCallDetails DeserializeInternalFunctionToolCallDetails(JsonElement element, ModelReaderWriterOptions options = null) { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; @@ -21,6 +81,8 @@ internal static InternalFunctionToolCallDetails DeserializeInternalFunctionToolC string name = default; string arguments = default; string output = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("name"u8)) @@ -43,10 +105,46 @@ internal static InternalFunctionToolCallDetails DeserializeInternalFunctionToolC output = property.Value.GetString(); continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new InternalFunctionToolCallDetails(name, arguments, output, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(InternalFunctionToolCallDetails)} does not support '{options.Format}' format."); + } + } + + InternalFunctionToolCallDetails IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInternalFunctionToolCallDetails(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InternalFunctionToolCallDetails)} does not support '{options.Format}' format."); } - return new InternalFunctionToolCallDetails(name, arguments, output); } + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + /// Deserializes the model from a raw response. /// The response to deserialize the model from. internal static InternalFunctionToolCallDetails FromResponse(Response response) @@ -54,5 +152,13 @@ internal static InternalFunctionToolCallDetails FromResponse(Response response) using var document = JsonDocument.Parse(response.Content); return DeserializeInternalFunctionToolCallDetails(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFunctionToolCallDetails.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFunctionToolCallDetails.cs index ae250e18735a..32590cc3c54f 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFunctionToolCallDetails.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalFunctionToolCallDetails.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.Collections.Generic; using Azure.Core; namespace Azure.AI.OpenAI.Assistants @@ -13,6 +14,38 @@ namespace Azure.AI.OpenAI.Assistants /// The detailed information about the function called by the model. internal partial class InternalFunctionToolCallDetails { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . /// The name of the function. /// The arguments that the model requires are provided to the named function. @@ -28,6 +61,24 @@ internal InternalFunctionToolCallDetails(string name, string arguments, string o Output = output; } + /// Initializes a new instance of . + /// The name of the function. + /// The arguments that the model requires are provided to the named function. + /// The output of the function, only populated for function calls that have already have had their outputs submitted. + /// Keeps track of any properties unknown to the library. + internal InternalFunctionToolCallDetails(string name, string arguments, string output, IDictionary serializedAdditionalRawData) + { + Name = name; + Arguments = arguments; + Output = output; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal InternalFunctionToolCallDetails() + { + } + /// The name of the function. public string Name { get; } /// The arguments that the model requires are provided to the named function. diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageImageFileDetails.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageImageFileDetails.Serialization.cs index a03d109c7b5a..b783eb07d878 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageImageFileDetails.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageImageFileDetails.Serialization.cs @@ -5,20 +5,71 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - internal partial class InternalMessageImageFileDetails + internal partial class InternalMessageImageFileDetails : IUtf8JsonSerializable, IJsonModel { - internal static InternalMessageImageFileDetails DeserializeInternalMessageImageFileDetails(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalMessageImageFileDetails)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("file_id"u8); + writer.WriteObjectValue(InternalDetails); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + InternalMessageImageFileDetails IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalMessageImageFileDetails)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInternalMessageImageFileDetails(document.RootElement, options); + } + + internal static InternalMessageImageFileDetails DeserializeInternalMessageImageFileDetails(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; } InternalMessageImageFileIdDetails fileId = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("file_id"u8)) @@ -26,10 +77,46 @@ internal static InternalMessageImageFileDetails DeserializeInternalMessageImageF fileId = InternalMessageImageFileIdDetails.DeserializeInternalMessageImageFileIdDetails(property.Value); continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new InternalMessageImageFileDetails(fileId, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(InternalMessageImageFileDetails)} does not support '{options.Format}' format."); + } + } + + InternalMessageImageFileDetails IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInternalMessageImageFileDetails(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InternalMessageImageFileDetails)} does not support '{options.Format}' format."); } - return new InternalMessageImageFileDetails(fileId); } + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + /// Deserializes the model from a raw response. /// The response to deserialize the model from. internal static InternalMessageImageFileDetails FromResponse(Response response) @@ -37,5 +124,13 @@ internal static InternalMessageImageFileDetails FromResponse(Response response) using var document = JsonDocument.Parse(response.Content); return DeserializeInternalMessageImageFileDetails(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageImageFileDetails.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageImageFileDetails.cs index 42c7412fcd4e..8b8f2efbcb1f 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageImageFileDetails.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageImageFileDetails.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.Collections.Generic; using Azure.Core; namespace Azure.AI.OpenAI.Assistants @@ -13,6 +14,38 @@ namespace Azure.AI.OpenAI.Assistants /// An image reference, as represented in thread message content. internal partial class InternalMessageImageFileDetails { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . /// The ID for the file associated with this image. /// is null. @@ -23,6 +56,20 @@ internal InternalMessageImageFileDetails(InternalMessageImageFileIdDetails inter InternalDetails = internalDetails; } + /// Initializes a new instance of . + /// The ID for the file associated with this image. + /// Keeps track of any properties unknown to the library. + internal InternalMessageImageFileDetails(InternalMessageImageFileIdDetails internalDetails, IDictionary serializedAdditionalRawData) + { + InternalDetails = internalDetails; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal InternalMessageImageFileDetails() + { + } + /// The ID for the file associated with this image. public InternalMessageImageFileIdDetails InternalDetails { get; } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageImageFileIdDetails.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageImageFileIdDetails.Serialization.cs index 6a8e7b8e4065..b1e97548173a 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageImageFileIdDetails.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageImageFileIdDetails.Serialization.cs @@ -5,20 +5,71 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - internal partial class InternalMessageImageFileIdDetails + internal partial class InternalMessageImageFileIdDetails : IUtf8JsonSerializable, IJsonModel { - internal static InternalMessageImageFileIdDetails DeserializeInternalMessageImageFileIdDetails(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalMessageImageFileIdDetails)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("file_id"u8); + writer.WriteStringValue(FileId); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + InternalMessageImageFileIdDetails IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalMessageImageFileIdDetails)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInternalMessageImageFileIdDetails(document.RootElement, options); + } + + internal static InternalMessageImageFileIdDetails DeserializeInternalMessageImageFileIdDetails(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; } string fileId = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("file_id"u8)) @@ -26,10 +77,46 @@ internal static InternalMessageImageFileIdDetails DeserializeInternalMessageImag fileId = property.Value.GetString(); continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new InternalMessageImageFileIdDetails(fileId, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(InternalMessageImageFileIdDetails)} does not support '{options.Format}' format."); + } + } + + InternalMessageImageFileIdDetails IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInternalMessageImageFileIdDetails(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InternalMessageImageFileIdDetails)} does not support '{options.Format}' format."); } - return new InternalMessageImageFileIdDetails(fileId); } + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + /// Deserializes the model from a raw response. /// The response to deserialize the model from. internal static InternalMessageImageFileIdDetails FromResponse(Response response) @@ -37,5 +124,13 @@ internal static InternalMessageImageFileIdDetails FromResponse(Response response using var document = JsonDocument.Parse(response.Content); return DeserializeInternalMessageImageFileIdDetails(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageImageFileIdDetails.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageImageFileIdDetails.cs index f69325bb0542..92bc2193e9ab 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageImageFileIdDetails.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageImageFileIdDetails.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.Collections.Generic; using Azure.Core; namespace Azure.AI.OpenAI.Assistants @@ -13,6 +14,38 @@ namespace Azure.AI.OpenAI.Assistants /// An encapsulation of an image file ID, as used by message image content. internal partial class InternalMessageImageFileIdDetails { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . /// The ID of the specific image file. /// is null. @@ -23,6 +56,20 @@ internal InternalMessageImageFileIdDetails(string fileId) FileId = fileId; } + /// Initializes a new instance of . + /// The ID of the specific image file. + /// Keeps track of any properties unknown to the library. + internal InternalMessageImageFileIdDetails(string fileId, IDictionary serializedAdditionalRawData) + { + FileId = fileId; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal InternalMessageImageFileIdDetails() + { + } + /// The ID of the specific image file. public string FileId { get; } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextDetails.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextDetails.Serialization.cs index 4107400831b8..ba917b8e3d86 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextDetails.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextDetails.Serialization.cs @@ -5,22 +5,79 @@ #nullable disable +using System; +using System.ClientModel.Primitives; using System.Collections.Generic; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - internal partial class InternalMessageTextDetails + internal partial class InternalMessageTextDetails : IUtf8JsonSerializable, IJsonModel { - internal static InternalMessageTextDetails DeserializeInternalMessageTextDetails(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalMessageTextDetails)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(Text); + writer.WritePropertyName("annotations"u8); + writer.WriteStartArray(); + foreach (var item in Annotations) + { + writer.WriteObjectValue(item); + } + writer.WriteEndArray(); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + InternalMessageTextDetails IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalMessageTextDetails)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInternalMessageTextDetails(document.RootElement, options); + } + + internal static InternalMessageTextDetails DeserializeInternalMessageTextDetails(JsonElement element, ModelReaderWriterOptions options = null) { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; } string value = default; IReadOnlyList annotations = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("value"u8)) @@ -38,10 +95,46 @@ internal static InternalMessageTextDetails DeserializeInternalMessageTextDetails annotations = array; continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } } - return new InternalMessageTextDetails(value, annotations); + serializedAdditionalRawData = additionalPropertiesDictionary; + return new InternalMessageTextDetails(value, annotations, serializedAdditionalRawData); } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(InternalMessageTextDetails)} does not support '{options.Format}' format."); + } + } + + InternalMessageTextDetails IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInternalMessageTextDetails(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InternalMessageTextDetails)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + /// Deserializes the model from a raw response. /// The response to deserialize the model from. internal static InternalMessageTextDetails FromResponse(Response response) @@ -49,5 +142,13 @@ internal static InternalMessageTextDetails FromResponse(Response response) using var document = JsonDocument.Parse(response.Content); return DeserializeInternalMessageTextDetails(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextDetails.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextDetails.cs index 84f5a03f57ce..77f06da0bb5d 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextDetails.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextDetails.cs @@ -15,6 +15,38 @@ namespace Azure.AI.OpenAI.Assistants /// The text and associated annotations for a single item of assistant thread message content. internal partial class InternalMessageTextDetails { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . /// The text data. /// A list of annotations associated with this text. @@ -31,10 +63,17 @@ internal InternalMessageTextDetails(string text, IEnumerable Initializes a new instance of . /// The text data. /// A list of annotations associated with this text. - internal InternalMessageTextDetails(string text, IReadOnlyList annotations) + /// Keeps track of any properties unknown to the library. + internal InternalMessageTextDetails(string text, IReadOnlyList annotations, IDictionary serializedAdditionalRawData) { Text = text; Annotations = annotations; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal InternalMessageTextDetails() + { } /// The text data. diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextFileCitationDetails.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextFileCitationDetails.Serialization.cs index 21da36cc3673..996a5ddae602 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextFileCitationDetails.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextFileCitationDetails.Serialization.cs @@ -5,21 +5,74 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - internal partial class InternalMessageTextFileCitationDetails + internal partial class InternalMessageTextFileCitationDetails : IUtf8JsonSerializable, IJsonModel { - internal static InternalMessageTextFileCitationDetails DeserializeInternalMessageTextFileCitationDetails(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalMessageTextFileCitationDetails)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("file_id"u8); + writer.WriteStringValue(FileId); + writer.WritePropertyName("quote"u8); + writer.WriteStringValue(Quote); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + InternalMessageTextFileCitationDetails IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalMessageTextFileCitationDetails)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInternalMessageTextFileCitationDetails(document.RootElement, options); + } + + internal static InternalMessageTextFileCitationDetails DeserializeInternalMessageTextFileCitationDetails(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; } string fileId = default; string quote = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("file_id"u8)) @@ -32,10 +85,46 @@ internal static InternalMessageTextFileCitationDetails DeserializeInternalMessag quote = property.Value.GetString(); continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new InternalMessageTextFileCitationDetails(fileId, quote, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(InternalMessageTextFileCitationDetails)} does not support '{options.Format}' format."); + } + } + + InternalMessageTextFileCitationDetails IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInternalMessageTextFileCitationDetails(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InternalMessageTextFileCitationDetails)} does not support '{options.Format}' format."); } - return new InternalMessageTextFileCitationDetails(fileId, quote); } + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + /// Deserializes the model from a raw response. /// The response to deserialize the model from. internal static InternalMessageTextFileCitationDetails FromResponse(Response response) @@ -43,5 +132,13 @@ internal static InternalMessageTextFileCitationDetails FromResponse(Response res using var document = JsonDocument.Parse(response.Content); return DeserializeInternalMessageTextFileCitationDetails(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextFileCitationDetails.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextFileCitationDetails.cs index ea056e46c5d1..b7feb88df762 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextFileCitationDetails.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextFileCitationDetails.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.Collections.Generic; using Azure.Core; namespace Azure.AI.OpenAI.Assistants @@ -13,6 +14,38 @@ namespace Azure.AI.OpenAI.Assistants /// A representation of a file-based text citation, as used in a file-based annotation of text thread message content. internal partial class InternalMessageTextFileCitationDetails { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . /// The ID of the file associated with this citation. /// The specific quote cited in the associated file. @@ -26,6 +59,22 @@ internal InternalMessageTextFileCitationDetails(string fileId, string quote) Quote = quote; } + /// Initializes a new instance of . + /// The ID of the file associated with this citation. + /// The specific quote cited in the associated file. + /// Keeps track of any properties unknown to the library. + internal InternalMessageTextFileCitationDetails(string fileId, string quote, IDictionary serializedAdditionalRawData) + { + FileId = fileId; + Quote = quote; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal InternalMessageTextFileCitationDetails() + { + } + /// The ID of the file associated with this citation. public string FileId { get; } /// The specific quote cited in the associated file. diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextFilePathDetails.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextFilePathDetails.Serialization.cs index 569554542dc4..041ce476cd34 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextFilePathDetails.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextFilePathDetails.Serialization.cs @@ -5,20 +5,71 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - internal partial class InternalMessageTextFilePathDetails + internal partial class InternalMessageTextFilePathDetails : IUtf8JsonSerializable, IJsonModel { - internal static InternalMessageTextFilePathDetails DeserializeInternalMessageTextFilePathDetails(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalMessageTextFilePathDetails)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("file_id"u8); + writer.WriteStringValue(FileId); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + InternalMessageTextFilePathDetails IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalMessageTextFilePathDetails)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInternalMessageTextFilePathDetails(document.RootElement, options); + } + + internal static InternalMessageTextFilePathDetails DeserializeInternalMessageTextFilePathDetails(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; } string fileId = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("file_id"u8)) @@ -26,10 +77,46 @@ internal static InternalMessageTextFilePathDetails DeserializeInternalMessageTex fileId = property.Value.GetString(); continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new InternalMessageTextFilePathDetails(fileId, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(InternalMessageTextFilePathDetails)} does not support '{options.Format}' format."); + } + } + + InternalMessageTextFilePathDetails IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInternalMessageTextFilePathDetails(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InternalMessageTextFilePathDetails)} does not support '{options.Format}' format."); } - return new InternalMessageTextFilePathDetails(fileId); } + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + /// Deserializes the model from a raw response. /// The response to deserialize the model from. internal static InternalMessageTextFilePathDetails FromResponse(Response response) @@ -37,5 +124,13 @@ internal static InternalMessageTextFilePathDetails FromResponse(Response respons using var document = JsonDocument.Parse(response.Content); return DeserializeInternalMessageTextFilePathDetails(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextFilePathDetails.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextFilePathDetails.cs index 60dc0f0b42e6..1232dcf47366 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextFilePathDetails.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextFilePathDetails.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.Collections.Generic; using Azure.Core; namespace Azure.AI.OpenAI.Assistants @@ -13,6 +14,38 @@ namespace Azure.AI.OpenAI.Assistants /// An encapsulation of an image file ID, as used by message image content. internal partial class InternalMessageTextFilePathDetails { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . /// The ID of the specific file that the citation is from. /// is null. @@ -23,6 +56,20 @@ internal InternalMessageTextFilePathDetails(string fileId) FileId = fileId; } + /// Initializes a new instance of . + /// The ID of the specific file that the citation is from. + /// Keeps track of any properties unknown to the library. + internal InternalMessageTextFilePathDetails(string fileId, IDictionary serializedAdditionalRawData) + { + FileId = fileId; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal InternalMessageTextFilePathDetails() + { + } + /// The ID of the specific file that the citation is from. public string FileId { get; } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfAssistant.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfAssistant.Serialization.cs index 3d336eb4727b..05bef7ef890f 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfAssistant.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfAssistant.Serialization.cs @@ -5,16 +5,77 @@ #nullable disable +using System; +using System.ClientModel.Primitives; using System.Collections.Generic; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - internal partial class InternalOpenAIPageableListOfAssistant + internal partial class InternalOpenAIPageableListOfAssistant : IUtf8JsonSerializable, IJsonModel { - internal static InternalOpenAIPageableListOfAssistant DeserializeInternalOpenAIPageableListOfAssistant(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalOpenAIPageableListOfAssistant)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("object"u8); + writer.WriteStringValue(Object.ToString()); + writer.WritePropertyName("data"u8); + writer.WriteStartArray(); + foreach (var item in Data) + { + writer.WriteObjectValue(item); + } + writer.WriteEndArray(); + writer.WritePropertyName("first_id"u8); + writer.WriteStringValue(FirstId); + writer.WritePropertyName("last_id"u8); + writer.WriteStringValue(LastId); + writer.WritePropertyName("has_more"u8); + writer.WriteBooleanValue(HasMore); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + InternalOpenAIPageableListOfAssistant IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalOpenAIPageableListOfAssistant)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInternalOpenAIPageableListOfAssistant(document.RootElement, options); + } + + internal static InternalOpenAIPageableListOfAssistant DeserializeInternalOpenAIPageableListOfAssistant(JsonElement element, ModelReaderWriterOptions options = null) { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; @@ -24,6 +85,8 @@ internal static InternalOpenAIPageableListOfAssistant DeserializeInternalOpenAIP string firstId = default; string lastId = default; bool hasMore = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("object"u8)) @@ -56,10 +119,46 @@ internal static InternalOpenAIPageableListOfAssistant DeserializeInternalOpenAIP hasMore = property.Value.GetBoolean(); continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } } - return new InternalOpenAIPageableListOfAssistant(@object, data, firstId, lastId, hasMore); + serializedAdditionalRawData = additionalPropertiesDictionary; + return new InternalOpenAIPageableListOfAssistant(@object, data, firstId, lastId, hasMore, serializedAdditionalRawData); } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(InternalOpenAIPageableListOfAssistant)} does not support '{options.Format}' format."); + } + } + + InternalOpenAIPageableListOfAssistant IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInternalOpenAIPageableListOfAssistant(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InternalOpenAIPageableListOfAssistant)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + /// Deserializes the model from a raw response. /// The response to deserialize the model from. internal static InternalOpenAIPageableListOfAssistant FromResponse(Response response) @@ -67,5 +166,13 @@ internal static InternalOpenAIPageableListOfAssistant FromResponse(Response resp using var document = JsonDocument.Parse(response.Content); return DeserializeInternalOpenAIPageableListOfAssistant(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfAssistant.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfAssistant.cs index f8c45e114523..d3dee02c8d60 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfAssistant.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfAssistant.cs @@ -15,6 +15,38 @@ namespace Azure.AI.OpenAI.Assistants /// The response data for a requested list of items. internal partial class InternalOpenAIPageableListOfAssistant { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . /// The requested list of items. /// The first ID represented in this list. @@ -39,13 +71,20 @@ internal InternalOpenAIPageableListOfAssistant(IEnumerable data, stri /// The first ID represented in this list. /// The last ID represented in this list. /// A value indicating whether there are additional values available not captured in this list. - internal InternalOpenAIPageableListOfAssistant(OpenAIPageableListOfAssistantObject @object, IReadOnlyList data, string firstId, string lastId, bool hasMore) + /// Keeps track of any properties unknown to the library. + internal InternalOpenAIPageableListOfAssistant(OpenAIPageableListOfAssistantObject @object, IReadOnlyList data, string firstId, string lastId, bool hasMore, IDictionary serializedAdditionalRawData) { Object = @object; Data = data; FirstId = firstId; LastId = lastId; HasMore = hasMore; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal InternalOpenAIPageableListOfAssistant() + { } /// The object type, which is always list. diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfAssistantFile.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfAssistantFile.Serialization.cs index 416222fe1a03..6bed40ebb82c 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfAssistantFile.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfAssistantFile.Serialization.cs @@ -5,16 +5,77 @@ #nullable disable +using System; +using System.ClientModel.Primitives; using System.Collections.Generic; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - internal partial class InternalOpenAIPageableListOfAssistantFile + internal partial class InternalOpenAIPageableListOfAssistantFile : IUtf8JsonSerializable, IJsonModel { - internal static InternalOpenAIPageableListOfAssistantFile DeserializeInternalOpenAIPageableListOfAssistantFile(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalOpenAIPageableListOfAssistantFile)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("object"u8); + writer.WriteStringValue(Object.ToString()); + writer.WritePropertyName("data"u8); + writer.WriteStartArray(); + foreach (var item in Data) + { + writer.WriteObjectValue(item); + } + writer.WriteEndArray(); + writer.WritePropertyName("first_id"u8); + writer.WriteStringValue(FirstId); + writer.WritePropertyName("last_id"u8); + writer.WriteStringValue(LastId); + writer.WritePropertyName("has_more"u8); + writer.WriteBooleanValue(HasMore); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + InternalOpenAIPageableListOfAssistantFile IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalOpenAIPageableListOfAssistantFile)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInternalOpenAIPageableListOfAssistantFile(document.RootElement, options); + } + + internal static InternalOpenAIPageableListOfAssistantFile DeserializeInternalOpenAIPageableListOfAssistantFile(JsonElement element, ModelReaderWriterOptions options = null) { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; @@ -24,6 +85,8 @@ internal static InternalOpenAIPageableListOfAssistantFile DeserializeInternalOpe string firstId = default; string lastId = default; bool hasMore = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("object"u8)) @@ -56,10 +119,46 @@ internal static InternalOpenAIPageableListOfAssistantFile DeserializeInternalOpe hasMore = property.Value.GetBoolean(); continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } } - return new InternalOpenAIPageableListOfAssistantFile(@object, data, firstId, lastId, hasMore); + serializedAdditionalRawData = additionalPropertiesDictionary; + return new InternalOpenAIPageableListOfAssistantFile(@object, data, firstId, lastId, hasMore, serializedAdditionalRawData); } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(InternalOpenAIPageableListOfAssistantFile)} does not support '{options.Format}' format."); + } + } + + InternalOpenAIPageableListOfAssistantFile IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInternalOpenAIPageableListOfAssistantFile(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InternalOpenAIPageableListOfAssistantFile)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + /// Deserializes the model from a raw response. /// The response to deserialize the model from. internal static InternalOpenAIPageableListOfAssistantFile FromResponse(Response response) @@ -67,5 +166,13 @@ internal static InternalOpenAIPageableListOfAssistantFile FromResponse(Response using var document = JsonDocument.Parse(response.Content); return DeserializeInternalOpenAIPageableListOfAssistantFile(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfAssistantFile.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfAssistantFile.cs index 093d5095f0a2..f6ea4a937d22 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfAssistantFile.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfAssistantFile.cs @@ -15,6 +15,38 @@ namespace Azure.AI.OpenAI.Assistants /// The response data for a requested list of items. internal partial class InternalOpenAIPageableListOfAssistantFile { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . /// The requested list of items. /// The first ID represented in this list. @@ -39,13 +71,20 @@ internal InternalOpenAIPageableListOfAssistantFile(IEnumerable da /// The first ID represented in this list. /// The last ID represented in this list. /// A value indicating whether there are additional values available not captured in this list. - internal InternalOpenAIPageableListOfAssistantFile(OpenAIPageableListOfAssistantFileObject @object, IReadOnlyList data, string firstId, string lastId, bool hasMore) + /// Keeps track of any properties unknown to the library. + internal InternalOpenAIPageableListOfAssistantFile(OpenAIPageableListOfAssistantFileObject @object, IReadOnlyList data, string firstId, string lastId, bool hasMore, IDictionary serializedAdditionalRawData) { Object = @object; Data = data; FirstId = firstId; LastId = lastId; HasMore = hasMore; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal InternalOpenAIPageableListOfAssistantFile() + { } /// The object type, which is always list. diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfMessageFile.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfMessageFile.Serialization.cs index 799114f747b6..667ccd702213 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfMessageFile.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfMessageFile.Serialization.cs @@ -5,16 +5,77 @@ #nullable disable +using System; +using System.ClientModel.Primitives; using System.Collections.Generic; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - internal partial class InternalOpenAIPageableListOfMessageFile + internal partial class InternalOpenAIPageableListOfMessageFile : IUtf8JsonSerializable, IJsonModel { - internal static InternalOpenAIPageableListOfMessageFile DeserializeInternalOpenAIPageableListOfMessageFile(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalOpenAIPageableListOfMessageFile)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("object"u8); + writer.WriteStringValue(Object.ToString()); + writer.WritePropertyName("data"u8); + writer.WriteStartArray(); + foreach (var item in Data) + { + writer.WriteObjectValue(item); + } + writer.WriteEndArray(); + writer.WritePropertyName("first_id"u8); + writer.WriteStringValue(FirstId); + writer.WritePropertyName("last_id"u8); + writer.WriteStringValue(LastId); + writer.WritePropertyName("has_more"u8); + writer.WriteBooleanValue(HasMore); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + InternalOpenAIPageableListOfMessageFile IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalOpenAIPageableListOfMessageFile)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInternalOpenAIPageableListOfMessageFile(document.RootElement, options); + } + + internal static InternalOpenAIPageableListOfMessageFile DeserializeInternalOpenAIPageableListOfMessageFile(JsonElement element, ModelReaderWriterOptions options = null) { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; @@ -24,6 +85,8 @@ internal static InternalOpenAIPageableListOfMessageFile DeserializeInternalOpenA string firstId = default; string lastId = default; bool hasMore = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("object"u8)) @@ -56,10 +119,46 @@ internal static InternalOpenAIPageableListOfMessageFile DeserializeInternalOpenA hasMore = property.Value.GetBoolean(); continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } } - return new InternalOpenAIPageableListOfMessageFile(@object, data, firstId, lastId, hasMore); + serializedAdditionalRawData = additionalPropertiesDictionary; + return new InternalOpenAIPageableListOfMessageFile(@object, data, firstId, lastId, hasMore, serializedAdditionalRawData); } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(InternalOpenAIPageableListOfMessageFile)} does not support '{options.Format}' format."); + } + } + + InternalOpenAIPageableListOfMessageFile IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInternalOpenAIPageableListOfMessageFile(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InternalOpenAIPageableListOfMessageFile)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + /// Deserializes the model from a raw response. /// The response to deserialize the model from. internal static InternalOpenAIPageableListOfMessageFile FromResponse(Response response) @@ -67,5 +166,13 @@ internal static InternalOpenAIPageableListOfMessageFile FromResponse(Response re using var document = JsonDocument.Parse(response.Content); return DeserializeInternalOpenAIPageableListOfMessageFile(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfMessageFile.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfMessageFile.cs index 6168736cef3e..1f15b7993464 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfMessageFile.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfMessageFile.cs @@ -15,6 +15,38 @@ namespace Azure.AI.OpenAI.Assistants /// The response data for a requested list of items. internal partial class InternalOpenAIPageableListOfMessageFile { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . /// The requested list of items. /// The first ID represented in this list. @@ -39,13 +71,20 @@ internal InternalOpenAIPageableListOfMessageFile(IEnumerable data, /// The first ID represented in this list. /// The last ID represented in this list. /// A value indicating whether there are additional values available not captured in this list. - internal InternalOpenAIPageableListOfMessageFile(OpenAIPageableListOfMessageFileObject @object, IReadOnlyList data, string firstId, string lastId, bool hasMore) + /// Keeps track of any properties unknown to the library. + internal InternalOpenAIPageableListOfMessageFile(OpenAIPageableListOfMessageFileObject @object, IReadOnlyList data, string firstId, string lastId, bool hasMore, IDictionary serializedAdditionalRawData) { Object = @object; Data = data; FirstId = firstId; LastId = lastId; HasMore = hasMore; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal InternalOpenAIPageableListOfMessageFile() + { } /// The object type, which is always list. diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfRunStep.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfRunStep.Serialization.cs index dfa4bb0c4359..7cb7d6fad7c6 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfRunStep.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfRunStep.Serialization.cs @@ -5,16 +5,77 @@ #nullable disable +using System; +using System.ClientModel.Primitives; using System.Collections.Generic; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - internal partial class InternalOpenAIPageableListOfRunStep + internal partial class InternalOpenAIPageableListOfRunStep : IUtf8JsonSerializable, IJsonModel { - internal static InternalOpenAIPageableListOfRunStep DeserializeInternalOpenAIPageableListOfRunStep(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalOpenAIPageableListOfRunStep)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("object"u8); + writer.WriteStringValue(Object.ToString()); + writer.WritePropertyName("data"u8); + writer.WriteStartArray(); + foreach (var item in Data) + { + writer.WriteObjectValue(item); + } + writer.WriteEndArray(); + writer.WritePropertyName("first_id"u8); + writer.WriteStringValue(FirstId); + writer.WritePropertyName("last_id"u8); + writer.WriteStringValue(LastId); + writer.WritePropertyName("has_more"u8); + writer.WriteBooleanValue(HasMore); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + InternalOpenAIPageableListOfRunStep IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalOpenAIPageableListOfRunStep)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInternalOpenAIPageableListOfRunStep(document.RootElement, options); + } + + internal static InternalOpenAIPageableListOfRunStep DeserializeInternalOpenAIPageableListOfRunStep(JsonElement element, ModelReaderWriterOptions options = null) { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; @@ -24,6 +85,8 @@ internal static InternalOpenAIPageableListOfRunStep DeserializeInternalOpenAIPag string firstId = default; string lastId = default; bool hasMore = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("object"u8)) @@ -56,10 +119,46 @@ internal static InternalOpenAIPageableListOfRunStep DeserializeInternalOpenAIPag hasMore = property.Value.GetBoolean(); continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } } - return new InternalOpenAIPageableListOfRunStep(@object, data, firstId, lastId, hasMore); + serializedAdditionalRawData = additionalPropertiesDictionary; + return new InternalOpenAIPageableListOfRunStep(@object, data, firstId, lastId, hasMore, serializedAdditionalRawData); } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(InternalOpenAIPageableListOfRunStep)} does not support '{options.Format}' format."); + } + } + + InternalOpenAIPageableListOfRunStep IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInternalOpenAIPageableListOfRunStep(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InternalOpenAIPageableListOfRunStep)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + /// Deserializes the model from a raw response. /// The response to deserialize the model from. internal static InternalOpenAIPageableListOfRunStep FromResponse(Response response) @@ -67,5 +166,13 @@ internal static InternalOpenAIPageableListOfRunStep FromResponse(Response respon using var document = JsonDocument.Parse(response.Content); return DeserializeInternalOpenAIPageableListOfRunStep(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfRunStep.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfRunStep.cs index 3b8704211093..a854a8b9380b 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfRunStep.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfRunStep.cs @@ -15,6 +15,38 @@ namespace Azure.AI.OpenAI.Assistants /// The response data for a requested list of items. internal partial class InternalOpenAIPageableListOfRunStep { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . /// The requested list of items. /// The first ID represented in this list. @@ -39,13 +71,20 @@ internal InternalOpenAIPageableListOfRunStep(IEnumerable data, string f /// The first ID represented in this list. /// The last ID represented in this list. /// A value indicating whether there are additional values available not captured in this list. - internal InternalOpenAIPageableListOfRunStep(OpenAIPageableListOfRunStepObject @object, IReadOnlyList data, string firstId, string lastId, bool hasMore) + /// Keeps track of any properties unknown to the library. + internal InternalOpenAIPageableListOfRunStep(OpenAIPageableListOfRunStepObject @object, IReadOnlyList data, string firstId, string lastId, bool hasMore, IDictionary serializedAdditionalRawData) { Object = @object; Data = data; FirstId = firstId; LastId = lastId; HasMore = hasMore; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal InternalOpenAIPageableListOfRunStep() + { } /// The object type, which is always list. diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfThreadMessage.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfThreadMessage.Serialization.cs index 9fdfad45e9f9..f3eadf6c81a5 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfThreadMessage.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfThreadMessage.Serialization.cs @@ -5,16 +5,77 @@ #nullable disable +using System; +using System.ClientModel.Primitives; using System.Collections.Generic; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - internal partial class InternalOpenAIPageableListOfThreadMessage + internal partial class InternalOpenAIPageableListOfThreadMessage : IUtf8JsonSerializable, IJsonModel { - internal static InternalOpenAIPageableListOfThreadMessage DeserializeInternalOpenAIPageableListOfThreadMessage(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalOpenAIPageableListOfThreadMessage)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("object"u8); + writer.WriteStringValue(Object.ToString()); + writer.WritePropertyName("data"u8); + writer.WriteStartArray(); + foreach (var item in Data) + { + writer.WriteObjectValue(item); + } + writer.WriteEndArray(); + writer.WritePropertyName("first_id"u8); + writer.WriteStringValue(FirstId); + writer.WritePropertyName("last_id"u8); + writer.WriteStringValue(LastId); + writer.WritePropertyName("has_more"u8); + writer.WriteBooleanValue(HasMore); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + InternalOpenAIPageableListOfThreadMessage IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalOpenAIPageableListOfThreadMessage)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInternalOpenAIPageableListOfThreadMessage(document.RootElement, options); + } + + internal static InternalOpenAIPageableListOfThreadMessage DeserializeInternalOpenAIPageableListOfThreadMessage(JsonElement element, ModelReaderWriterOptions options = null) { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; @@ -24,6 +85,8 @@ internal static InternalOpenAIPageableListOfThreadMessage DeserializeInternalOpe string firstId = default; string lastId = default; bool hasMore = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("object"u8)) @@ -56,10 +119,46 @@ internal static InternalOpenAIPageableListOfThreadMessage DeserializeInternalOpe hasMore = property.Value.GetBoolean(); continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } } - return new InternalOpenAIPageableListOfThreadMessage(@object, data, firstId, lastId, hasMore); + serializedAdditionalRawData = additionalPropertiesDictionary; + return new InternalOpenAIPageableListOfThreadMessage(@object, data, firstId, lastId, hasMore, serializedAdditionalRawData); } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(InternalOpenAIPageableListOfThreadMessage)} does not support '{options.Format}' format."); + } + } + + InternalOpenAIPageableListOfThreadMessage IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInternalOpenAIPageableListOfThreadMessage(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InternalOpenAIPageableListOfThreadMessage)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + /// Deserializes the model from a raw response. /// The response to deserialize the model from. internal static InternalOpenAIPageableListOfThreadMessage FromResponse(Response response) @@ -67,5 +166,13 @@ internal static InternalOpenAIPageableListOfThreadMessage FromResponse(Response using var document = JsonDocument.Parse(response.Content); return DeserializeInternalOpenAIPageableListOfThreadMessage(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfThreadMessage.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfThreadMessage.cs index baa672b694b3..044b85e374f1 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfThreadMessage.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfThreadMessage.cs @@ -15,6 +15,38 @@ namespace Azure.AI.OpenAI.Assistants /// The response data for a requested list of items. internal partial class InternalOpenAIPageableListOfThreadMessage { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . /// The requested list of items. /// The first ID represented in this list. @@ -39,13 +71,20 @@ internal InternalOpenAIPageableListOfThreadMessage(IEnumerable da /// The first ID represented in this list. /// The last ID represented in this list. /// A value indicating whether there are additional values available not captured in this list. - internal InternalOpenAIPageableListOfThreadMessage(OpenAIPageableListOfThreadMessageObject @object, IReadOnlyList data, string firstId, string lastId, bool hasMore) + /// Keeps track of any properties unknown to the library. + internal InternalOpenAIPageableListOfThreadMessage(OpenAIPageableListOfThreadMessageObject @object, IReadOnlyList data, string firstId, string lastId, bool hasMore, IDictionary serializedAdditionalRawData) { Object = @object; Data = data; FirstId = firstId; LastId = lastId; HasMore = hasMore; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal InternalOpenAIPageableListOfThreadMessage() + { } /// The object type, which is always list. diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfThreadRun.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfThreadRun.Serialization.cs index 0fbe99c9997b..d5961758a854 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfThreadRun.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfThreadRun.Serialization.cs @@ -5,16 +5,77 @@ #nullable disable +using System; +using System.ClientModel.Primitives; using System.Collections.Generic; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - internal partial class InternalOpenAIPageableListOfThreadRun + internal partial class InternalOpenAIPageableListOfThreadRun : IUtf8JsonSerializable, IJsonModel { - internal static InternalOpenAIPageableListOfThreadRun DeserializeInternalOpenAIPageableListOfThreadRun(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalOpenAIPageableListOfThreadRun)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("object"u8); + writer.WriteStringValue(Object.ToString()); + writer.WritePropertyName("data"u8); + writer.WriteStartArray(); + foreach (var item in Data) + { + writer.WriteObjectValue(item); + } + writer.WriteEndArray(); + writer.WritePropertyName("first_id"u8); + writer.WriteStringValue(FirstId); + writer.WritePropertyName("last_id"u8); + writer.WriteStringValue(LastId); + writer.WritePropertyName("has_more"u8); + writer.WriteBooleanValue(HasMore); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + InternalOpenAIPageableListOfThreadRun IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalOpenAIPageableListOfThreadRun)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInternalOpenAIPageableListOfThreadRun(document.RootElement, options); + } + + internal static InternalOpenAIPageableListOfThreadRun DeserializeInternalOpenAIPageableListOfThreadRun(JsonElement element, ModelReaderWriterOptions options = null) { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; @@ -24,6 +85,8 @@ internal static InternalOpenAIPageableListOfThreadRun DeserializeInternalOpenAIP string firstId = default; string lastId = default; bool hasMore = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("object"u8)) @@ -56,10 +119,46 @@ internal static InternalOpenAIPageableListOfThreadRun DeserializeInternalOpenAIP hasMore = property.Value.GetBoolean(); continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } } - return new InternalOpenAIPageableListOfThreadRun(@object, data, firstId, lastId, hasMore); + serializedAdditionalRawData = additionalPropertiesDictionary; + return new InternalOpenAIPageableListOfThreadRun(@object, data, firstId, lastId, hasMore, serializedAdditionalRawData); } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(InternalOpenAIPageableListOfThreadRun)} does not support '{options.Format}' format."); + } + } + + InternalOpenAIPageableListOfThreadRun IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInternalOpenAIPageableListOfThreadRun(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InternalOpenAIPageableListOfThreadRun)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + /// Deserializes the model from a raw response. /// The response to deserialize the model from. internal static InternalOpenAIPageableListOfThreadRun FromResponse(Response response) @@ -67,5 +166,13 @@ internal static InternalOpenAIPageableListOfThreadRun FromResponse(Response resp using var document = JsonDocument.Parse(response.Content); return DeserializeInternalOpenAIPageableListOfThreadRun(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfThreadRun.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfThreadRun.cs index 51f283ff04f1..a424af2dc28c 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfThreadRun.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfThreadRun.cs @@ -15,6 +15,38 @@ namespace Azure.AI.OpenAI.Assistants /// The response data for a requested list of items. internal partial class InternalOpenAIPageableListOfThreadRun { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . /// The requested list of items. /// The first ID represented in this list. @@ -39,13 +71,20 @@ internal InternalOpenAIPageableListOfThreadRun(IEnumerable data, stri /// The first ID represented in this list. /// The last ID represented in this list. /// A value indicating whether there are additional values available not captured in this list. - internal InternalOpenAIPageableListOfThreadRun(OpenAIPageableListOfThreadRunObject @object, IReadOnlyList data, string firstId, string lastId, bool hasMore) + /// Keeps track of any properties unknown to the library. + internal InternalOpenAIPageableListOfThreadRun(OpenAIPageableListOfThreadRunObject @object, IReadOnlyList data, string firstId, string lastId, bool hasMore, IDictionary serializedAdditionalRawData) { Object = @object; Data = data; FirstId = firstId; LastId = lastId; HasMore = hasMore; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal InternalOpenAIPageableListOfThreadRun() + { } /// The object type, which is always list. diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalSubmitToolOutputsDetails.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalSubmitToolOutputsDetails.Serialization.cs index ba3ba9a78e57..ecc0b7d88c93 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalSubmitToolOutputsDetails.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalSubmitToolOutputsDetails.Serialization.cs @@ -5,21 +5,76 @@ #nullable disable +using System; +using System.ClientModel.Primitives; using System.Collections.Generic; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - internal partial class InternalSubmitToolOutputsDetails + internal partial class InternalSubmitToolOutputsDetails : IUtf8JsonSerializable, IJsonModel { - internal static InternalSubmitToolOutputsDetails DeserializeInternalSubmitToolOutputsDetails(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalSubmitToolOutputsDetails)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("tool_calls"u8); + writer.WriteStartArray(); + foreach (var item in ToolCalls) + { + writer.WriteObjectValue(item); + } + writer.WriteEndArray(); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + InternalSubmitToolOutputsDetails IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalSubmitToolOutputsDetails)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInternalSubmitToolOutputsDetails(document.RootElement, options); + } + + internal static InternalSubmitToolOutputsDetails DeserializeInternalSubmitToolOutputsDetails(JsonElement element, ModelReaderWriterOptions options = null) { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; } IReadOnlyList toolCalls = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("tool_calls"u8)) @@ -32,10 +87,46 @@ internal static InternalSubmitToolOutputsDetails DeserializeInternalSubmitToolOu toolCalls = array; continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } } - return new InternalSubmitToolOutputsDetails(toolCalls); + serializedAdditionalRawData = additionalPropertiesDictionary; + return new InternalSubmitToolOutputsDetails(toolCalls, serializedAdditionalRawData); } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(InternalSubmitToolOutputsDetails)} does not support '{options.Format}' format."); + } + } + + InternalSubmitToolOutputsDetails IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInternalSubmitToolOutputsDetails(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InternalSubmitToolOutputsDetails)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + /// Deserializes the model from a raw response. /// The response to deserialize the model from. internal static InternalSubmitToolOutputsDetails FromResponse(Response response) @@ -43,5 +134,13 @@ internal static InternalSubmitToolOutputsDetails FromResponse(Response response) using var document = JsonDocument.Parse(response.Content); return DeserializeInternalSubmitToolOutputsDetails(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalSubmitToolOutputsDetails.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalSubmitToolOutputsDetails.cs index 60d6550f38d2..82c13ede5f46 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalSubmitToolOutputsDetails.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalSubmitToolOutputsDetails.cs @@ -15,6 +15,38 @@ namespace Azure.AI.OpenAI.Assistants /// The details describing tools that should be called to submit tool outputs. internal partial class InternalSubmitToolOutputsDetails { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . /// The list of tool calls that must be resolved for the assistant thread run to continue. /// is null. @@ -27,9 +59,16 @@ internal InternalSubmitToolOutputsDetails(IEnumerable toolCall /// Initializes a new instance of . /// The list of tool calls that must be resolved for the assistant thread run to continue. - internal InternalSubmitToolOutputsDetails(IReadOnlyList toolCalls) + /// Keeps track of any properties unknown to the library. + internal InternalSubmitToolOutputsDetails(IReadOnlyList toolCalls, IDictionary serializedAdditionalRawData) { ToolCalls = toolCalls; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal InternalSubmitToolOutputsDetails() + { } /// diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageContent.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageContent.Serialization.cs index b4bea2abb9b6..e50c2d8a3546 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageContent.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageContent.Serialization.cs @@ -5,15 +5,64 @@ #nullable disable +using System; +using System.ClientModel.Primitives; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - public partial class MessageContent + [PersistableModelProxy(typeof(UnknownMessageContent))] + public partial class MessageContent : IUtf8JsonSerializable, IJsonModel { - internal static MessageContent DeserializeMessageContent(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(MessageContent)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + MessageContent IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(MessageContent)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeMessageContent(document.RootElement, options); + } + + internal static MessageContent DeserializeMessageContent(JsonElement element, ModelReaderWriterOptions options = null) { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; @@ -29,6 +78,37 @@ internal static MessageContent DeserializeMessageContent(JsonElement element) return UnknownMessageContent.DeserializeUnknownMessageContent(element); } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(MessageContent)} does not support '{options.Format}' format."); + } + } + + MessageContent IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeMessageContent(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(MessageContent)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + /// Deserializes the model from a raw response. /// The response to deserialize the model from. internal static MessageContent FromResponse(Response response) @@ -36,5 +116,13 @@ internal static MessageContent FromResponse(Response response) using var document = JsonDocument.Parse(response.Content); return DeserializeMessageContent(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageContent.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageContent.cs index a75e867c6a1d..86764d6ee16e 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageContent.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageContent.cs @@ -5,6 +5,9 @@ #nullable disable +using System; +using System.Collections.Generic; + namespace Azure.AI.OpenAI.Assistants { /// @@ -14,6 +17,38 @@ namespace Azure.AI.OpenAI.Assistants /// public abstract partial class MessageContent { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private protected IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . protected MessageContent() { @@ -21,9 +56,11 @@ protected MessageContent() /// Initializes a new instance of . /// The object type. - internal MessageContent(string type) + /// Keeps track of any properties unknown to the library. + internal MessageContent(string type, IDictionary serializedAdditionalRawData) { Type = type; + _serializedAdditionalRawData = serializedAdditionalRawData; } /// The object type. diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageFile.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageFile.Serialization.cs index 6acd4c501c7d..79bbce3f1025 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageFile.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageFile.Serialization.cs @@ -6,15 +6,69 @@ #nullable disable using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - public partial class MessageFile + public partial class MessageFile : IUtf8JsonSerializable, IJsonModel { - internal static MessageFile DeserializeMessageFile(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(MessageFile)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("id"u8); + writer.WriteStringValue(Id); + writer.WritePropertyName("object"u8); + writer.WriteStringValue(Object); + writer.WritePropertyName("created_at"u8); + writer.WriteNumberValue(CreatedAt, "U"); + writer.WritePropertyName("message_id"u8); + writer.WriteStringValue(MessageId); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + MessageFile IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(MessageFile)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeMessageFile(document.RootElement, options); + } + + internal static MessageFile DeserializeMessageFile(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; @@ -23,6 +77,8 @@ internal static MessageFile DeserializeMessageFile(JsonElement element) string @object = default; DateTimeOffset createdAt = default; string messageId = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("id"u8)) @@ -45,10 +101,46 @@ internal static MessageFile DeserializeMessageFile(JsonElement element) messageId = property.Value.GetString(); continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new MessageFile(id, @object, createdAt, messageId, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(MessageFile)} does not support '{options.Format}' format."); + } + } + + MessageFile IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeMessageFile(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(MessageFile)} does not support '{options.Format}' format."); } - return new MessageFile(id, @object, createdAt, messageId); } + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + /// Deserializes the model from a raw response. /// The response to deserialize the model from. internal static MessageFile FromResponse(Response response) @@ -56,5 +148,13 @@ internal static MessageFile FromResponse(Response response) using var document = JsonDocument.Parse(response.Content); return DeserializeMessageFile(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageFile.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageFile.cs index 631254447a24..6d6004cda2bc 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageFile.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageFile.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.Collections.Generic; using Azure.Core; namespace Azure.AI.OpenAI.Assistants @@ -13,6 +14,38 @@ namespace Azure.AI.OpenAI.Assistants /// Information about a file attached to an assistant thread message. public partial class MessageFile { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . /// The identifier, which can be referenced in API endpoints. /// The Unix timestamp, in seconds, representing when this object was created. @@ -33,12 +66,19 @@ internal MessageFile(string id, DateTimeOffset createdAt, string messageId) /// The object type, which is always 'thread.message.file'. /// The Unix timestamp, in seconds, representing when this object was created. /// The ID of the message that this file is attached to. - internal MessageFile(string id, string @object, DateTimeOffset createdAt, string messageId) + /// Keeps track of any properties unknown to the library. + internal MessageFile(string id, string @object, DateTimeOffset createdAt, string messageId, IDictionary serializedAdditionalRawData) { Id = id; Object = @object; CreatedAt = createdAt; MessageId = messageId; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal MessageFile() + { } /// The identifier, which can be referenced in API endpoints. diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageImageFileContent.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageImageFileContent.Serialization.cs index 82ae85e4100a..e0f4eaecd674 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageImageFileContent.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageImageFileContent.Serialization.cs @@ -5,21 +5,74 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - public partial class MessageImageFileContent + public partial class MessageImageFileContent : IUtf8JsonSerializable, IJsonModel { - internal static MessageImageFileContent DeserializeMessageImageFileContent(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(MessageImageFileContent)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("image_file"u8); + writer.WriteObjectValue(InternalDetails); + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + MessageImageFileContent IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(MessageImageFileContent)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeMessageImageFileContent(document.RootElement, options); + } + + internal static MessageImageFileContent DeserializeMessageImageFileContent(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; } InternalMessageImageFileDetails imageFile = default; string type = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("image_file"u8)) @@ -32,10 +85,46 @@ internal static MessageImageFileContent DeserializeMessageImageFileContent(JsonE type = property.Value.GetString(); continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new MessageImageFileContent(type, serializedAdditionalRawData, imageFile); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(MessageImageFileContent)} does not support '{options.Format}' format."); + } + } + + MessageImageFileContent IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeMessageImageFileContent(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(MessageImageFileContent)} does not support '{options.Format}' format."); } - return new MessageImageFileContent(type, imageFile); } + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + /// Deserializes the model from a raw response. /// The response to deserialize the model from. internal static new MessageImageFileContent FromResponse(Response response) @@ -43,5 +132,13 @@ internal static MessageImageFileContent DeserializeMessageImageFileContent(JsonE using var document = JsonDocument.Parse(response.Content); return DeserializeMessageImageFileContent(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal override RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageImageFileContent.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageImageFileContent.cs index 4276cc66bc70..263ea19d70bf 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageImageFileContent.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageImageFileContent.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.Collections.Generic; using Azure.Core; namespace Azure.AI.OpenAI.Assistants @@ -26,10 +27,16 @@ internal MessageImageFileContent(InternalMessageImageFileDetails internalDetails /// Initializes a new instance of . /// The object type. + /// Keeps track of any properties unknown to the library. /// The image file for this thread message content item. - internal MessageImageFileContent(string type, InternalMessageImageFileDetails internalDetails) : base(type) + internal MessageImageFileContent(string type, IDictionary serializedAdditionalRawData, InternalMessageImageFileDetails internalDetails) : base(type, serializedAdditionalRawData) { InternalDetails = internalDetails; } + + /// Initializes a new instance of for deserialization. + internal MessageImageFileContent() + { + } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextAnnotation.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextAnnotation.Serialization.cs index 168e5a35e517..bd6167800521 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextAnnotation.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextAnnotation.Serialization.cs @@ -5,15 +5,70 @@ #nullable disable +using System; +using System.ClientModel.Primitives; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - public partial class MessageTextAnnotation + [PersistableModelProxy(typeof(UnknownMessageTextAnnotation))] + public partial class MessageTextAnnotation : IUtf8JsonSerializable, IJsonModel { - internal static MessageTextAnnotation DeserializeMessageTextAnnotation(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(MessageTextAnnotation)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type); + writer.WritePropertyName("text"u8); + writer.WriteStringValue(Text); + writer.WritePropertyName("start_index"u8); + writer.WriteNumberValue(StartIndex); + writer.WritePropertyName("end_index"u8); + writer.WriteNumberValue(EndIndex); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + MessageTextAnnotation IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(MessageTextAnnotation)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeMessageTextAnnotation(document.RootElement, options); + } + + internal static MessageTextAnnotation DeserializeMessageTextAnnotation(JsonElement element, ModelReaderWriterOptions options = null) { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; @@ -29,6 +84,37 @@ internal static MessageTextAnnotation DeserializeMessageTextAnnotation(JsonEleme return UnknownMessageTextAnnotation.DeserializeUnknownMessageTextAnnotation(element); } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(MessageTextAnnotation)} does not support '{options.Format}' format."); + } + } + + MessageTextAnnotation IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeMessageTextAnnotation(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(MessageTextAnnotation)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + /// Deserializes the model from a raw response. /// The response to deserialize the model from. internal static MessageTextAnnotation FromResponse(Response response) @@ -36,5 +122,13 @@ internal static MessageTextAnnotation FromResponse(Response response) using var document = JsonDocument.Parse(response.Content); return DeserializeMessageTextAnnotation(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextAnnotation.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextAnnotation.cs index f602b67aee86..95cec642d71d 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextAnnotation.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextAnnotation.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.Collections.Generic; using Azure.Core; namespace Azure.AI.OpenAI.Assistants @@ -17,6 +18,38 @@ namespace Azure.AI.OpenAI.Assistants /// public abstract partial class MessageTextAnnotation { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private protected IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . /// The textual content associated with this text annotation item. /// The first text index associated with this text annotation. @@ -36,12 +69,19 @@ protected MessageTextAnnotation(string text, int startIndex, int endIndex) /// The textual content associated with this text annotation item. /// The first text index associated with this text annotation. /// The last text index associated with this text annotation. - internal MessageTextAnnotation(string type, string text, int startIndex, int endIndex) + /// Keeps track of any properties unknown to the library. + internal MessageTextAnnotation(string type, string text, int startIndex, int endIndex, IDictionary serializedAdditionalRawData) { Type = type; Text = text; StartIndex = startIndex; EndIndex = endIndex; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal MessageTextAnnotation() + { } /// The object type. diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextContent.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextContent.Serialization.cs index 8f76e413ddf1..5b0edb96d447 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextContent.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextContent.Serialization.cs @@ -5,21 +5,74 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - public partial class MessageTextContent + public partial class MessageTextContent : IUtf8JsonSerializable, IJsonModel { - internal static MessageTextContent DeserializeMessageTextContent(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(MessageTextContent)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("text"u8); + writer.WriteObjectValue(InternalDetails); + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + MessageTextContent IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(MessageTextContent)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeMessageTextContent(document.RootElement, options); + } + + internal static MessageTextContent DeserializeMessageTextContent(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; } InternalMessageTextDetails text = default; string type = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("text"u8)) @@ -32,10 +85,46 @@ internal static MessageTextContent DeserializeMessageTextContent(JsonElement ele type = property.Value.GetString(); continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new MessageTextContent(type, serializedAdditionalRawData, text); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(MessageTextContent)} does not support '{options.Format}' format."); + } + } + + MessageTextContent IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeMessageTextContent(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(MessageTextContent)} does not support '{options.Format}' format."); } - return new MessageTextContent(type, text); } + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + /// Deserializes the model from a raw response. /// The response to deserialize the model from. internal static new MessageTextContent FromResponse(Response response) @@ -43,5 +132,13 @@ internal static MessageTextContent DeserializeMessageTextContent(JsonElement ele using var document = JsonDocument.Parse(response.Content); return DeserializeMessageTextContent(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal override RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextContent.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextContent.cs index 12b0e4b8c69d..bfe842a9d9fe 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextContent.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextContent.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.Collections.Generic; using Azure.Core; namespace Azure.AI.OpenAI.Assistants @@ -26,10 +27,16 @@ internal MessageTextContent(InternalMessageTextDetails internalDetails) /// Initializes a new instance of . /// The object type. + /// Keeps track of any properties unknown to the library. /// The text and associated annotations for this thread message content item. - internal MessageTextContent(string type, InternalMessageTextDetails internalDetails) : base(type) + internal MessageTextContent(string type, IDictionary serializedAdditionalRawData, InternalMessageTextDetails internalDetails) : base(type, serializedAdditionalRawData) { InternalDetails = internalDetails; } + + /// Initializes a new instance of for deserialization. + internal MessageTextContent() + { + } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextFileCitationAnnotation.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextFileCitationAnnotation.Serialization.cs index 8993420f138a..db6ffb9d6950 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextFileCitationAnnotation.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextFileCitationAnnotation.Serialization.cs @@ -5,15 +5,72 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - public partial class MessageTextFileCitationAnnotation + public partial class MessageTextFileCitationAnnotation : IUtf8JsonSerializable, IJsonModel { - internal static MessageTextFileCitationAnnotation DeserializeMessageTextFileCitationAnnotation(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(MessageTextFileCitationAnnotation)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("file_citation"u8); + writer.WriteObjectValue(InternalDetails); + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type); + writer.WritePropertyName("text"u8); + writer.WriteStringValue(Text); + writer.WritePropertyName("start_index"u8); + writer.WriteNumberValue(StartIndex); + writer.WritePropertyName("end_index"u8); + writer.WriteNumberValue(EndIndex); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + MessageTextFileCitationAnnotation IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(MessageTextFileCitationAnnotation)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeMessageTextFileCitationAnnotation(document.RootElement, options); + } + + internal static MessageTextFileCitationAnnotation DeserializeMessageTextFileCitationAnnotation(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; @@ -23,6 +80,8 @@ internal static MessageTextFileCitationAnnotation DeserializeMessageTextFileCita string text = default; int startIndex = default; int endIndex = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("file_citation"u8)) @@ -50,10 +109,46 @@ internal static MessageTextFileCitationAnnotation DeserializeMessageTextFileCita endIndex = property.Value.GetInt32(); continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new MessageTextFileCitationAnnotation(type, text, startIndex, endIndex, serializedAdditionalRawData, fileCitation); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(MessageTextFileCitationAnnotation)} does not support '{options.Format}' format."); + } + } + + MessageTextFileCitationAnnotation IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeMessageTextFileCitationAnnotation(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(MessageTextFileCitationAnnotation)} does not support '{options.Format}' format."); } - return new MessageTextFileCitationAnnotation(type, text, startIndex, endIndex, fileCitation); } + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + /// Deserializes the model from a raw response. /// The response to deserialize the model from. internal static new MessageTextFileCitationAnnotation FromResponse(Response response) @@ -61,5 +156,13 @@ internal static MessageTextFileCitationAnnotation DeserializeMessageTextFileCita using var document = JsonDocument.Parse(response.Content); return DeserializeMessageTextFileCitationAnnotation(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal override RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextFileCitationAnnotation.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextFileCitationAnnotation.cs index beb3871fd74b..bb11c428612b 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextFileCitationAnnotation.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextFileCitationAnnotation.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.Collections.Generic; using Azure.Core; namespace Azure.AI.OpenAI.Assistants @@ -36,13 +37,19 @@ internal MessageTextFileCitationAnnotation(string text, int startIndex, int endI /// The textual content associated with this text annotation item. /// The first text index associated with this text annotation. /// The last text index associated with this text annotation. + /// Keeps track of any properties unknown to the library. /// /// A citation within the message that points to a specific quote from a specific file. /// Generated when the assistant uses the "retrieval" tool to search files. /// - internal MessageTextFileCitationAnnotation(string type, string text, int startIndex, int endIndex, InternalMessageTextFileCitationDetails internalDetails) : base(type, text, startIndex, endIndex) + internal MessageTextFileCitationAnnotation(string type, string text, int startIndex, int endIndex, IDictionary serializedAdditionalRawData, InternalMessageTextFileCitationDetails internalDetails) : base(type, text, startIndex, endIndex, serializedAdditionalRawData) { InternalDetails = internalDetails; } + + /// Initializes a new instance of for deserialization. + internal MessageTextFileCitationAnnotation() + { + } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextFilePathAnnotation.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextFilePathAnnotation.Serialization.cs index e0dddab8f430..e2454fdda9a8 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextFilePathAnnotation.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextFilePathAnnotation.Serialization.cs @@ -5,15 +5,72 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - public partial class MessageTextFilePathAnnotation + public partial class MessageTextFilePathAnnotation : IUtf8JsonSerializable, IJsonModel { - internal static MessageTextFilePathAnnotation DeserializeMessageTextFilePathAnnotation(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(MessageTextFilePathAnnotation)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("file_path"u8); + writer.WriteObjectValue(InternalDetails); + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type); + writer.WritePropertyName("text"u8); + writer.WriteStringValue(Text); + writer.WritePropertyName("start_index"u8); + writer.WriteNumberValue(StartIndex); + writer.WritePropertyName("end_index"u8); + writer.WriteNumberValue(EndIndex); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + MessageTextFilePathAnnotation IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(MessageTextFilePathAnnotation)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeMessageTextFilePathAnnotation(document.RootElement, options); + } + + internal static MessageTextFilePathAnnotation DeserializeMessageTextFilePathAnnotation(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; @@ -23,6 +80,8 @@ internal static MessageTextFilePathAnnotation DeserializeMessageTextFilePathAnno string text = default; int startIndex = default; int endIndex = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("file_path"u8)) @@ -50,10 +109,46 @@ internal static MessageTextFilePathAnnotation DeserializeMessageTextFilePathAnno endIndex = property.Value.GetInt32(); continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new MessageTextFilePathAnnotation(type, text, startIndex, endIndex, serializedAdditionalRawData, filePath); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(MessageTextFilePathAnnotation)} does not support '{options.Format}' format."); + } + } + + MessageTextFilePathAnnotation IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeMessageTextFilePathAnnotation(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(MessageTextFilePathAnnotation)} does not support '{options.Format}' format."); } - return new MessageTextFilePathAnnotation(type, text, startIndex, endIndex, filePath); } + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + /// Deserializes the model from a raw response. /// The response to deserialize the model from. internal static new MessageTextFilePathAnnotation FromResponse(Response response) @@ -61,5 +156,13 @@ internal static MessageTextFilePathAnnotation DeserializeMessageTextFilePathAnno using var document = JsonDocument.Parse(response.Content); return DeserializeMessageTextFilePathAnnotation(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal override RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextFilePathAnnotation.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextFilePathAnnotation.cs index 840d0f1625d6..85945355879f 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextFilePathAnnotation.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextFilePathAnnotation.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.Collections.Generic; using Azure.Core; namespace Azure.AI.OpenAI.Assistants @@ -33,10 +34,16 @@ internal MessageTextFilePathAnnotation(string text, int startIndex, int endIndex /// The textual content associated with this text annotation item. /// The first text index associated with this text annotation. /// The last text index associated with this text annotation. + /// Keeps track of any properties unknown to the library. /// A URL for the file that's generated when the assistant used the code_interpreter tool to generate a file. - internal MessageTextFilePathAnnotation(string type, string text, int startIndex, int endIndex, InternalMessageTextFilePathDetails internalDetails) : base(type, text, startIndex, endIndex) + internal MessageTextFilePathAnnotation(string type, string text, int startIndex, int endIndex, IDictionary serializedAdditionalRawData, InternalMessageTextFilePathDetails internalDetails) : base(type, text, startIndex, endIndex, serializedAdditionalRawData) { InternalDetails = internalDetails; } + + /// Initializes a new instance of for deserialization. + internal MessageTextFilePathAnnotation() + { + } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIFile.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIFile.Serialization.cs index 8069a695b136..2fb77dc68132 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIFile.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIFile.Serialization.cs @@ -6,15 +6,73 @@ #nullable disable using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - public partial class OpenAIFile + public partial class OpenAIFile : IUtf8JsonSerializable, IJsonModel { - internal static OpenAIFile DeserializeOpenAIFile(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(OpenAIFile)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("object"u8); + writer.WriteStringValue(Object); + writer.WritePropertyName("id"u8); + writer.WriteStringValue(Id); + writer.WritePropertyName("bytes"u8); + writer.WriteNumberValue(Size); + writer.WritePropertyName("filename"u8); + writer.WriteStringValue(Filename); + writer.WritePropertyName("created_at"u8); + writer.WriteNumberValue(CreatedAt, "U"); + writer.WritePropertyName("purpose"u8); + writer.WriteStringValue(Purpose.ToString()); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + OpenAIFile IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(OpenAIFile)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeOpenAIFile(document.RootElement, options); + } + + internal static OpenAIFile DeserializeOpenAIFile(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; @@ -25,6 +83,8 @@ internal static OpenAIFile DeserializeOpenAIFile(JsonElement element) string filename = default; DateTimeOffset createdAt = default; OpenAIFilePurpose purpose = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("object"u8)) @@ -57,10 +117,46 @@ internal static OpenAIFile DeserializeOpenAIFile(JsonElement element) purpose = new OpenAIFilePurpose(property.Value.GetString()); continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new OpenAIFile(@object, id, bytes, filename, createdAt, purpose, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(OpenAIFile)} does not support '{options.Format}' format."); + } + } + + OpenAIFile IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeOpenAIFile(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(OpenAIFile)} does not support '{options.Format}' format."); } - return new OpenAIFile(@object, id, bytes, filename, createdAt, purpose); } + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + /// Deserializes the model from a raw response. /// The response to deserialize the model from. internal static OpenAIFile FromResponse(Response response) @@ -68,5 +164,13 @@ internal static OpenAIFile FromResponse(Response response) using var document = JsonDocument.Parse(response.Content); return DeserializeOpenAIFile(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIFile.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIFile.cs index 4d7f08dd0c9c..7bae4371f940 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIFile.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIFile.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.Collections.Generic; using Azure.Core; namespace Azure.AI.OpenAI.Assistants @@ -13,6 +14,38 @@ namespace Azure.AI.OpenAI.Assistants /// Represents an assistant that can call the model and use tools. public partial class OpenAIFile { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . /// The identifier, which can be referenced in API endpoints. /// The size of the file, in bytes. @@ -39,7 +72,8 @@ internal OpenAIFile(string id, int size, string filename, DateTimeOffset created /// The name of the file. /// The Unix timestamp, in seconds, representing when this object was created. /// The intended purpose of a file. - internal OpenAIFile(string @object, string id, int size, string filename, DateTimeOffset createdAt, OpenAIFilePurpose purpose) + /// Keeps track of any properties unknown to the library. + internal OpenAIFile(string @object, string id, int size, string filename, DateTimeOffset createdAt, OpenAIFilePurpose purpose, IDictionary serializedAdditionalRawData) { Object = @object; Id = id; @@ -47,6 +81,12 @@ internal OpenAIFile(string @object, string id, int size, string filename, DateTi Filename = filename; CreatedAt = createdAt; Purpose = purpose; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal OpenAIFile() + { } /// The identifier, which can be referenced in API endpoints. diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RequiredAction.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RequiredAction.Serialization.cs index 9eab1cee82ae..92b0930efe4f 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RequiredAction.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RequiredAction.Serialization.cs @@ -5,15 +5,64 @@ #nullable disable +using System; +using System.ClientModel.Primitives; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - public partial class RequiredAction + [PersistableModelProxy(typeof(UnknownRequiredAction))] + public partial class RequiredAction : IUtf8JsonSerializable, IJsonModel { - internal static RequiredAction DeserializeRequiredAction(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(RequiredAction)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + RequiredAction IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(RequiredAction)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeRequiredAction(document.RootElement, options); + } + + internal static RequiredAction DeserializeRequiredAction(JsonElement element, ModelReaderWriterOptions options = null) { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; @@ -28,6 +77,37 @@ internal static RequiredAction DeserializeRequiredAction(JsonElement element) return UnknownRequiredAction.DeserializeUnknownRequiredAction(element); } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(RequiredAction)} does not support '{options.Format}' format."); + } + } + + RequiredAction IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeRequiredAction(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(RequiredAction)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + /// Deserializes the model from a raw response. /// The response to deserialize the model from. internal static RequiredAction FromResponse(Response response) @@ -35,5 +115,13 @@ internal static RequiredAction FromResponse(Response response) using var document = JsonDocument.Parse(response.Content); return DeserializeRequiredAction(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RequiredAction.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RequiredAction.cs index 5ed051d278a8..ceb1a3feb518 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RequiredAction.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RequiredAction.cs @@ -5,6 +5,9 @@ #nullable disable +using System; +using System.Collections.Generic; + namespace Azure.AI.OpenAI.Assistants { /// @@ -14,6 +17,38 @@ namespace Azure.AI.OpenAI.Assistants /// public abstract partial class RequiredAction { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private protected IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . protected RequiredAction() { @@ -21,9 +56,11 @@ protected RequiredAction() /// Initializes a new instance of . /// The object type. - internal RequiredAction(string type) + /// Keeps track of any properties unknown to the library. + internal RequiredAction(string type, IDictionary serializedAdditionalRawData) { Type = type; + _serializedAdditionalRawData = serializedAdditionalRawData; } /// The object type. diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RequiredFunctionToolCall.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RequiredFunctionToolCall.Serialization.cs index 569f9dde89cf..e4b207cdafb1 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RequiredFunctionToolCall.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RequiredFunctionToolCall.Serialization.cs @@ -5,15 +5,68 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - public partial class RequiredFunctionToolCall + public partial class RequiredFunctionToolCall : IUtf8JsonSerializable, IJsonModel { - internal static RequiredFunctionToolCall DeserializeRequiredFunctionToolCall(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(RequiredFunctionToolCall)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("function"u8); + writer.WriteObjectValue(InternalFunctionDefinition); + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type); + writer.WritePropertyName("id"u8); + writer.WriteStringValue(Id); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + RequiredFunctionToolCall IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(RequiredFunctionToolCall)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeRequiredFunctionToolCall(document.RootElement, options); + } + + internal static RequiredFunctionToolCall DeserializeRequiredFunctionToolCall(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; @@ -21,6 +74,8 @@ internal static RequiredFunctionToolCall DeserializeRequiredFunctionToolCall(Jso InternalFunctionDefinition function = default; string type = default; string id = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("function"u8)) @@ -38,10 +93,46 @@ internal static RequiredFunctionToolCall DeserializeRequiredFunctionToolCall(Jso id = property.Value.GetString(); continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new RequiredFunctionToolCall(type, id, serializedAdditionalRawData, function); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(RequiredFunctionToolCall)} does not support '{options.Format}' format."); + } + } + + RequiredFunctionToolCall IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeRequiredFunctionToolCall(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(RequiredFunctionToolCall)} does not support '{options.Format}' format."); } - return new RequiredFunctionToolCall(type, id, function); } + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + /// Deserializes the model from a raw response. /// The response to deserialize the model from. internal static new RequiredFunctionToolCall FromResponse(Response response) @@ -49,5 +140,13 @@ internal static RequiredFunctionToolCall DeserializeRequiredFunctionToolCall(Jso using var document = JsonDocument.Parse(response.Content); return DeserializeRequiredFunctionToolCall(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal override RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RequiredFunctionToolCall.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RequiredFunctionToolCall.cs index 2ed873ffb523..8e9469a74b93 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RequiredFunctionToolCall.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RequiredFunctionToolCall.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.Collections.Generic; using Azure.Core; namespace Azure.AI.OpenAI.Assistants @@ -29,10 +30,16 @@ internal RequiredFunctionToolCall(string id, InternalFunctionDefinition internal /// Initializes a new instance of . /// The object type for the required tool call. /// The ID of the tool call. This ID must be referenced when submitting tool outputs. + /// Keeps track of any properties unknown to the library. /// Detailed information about the function to be executed by the tool that includes name and arguments. - internal RequiredFunctionToolCall(string type, string id, InternalFunctionDefinition internalFunctionDefinition) : base(type, id) + internal RequiredFunctionToolCall(string type, string id, IDictionary serializedAdditionalRawData, InternalFunctionDefinition internalFunctionDefinition) : base(type, id, serializedAdditionalRawData) { InternalFunctionDefinition = internalFunctionDefinition; } + + /// Initializes a new instance of for deserialization. + internal RequiredFunctionToolCall() + { + } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RequiredToolCall.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RequiredToolCall.Serialization.cs index 5d0b6e5f3773..fe33876bb0e8 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RequiredToolCall.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RequiredToolCall.Serialization.cs @@ -5,15 +5,66 @@ #nullable disable +using System; +using System.ClientModel.Primitives; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - public partial class RequiredToolCall + [PersistableModelProxy(typeof(UnknownRequiredToolCall))] + public partial class RequiredToolCall : IUtf8JsonSerializable, IJsonModel { - internal static RequiredToolCall DeserializeRequiredToolCall(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(RequiredToolCall)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type); + writer.WritePropertyName("id"u8); + writer.WriteStringValue(Id); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + RequiredToolCall IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(RequiredToolCall)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeRequiredToolCall(document.RootElement, options); + } + + internal static RequiredToolCall DeserializeRequiredToolCall(JsonElement element, ModelReaderWriterOptions options = null) { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; @@ -28,6 +79,37 @@ internal static RequiredToolCall DeserializeRequiredToolCall(JsonElement element return UnknownRequiredToolCall.DeserializeUnknownRequiredToolCall(element); } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(RequiredToolCall)} does not support '{options.Format}' format."); + } + } + + RequiredToolCall IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeRequiredToolCall(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(RequiredToolCall)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + /// Deserializes the model from a raw response. /// The response to deserialize the model from. internal static RequiredToolCall FromResponse(Response response) @@ -35,5 +117,13 @@ internal static RequiredToolCall FromResponse(Response response) using var document = JsonDocument.Parse(response.Content); return DeserializeRequiredToolCall(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RequiredToolCall.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RequiredToolCall.cs index 9bc55d38e1d0..0e7b20869a0c 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RequiredToolCall.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RequiredToolCall.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.Collections.Generic; using Azure.Core; namespace Azure.AI.OpenAI.Assistants @@ -17,6 +18,38 @@ namespace Azure.AI.OpenAI.Assistants /// public abstract partial class RequiredToolCall { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private protected IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . /// The ID of the tool call. This ID must be referenced when submitting tool outputs. /// is null. @@ -30,10 +63,17 @@ protected RequiredToolCall(string id) /// Initializes a new instance of . /// The object type for the required tool call. /// The ID of the tool call. This ID must be referenced when submitting tool outputs. - internal RequiredToolCall(string type, string id) + /// Keeps track of any properties unknown to the library. + internal RequiredToolCall(string type, string id, IDictionary serializedAdditionalRawData) { Type = type; Id = id; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal RequiredToolCall() + { } /// The object type for the required tool call. diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RetrievalToolCall.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RetrievalToolCall.Serialization.cs index a53d39532661..10a91b4872fc 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RetrievalToolCall.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RetrievalToolCall.Serialization.cs @@ -5,16 +5,74 @@ #nullable disable +using System; +using System.ClientModel.Primitives; using System.Collections.Generic; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - public partial class RetrievalToolCall + public partial class RetrievalToolCall : IUtf8JsonSerializable, IJsonModel { - internal static RetrievalToolCall DeserializeRetrievalToolCall(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(RetrievalToolCall)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("retrieval"u8); + writer.WriteStartObject(); + foreach (var item in Retrieval) + { + writer.WritePropertyName(item.Key); + writer.WriteStringValue(item.Value); + } + writer.WriteEndObject(); + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type); + writer.WritePropertyName("id"u8); + writer.WriteStringValue(Id); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + RetrievalToolCall IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(RetrievalToolCall)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeRetrievalToolCall(document.RootElement, options); + } + + internal static RetrievalToolCall DeserializeRetrievalToolCall(JsonElement element, ModelReaderWriterOptions options = null) { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; @@ -22,6 +80,8 @@ internal static RetrievalToolCall DeserializeRetrievalToolCall(JsonElement eleme IReadOnlyDictionary retrieval = default; string type = default; string id = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("retrieval"u8)) @@ -44,10 +104,46 @@ internal static RetrievalToolCall DeserializeRetrievalToolCall(JsonElement eleme id = property.Value.GetString(); continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } } - return new RetrievalToolCall(type, id, retrieval); + serializedAdditionalRawData = additionalPropertiesDictionary; + return new RetrievalToolCall(type, id, serializedAdditionalRawData, retrieval); } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(RetrievalToolCall)} does not support '{options.Format}' format."); + } + } + + RetrievalToolCall IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeRetrievalToolCall(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(RetrievalToolCall)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + /// Deserializes the model from a raw response. /// The response to deserialize the model from. internal static new RetrievalToolCall FromResponse(Response response) @@ -55,5 +151,13 @@ internal static RetrievalToolCall DeserializeRetrievalToolCall(JsonElement eleme using var document = JsonDocument.Parse(response.Content); return DeserializeRetrievalToolCall(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal override RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RetrievalToolCall.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RetrievalToolCall.cs index ac46f2942ab8..1071b2e8cca0 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RetrievalToolCall.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RetrievalToolCall.cs @@ -33,12 +33,18 @@ internal RetrievalToolCall(string id, IReadOnlyDictionary retrie /// Initializes a new instance of . /// The object type. /// The ID of the tool call. This ID must be referenced when you submit tool outputs. + /// Keeps track of any properties unknown to the library. /// The key/value pairs produced by the retrieval tool. - internal RetrievalToolCall(string type, string id, IReadOnlyDictionary retrieval) : base(type, id) + internal RetrievalToolCall(string type, string id, IDictionary serializedAdditionalRawData, IReadOnlyDictionary retrieval) : base(type, id, serializedAdditionalRawData) { Retrieval = retrieval; } + /// Initializes a new instance of for deserialization. + internal RetrievalToolCall() + { + } + /// The key/value pairs produced by the retrieval tool. public IReadOnlyDictionary Retrieval { get; } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RetrievalToolDefinition.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RetrievalToolDefinition.Serialization.cs index b91f51687b42..075aa95c7338 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RetrievalToolDefinition.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RetrievalToolDefinition.Serialization.cs @@ -5,29 +5,71 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; using Azure; using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - public partial class RetrievalToolDefinition : IUtf8JsonSerializable + public partial class RetrievalToolDefinition : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(RetrievalToolDefinition)} does not support '{format}' format."); + } + writer.WriteStartObject(); writer.WritePropertyName("type"u8); writer.WriteStringValue(Type); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } - internal static RetrievalToolDefinition DeserializeRetrievalToolDefinition(JsonElement element) + RetrievalToolDefinition IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(RetrievalToolDefinition)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeRetrievalToolDefinition(document.RootElement, options); + } + + internal static RetrievalToolDefinition DeserializeRetrievalToolDefinition(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; } string type = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("type"u8)) @@ -35,10 +77,46 @@ internal static RetrievalToolDefinition DeserializeRetrievalToolDefinition(JsonE type = property.Value.GetString(); continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new RetrievalToolDefinition(type, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(RetrievalToolDefinition)} does not support '{options.Format}' format."); } - return new RetrievalToolDefinition(type); } + RetrievalToolDefinition IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeRetrievalToolDefinition(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(RetrievalToolDefinition)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + /// Deserializes the model from a raw response. /// The response to deserialize the model from. internal static new RetrievalToolDefinition FromResponse(Response response) diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RetrievalToolDefinition.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RetrievalToolDefinition.cs index 28232f82fb20..f2f39855b348 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RetrievalToolDefinition.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RetrievalToolDefinition.cs @@ -5,6 +5,9 @@ #nullable disable +using System; +using System.Collections.Generic; + namespace Azure.AI.OpenAI.Assistants { /// The input definition information for a retrieval tool as used to configure an assistant. @@ -18,7 +21,8 @@ public RetrievalToolDefinition() /// Initializes a new instance of . /// The object type. - internal RetrievalToolDefinition(string type) : base(type) + /// Keeps track of any properties unknown to the library. + internal RetrievalToolDefinition(string type, IDictionary serializedAdditionalRawData) : base(type, serializedAdditionalRawData) { } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunError.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunError.Serialization.cs index 224a74ade6d1..064367c9da83 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunError.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunError.Serialization.cs @@ -5,21 +5,74 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - public partial class RunError + public partial class RunError : IUtf8JsonSerializable, IJsonModel { - internal static RunError DeserializeRunError(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(RunError)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("code"u8); + writer.WriteStringValue(Code); + writer.WritePropertyName("message"u8); + writer.WriteStringValue(Message); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + RunError IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(RunError)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeRunError(document.RootElement, options); + } + + internal static RunError DeserializeRunError(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; } string code = default; string message = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("code"u8)) @@ -32,10 +85,46 @@ internal static RunError DeserializeRunError(JsonElement element) message = property.Value.GetString(); continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new RunError(code, message, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(RunError)} does not support '{options.Format}' format."); + } + } + + RunError IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeRunError(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(RunError)} does not support '{options.Format}' format."); } - return new RunError(code, message); } + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + /// Deserializes the model from a raw response. /// The response to deserialize the model from. internal static RunError FromResponse(Response response) @@ -43,5 +132,13 @@ internal static RunError FromResponse(Response response) using var document = JsonDocument.Parse(response.Content); return DeserializeRunError(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunError.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunError.cs index 5da23eb4495a..08cc091c1956 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunError.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunError.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.Collections.Generic; using Azure.Core; namespace Azure.AI.OpenAI.Assistants @@ -13,6 +14,38 @@ namespace Azure.AI.OpenAI.Assistants /// The details of an error as encountered by an assistant thread run. public partial class RunError { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . /// The status for the error. /// The human-readable text associated with the error. @@ -26,6 +59,22 @@ internal RunError(string code, string message) Message = message; } + /// Initializes a new instance of . + /// The status for the error. + /// The human-readable text associated with the error. + /// Keeps track of any properties unknown to the library. + internal RunError(string code, string message, IDictionary serializedAdditionalRawData) + { + Code = code; + Message = message; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal RunError() + { + } + /// The status for the error. public string Code { get; } /// The human-readable text associated with the error. diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStep.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStep.Serialization.cs index ad34cf9cb5e1..7e9cee4435ea 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStep.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStep.Serialization.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.ClientModel.Primitives; using System.Collections.Generic; using System.Text.Json; using Azure; @@ -13,10 +14,131 @@ namespace Azure.AI.OpenAI.Assistants { - public partial class RunStep + public partial class RunStep : IUtf8JsonSerializable, IJsonModel { - internal static RunStep DeserializeRunStep(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(RunStep)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("id"u8); + writer.WriteStringValue(Id); + writer.WritePropertyName("object"u8); + writer.WriteStringValue(Object); + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type.ToString()); + writer.WritePropertyName("assistant_id"u8); + writer.WriteStringValue(AssistantId); + writer.WritePropertyName("thread_id"u8); + writer.WriteStringValue(ThreadId); + writer.WritePropertyName("run_id"u8); + writer.WriteStringValue(RunId); + writer.WritePropertyName("status"u8); + writer.WriteStringValue(Status.ToString()); + writer.WritePropertyName("step_details"u8); + writer.WriteObjectValue(StepDetails); + if (LastError != null) + { + writer.WritePropertyName("last_error"u8); + writer.WriteObjectValue(LastError); + } + else + { + writer.WriteNull("last_error"); + } + writer.WritePropertyName("created_at"u8); + writer.WriteNumberValue(CreatedAt, "U"); + if (ExpiredAt != null) + { + writer.WritePropertyName("expired_at"u8); + writer.WriteStringValue(ExpiredAt.Value, "O"); + } + else + { + writer.WriteNull("expired_at"); + } + if (CompletedAt != null) + { + writer.WritePropertyName("completed_at"u8); + writer.WriteStringValue(CompletedAt.Value, "O"); + } + else + { + writer.WriteNull("completed_at"); + } + if (CancelledAt != null) + { + writer.WritePropertyName("cancelled_at"u8); + writer.WriteStringValue(CancelledAt.Value, "O"); + } + else + { + writer.WriteNull("cancelled_at"); + } + if (FailedAt != null) + { + writer.WritePropertyName("failed_at"u8); + writer.WriteStringValue(FailedAt.Value, "O"); + } + else + { + writer.WriteNull("failed_at"); + } + if (Metadata != null && Optional.IsCollectionDefined(Metadata)) + { + writer.WritePropertyName("metadata"u8); + writer.WriteStartObject(); + foreach (var item in Metadata) + { + writer.WritePropertyName(item.Key); + writer.WriteStringValue(item.Value); + } + writer.WriteEndObject(); + } + else + { + writer.WriteNull("metadata"); + } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + RunStep IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(RunStep)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeRunStep(document.RootElement, options); + } + + internal static RunStep DeserializeRunStep(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; @@ -36,6 +158,8 @@ internal static RunStep DeserializeRunStep(JsonElement element) DateTimeOffset? cancelledAt = default; DateTimeOffset? failedAt = default; IReadOnlyDictionary metadata = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("id"u8)) @@ -128,10 +252,46 @@ internal static RunStep DeserializeRunStep(JsonElement element) metadata = dictionary; continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } } - return new RunStep(id, @object, type, assistantId, threadId, runId, status, stepDetails, lastError, createdAt, expiredAt, completedAt, cancelledAt, failedAt, metadata); + serializedAdditionalRawData = additionalPropertiesDictionary; + return new RunStep(id, @object, type, assistantId, threadId, runId, status, stepDetails, lastError, createdAt, expiredAt, completedAt, cancelledAt, failedAt, metadata, serializedAdditionalRawData); } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(RunStep)} does not support '{options.Format}' format."); + } + } + + RunStep IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeRunStep(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(RunStep)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + /// Deserializes the model from a raw response. /// The response to deserialize the model from. internal static RunStep FromResponse(Response response) @@ -139,5 +299,13 @@ internal static RunStep FromResponse(Response response) using var document = JsonDocument.Parse(response.Content); return DeserializeRunStep(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStep.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStep.cs index c6476b44a586..b7471d0f255e 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStep.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStep.cs @@ -14,6 +14,38 @@ namespace Azure.AI.OpenAI.Assistants /// Detailed information about a single step of an assistant thread run. public partial class RunStep { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . /// The identifier, which can be referenced in API endpoints. /// The type of run step, which can be either message_creation or tool_calls. @@ -70,7 +102,8 @@ internal RunStep(string id, RunStepType type, string assistantId, string threadI /// The Unix timestamp, in seconds, representing when this was cancelled. /// The Unix timestamp, in seconds, representing when this failed. /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. - internal RunStep(string id, string @object, RunStepType type, string assistantId, string threadId, string runId, RunStepStatus status, RunStepDetails stepDetails, RunStepError lastError, DateTimeOffset createdAt, DateTimeOffset? expiredAt, DateTimeOffset? completedAt, DateTimeOffset? cancelledAt, DateTimeOffset? failedAt, IReadOnlyDictionary metadata) + /// Keeps track of any properties unknown to the library. + internal RunStep(string id, string @object, RunStepType type, string assistantId, string threadId, string runId, RunStepStatus status, RunStepDetails stepDetails, RunStepError lastError, DateTimeOffset createdAt, DateTimeOffset? expiredAt, DateTimeOffset? completedAt, DateTimeOffset? cancelledAt, DateTimeOffset? failedAt, IReadOnlyDictionary metadata, IDictionary serializedAdditionalRawData) { Id = id; Object = @object; @@ -87,6 +120,12 @@ internal RunStep(string id, string @object, RunStepType type, string assistantId CancelledAt = cancelledAt; FailedAt = failedAt; Metadata = metadata; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal RunStep() + { } /// The identifier, which can be referenced in API endpoints. diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDetails.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDetails.Serialization.cs index 89eb4f0e9e17..d705bccfa2f2 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDetails.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDetails.Serialization.cs @@ -5,15 +5,64 @@ #nullable disable +using System; +using System.ClientModel.Primitives; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - public partial class RunStepDetails + [PersistableModelProxy(typeof(UnknownRunStepDetails))] + public partial class RunStepDetails : IUtf8JsonSerializable, IJsonModel { - internal static RunStepDetails DeserializeRunStepDetails(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(RunStepDetails)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type.ToString()); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + RunStepDetails IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(RunStepDetails)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeRunStepDetails(document.RootElement, options); + } + + internal static RunStepDetails DeserializeRunStepDetails(JsonElement element, ModelReaderWriterOptions options = null) { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; @@ -29,6 +78,37 @@ internal static RunStepDetails DeserializeRunStepDetails(JsonElement element) return UnknownRunStepDetails.DeserializeUnknownRunStepDetails(element); } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(RunStepDetails)} does not support '{options.Format}' format."); + } + } + + RunStepDetails IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeRunStepDetails(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(RunStepDetails)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + /// Deserializes the model from a raw response. /// The response to deserialize the model from. internal static RunStepDetails FromResponse(Response response) @@ -36,5 +116,13 @@ internal static RunStepDetails FromResponse(Response response) using var document = JsonDocument.Parse(response.Content); return DeserializeRunStepDetails(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDetails.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDetails.cs index 1edaf9589694..a483afac69d6 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDetails.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDetails.cs @@ -5,6 +5,9 @@ #nullable disable +using System; +using System.Collections.Generic; + namespace Azure.AI.OpenAI.Assistants { /// @@ -14,6 +17,38 @@ namespace Azure.AI.OpenAI.Assistants /// public abstract partial class RunStepDetails { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private protected IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . protected RunStepDetails() { @@ -21,9 +56,11 @@ protected RunStepDetails() /// Initializes a new instance of . /// The object type. - internal RunStepDetails(RunStepType type) + /// Keeps track of any properties unknown to the library. + internal RunStepDetails(RunStepType type, IDictionary serializedAdditionalRawData) { Type = type; + _serializedAdditionalRawData = serializedAdditionalRawData; } /// The object type. diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepError.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepError.Serialization.cs index 143e744b02a9..889e02dfe650 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepError.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepError.Serialization.cs @@ -5,21 +5,74 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - public partial class RunStepError + public partial class RunStepError : IUtf8JsonSerializable, IJsonModel { - internal static RunStepError DeserializeRunStepError(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(RunStepError)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("code"u8); + writer.WriteStringValue(Code.ToString()); + writer.WritePropertyName("message"u8); + writer.WriteStringValue(Message); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + RunStepError IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(RunStepError)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeRunStepError(document.RootElement, options); + } + + internal static RunStepError DeserializeRunStepError(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; } RunStepErrorCode code = default; string message = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("code"u8)) @@ -32,10 +85,46 @@ internal static RunStepError DeserializeRunStepError(JsonElement element) message = property.Value.GetString(); continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new RunStepError(code, message, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(RunStepError)} does not support '{options.Format}' format."); + } + } + + RunStepError IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeRunStepError(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(RunStepError)} does not support '{options.Format}' format."); } - return new RunStepError(code, message); } + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + /// Deserializes the model from a raw response. /// The response to deserialize the model from. internal static RunStepError FromResponse(Response response) @@ -43,5 +132,13 @@ internal static RunStepError FromResponse(Response response) using var document = JsonDocument.Parse(response.Content); return DeserializeRunStepError(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepError.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepError.cs index fc946ebe690f..78b64982ff48 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepError.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepError.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.Collections.Generic; using Azure.Core; namespace Azure.AI.OpenAI.Assistants @@ -13,6 +14,38 @@ namespace Azure.AI.OpenAI.Assistants /// The error information associated with a failed run step. public partial class RunStepError { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . /// The error code for this error. /// The human-readable text associated with this error. @@ -25,6 +58,22 @@ internal RunStepError(RunStepErrorCode code, string message) Message = message; } + /// Initializes a new instance of . + /// The error code for this error. + /// The human-readable text associated with this error. + /// Keeps track of any properties unknown to the library. + internal RunStepError(RunStepErrorCode code, string message, IDictionary serializedAdditionalRawData) + { + Code = code; + Message = message; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal RunStepError() + { + } + /// The error code for this error. public RunStepErrorCode Code { get; } /// The human-readable text associated with this error. diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepMessageCreationDetails.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepMessageCreationDetails.Serialization.cs index 88ec9daa25ff..3f79f1d6b844 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepMessageCreationDetails.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepMessageCreationDetails.Serialization.cs @@ -5,21 +5,74 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - public partial class RunStepMessageCreationDetails + public partial class RunStepMessageCreationDetails : IUtf8JsonSerializable, IJsonModel { - internal static RunStepMessageCreationDetails DeserializeRunStepMessageCreationDetails(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(RunStepMessageCreationDetails)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("message_creation"u8); + writer.WriteObjectValue(MessageCreation); + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type.ToString()); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + RunStepMessageCreationDetails IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(RunStepMessageCreationDetails)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeRunStepMessageCreationDetails(document.RootElement, options); + } + + internal static RunStepMessageCreationDetails DeserializeRunStepMessageCreationDetails(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; } RunStepMessageCreationReference messageCreation = default; RunStepType type = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("message_creation"u8)) @@ -32,10 +85,46 @@ internal static RunStepMessageCreationDetails DeserializeRunStepMessageCreationD type = new RunStepType(property.Value.GetString()); continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new RunStepMessageCreationDetails(type, serializedAdditionalRawData, messageCreation); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(RunStepMessageCreationDetails)} does not support '{options.Format}' format."); + } + } + + RunStepMessageCreationDetails IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeRunStepMessageCreationDetails(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(RunStepMessageCreationDetails)} does not support '{options.Format}' format."); } - return new RunStepMessageCreationDetails(type, messageCreation); } + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + /// Deserializes the model from a raw response. /// The response to deserialize the model from. internal static new RunStepMessageCreationDetails FromResponse(Response response) @@ -43,5 +132,13 @@ internal static RunStepMessageCreationDetails DeserializeRunStepMessageCreationD using var document = JsonDocument.Parse(response.Content); return DeserializeRunStepMessageCreationDetails(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal override RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepMessageCreationDetails.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepMessageCreationDetails.cs index 2c59cdfa44e0..526bd1c6e175 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepMessageCreationDetails.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepMessageCreationDetails.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.Collections.Generic; using Azure.Core; namespace Azure.AI.OpenAI.Assistants @@ -26,12 +27,18 @@ internal RunStepMessageCreationDetails(RunStepMessageCreationReference messageCr /// Initializes a new instance of . /// The object type. + /// Keeps track of any properties unknown to the library. /// Information about the message creation associated with this run step. - internal RunStepMessageCreationDetails(RunStepType type, RunStepMessageCreationReference messageCreation) : base(type) + internal RunStepMessageCreationDetails(RunStepType type, IDictionary serializedAdditionalRawData, RunStepMessageCreationReference messageCreation) : base(type, serializedAdditionalRawData) { MessageCreation = messageCreation; } + /// Initializes a new instance of for deserialization. + internal RunStepMessageCreationDetails() + { + } + /// Information about the message creation associated with this run step. public RunStepMessageCreationReference MessageCreation { get; } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepMessageCreationReference.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepMessageCreationReference.Serialization.cs index c521a3ffc99b..8ef60d754214 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepMessageCreationReference.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepMessageCreationReference.Serialization.cs @@ -5,20 +5,71 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - public partial class RunStepMessageCreationReference + public partial class RunStepMessageCreationReference : IUtf8JsonSerializable, IJsonModel { - internal static RunStepMessageCreationReference DeserializeRunStepMessageCreationReference(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(RunStepMessageCreationReference)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("message_id"u8); + writer.WriteStringValue(MessageId); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + RunStepMessageCreationReference IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(RunStepMessageCreationReference)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeRunStepMessageCreationReference(document.RootElement, options); + } + + internal static RunStepMessageCreationReference DeserializeRunStepMessageCreationReference(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; } string messageId = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("message_id"u8)) @@ -26,10 +77,46 @@ internal static RunStepMessageCreationReference DeserializeRunStepMessageCreatio messageId = property.Value.GetString(); continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new RunStepMessageCreationReference(messageId, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(RunStepMessageCreationReference)} does not support '{options.Format}' format."); + } + } + + RunStepMessageCreationReference IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeRunStepMessageCreationReference(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(RunStepMessageCreationReference)} does not support '{options.Format}' format."); } - return new RunStepMessageCreationReference(messageId); } + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + /// Deserializes the model from a raw response. /// The response to deserialize the model from. internal static RunStepMessageCreationReference FromResponse(Response response) @@ -37,5 +124,13 @@ internal static RunStepMessageCreationReference FromResponse(Response response) using var document = JsonDocument.Parse(response.Content); return DeserializeRunStepMessageCreationReference(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepMessageCreationReference.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepMessageCreationReference.cs index 9adfea67a990..55263d6961df 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepMessageCreationReference.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepMessageCreationReference.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.Collections.Generic; using Azure.Core; namespace Azure.AI.OpenAI.Assistants @@ -13,6 +14,38 @@ namespace Azure.AI.OpenAI.Assistants /// The details of a message created as a part of a run step. public partial class RunStepMessageCreationReference { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . /// The ID of the message created by this run step. /// is null. @@ -23,6 +56,20 @@ internal RunStepMessageCreationReference(string messageId) MessageId = messageId; } + /// Initializes a new instance of . + /// The ID of the message created by this run step. + /// Keeps track of any properties unknown to the library. + internal RunStepMessageCreationReference(string messageId, IDictionary serializedAdditionalRawData) + { + MessageId = messageId; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal RunStepMessageCreationReference() + { + } + /// The ID of the message created by this run step. public string MessageId { get; } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepToolCallDetails.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepToolCallDetails.Serialization.cs index 69f3173bd90f..c3daaea77d9e 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepToolCallDetails.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepToolCallDetails.Serialization.cs @@ -5,22 +5,79 @@ #nullable disable +using System; +using System.ClientModel.Primitives; using System.Collections.Generic; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - public partial class RunStepToolCallDetails + public partial class RunStepToolCallDetails : IUtf8JsonSerializable, IJsonModel { - internal static RunStepToolCallDetails DeserializeRunStepToolCallDetails(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(RunStepToolCallDetails)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("tool_calls"u8); + writer.WriteStartArray(); + foreach (var item in ToolCalls) + { + writer.WriteObjectValue(item); + } + writer.WriteEndArray(); + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type.ToString()); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + RunStepToolCallDetails IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(RunStepToolCallDetails)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeRunStepToolCallDetails(document.RootElement, options); + } + + internal static RunStepToolCallDetails DeserializeRunStepToolCallDetails(JsonElement element, ModelReaderWriterOptions options = null) { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; } IReadOnlyList toolCalls = default; RunStepType type = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("tool_calls"u8)) @@ -38,10 +95,46 @@ internal static RunStepToolCallDetails DeserializeRunStepToolCallDetails(JsonEle type = new RunStepType(property.Value.GetString()); continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } } - return new RunStepToolCallDetails(type, toolCalls); + serializedAdditionalRawData = additionalPropertiesDictionary; + return new RunStepToolCallDetails(type, serializedAdditionalRawData, toolCalls); } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(RunStepToolCallDetails)} does not support '{options.Format}' format."); + } + } + + RunStepToolCallDetails IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeRunStepToolCallDetails(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(RunStepToolCallDetails)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + /// Deserializes the model from a raw response. /// The response to deserialize the model from. internal static new RunStepToolCallDetails FromResponse(Response response) @@ -49,5 +142,13 @@ internal static RunStepToolCallDetails DeserializeRunStepToolCallDetails(JsonEle using var document = JsonDocument.Parse(response.Content); return DeserializeRunStepToolCallDetails(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal override RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepToolCallDetails.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepToolCallDetails.cs index 7b6b186a8e19..a543cfe75988 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepToolCallDetails.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepToolCallDetails.cs @@ -28,12 +28,18 @@ internal RunStepToolCallDetails(IEnumerable toolCalls) /// Initializes a new instance of . /// The object type. + /// Keeps track of any properties unknown to the library. /// A list of tool call details for this run step. - internal RunStepToolCallDetails(RunStepType type, IReadOnlyList toolCalls) : base(type) + internal RunStepToolCallDetails(RunStepType type, IDictionary serializedAdditionalRawData, IReadOnlyList toolCalls) : base(type, serializedAdditionalRawData) { ToolCalls = toolCalls; } + /// Initializes a new instance of for deserialization. + internal RunStepToolCallDetails() + { + } + /// /// A list of tool call details for this run step. /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/SubmitToolOutputsAction.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/SubmitToolOutputsAction.Serialization.cs index 199c8c1adf75..1c2aacdfc45f 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/SubmitToolOutputsAction.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/SubmitToolOutputsAction.Serialization.cs @@ -5,21 +5,74 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - public partial class SubmitToolOutputsAction + public partial class SubmitToolOutputsAction : IUtf8JsonSerializable, IJsonModel { - internal static SubmitToolOutputsAction DeserializeSubmitToolOutputsAction(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(SubmitToolOutputsAction)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("submit_tool_outputs"u8); + writer.WriteObjectValue(InternalDetails); + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + SubmitToolOutputsAction IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(SubmitToolOutputsAction)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeSubmitToolOutputsAction(document.RootElement, options); + } + + internal static SubmitToolOutputsAction DeserializeSubmitToolOutputsAction(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; } InternalSubmitToolOutputsDetails submitToolOutputs = default; string type = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("submit_tool_outputs"u8)) @@ -32,10 +85,46 @@ internal static SubmitToolOutputsAction DeserializeSubmitToolOutputsAction(JsonE type = property.Value.GetString(); continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new SubmitToolOutputsAction(type, serializedAdditionalRawData, submitToolOutputs); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(SubmitToolOutputsAction)} does not support '{options.Format}' format."); + } + } + + SubmitToolOutputsAction IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeSubmitToolOutputsAction(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(SubmitToolOutputsAction)} does not support '{options.Format}' format."); } - return new SubmitToolOutputsAction(type, submitToolOutputs); } + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + /// Deserializes the model from a raw response. /// The response to deserialize the model from. internal static new SubmitToolOutputsAction FromResponse(Response response) @@ -43,5 +132,13 @@ internal static SubmitToolOutputsAction DeserializeSubmitToolOutputsAction(JsonE using var document = JsonDocument.Parse(response.Content); return DeserializeSubmitToolOutputsAction(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal override RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/SubmitToolOutputsAction.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/SubmitToolOutputsAction.cs index 9ad109c3fc58..499096eec2be 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/SubmitToolOutputsAction.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/SubmitToolOutputsAction.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.Collections.Generic; using Azure.Core; namespace Azure.AI.OpenAI.Assistants @@ -26,10 +27,16 @@ internal SubmitToolOutputsAction(InternalSubmitToolOutputsDetails internalDetail /// Initializes a new instance of . /// The object type. + /// Keeps track of any properties unknown to the library. /// The details describing tools that should be called to submit tool outputs. - internal SubmitToolOutputsAction(string type, InternalSubmitToolOutputsDetails internalDetails) : base(type) + internal SubmitToolOutputsAction(string type, IDictionary serializedAdditionalRawData, InternalSubmitToolOutputsDetails internalDetails) : base(type, serializedAdditionalRawData) { InternalDetails = internalDetails; } + + /// Initializes a new instance of for deserialization. + internal SubmitToolOutputsAction() + { + } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/SubmitToolOutputsToRunRequest.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/SubmitToolOutputsToRunRequest.Serialization.cs index d6db7a7e06ed..f34745a290dc 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/SubmitToolOutputsToRunRequest.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/SubmitToolOutputsToRunRequest.Serialization.cs @@ -5,15 +5,27 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; +using Azure; using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - internal partial class SubmitToolOutputsToRunRequest : IUtf8JsonSerializable + internal partial class SubmitToolOutputsToRunRequest : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(SubmitToolOutputsToRunRequest)} does not support '{format}' format."); + } + writer.WriteStartObject(); writer.WritePropertyName("tool_outputs"u8); writer.WriteStartArray(); @@ -22,9 +34,107 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) writer.WriteObjectValue(item); } writer.WriteEndArray(); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } + SubmitToolOutputsToRunRequest IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(SubmitToolOutputsToRunRequest)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeSubmitToolOutputsToRunRequest(document.RootElement, options); + } + + internal static SubmitToolOutputsToRunRequest DeserializeSubmitToolOutputsToRunRequest(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + IList toolOutputs = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("tool_outputs"u8)) + { + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(ToolOutput.DeserializeToolOutput(item)); + } + toolOutputs = array; + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new SubmitToolOutputsToRunRequest(toolOutputs, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(SubmitToolOutputsToRunRequest)} does not support '{options.Format}' format."); + } + } + + SubmitToolOutputsToRunRequest IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeSubmitToolOutputsToRunRequest(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(SubmitToolOutputsToRunRequest)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static SubmitToolOutputsToRunRequest FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeSubmitToolOutputsToRunRequest(document.RootElement); + } + /// Convert into a Utf8JsonRequestContent. internal virtual RequestContent ToRequestContent() { diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/SubmitToolOutputsToRunRequest.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/SubmitToolOutputsToRunRequest.cs index 45e5cd8b047c..8758e67f4632 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/SubmitToolOutputsToRunRequest.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/SubmitToolOutputsToRunRequest.cs @@ -15,6 +15,38 @@ namespace Azure.AI.OpenAI.Assistants /// The SubmitToolOutputsToRunRequest. internal partial class SubmitToolOutputsToRunRequest { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . /// The list of tool outputs requested by tool calls from the specified run. /// is null. @@ -27,9 +59,16 @@ public SubmitToolOutputsToRunRequest(IEnumerable toolOutputs) /// Initializes a new instance of . /// The list of tool outputs requested by tool calls from the specified run. - internal SubmitToolOutputsToRunRequest(IList toolOutputs) + /// Keeps track of any properties unknown to the library. + internal SubmitToolOutputsToRunRequest(IList toolOutputs, IDictionary serializedAdditionalRawData) { ToolOutputs = toolOutputs; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal SubmitToolOutputsToRunRequest() + { } /// The list of tool outputs requested by tool calls from the specified run. diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadDeletionStatus.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadDeletionStatus.Serialization.cs index ba0871f60dc1..a75f90da2f1c 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadDeletionStatus.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadDeletionStatus.Serialization.cs @@ -5,15 +5,68 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - internal partial class ThreadDeletionStatus + internal partial class ThreadDeletionStatus : IUtf8JsonSerializable, IJsonModel { - internal static ThreadDeletionStatus DeserializeThreadDeletionStatus(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ThreadDeletionStatus)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("id"u8); + writer.WriteStringValue(Id); + writer.WritePropertyName("deleted"u8); + writer.WriteBooleanValue(Deleted); + writer.WritePropertyName("object"u8); + writer.WriteStringValue(Object.ToString()); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ThreadDeletionStatus IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ThreadDeletionStatus)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeThreadDeletionStatus(document.RootElement, options); + } + + internal static ThreadDeletionStatus DeserializeThreadDeletionStatus(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; @@ -21,6 +74,8 @@ internal static ThreadDeletionStatus DeserializeThreadDeletionStatus(JsonElement string id = default; bool deleted = default; ThreadDeletionStatusObject @object = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("id"u8)) @@ -38,10 +93,46 @@ internal static ThreadDeletionStatus DeserializeThreadDeletionStatus(JsonElement @object = new ThreadDeletionStatusObject(property.Value.GetString()); continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new ThreadDeletionStatus(id, deleted, @object, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(ThreadDeletionStatus)} does not support '{options.Format}' format."); + } + } + + ThreadDeletionStatus IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeThreadDeletionStatus(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ThreadDeletionStatus)} does not support '{options.Format}' format."); } - return new ThreadDeletionStatus(id, deleted, @object); } + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + /// Deserializes the model from a raw response. /// The response to deserialize the model from. internal static ThreadDeletionStatus FromResponse(Response response) @@ -49,5 +140,13 @@ internal static ThreadDeletionStatus FromResponse(Response response) using var document = JsonDocument.Parse(response.Content); return DeserializeThreadDeletionStatus(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadDeletionStatus.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadDeletionStatus.cs index b75cd3499f16..9a7016bc025b 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadDeletionStatus.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadDeletionStatus.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.Collections.Generic; using Azure.Core; namespace Azure.AI.OpenAI.Assistants @@ -13,6 +14,38 @@ namespace Azure.AI.OpenAI.Assistants /// The status of a thread deletion operation. internal partial class ThreadDeletionStatus { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . /// The ID of the resource specified for deletion. /// A value indicating whether deletion was successful. @@ -29,11 +62,18 @@ internal ThreadDeletionStatus(string id, bool deleted) /// The ID of the resource specified for deletion. /// A value indicating whether deletion was successful. /// The object type, which is always 'thread.deleted'. - internal ThreadDeletionStatus(string id, bool deleted, ThreadDeletionStatusObject @object) + /// Keeps track of any properties unknown to the library. + internal ThreadDeletionStatus(string id, bool deleted, ThreadDeletionStatusObject @object, IDictionary serializedAdditionalRawData) { Id = id; Deleted = deleted; Object = @object; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal ThreadDeletionStatus() + { } /// The ID of the resource specified for deletion. diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadInitializationMessage.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadInitializationMessage.Serialization.cs index df66a59a730d..8a54eb98c146 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadInitializationMessage.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadInitializationMessage.Serialization.cs @@ -5,15 +5,27 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; +using Azure; using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - public partial class ThreadInitializationMessage : IUtf8JsonSerializable + public partial class ThreadInitializationMessage : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ThreadInitializationMessage)} does not support '{format}' format."); + } + writer.WriteStartObject(); writer.WritePropertyName("role"u8); writer.WriteStringValue(Role.ToString()); @@ -47,9 +59,138 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) writer.WriteNull("metadata"); } } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } + ThreadInitializationMessage IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ThreadInitializationMessage)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeThreadInitializationMessage(document.RootElement, options); + } + + internal static ThreadInitializationMessage DeserializeThreadInitializationMessage(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + MessageRole role = default; + string content = default; + Optional> fileIds = default; + Optional> metadata = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("role"u8)) + { + role = new MessageRole(property.Value.GetString()); + continue; + } + if (property.NameEquals("content"u8)) + { + content = property.Value.GetString(); + continue; + } + if (property.NameEquals("file_ids"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(item.GetString()); + } + fileIds = array; + continue; + } + if (property.NameEquals("metadata"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + Dictionary dictionary = new Dictionary(); + foreach (var property0 in property.Value.EnumerateObject()) + { + dictionary.Add(property0.Name, property0.Value.GetString()); + } + metadata = dictionary; + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new ThreadInitializationMessage(role, content, Optional.ToList(fileIds), Optional.ToDictionary(metadata), serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(ThreadInitializationMessage)} does not support '{options.Format}' format."); + } + } + + ThreadInitializationMessage IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeThreadInitializationMessage(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ThreadInitializationMessage)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static ThreadInitializationMessage FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeThreadInitializationMessage(document.RootElement); + } + /// Convert into a Utf8JsonRequestContent. internal virtual RequestContent ToRequestContent() { diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadInitializationMessage.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadInitializationMessage.cs index abf26ec513ec..13fd8b6cc1e2 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadInitializationMessage.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadInitializationMessage.cs @@ -14,6 +14,38 @@ namespace Azure.AI.OpenAI.Assistants /// A single message within an assistant thread, as provided during that thread's creation for its initial state. public partial class ThreadInitializationMessage { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . /// The role associated with the assistant thread message. Currently, only 'user' is supported when providing initial messages to a new thread. /// The textual content of the initial message. Currently, robust input including images and annotated text may only be provided via a separate call to the create message API. @@ -36,12 +68,19 @@ public ThreadInitializationMessage(MessageRole role, string content) /// access files. /// /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. - internal ThreadInitializationMessage(MessageRole role, string content, IList fileIds, IDictionary metadata) + /// Keeps track of any properties unknown to the library. + internal ThreadInitializationMessage(MessageRole role, string content, IList fileIds, IDictionary metadata, IDictionary serializedAdditionalRawData) { Role = role; Content = content; FileIds = fileIds; Metadata = metadata; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal ThreadInitializationMessage() + { } /// The role associated with the assistant thread message. Currently, only 'user' is supported when providing initial messages to a new thread. diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadMessage.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadMessage.Serialization.cs index 49e54a54d6e7..a56e93f5f386 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadMessage.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadMessage.Serialization.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.ClientModel.Primitives; using System.Collections.Generic; using System.Text.Json; using Azure; @@ -13,10 +14,102 @@ namespace Azure.AI.OpenAI.Assistants { - public partial class ThreadMessage + public partial class ThreadMessage : IUtf8JsonSerializable, IJsonModel { - internal static ThreadMessage DeserializeThreadMessage(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ThreadMessage)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("id"u8); + writer.WriteStringValue(Id); + writer.WritePropertyName("object"u8); + writer.WriteStringValue(Object); + writer.WritePropertyName("created_at"u8); + writer.WriteNumberValue(CreatedAt, "U"); + writer.WritePropertyName("thread_id"u8); + writer.WriteStringValue(ThreadId); + writer.WritePropertyName("role"u8); + writer.WriteStringValue(Role.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStartArray(); + foreach (var item in ContentItems) + { + writer.WriteObjectValue(item); + } + writer.WriteEndArray(); + if (Optional.IsDefined(AssistantId)) + { + writer.WritePropertyName("assistant_id"u8); + writer.WriteStringValue(AssistantId); + } + if (Optional.IsDefined(RunId)) + { + writer.WritePropertyName("run_id"u8); + writer.WriteStringValue(RunId); + } + writer.WritePropertyName("file_ids"u8); + writer.WriteStartArray(); + foreach (var item in FileIds) + { + writer.WriteStringValue(item); + } + writer.WriteEndArray(); + if (Metadata != null && Optional.IsCollectionDefined(Metadata)) + { + writer.WritePropertyName("metadata"u8); + writer.WriteStartObject(); + foreach (var item in Metadata) + { + writer.WritePropertyName(item.Key); + writer.WriteStringValue(item.Value); + } + writer.WriteEndObject(); + } + else + { + writer.WriteNull("metadata"); + } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ThreadMessage IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ThreadMessage)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeThreadMessage(document.RootElement, options); + } + + internal static ThreadMessage DeserializeThreadMessage(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; @@ -31,6 +124,8 @@ internal static ThreadMessage DeserializeThreadMessage(JsonElement element) Optional runId = default; IReadOnlyList fileIds = default; IReadOnlyDictionary metadata = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("id"u8)) @@ -103,10 +198,46 @@ internal static ThreadMessage DeserializeThreadMessage(JsonElement element) metadata = dictionary; continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } } - return new ThreadMessage(id, @object, createdAt, threadId, role, content, assistantId.Value, runId.Value, fileIds, metadata); + serializedAdditionalRawData = additionalPropertiesDictionary; + return new ThreadMessage(id, @object, createdAt, threadId, role, content, assistantId.Value, runId.Value, fileIds, metadata, serializedAdditionalRawData); } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(ThreadMessage)} does not support '{options.Format}' format."); + } + } + + ThreadMessage IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeThreadMessage(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ThreadMessage)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + /// Deserializes the model from a raw response. /// The response to deserialize the model from. internal static ThreadMessage FromResponse(Response response) @@ -114,5 +245,13 @@ internal static ThreadMessage FromResponse(Response response) using var document = JsonDocument.Parse(response.Content); return DeserializeThreadMessage(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadMessage.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadMessage.cs index a318019f31f6..9fc6a9485244 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadMessage.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadMessage.cs @@ -15,6 +15,38 @@ namespace Azure.AI.OpenAI.Assistants /// A single, existing message within an assistant thread. public partial class ThreadMessage { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . /// The identifier, which can be referenced in API endpoints. /// The Unix timestamp, in seconds, representing when this object was created. @@ -57,7 +89,8 @@ internal ThreadMessage(string id, DateTimeOffset createdAt, string threadId, Mes /// access files. /// /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. - internal ThreadMessage(string id, string @object, DateTimeOffset createdAt, string threadId, MessageRole role, IReadOnlyList contentItems, string assistantId, string runId, IReadOnlyList fileIds, IReadOnlyDictionary metadata) + /// Keeps track of any properties unknown to the library. + internal ThreadMessage(string id, string @object, DateTimeOffset createdAt, string threadId, MessageRole role, IReadOnlyList contentItems, string assistantId, string runId, IReadOnlyList fileIds, IReadOnlyDictionary metadata, IDictionary serializedAdditionalRawData) { Id = id; Object = @object; @@ -69,6 +102,12 @@ internal ThreadMessage(string id, string @object, DateTimeOffset createdAt, stri RunId = runId; FileIds = fileIds; Metadata = metadata; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal ThreadMessage() + { } /// The identifier, which can be referenced in API endpoints. diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadRun.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadRun.Serialization.cs index 35c0283a6e32..510c1142e076 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadRun.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadRun.Serialization.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.ClientModel.Primitives; using System.Collections.Generic; using System.Text.Json; using Azure; @@ -13,10 +14,164 @@ namespace Azure.AI.OpenAI.Assistants { - public partial class ThreadRun + public partial class ThreadRun : IUtf8JsonSerializable, IJsonModel { - internal static ThreadRun DeserializeThreadRun(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ThreadRun)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("id"u8); + writer.WriteStringValue(Id); + writer.WritePropertyName("object"u8); + writer.WriteStringValue(Object); + writer.WritePropertyName("thread_id"u8); + writer.WriteStringValue(ThreadId); + writer.WritePropertyName("assistant_id"u8); + writer.WriteStringValue(AssistantId); + writer.WritePropertyName("status"u8); + writer.WriteStringValue(Status.ToString()); + if (Optional.IsDefined(RequiredAction)) + { + if (RequiredAction != null) + { + writer.WritePropertyName("required_action"u8); + writer.WriteObjectValue(RequiredAction); + } + else + { + writer.WriteNull("required_action"); + } + } + if (LastError != null) + { + writer.WritePropertyName("last_error"u8); + writer.WriteObjectValue(LastError); + } + else + { + writer.WriteNull("last_error"); + } + writer.WritePropertyName("model"u8); + writer.WriteStringValue(Model); + writer.WritePropertyName("instructions"u8); + writer.WriteStringValue(Instructions); + writer.WritePropertyName("tools"u8); + writer.WriteStartArray(); + foreach (var item in Tools) + { + writer.WriteObjectValue(item); + } + writer.WriteEndArray(); + writer.WritePropertyName("file_ids"u8); + writer.WriteStartArray(); + foreach (var item in FileIds) + { + writer.WriteStringValue(item); + } + writer.WriteEndArray(); + writer.WritePropertyName("created_at"u8); + writer.WriteNumberValue(CreatedAt, "U"); + if (ExpiresAt != null) + { + writer.WritePropertyName("expires_at"u8); + writer.WriteStringValue(ExpiresAt.Value, "O"); + } + else + { + writer.WriteNull("expires_at"); + } + if (StartedAt != null) + { + writer.WritePropertyName("started_at"u8); + writer.WriteStringValue(StartedAt.Value, "O"); + } + else + { + writer.WriteNull("started_at"); + } + if (CompletedAt != null) + { + writer.WritePropertyName("completed_at"u8); + writer.WriteStringValue(CompletedAt.Value, "O"); + } + else + { + writer.WriteNull("completed_at"); + } + if (CancelledAt != null) + { + writer.WritePropertyName("cancelled_at"u8); + writer.WriteStringValue(CancelledAt.Value, "O"); + } + else + { + writer.WriteNull("cancelled_at"); + } + if (FailedAt != null) + { + writer.WritePropertyName("failed_at"u8); + writer.WriteStringValue(FailedAt.Value, "O"); + } + else + { + writer.WriteNull("failed_at"); + } + if (Metadata != null && Optional.IsCollectionDefined(Metadata)) + { + writer.WritePropertyName("metadata"u8); + writer.WriteStartObject(); + foreach (var item in Metadata) + { + writer.WritePropertyName(item.Key); + writer.WriteStringValue(item.Value); + } + writer.WriteEndObject(); + } + else + { + writer.WriteNull("metadata"); + } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ThreadRun IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ThreadRun)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeThreadRun(document.RootElement, options); + } + + internal static ThreadRun DeserializeThreadRun(JsonElement element, ModelReaderWriterOptions options = null) { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; @@ -39,6 +194,8 @@ internal static ThreadRun DeserializeThreadRun(JsonElement element) DateTimeOffset? cancelledAt = default; DateTimeOffset? failedAt = default; IReadOnlyDictionary metadata = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("id"u8)) @@ -161,10 +318,46 @@ internal static ThreadRun DeserializeThreadRun(JsonElement element) metadata = dictionary; continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new ThreadRun(id, @object, threadId, assistantId, status, requiredAction.Value, lastError, model, instructions, tools, fileIds, createdAt, expiresAt, startedAt, completedAt, cancelledAt, failedAt, metadata, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(ThreadRun)} does not support '{options.Format}' format."); + } + } + + ThreadRun IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeThreadRun(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ThreadRun)} does not support '{options.Format}' format."); } - return new ThreadRun(id, @object, threadId, assistantId, status, requiredAction.Value, lastError, model, instructions, tools, fileIds, createdAt, expiresAt, startedAt, completedAt, cancelledAt, failedAt, metadata); } + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + /// Deserializes the model from a raw response. /// The response to deserialize the model from. internal static ThreadRun FromResponse(Response response) @@ -172,5 +365,13 @@ internal static ThreadRun FromResponse(Response response) using var document = JsonDocument.Parse(response.Content); return DeserializeThreadRun(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadRun.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadRun.cs index bc2175644c1a..5e809dc9ae15 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadRun.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadRun.cs @@ -15,6 +15,38 @@ namespace Azure.AI.OpenAI.Assistants /// Data representing a single evaluation run of an assistant thread. public partial class ThreadRun { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . /// The identifier, which can be referenced in API endpoints. /// The ID of the thread associated with this run. @@ -80,7 +112,8 @@ internal ThreadRun(string id, string threadId, string assistantId, RunStatus sta /// The Unix timestamp, in seconds, representing when this was cancelled. /// The Unix timestamp, in seconds, representing when this failed. /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. - internal ThreadRun(string id, string @object, string threadId, string assistantId, RunStatus status, RequiredAction requiredAction, RunError lastError, string model, string instructions, IReadOnlyList tools, IReadOnlyList fileIds, DateTimeOffset createdAt, DateTimeOffset? expiresAt, DateTimeOffset? startedAt, DateTimeOffset? completedAt, DateTimeOffset? cancelledAt, DateTimeOffset? failedAt, IReadOnlyDictionary metadata) + /// Keeps track of any properties unknown to the library. + internal ThreadRun(string id, string @object, string threadId, string assistantId, RunStatus status, RequiredAction requiredAction, RunError lastError, string model, string instructions, IReadOnlyList tools, IReadOnlyList fileIds, DateTimeOffset createdAt, DateTimeOffset? expiresAt, DateTimeOffset? startedAt, DateTimeOffset? completedAt, DateTimeOffset? cancelledAt, DateTimeOffset? failedAt, IReadOnlyDictionary metadata, IDictionary serializedAdditionalRawData) { Id = id; Object = @object; @@ -100,6 +133,12 @@ internal ThreadRun(string id, string @object, string threadId, string assistantI CancelledAt = cancelledAt; FailedAt = failedAt; Metadata = metadata; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal ThreadRun() + { } /// The identifier, which can be referenced in API endpoints. diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ToolCall.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ToolCall.Serialization.cs index bcf917e9258f..4a6470f90fa1 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ToolCall.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ToolCall.Serialization.cs @@ -5,15 +5,66 @@ #nullable disable +using System; +using System.ClientModel.Primitives; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - public partial class ToolCall + [PersistableModelProxy(typeof(UnknownToolCall))] + public partial class ToolCall : IUtf8JsonSerializable, IJsonModel { - internal static ToolCall DeserializeToolCall(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ToolCall)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type); + writer.WritePropertyName("id"u8); + writer.WriteStringValue(Id); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ToolCall IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ToolCall)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeToolCall(document.RootElement, options); + } + + internal static ToolCall DeserializeToolCall(JsonElement element, ModelReaderWriterOptions options = null) { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; @@ -30,6 +81,37 @@ internal static ToolCall DeserializeToolCall(JsonElement element) return UnknownToolCall.DeserializeUnknownToolCall(element); } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(ToolCall)} does not support '{options.Format}' format."); + } + } + + ToolCall IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeToolCall(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ToolCall)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + /// Deserializes the model from a raw response. /// The response to deserialize the model from. internal static ToolCall FromResponse(Response response) @@ -37,5 +119,13 @@ internal static ToolCall FromResponse(Response response) using var document = JsonDocument.Parse(response.Content); return DeserializeToolCall(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ToolCall.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ToolCall.cs index 3fb7c57e56a4..4b3ac05b0566 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ToolCall.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ToolCall.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.Collections.Generic; using Azure.Core; namespace Azure.AI.OpenAI.Assistants @@ -17,6 +18,38 @@ namespace Azure.AI.OpenAI.Assistants /// public abstract partial class ToolCall { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private protected IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . /// The ID of the tool call. This ID must be referenced when you submit tool outputs. /// is null. @@ -30,10 +63,17 @@ protected ToolCall(string id) /// Initializes a new instance of . /// The object type. /// The ID of the tool call. This ID must be referenced when you submit tool outputs. - internal ToolCall(string type, string id) + /// Keeps track of any properties unknown to the library. + internal ToolCall(string type, string id, IDictionary serializedAdditionalRawData) { Type = type; Id = id; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal ToolCall() + { } /// The object type. diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ToolDefinition.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ToolDefinition.Serialization.cs index a918fe002774..2effa166cbe0 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ToolDefinition.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ToolDefinition.Serialization.cs @@ -5,24 +5,64 @@ #nullable disable +using System; +using System.ClientModel.Primitives; using System.Text.Json; using Azure; using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - public partial class ToolDefinition : IUtf8JsonSerializable + [PersistableModelProxy(typeof(UnknownToolDefinition))] + public partial class ToolDefinition : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ToolDefinition)} does not support '{format}' format."); + } + writer.WriteStartObject(); writer.WritePropertyName("type"u8); writer.WriteStringValue(Type); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } - internal static ToolDefinition DeserializeToolDefinition(JsonElement element) + ToolDefinition IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ToolDefinition)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeToolDefinition(document.RootElement, options); + } + + internal static ToolDefinition DeserializeToolDefinition(JsonElement element, ModelReaderWriterOptions options = null) { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; @@ -39,6 +79,37 @@ internal static ToolDefinition DeserializeToolDefinition(JsonElement element) return UnknownToolDefinition.DeserializeUnknownToolDefinition(element); } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(ToolDefinition)} does not support '{options.Format}' format."); + } + } + + ToolDefinition IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeToolDefinition(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ToolDefinition)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + /// Deserializes the model from a raw response. /// The response to deserialize the model from. internal static ToolDefinition FromResponse(Response response) diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ToolDefinition.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ToolDefinition.cs index 58fdafa2bf54..d2c10bd1ac3c 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ToolDefinition.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ToolDefinition.cs @@ -5,6 +5,9 @@ #nullable disable +using System; +using System.Collections.Generic; + namespace Azure.AI.OpenAI.Assistants { /// @@ -14,6 +17,38 @@ namespace Azure.AI.OpenAI.Assistants /// public abstract partial class ToolDefinition { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private protected IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . protected ToolDefinition() { @@ -21,9 +56,11 @@ protected ToolDefinition() /// Initializes a new instance of . /// The object type. - internal ToolDefinition(string type) + /// Keeps track of any properties unknown to the library. + internal ToolDefinition(string type, IDictionary serializedAdditionalRawData) { Type = type; + _serializedAdditionalRawData = serializedAdditionalRawData; } /// The object type. diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ToolOutput.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ToolOutput.Serialization.cs index 2edb9ae393c0..828982535d38 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ToolOutput.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ToolOutput.Serialization.cs @@ -5,15 +5,27 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; +using Azure; using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - public partial class ToolOutput : IUtf8JsonSerializable + public partial class ToolOutput : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ToolOutput)} does not support '{format}' format."); + } + writer.WriteStartObject(); if (Optional.IsDefined(ToolCallId)) { @@ -25,9 +37,108 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) writer.WritePropertyName("output"u8); writer.WriteStringValue(Output); } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } + ToolOutput IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ToolOutput)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeToolOutput(document.RootElement, options); + } + + internal static ToolOutput DeserializeToolOutput(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + Optional toolCallId = default; + Optional output = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("tool_call_id"u8)) + { + toolCallId = property.Value.GetString(); + continue; + } + if (property.NameEquals("output"u8)) + { + output = property.Value.GetString(); + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new ToolOutput(toolCallId.Value, output.Value, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(ToolOutput)} does not support '{options.Format}' format."); + } + } + + ToolOutput IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeToolOutput(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ToolOutput)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static ToolOutput FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeToolOutput(document.RootElement); + } + /// Convert into a Utf8JsonRequestContent. internal virtual RequestContent ToRequestContent() { diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ToolOutput.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ToolOutput.cs index 4e788e8ccff2..dea8cd8b4785 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ToolOutput.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ToolOutput.cs @@ -5,16 +5,62 @@ #nullable disable +using System; +using System.Collections.Generic; + namespace Azure.AI.OpenAI.Assistants { /// The data provided during a tool outputs submission to resolve pending tool calls and allow the model to continue. public partial class ToolOutput { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . public ToolOutput() { } + /// Initializes a new instance of . + /// The ID of the tool call being resolved, as provided in the tool calls of a required action from a run. + /// The output from the tool to be submitted. + /// Keeps track of any properties unknown to the library. + internal ToolOutput(string toolCallId, string output, IDictionary serializedAdditionalRawData) + { + ToolCallId = toolCallId; + Output = output; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + /// The ID of the tool call being resolved, as provided in the tool calls of a required action from a run. public string ToolCallId { get; set; } /// The output from the tool to be submitted. diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownCodeInterpreterToolCallOutput.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownCodeInterpreterToolCallOutput.Serialization.cs index b8f6a4947e62..4a283de3f8bf 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownCodeInterpreterToolCallOutput.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownCodeInterpreterToolCallOutput.Serialization.cs @@ -5,20 +5,71 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - internal partial class UnknownCodeInterpreterToolCallOutput + internal partial class UnknownCodeInterpreterToolCallOutput : IUtf8JsonSerializable, IJsonModel { - internal static UnknownCodeInterpreterToolCallOutput DeserializeUnknownCodeInterpreterToolCallOutput(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(CodeInterpreterToolCallOutput)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + CodeInterpreterToolCallOutput IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(CodeInterpreterToolCallOutput)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeUnknownCodeInterpreterToolCallOutput(document.RootElement, options); + } + + internal static UnknownCodeInterpreterToolCallOutput DeserializeUnknownCodeInterpreterToolCallOutput(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; } string type = "Unknown"; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("type"u8)) @@ -26,10 +77,46 @@ internal static UnknownCodeInterpreterToolCallOutput DeserializeUnknownCodeInter type = property.Value.GetString(); continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new UnknownCodeInterpreterToolCallOutput(type, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(CodeInterpreterToolCallOutput)} does not support '{options.Format}' format."); + } + } + + CodeInterpreterToolCallOutput IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeUnknownCodeInterpreterToolCallOutput(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(CodeInterpreterToolCallOutput)} does not support '{options.Format}' format."); } - return new UnknownCodeInterpreterToolCallOutput(type); } + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + /// Deserializes the model from a raw response. /// The response to deserialize the model from. internal static new UnknownCodeInterpreterToolCallOutput FromResponse(Response response) @@ -37,5 +124,13 @@ internal static UnknownCodeInterpreterToolCallOutput DeserializeUnknownCodeInter using var document = JsonDocument.Parse(response.Content); return DeserializeUnknownCodeInterpreterToolCallOutput(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal override RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownCodeInterpreterToolCallOutput.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownCodeInterpreterToolCallOutput.cs index 956c72b0c974..e623e2c0d790 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownCodeInterpreterToolCallOutput.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownCodeInterpreterToolCallOutput.cs @@ -5,6 +5,9 @@ #nullable disable +using System; +using System.Collections.Generic; + namespace Azure.AI.OpenAI.Assistants { /// Unknown version of CodeInterpreterToolCallOutput. @@ -12,7 +15,13 @@ internal partial class UnknownCodeInterpreterToolCallOutput : CodeInterpreterToo { /// Initializes a new instance of . /// The object type. - internal UnknownCodeInterpreterToolCallOutput(string type) : base(type) + /// Keeps track of any properties unknown to the library. + internal UnknownCodeInterpreterToolCallOutput(string type, IDictionary serializedAdditionalRawData) : base(type, serializedAdditionalRawData) + { + } + + /// Initializes a new instance of for deserialization. + internal UnknownCodeInterpreterToolCallOutput() { } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownMessageContent.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownMessageContent.Serialization.cs index ed11d5513fed..6eb981cd658d 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownMessageContent.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownMessageContent.Serialization.cs @@ -5,20 +5,71 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - internal partial class UnknownMessageContent + internal partial class UnknownMessageContent : IUtf8JsonSerializable, IJsonModel { - internal static UnknownMessageContent DeserializeUnknownMessageContent(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(MessageContent)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + MessageContent IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(MessageContent)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeUnknownMessageContent(document.RootElement, options); + } + + internal static UnknownMessageContent DeserializeUnknownMessageContent(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; } string type = "Unknown"; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("type"u8)) @@ -26,10 +77,46 @@ internal static UnknownMessageContent DeserializeUnknownMessageContent(JsonEleme type = property.Value.GetString(); continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new UnknownMessageContent(type, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(MessageContent)} does not support '{options.Format}' format."); + } + } + + MessageContent IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeUnknownMessageContent(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(MessageContent)} does not support '{options.Format}' format."); } - return new UnknownMessageContent(type); } + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + /// Deserializes the model from a raw response. /// The response to deserialize the model from. internal static new UnknownMessageContent FromResponse(Response response) @@ -37,5 +124,13 @@ internal static UnknownMessageContent DeserializeUnknownMessageContent(JsonEleme using var document = JsonDocument.Parse(response.Content); return DeserializeUnknownMessageContent(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal override RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownMessageContent.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownMessageContent.cs index c99054419730..b97dd8996dda 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownMessageContent.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownMessageContent.cs @@ -5,6 +5,9 @@ #nullable disable +using System; +using System.Collections.Generic; + namespace Azure.AI.OpenAI.Assistants { /// Unknown version of MessageContent. @@ -12,7 +15,13 @@ internal partial class UnknownMessageContent : MessageContent { /// Initializes a new instance of . /// The object type. - internal UnknownMessageContent(string type) : base(type) + /// Keeps track of any properties unknown to the library. + internal UnknownMessageContent(string type, IDictionary serializedAdditionalRawData) : base(type, serializedAdditionalRawData) + { + } + + /// Initializes a new instance of for deserialization. + internal UnknownMessageContent() { } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownMessageTextAnnotation.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownMessageTextAnnotation.Serialization.cs index 117f1a217fa8..04d78ff43e8d 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownMessageTextAnnotation.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownMessageTextAnnotation.Serialization.cs @@ -5,15 +5,70 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - internal partial class UnknownMessageTextAnnotation + internal partial class UnknownMessageTextAnnotation : IUtf8JsonSerializable, IJsonModel { - internal static UnknownMessageTextAnnotation DeserializeUnknownMessageTextAnnotation(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(MessageTextAnnotation)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type); + writer.WritePropertyName("text"u8); + writer.WriteStringValue(Text); + writer.WritePropertyName("start_index"u8); + writer.WriteNumberValue(StartIndex); + writer.WritePropertyName("end_index"u8); + writer.WriteNumberValue(EndIndex); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + MessageTextAnnotation IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(MessageTextAnnotation)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeUnknownMessageTextAnnotation(document.RootElement, options); + } + + internal static UnknownMessageTextAnnotation DeserializeUnknownMessageTextAnnotation(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; @@ -22,6 +77,8 @@ internal static UnknownMessageTextAnnotation DeserializeUnknownMessageTextAnnota string text = default; int startIndex = default; int endIndex = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("type"u8)) @@ -44,10 +101,46 @@ internal static UnknownMessageTextAnnotation DeserializeUnknownMessageTextAnnota endIndex = property.Value.GetInt32(); continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new UnknownMessageTextAnnotation(type, text, startIndex, endIndex, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(MessageTextAnnotation)} does not support '{options.Format}' format."); + } + } + + MessageTextAnnotation IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeUnknownMessageTextAnnotation(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(MessageTextAnnotation)} does not support '{options.Format}' format."); } - return new UnknownMessageTextAnnotation(type, text, startIndex, endIndex); } + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + /// Deserializes the model from a raw response. /// The response to deserialize the model from. internal static new UnknownMessageTextAnnotation FromResponse(Response response) @@ -55,5 +148,13 @@ internal static UnknownMessageTextAnnotation DeserializeUnknownMessageTextAnnota using var document = JsonDocument.Parse(response.Content); return DeserializeUnknownMessageTextAnnotation(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal override RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownMessageTextAnnotation.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownMessageTextAnnotation.cs index dfe14d871079..707b99138307 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownMessageTextAnnotation.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownMessageTextAnnotation.cs @@ -5,6 +5,9 @@ #nullable disable +using System; +using System.Collections.Generic; + namespace Azure.AI.OpenAI.Assistants { /// Unknown version of MessageTextAnnotation. @@ -15,7 +18,13 @@ internal partial class UnknownMessageTextAnnotation : MessageTextAnnotation /// The textual content associated with this text annotation item. /// The first text index associated with this text annotation. /// The last text index associated with this text annotation. - internal UnknownMessageTextAnnotation(string type, string text, int startIndex, int endIndex) : base(type, text, startIndex, endIndex) + /// Keeps track of any properties unknown to the library. + internal UnknownMessageTextAnnotation(string type, string text, int startIndex, int endIndex, IDictionary serializedAdditionalRawData) : base(type, text, startIndex, endIndex, serializedAdditionalRawData) + { + } + + /// Initializes a new instance of for deserialization. + internal UnknownMessageTextAnnotation() { } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownRequiredAction.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownRequiredAction.Serialization.cs index efefccd1d711..c0ffdcc2acc6 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownRequiredAction.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownRequiredAction.Serialization.cs @@ -5,20 +5,71 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - internal partial class UnknownRequiredAction + internal partial class UnknownRequiredAction : IUtf8JsonSerializable, IJsonModel { - internal static UnknownRequiredAction DeserializeUnknownRequiredAction(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(RequiredAction)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + RequiredAction IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(RequiredAction)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeUnknownRequiredAction(document.RootElement, options); + } + + internal static UnknownRequiredAction DeserializeUnknownRequiredAction(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; } string type = "Unknown"; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("type"u8)) @@ -26,10 +77,46 @@ internal static UnknownRequiredAction DeserializeUnknownRequiredAction(JsonEleme type = property.Value.GetString(); continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new UnknownRequiredAction(type, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(RequiredAction)} does not support '{options.Format}' format."); + } + } + + RequiredAction IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeUnknownRequiredAction(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(RequiredAction)} does not support '{options.Format}' format."); } - return new UnknownRequiredAction(type); } + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + /// Deserializes the model from a raw response. /// The response to deserialize the model from. internal static new UnknownRequiredAction FromResponse(Response response) @@ -37,5 +124,13 @@ internal static UnknownRequiredAction DeserializeUnknownRequiredAction(JsonEleme using var document = JsonDocument.Parse(response.Content); return DeserializeUnknownRequiredAction(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal override RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownRequiredAction.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownRequiredAction.cs index c8e25ca01bd8..6d2d70960de5 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownRequiredAction.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownRequiredAction.cs @@ -5,6 +5,9 @@ #nullable disable +using System; +using System.Collections.Generic; + namespace Azure.AI.OpenAI.Assistants { /// Unknown version of RequiredAction. @@ -12,7 +15,13 @@ internal partial class UnknownRequiredAction : RequiredAction { /// Initializes a new instance of . /// The object type. - internal UnknownRequiredAction(string type) : base(type) + /// Keeps track of any properties unknown to the library. + internal UnknownRequiredAction(string type, IDictionary serializedAdditionalRawData) : base(type, serializedAdditionalRawData) + { + } + + /// Initializes a new instance of for deserialization. + internal UnknownRequiredAction() { } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownRequiredToolCall.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownRequiredToolCall.Serialization.cs index 18b96e83ca6e..231968ca550c 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownRequiredToolCall.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownRequiredToolCall.Serialization.cs @@ -5,21 +5,74 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - internal partial class UnknownRequiredToolCall + internal partial class UnknownRequiredToolCall : IUtf8JsonSerializable, IJsonModel { - internal static UnknownRequiredToolCall DeserializeUnknownRequiredToolCall(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(RequiredToolCall)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type); + writer.WritePropertyName("id"u8); + writer.WriteStringValue(Id); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + RequiredToolCall IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(RequiredToolCall)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeUnknownRequiredToolCall(document.RootElement, options); + } + + internal static UnknownRequiredToolCall DeserializeUnknownRequiredToolCall(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; } string type = "Unknown"; string id = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("type"u8)) @@ -32,10 +85,46 @@ internal static UnknownRequiredToolCall DeserializeUnknownRequiredToolCall(JsonE id = property.Value.GetString(); continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new UnknownRequiredToolCall(type, id, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(RequiredToolCall)} does not support '{options.Format}' format."); + } + } + + RequiredToolCall IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeUnknownRequiredToolCall(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(RequiredToolCall)} does not support '{options.Format}' format."); } - return new UnknownRequiredToolCall(type, id); } + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + /// Deserializes the model from a raw response. /// The response to deserialize the model from. internal static new UnknownRequiredToolCall FromResponse(Response response) @@ -43,5 +132,13 @@ internal static UnknownRequiredToolCall DeserializeUnknownRequiredToolCall(JsonE using var document = JsonDocument.Parse(response.Content); return DeserializeUnknownRequiredToolCall(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal override RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownRequiredToolCall.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownRequiredToolCall.cs index c9b4ade3898b..bd858412c475 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownRequiredToolCall.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownRequiredToolCall.cs @@ -5,6 +5,9 @@ #nullable disable +using System; +using System.Collections.Generic; + namespace Azure.AI.OpenAI.Assistants { /// Unknown version of RequiredToolCall. @@ -13,7 +16,13 @@ internal partial class UnknownRequiredToolCall : RequiredToolCall /// Initializes a new instance of . /// The object type for the required tool call. /// The ID of the tool call. This ID must be referenced when submitting tool outputs. - internal UnknownRequiredToolCall(string type, string id) : base(type, id) + /// Keeps track of any properties unknown to the library. + internal UnknownRequiredToolCall(string type, string id, IDictionary serializedAdditionalRawData) : base(type, id, serializedAdditionalRawData) + { + } + + /// Initializes a new instance of for deserialization. + internal UnknownRequiredToolCall() { } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownRunStepDetails.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownRunStepDetails.Serialization.cs index f054ddaa6d6d..ccce2282e66e 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownRunStepDetails.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownRunStepDetails.Serialization.cs @@ -5,20 +5,71 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - internal partial class UnknownRunStepDetails + internal partial class UnknownRunStepDetails : IUtf8JsonSerializable, IJsonModel { - internal static UnknownRunStepDetails DeserializeUnknownRunStepDetails(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(RunStepDetails)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type.ToString()); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + RunStepDetails IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(RunStepDetails)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeUnknownRunStepDetails(document.RootElement, options); + } + + internal static UnknownRunStepDetails DeserializeUnknownRunStepDetails(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; } RunStepType type = "Unknown"; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("type"u8)) @@ -26,10 +77,46 @@ internal static UnknownRunStepDetails DeserializeUnknownRunStepDetails(JsonEleme type = new RunStepType(property.Value.GetString()); continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new UnknownRunStepDetails(type, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(RunStepDetails)} does not support '{options.Format}' format."); + } + } + + RunStepDetails IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeUnknownRunStepDetails(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(RunStepDetails)} does not support '{options.Format}' format."); } - return new UnknownRunStepDetails(type); } + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + /// Deserializes the model from a raw response. /// The response to deserialize the model from. internal static new UnknownRunStepDetails FromResponse(Response response) @@ -37,5 +124,13 @@ internal static UnknownRunStepDetails DeserializeUnknownRunStepDetails(JsonEleme using var document = JsonDocument.Parse(response.Content); return DeserializeUnknownRunStepDetails(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal override RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownRunStepDetails.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownRunStepDetails.cs index 023e9b33a506..11d6cdeccbe7 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownRunStepDetails.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownRunStepDetails.cs @@ -5,6 +5,9 @@ #nullable disable +using System; +using System.Collections.Generic; + namespace Azure.AI.OpenAI.Assistants { /// Unknown version of RunStepDetails. @@ -12,7 +15,13 @@ internal partial class UnknownRunStepDetails : RunStepDetails { /// Initializes a new instance of . /// The object type. - internal UnknownRunStepDetails(RunStepType type) : base(type) + /// Keeps track of any properties unknown to the library. + internal UnknownRunStepDetails(RunStepType type, IDictionary serializedAdditionalRawData) : base(type, serializedAdditionalRawData) + { + } + + /// Initializes a new instance of for deserialization. + internal UnknownRunStepDetails() { } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownToolCall.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownToolCall.Serialization.cs index 976feed0182c..dbc8cdcda823 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownToolCall.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownToolCall.Serialization.cs @@ -5,21 +5,74 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - internal partial class UnknownToolCall + internal partial class UnknownToolCall : IUtf8JsonSerializable, IJsonModel { - internal static UnknownToolCall DeserializeUnknownToolCall(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ToolCall)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type); + writer.WritePropertyName("id"u8); + writer.WriteStringValue(Id); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ToolCall IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ToolCall)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeUnknownToolCall(document.RootElement, options); + } + + internal static UnknownToolCall DeserializeUnknownToolCall(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; } string type = "Unknown"; string id = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("type"u8)) @@ -32,10 +85,46 @@ internal static UnknownToolCall DeserializeUnknownToolCall(JsonElement element) id = property.Value.GetString(); continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new UnknownToolCall(type, id, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(ToolCall)} does not support '{options.Format}' format."); + } + } + + ToolCall IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeUnknownToolCall(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ToolCall)} does not support '{options.Format}' format."); } - return new UnknownToolCall(type, id); } + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + /// Deserializes the model from a raw response. /// The response to deserialize the model from. internal static new UnknownToolCall FromResponse(Response response) @@ -43,5 +132,13 @@ internal static UnknownToolCall DeserializeUnknownToolCall(JsonElement element) using var document = JsonDocument.Parse(response.Content); return DeserializeUnknownToolCall(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal override RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownToolCall.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownToolCall.cs index 4db2276f6d45..066509524dbb 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownToolCall.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownToolCall.cs @@ -5,6 +5,9 @@ #nullable disable +using System; +using System.Collections.Generic; + namespace Azure.AI.OpenAI.Assistants { /// Unknown version of ToolCall. @@ -13,7 +16,13 @@ internal partial class UnknownToolCall : ToolCall /// Initializes a new instance of . /// The object type. /// The ID of the tool call. This ID must be referenced when you submit tool outputs. - internal UnknownToolCall(string type, string id) : base(type, id) + /// Keeps track of any properties unknown to the library. + internal UnknownToolCall(string type, string id, IDictionary serializedAdditionalRawData) : base(type, id, serializedAdditionalRawData) + { + } + + /// Initializes a new instance of for deserialization. + internal UnknownToolCall() { } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownToolDefinition.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownToolDefinition.Serialization.cs index 245df8cfb60d..01fe6ce100ae 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownToolDefinition.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownToolDefinition.Serialization.cs @@ -5,20 +5,71 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - internal partial class UnknownToolDefinition + internal partial class UnknownToolDefinition : IUtf8JsonSerializable, IJsonModel { - internal static UnknownToolDefinition DeserializeUnknownToolDefinition(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ToolDefinition)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ToolDefinition IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ToolDefinition)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeUnknownToolDefinition(document.RootElement, options); + } + + internal static UnknownToolDefinition DeserializeUnknownToolDefinition(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; } string type = "Unknown"; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("type"u8)) @@ -26,10 +77,46 @@ internal static UnknownToolDefinition DeserializeUnknownToolDefinition(JsonEleme type = property.Value.GetString(); continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new UnknownToolDefinition(type, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(ToolDefinition)} does not support '{options.Format}' format."); + } + } + + ToolDefinition IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeUnknownToolDefinition(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ToolDefinition)} does not support '{options.Format}' format."); } - return new UnknownToolDefinition(type); } + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + /// Deserializes the model from a raw response. /// The response to deserialize the model from. internal static new UnknownToolDefinition FromResponse(Response response) @@ -37,5 +124,13 @@ internal static UnknownToolDefinition DeserializeUnknownToolDefinition(JsonEleme using var document = JsonDocument.Parse(response.Content); return DeserializeUnknownToolDefinition(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal override RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownToolDefinition.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownToolDefinition.cs index 6c06da69d2e3..9d7f65acf52c 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownToolDefinition.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownToolDefinition.cs @@ -5,6 +5,9 @@ #nullable disable +using System; +using System.Collections.Generic; + namespace Azure.AI.OpenAI.Assistants { /// Unknown version of ToolDefinition. @@ -12,7 +15,13 @@ internal partial class UnknownToolDefinition : ToolDefinition { /// Initializes a new instance of . /// The object type. - internal UnknownToolDefinition(string type) : base(type) + /// Keeps track of any properties unknown to the library. + internal UnknownToolDefinition(string type, IDictionary serializedAdditionalRawData) : base(type, serializedAdditionalRawData) + { + } + + /// Initializes a new instance of for deserialization. + internal UnknownToolDefinition() { } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateAssistantOptions.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateAssistantOptions.Serialization.cs index f34faaa5e02f..62a40df0870d 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateAssistantOptions.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateAssistantOptions.Serialization.cs @@ -5,15 +5,27 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; +using Azure; using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - public partial class UpdateAssistantOptions : IUtf8JsonSerializable + public partial class UpdateAssistantOptions : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(UpdateAssistantOptions)} does not support '{format}' format."); + } + writer.WriteStartObject(); if (Optional.IsDefined(Model)) { @@ -94,9 +106,180 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) writer.WriteNull("metadata"); } } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } + UpdateAssistantOptions IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(UpdateAssistantOptions)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeUpdateAssistantOptions(document.RootElement, options); + } + + internal static UpdateAssistantOptions DeserializeUpdateAssistantOptions(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + Optional model = default; + Optional name = default; + Optional description = default; + Optional instructions = default; + Optional> tools = default; + Optional> fileIds = default; + Optional> metadata = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("model"u8)) + { + model = property.Value.GetString(); + continue; + } + if (property.NameEquals("name"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + name = null; + continue; + } + name = property.Value.GetString(); + continue; + } + if (property.NameEquals("description"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + description = null; + continue; + } + description = property.Value.GetString(); + continue; + } + if (property.NameEquals("instructions"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + instructions = null; + continue; + } + instructions = property.Value.GetString(); + continue; + } + if (property.NameEquals("tools"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(ToolDefinition.DeserializeToolDefinition(item)); + } + tools = array; + continue; + } + if (property.NameEquals("file_ids"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(item.GetString()); + } + fileIds = array; + continue; + } + if (property.NameEquals("metadata"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + Dictionary dictionary = new Dictionary(); + foreach (var property0 in property.Value.EnumerateObject()) + { + dictionary.Add(property0.Name, property0.Value.GetString()); + } + metadata = dictionary; + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new UpdateAssistantOptions(model.Value, name.Value, description.Value, instructions.Value, Optional.ToList(tools), Optional.ToList(fileIds), Optional.ToDictionary(metadata), serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(UpdateAssistantOptions)} does not support '{options.Format}' format."); + } + } + + UpdateAssistantOptions IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeUpdateAssistantOptions(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(UpdateAssistantOptions)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static UpdateAssistantOptions FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeUpdateAssistantOptions(document.RootElement); + } + /// Convert into a Utf8JsonRequestContent. internal virtual RequestContent ToRequestContent() { diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateAssistantOptions.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateAssistantOptions.cs index 3d300ca50e04..d69298f5f65a 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateAssistantOptions.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateAssistantOptions.cs @@ -5,6 +5,7 @@ #nullable disable +using System; using System.Collections.Generic; using Azure.Core; @@ -13,6 +14,38 @@ namespace Azure.AI.OpenAI.Assistants /// The request details to use when modifying an existing assistant. public partial class UpdateAssistantOptions { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . public UpdateAssistantOptions() { @@ -29,7 +62,8 @@ public UpdateAssistantOptions() /// The modified collection of tools to enable for the assistant. /// The modified list of previously uploaded fileIDs to attach to the assistant. /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. - internal UpdateAssistantOptions(string model, string name, string description, string instructions, IList tools, IList fileIds, IDictionary metadata) + /// Keeps track of any properties unknown to the library. + internal UpdateAssistantOptions(string model, string name, string description, string instructions, IList tools, IList fileIds, IDictionary metadata, IDictionary serializedAdditionalRawData) { Model = model; Name = name; @@ -38,6 +72,7 @@ internal UpdateAssistantOptions(string model, string name, string description, s Tools = tools; FileIds = fileIds; Metadata = metadata; + _serializedAdditionalRawData = serializedAdditionalRawData; } /// The ID of the model to use. diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateMessageRequest.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateMessageRequest.Serialization.cs index 87c5f61ca88f..aac2c62a0ec4 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateMessageRequest.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateMessageRequest.Serialization.cs @@ -5,15 +5,27 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; +using Azure; using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - internal partial class UpdateMessageRequest : IUtf8JsonSerializable + internal partial class UpdateMessageRequest : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(UpdateMessageRequest)} does not support '{format}' format."); + } + writer.WriteStartObject(); if (Optional.IsCollectionDefined(Metadata)) { @@ -33,9 +45,111 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) writer.WriteNull("metadata"); } } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } + UpdateMessageRequest IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(UpdateMessageRequest)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeUpdateMessageRequest(document.RootElement, options); + } + + internal static UpdateMessageRequest DeserializeUpdateMessageRequest(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + Optional> metadata = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("metadata"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + Dictionary dictionary = new Dictionary(); + foreach (var property0 in property.Value.EnumerateObject()) + { + dictionary.Add(property0.Name, property0.Value.GetString()); + } + metadata = dictionary; + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new UpdateMessageRequest(Optional.ToDictionary(metadata), serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(UpdateMessageRequest)} does not support '{options.Format}' format."); + } + } + + UpdateMessageRequest IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeUpdateMessageRequest(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(UpdateMessageRequest)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static UpdateMessageRequest FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeUpdateMessageRequest(document.RootElement); + } + /// Convert into a Utf8JsonRequestContent. internal virtual RequestContent ToRequestContent() { diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateMessageRequest.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateMessageRequest.cs index 6a666c7f4f67..ca29b11092ff 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateMessageRequest.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateMessageRequest.cs @@ -5,6 +5,7 @@ #nullable disable +using System; using System.Collections.Generic; using Azure.Core; @@ -13,6 +14,38 @@ namespace Azure.AI.OpenAI.Assistants /// The UpdateMessageRequest. internal partial class UpdateMessageRequest { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . public UpdateMessageRequest() { @@ -21,9 +54,11 @@ public UpdateMessageRequest() /// Initializes a new instance of . /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. - internal UpdateMessageRequest(IDictionary metadata) + /// Keeps track of any properties unknown to the library. + internal UpdateMessageRequest(IDictionary metadata, IDictionary serializedAdditionalRawData) { Metadata = metadata; + _serializedAdditionalRawData = serializedAdditionalRawData; } /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateRunRequest.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateRunRequest.Serialization.cs index 403a81afc374..79876c604db9 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateRunRequest.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateRunRequest.Serialization.cs @@ -5,15 +5,27 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; +using Azure; using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - internal partial class UpdateRunRequest : IUtf8JsonSerializable + internal partial class UpdateRunRequest : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(UpdateRunRequest)} does not support '{format}' format."); + } + writer.WriteStartObject(); if (Optional.IsCollectionDefined(Metadata)) { @@ -33,9 +45,111 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) writer.WriteNull("metadata"); } } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } + UpdateRunRequest IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(UpdateRunRequest)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeUpdateRunRequest(document.RootElement, options); + } + + internal static UpdateRunRequest DeserializeUpdateRunRequest(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + Optional> metadata = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("metadata"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + Dictionary dictionary = new Dictionary(); + foreach (var property0 in property.Value.EnumerateObject()) + { + dictionary.Add(property0.Name, property0.Value.GetString()); + } + metadata = dictionary; + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new UpdateRunRequest(Optional.ToDictionary(metadata), serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(UpdateRunRequest)} does not support '{options.Format}' format."); + } + } + + UpdateRunRequest IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeUpdateRunRequest(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(UpdateRunRequest)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static UpdateRunRequest FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeUpdateRunRequest(document.RootElement); + } + /// Convert into a Utf8JsonRequestContent. internal virtual RequestContent ToRequestContent() { diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateRunRequest.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateRunRequest.cs index fff7fc1dde7d..f152fd715831 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateRunRequest.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateRunRequest.cs @@ -5,6 +5,7 @@ #nullable disable +using System; using System.Collections.Generic; using Azure.Core; @@ -13,6 +14,38 @@ namespace Azure.AI.OpenAI.Assistants /// The UpdateRunRequest. internal partial class UpdateRunRequest { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . public UpdateRunRequest() { @@ -21,9 +54,11 @@ public UpdateRunRequest() /// Initializes a new instance of . /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. - internal UpdateRunRequest(IDictionary metadata) + /// Keeps track of any properties unknown to the library. + internal UpdateRunRequest(IDictionary metadata, IDictionary serializedAdditionalRawData) { Metadata = metadata; + _serializedAdditionalRawData = serializedAdditionalRawData; } /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateThreadRequest.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateThreadRequest.Serialization.cs index 1152d8d9b446..cf64c90c7641 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateThreadRequest.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateThreadRequest.Serialization.cs @@ -5,15 +5,27 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; +using Azure; using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - internal partial class UpdateThreadRequest : IUtf8JsonSerializable + internal partial class UpdateThreadRequest : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(UpdateThreadRequest)} does not support '{format}' format."); + } + writer.WriteStartObject(); if (Optional.IsCollectionDefined(Metadata)) { @@ -33,9 +45,111 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) writer.WriteNull("metadata"); } } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } + UpdateThreadRequest IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(UpdateThreadRequest)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeUpdateThreadRequest(document.RootElement, options); + } + + internal static UpdateThreadRequest DeserializeUpdateThreadRequest(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + Optional> metadata = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("metadata"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + Dictionary dictionary = new Dictionary(); + foreach (var property0 in property.Value.EnumerateObject()) + { + dictionary.Add(property0.Name, property0.Value.GetString()); + } + metadata = dictionary; + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new UpdateThreadRequest(Optional.ToDictionary(metadata), serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(UpdateThreadRequest)} does not support '{options.Format}' format."); + } + } + + UpdateThreadRequest IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeUpdateThreadRequest(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(UpdateThreadRequest)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static UpdateThreadRequest FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeUpdateThreadRequest(document.RootElement); + } + /// Convert into a Utf8JsonRequestContent. internal virtual RequestContent ToRequestContent() { diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateThreadRequest.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateThreadRequest.cs index 1932f7fe6e88..8705af25b827 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateThreadRequest.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateThreadRequest.cs @@ -5,6 +5,7 @@ #nullable disable +using System; using System.Collections.Generic; using Azure.Core; @@ -13,6 +14,38 @@ namespace Azure.AI.OpenAI.Assistants /// The UpdateThreadRequest. internal partial class UpdateThreadRequest { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . public UpdateThreadRequest() { @@ -21,9 +54,11 @@ public UpdateThreadRequest() /// Initializes a new instance of . /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. - internal UpdateThreadRequest(IDictionary metadata) + /// Keeps track of any properties unknown to the library. + internal UpdateThreadRequest(IDictionary metadata, IDictionary serializedAdditionalRawData) { Metadata = metadata; + _serializedAdditionalRawData = serializedAdditionalRawData; } /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UploadFileRequest.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UploadFileRequest.Serialization.cs index 0206b80fb3ef..1730b8d75417 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UploadFileRequest.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UploadFileRequest.Serialization.cs @@ -5,15 +5,27 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; +using Azure; using Azure.Core; namespace Azure.AI.OpenAI.Assistants { - internal partial class UploadFileRequest : IUtf8JsonSerializable + internal partial class UploadFileRequest : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(UploadFileRequest)} does not support '{format}' format."); + } + writer.WriteStartObject(); writer.WritePropertyName("file"u8); writer.WriteBase64StringValue(Data.ToArray(), "D"); @@ -24,7 +36,112 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) writer.WritePropertyName("filename"u8); writer.WriteStringValue(Filename); } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } + + UploadFileRequest IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(UploadFileRequest)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeUploadFileRequest(document.RootElement, options); + } + + internal static UploadFileRequest DeserializeUploadFileRequest(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + BinaryData file = default; + OpenAIFilePurpose purpose = default; + Optional filename = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("file"u8)) + { + file = BinaryData.FromBytes(property.Value.GetBytesFromBase64("D")); + continue; + } + if (property.NameEquals("purpose"u8)) + { + purpose = new OpenAIFilePurpose(property.Value.GetString()); + continue; + } + if (property.NameEquals("filename"u8)) + { + filename = property.Value.GetString(); + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new UploadFileRequest(file, purpose, filename.Value, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(UploadFileRequest)} does not support '{options.Format}' format."); + } + } + + UploadFileRequest IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeUploadFileRequest(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(UploadFileRequest)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static UploadFileRequest FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeUploadFileRequest(document.RootElement); + } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UploadFileRequest.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UploadFileRequest.cs index e276c52bea44..7167d9b9b836 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UploadFileRequest.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UploadFileRequest.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.Collections.Generic; using Azure.Core; namespace Azure.AI.OpenAI.Assistants @@ -13,6 +14,38 @@ namespace Azure.AI.OpenAI.Assistants /// The UploadFileRequest. internal partial class UploadFileRequest { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . /// The file data (not filename) to upload. /// The intended purpose of the file. @@ -29,11 +62,18 @@ public UploadFileRequest(BinaryData data, OpenAIFilePurpose purpose) /// The file data (not filename) to upload. /// The intended purpose of the file. /// A filename to associate with the uploaded data. - internal UploadFileRequest(BinaryData data, OpenAIFilePurpose purpose, string filename) + /// Keeps track of any properties unknown to the library. + internal UploadFileRequest(BinaryData data, OpenAIFilePurpose purpose, string filename, IDictionary serializedAdditionalRawData) { Data = data; Purpose = purpose; Filename = filename; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal UploadFileRequest() + { } /// diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/tsp-location.yaml b/sdk/openai/Azure.AI.OpenAI.Assistants/tsp-location.yaml index 867841ef36ac..7dcfadf887ed 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/tsp-location.yaml +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/tsp-location.yaml @@ -1,3 +1,3 @@ directory: specification/ai/OpenAI.Assistants -commit: cacb3dc095486d8691c47dea944fc9ed0f4d0e32 +commit: 58dfeeb745313762369e040f9e0d440c6868ebdb repo: Azure/azure-rest-api-specs