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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions api/OpenAI.net8.0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2623,8 +2623,8 @@ public class ConversationClient {
public virtual Task<ClientResult> GetConversationAsync(string conversationId, RequestOptions options = null);
public virtual ClientResult GetConversationItem(string conversationId, string itemId, IEnumerable<IncludedConversationItemProperty> include = null, RequestOptions options = null);
public virtual Task<ClientResult> GetConversationItemAsync(string conversationId, string itemId, IEnumerable<IncludedConversationItemProperty> include = null, RequestOptions options = null);
public virtual ClientResult GetConversationItems(string conversationId, long? limit = null, string order = null, string after = null, IEnumerable<IncludedConversationItemProperty> include = null, RequestOptions options = null);
public virtual Task<ClientResult> GetConversationItemsAsync(string conversationId, long? limit = null, string order = null, string after = null, IEnumerable<IncludedConversationItemProperty> include = null, RequestOptions options = null);
public virtual CollectionResult GetConversationItems(string conversationId, long? limit = null, string order = null, string after = null, IEnumerable<IncludedConversationItemProperty> include = null, RequestOptions options = null);
public virtual AsyncCollectionResult GetConversationItemsAsync(string conversationId, long? limit = null, string order = null, string after = null, IEnumerable<IncludedConversationItemProperty> include = null, RequestOptions options = null);
public virtual ClientResult UpdateConversation(string conversationId, BinaryContent content, RequestOptions options = null);
public virtual Task<ClientResult> UpdateConversationAsync(string conversationId, BinaryContent content, RequestOptions options = null);
}
Expand Down
4 changes: 2 additions & 2 deletions api/OpenAI.netstandard2.0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2257,8 +2257,8 @@ public class ConversationClient {
public virtual Task<ClientResult> GetConversationAsync(string conversationId, RequestOptions options = null);
public virtual ClientResult GetConversationItem(string conversationId, string itemId, IEnumerable<IncludedConversationItemProperty> include = null, RequestOptions options = null);
public virtual Task<ClientResult> GetConversationItemAsync(string conversationId, string itemId, IEnumerable<IncludedConversationItemProperty> include = null, RequestOptions options = null);
public virtual ClientResult GetConversationItems(string conversationId, long? limit = null, string order = null, string after = null, IEnumerable<IncludedConversationItemProperty> include = null, RequestOptions options = null);
public virtual Task<ClientResult> GetConversationItemsAsync(string conversationId, long? limit = null, string order = null, string after = null, IEnumerable<IncludedConversationItemProperty> include = null, RequestOptions options = null);
public virtual CollectionResult GetConversationItems(string conversationId, long? limit = null, string order = null, string after = null, IEnumerable<IncludedConversationItemProperty> include = null, RequestOptions options = null);
public virtual AsyncCollectionResult GetConversationItemsAsync(string conversationId, long? limit = null, string order = null, string after = null, IEnumerable<IncludedConversationItemProperty> include = null, RequestOptions options = null);
public virtual ClientResult UpdateConversation(string conversationId, BinaryContent content, RequestOptions options = null);
public virtual Task<ClientResult> UpdateConversationAsync(string conversationId, BinaryContent content, RequestOptions options = null);
}
Expand Down
33 changes: 23 additions & 10 deletions examples/Conversations/Example01_ConversationProtocol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using OpenAI.Conversations;
using System;
using System.ClientModel;
using System.ClientModel.Primitives;
using System.Collections.Generic;
using System.Text.Json;

namespace OpenAI.Examples;
Expand All @@ -25,6 +27,11 @@ public void Example01_ConversationProtocol()
"type": "message",
"role": "user",
"content": "Say 'this is a test.'"
},
{
"type": "message",
"role": "assistant",
"content": "This is a test."
}
]
}
Expand All @@ -37,26 +44,32 @@ public void Example01_ConversationProtocol()
.GetProperty("id"u8)
.GetString();

Console.WriteLine($"Conversation created. Conversation ID: {conversationId}");
Console.WriteLine($"Conversation created.");
Console.WriteLine($" Conversation ID: {conversationId}");
Console.WriteLine();

ClientResult getConversationItemsResult = client.GetConversationItems(conversationId);
using JsonDocument getConversationItemsResultAsJson = JsonDocument.Parse(getConversationItemsResult.GetRawResponse().Content.ToString());
string messageId = getConversationItemsResultAsJson.RootElement
.GetProperty("data"u8)[0]
.GetProperty("id"u8)
.ToString();
CollectionResult getConversationItemsResults = client.GetConversationItems(conversationId);
foreach (ClientResult result in getConversationItemsResults.GetRawPages())
{
using JsonDocument getConversationItemsResultAsJson = JsonDocument.Parse(result.GetRawResponse().Content.ToString());
foreach (JsonElement element in getConversationItemsResultAsJson.RootElement.GetProperty("data").EnumerateArray())
{
string messageId = element.GetProperty("id"u8).ToString();

Console.WriteLine($"Message retrieved. Message ID: {messageId}");
Console.WriteLine();
Console.WriteLine($"Message retrieved.");
Console.WriteLine($" Message ID: {messageId}");
Console.WriteLine();
}
}

ClientResult deleteConversationResult = client.DeleteConversation(conversationId);
using JsonDocument deleteConversationResultAsJson = JsonDocument.Parse(deleteConversationResult.GetRawResponse().Content.ToString());
bool deleted = deleteConversationResultAsJson.RootElement
.GetProperty("deleted"u8)
.GetBoolean();

Console.WriteLine($"Conversation deleted: {deleted}");
Console.WriteLine($"Conversation deleted.");
Console.WriteLine($" Deleted: {deleted}");
Console.WriteLine();
}
}
Expand Down
32 changes: 22 additions & 10 deletions examples/Conversations/Example01_ConversationProtocolAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using OpenAI.Conversations;
using System;
using System.ClientModel;
using System.ClientModel.Primitives;
using System.Text.Json;
using System.Threading.Tasks;

Expand All @@ -26,6 +27,11 @@ public async Task Example01_ConversationProtocolAsync()
"type": "message",
"role": "user",
"content": "Say 'this is a test.'"
},
{
"type": "message",
"role": "assistant",
"content": "This is a test."
}
]
}
Expand All @@ -38,26 +44,32 @@ public async Task Example01_ConversationProtocolAsync()
.GetProperty("id"u8)
.GetString();

Console.WriteLine($"Conversation created. Conversation ID: {conversationId}");
Console.WriteLine($"Conversation created.");
Console.WriteLine($" Conversation ID: {conversationId}");
Console.WriteLine();

ClientResult getConversationItemsResult = await client.GetConversationItemsAsync(conversationId);
using JsonDocument getConversationItemsResultAsJson = JsonDocument.Parse(getConversationItemsResult.GetRawResponse().Content.ToString());
string messageId = getConversationItemsResultAsJson.RootElement
.GetProperty("data"u8)[0]
.GetProperty("id"u8)
.ToString();
AsyncCollectionResult getConversationItemsResults = client.GetConversationItemsAsync(conversationId);
await foreach(ClientResult result in getConversationItemsResults.GetRawPagesAsync())
{
using JsonDocument getConversationItemsResultAsJson = JsonDocument.Parse(result.GetRawResponse().Content.ToString());
foreach (JsonElement element in getConversationItemsResultAsJson.RootElement.GetProperty("data").EnumerateArray())
{
string messageId = element.GetProperty("id"u8).ToString();

Console.WriteLine($"Message retrieved. Message ID: {messageId}");
Console.WriteLine();
Console.WriteLine($"Message retrieved.");
Console.WriteLine($" Message ID: {messageId}");
Console.WriteLine();
}
}

ClientResult deleteConversationResult = await client.DeleteConversationAsync(conversationId);
using JsonDocument deleteConversationResultAsJson = JsonDocument.Parse(deleteConversationResult.GetRawResponse().Content.ToString());
bool deleted = deleteConversationResultAsJson.RootElement
.GetProperty("deleted"u8)
.GetBoolean();

Console.WriteLine($"Conversation deleted: {deleted}");
Console.WriteLine($"Conversation deleted.");
Console.WriteLine($" Deleted: {deleted}");
Console.WriteLine();
}
}
Expand Down
4 changes: 2 additions & 2 deletions specification/base/typespec/conversations/models.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ model ConversationItemList {
object: "list";

/** A list of conversation items. */
data: ItemResource[];
@pageItems data: ItemResource[];

/** Whether there are more items available. */
#suppress "@azure-tools/typespec-azure-core/casing-style" "Auto-suppressed warnings non-applicable rules during import."
Expand All @@ -58,7 +58,7 @@ model ConversationItemList {

/** The ID of the last item in the list. */
#suppress "@azure-tools/typespec-azure-core/casing-style" "Auto-suppressed warnings non-applicable rules during import."
last_id: string;
@continuationToken last_id: string;
}

#suppress "@azure-tools/typespec-azure-core/documentation-required" "Auto-suppressed warnings non-applicable rules during import."
Expand Down
1 change: 1 addition & 0 deletions specification/base/typespec/conversations/operations.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ namespace OpenAI;
}
)
@tag("Conversations")
@list
op listConversationItems(
/** The ID of the conversation to list items for. */
#suppress "@azure-tools/typespec-azure-core/casing-style" "Auto-suppressed warnings non-applicable rules during import."
Expand Down
25 changes: 13 additions & 12 deletions specification/client/models/assistants.models.tsp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import "../../base/typespec/assistants/main.tsp";
import "./common.models.tsp";
import "@azure-tools/typespec-client-generator-core";

using Azure.ClientGenerator.Core;
Expand All @@ -23,9 +24,9 @@ union AssistantCollectionOrder {
@access(Access.public)
@usage(Usage.input)
model AssistantCollectionOptions {
...CollectionAfterQueryParameter,
...CollectionBeforeQueryParameter,
...CollectionLimitQueryParameter,
...DotNetCollectionAfterQueryParameter,
...DotNetCollectionBeforeQueryParameter,
...DotNetCollectionLimitQueryParameter,
...AssistantCollectionOrderQueryParameter,
}

Expand All @@ -46,18 +47,18 @@ union MessageCollectionOrder {
@access(Access.public)
@usage(Usage.input)
model MessageCollectionOptions {
...CollectionAfterQueryParameter,
...CollectionBeforeQueryParameter,
...CollectionLimitQueryParameter,
...DotNetCollectionAfterQueryParameter,
...DotNetCollectionBeforeQueryParameter,
...DotNetCollectionLimitQueryParameter,
...MessageCollectionOrderQueryParameter,
}

@access(Access.public)
@usage(Usage.input)
model RunCollectionOptions {
...CollectionAfterQueryParameter,
...CollectionBeforeQueryParameter,
...CollectionLimitQueryParameter,
...DotNetCollectionAfterQueryParameter,
...DotNetCollectionBeforeQueryParameter,
...DotNetCollectionLimitQueryParameter,
...RunCollectionOrderQueryParameter,
}

Expand All @@ -78,9 +79,9 @@ union RunCollectionOrder {
@access(Access.public)
@usage(Usage.input)
model RunStepCollectionOptions {
...CollectionAfterQueryParameter,
...CollectionBeforeQueryParameter,
...CollectionLimitQueryParameter,
...DotNetCollectionAfterQueryParameter,
...DotNetCollectionBeforeQueryParameter,
...DotNetCollectionLimitQueryParameter,
...RunStepCollectionOrderQueryParameter,
}

Expand Down
5 changes: 3 additions & 2 deletions specification/client/models/batch.models.tsp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import "../../base/typespec/batch/main.tsp";
import "./common.models.tsp";
import "@azure-tools/typespec-client-generator-core";

using Azure.ClientGenerator.Core;
Expand All @@ -8,8 +9,8 @@ namespace OpenAI;
@access(Access.public)
@usage(Usage.input)
model BatchCollectionOptions {
...CollectionAfterQueryParameter,
...CollectionLimitQueryParameter,
...DotNetCollectionAfterQueryParameter,
...DotNetCollectionLimitQueryParameter,
}


10 changes: 5 additions & 5 deletions specification/client/models/chat.models.tsp
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import "../../base/typespec/chat/main.tsp";
import "./common.models.tsp";
import "@azure-tools/typespec-client-generator-core";

using Azure.ClientGenerator.Core;
using TypeSpec.Http;

namespace OpenAI;


alias ChatCompletionCollectionOrderQueryParameter = {
/**
* Sort order by the `created_at` timestamp of the objects. `asc` for ascending order and`desc`
Expand All @@ -24,8 +24,8 @@ union ChatCompletionCollectionOrder {
@access(Access.public)
@usage(Usage.input)
model ChatCompletionCollectionOptions {
...CollectionAfterQueryParameter,
...CollectionLimitQueryParameter,
...DotNetCollectionAfterQueryParameter,
...DotNetCollectionLimitQueryParameter,
...ChatCompletionCollectionOrderQueryParameter,
@query metadata?: Record<string>,
@query `model`?: string,
Expand All @@ -48,8 +48,8 @@ union ChatCompletionMessageCollectionOrder {
@access(Access.public)
@usage(Usage.input)
model ChatCompletionMessageCollectionOptions {
...CollectionAfterQueryParameter,
...CollectionLimitQueryParameter,
...DotNetCollectionAfterQueryParameter,
...DotNetCollectionLimitQueryParameter,
...ChatCompletionMessageCollectionOrderQueryParameter,
}

Expand Down
6 changes: 3 additions & 3 deletions specification/client/models/common.models.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,15 @@ union DotNetRealtimeVoiceIds {

// CollectionQueryParameters

alias CollectionLimitQueryParameter = {
alias DotNetCollectionLimitQueryParameter = {
/**
* A limit on the number of objects to be returned. Limit can range between 1 and 100, and the
* default is 20.
*/
@query pageSizeLimit?: int32 = 20;
};

alias CollectionAfterQueryParameter = {
alias DotNetCollectionAfterQueryParameter = {
/**
* 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
Expand All @@ -136,7 +136,7 @@ alias CollectionAfterQueryParameter = {
@query @continuationToken afterId?: string;
};

alias CollectionBeforeQueryParameter = {
alias DotNetCollectionBeforeQueryParameter = {
/**
* 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, starting with obj_foo, your
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import "../../base/typespec/containers/main.tsp";
import "./common.models.tsp";
import "@azure-tools/typespec-client-generator-core";

using Azure.ClientGenerator.Core;
Expand All @@ -23,8 +24,8 @@ union ContainerCollectionOrder {
@access(Access.public)
@usage(Usage.input)
model ContainerCollectionOptions {
...CollectionAfterQueryParameter,
...CollectionLimitQueryParameter,
...DotNetCollectionAfterQueryParameter,
...DotNetCollectionLimitQueryParameter,
...ContainerCollectionOrderQueryParameter,
}

Expand All @@ -45,7 +46,7 @@ union ContainerFileCollectionOrder {
@access(Access.public)
@usage(Usage.input)
model ContainerFileCollectionOptions {
...CollectionAfterQueryParameter,
...CollectionLimitQueryParameter,
...DotNetCollectionAfterQueryParameter,
...DotNetCollectionLimitQueryParameter,
...ContainerFileCollectionOrderQueryParameter,
}
30 changes: 30 additions & 0 deletions specification/client/models/conversations.models.tsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import "../../base/typespec/conversations/main.tsp";
import "./common.models.tsp";
import "@azure-tools/typespec-client-generator-core";

using Azure.ClientGenerator.Core;
using TypeSpec.Http;

namespace OpenAI;

alias ConversationItemCollectionOrderQueryParameter = {
/**
* Sort order by the `created_at` timestamp of the objects. `asc` for ascending order and`desc`
* for descending order.
*/
@query order?: ConversationItemCollectionOrder;
};

union ConversationItemCollectionOrder {
string,
Ascending: "asc",
Descending: "desc",
}

@access(Access.public)
@usage(Usage.input)
model ConversationItemCollectionOptions {
...DotNetCollectionAfterQueryParameter,
...DotNetCollectionLimitQueryParameter,
...ConversationItemCollectionOrderQueryParameter,
}
7 changes: 4 additions & 3 deletions specification/client/models/responses.models.tsp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import "../../base/typespec/responses/main.tsp";
import "./common.models.tsp";
import "@azure-tools/typespec-client-generator-core";

using Azure.ClientGenerator.Core;
Expand Down Expand Up @@ -30,9 +31,9 @@ union ResponseItemCollectionOrder {
@access(Access.public)
@usage(Usage.input)
model ResponseItemCollectionOptions {
...CollectionAfterQueryParameter;
...CollectionBeforeQueryParameter;
...CollectionLimitQueryParameter;
...DotNetCollectionAfterQueryParameter;
...DotNetCollectionBeforeQueryParameter;
...DotNetCollectionLimitQueryParameter;
...ResponseItemCollectionOrderQueryParameter;
}

Expand Down
Loading
Loading