Skip to content

Commit 9222e88

Browse files
committed
wip fix Content for ResponseContentPart
1 parent 9320b2a commit 9222e88

30 files changed

+10978
-9969
lines changed

codegen/generator/src/Visitors/PaginationVisitor.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class PaginationVisitor : ScmLibraryVisitor
2222
private static readonly Dictionary<string, string> _paramReplacementMap = new()
2323
{
2424
{ "after", "AfterId" },
25-
{ "before", "LastId" },
25+
{ "before", "BeforeId" },
2626
{ "limit", "PageSizeLimit" },
2727
{ "order", "Order" },
2828
{ "model", "Model" },
@@ -40,11 +40,19 @@ public class PaginationVisitor : ScmLibraryVisitor
4040
},
4141
{
4242
"GetChatCompletionMessages",
43-
("ChatCompletionMessageListDatum", "ChatCompletionCollectionOptions", _chatParamsToReplace)
43+
("ChatCompletionMessageListDatum", "ChatCompletionMessageCollectionOptions", _chatParamsToReplace)
4444
},
4545
{
4646
"GetChatCompletionMessagesAsync",
4747
("ChatCompletionMessageListDatum", "ChatCompletionMessageCollectionOptions", _chatParamsToReplace)
48+
},
49+
{
50+
"GetInputItems",
51+
("ResponseItem", "ResponseItemCollectionOptions", _chatParamsToReplace)
52+
},
53+
{
54+
"GetInputItemsAsync",
55+
("ResponseItem", "ResponseItemCollectionOptions", _chatParamsToReplace)
4856
}
4957
};
5058

specification/base/typespec/responses/models.tsp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,7 +1272,7 @@ model ResponseItemList {
12721272
object: "list";
12731273

12741274
/** A list of items used to generate this response. */
1275-
data: ItemResource[];
1275+
@pageItems data: ItemResource[];
12761276

12771277
/** Whether there are more items available. */
12781278
has_more: boolean;
@@ -1281,7 +1281,7 @@ model ResponseItemList {
12811281
first_id: string;
12821282

12831283
/** The ID of the last item in the list. */
1284-
last_id: string;
1284+
@continuationToken last_id: string;
12851285
}
12861286

12871287
// Tool customization: Establish discriminated type base

specification/base/typespec/responses/operations.tsp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ interface Responses {
8282
@operationId("listInputItems")
8383
@get
8484
@route("{response_id}/input_items")
85+
@list
8586
listInputItems(
8687
@path
8788
@example("resp_677efb5139a88190b512bc3fef8e535d")

specification/client/models/common.models.tsp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,13 @@ alias CollectionAfterQueryParameter = {
144144
* subsequent call can include after=obj_foo in order to fetch the next page of the list.
145145
*/
146146
@query @continuationToken afterId?: string;
147+
};
148+
149+
alias CollectionBeforeQueryParameter = {
150+
/**
151+
* A cursor for use in pagination. `before` is an object ID that defines your place in the list.
152+
* For instance, if you make a list request and receive 100 objects, starting with obj_foo, your
153+
* subsequent call can include before=obj_foo in order to fetch the previous page of the list.
154+
*/
155+
@query beforeId?: string;
147156
};

specification/client/models/responses.models.tsp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import "../../base/typespec/responses/main.tsp";
22
import "@azure-tools/typespec-client-generator-core";
33

44
using Azure.ClientGenerator.Core;
5+
using TypeSpec.Http;
56

67
namespace OpenAI;
78

@@ -25,3 +26,26 @@ model DotNetItemReferenceItemResource extends ItemResource {
2526
type: ItemType.item_reference;
2627
...ItemReferenceItemBase;
2728
}
29+
30+
alias ResponseItemCollectionOrderQueryParameter = {
31+
/**
32+
* Sort order by the `created_at` timestamp of the objects. `asc` for ascending order and`desc`
33+
* for descending order.
34+
*/
35+
@query order?: ResponseItemCollectionOrder;
36+
};
37+
38+
union ResponseItemCollectionOrder {
39+
string,
40+
Ascending: "asc",
41+
Descending: "desc",
42+
}
43+
44+
@access(Access.public)
45+
@usage(Usage.input)
46+
model ResponseItemCollectionOptions {
47+
...CollectionAfterQueryParameter,
48+
...CollectionBeforeQueryParameter,
49+
...CollectionLimitQueryParameter,
50+
...ResponseItemCollectionOrderQueryParameter,
51+
}

src/Custom/Responses/Items/Internal/InternalResponsesUserMessage.cs renamed to src/Custom/Responses/Items/Internal/ResponsesUserMessage.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
namespace OpenAI.Responses;
44

55
[CodeGenType("ResponsesUserMessageItemResource")]
6-
internal partial class InternalResponsesUserMessage
6+
public partial class ResponsesUserMessage
77
{
88
// CUSTOM: Use generalized content type.
99
[CodeGenMember("Content")]
10-
public IList<ResponseContentPart> InternalContent { get; }
10+
public IList<ResponseContentPart> Content { get; }
1111

1212
// CUSTOM: For reuse as an input model
13-
internal InternalResponsesUserMessage(IEnumerable<ResponseContentPart> internalContent)
13+
internal ResponsesUserMessage(IEnumerable<ResponseContentPart> internalContent)
1414
: this(id: null, status: null, internalContent)
1515
{ }
1616
}

src/Custom/Responses/Items/MessageResponseItem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public MessageRole Role
2424

2525
// CUSTOM: Recombined content from derived types.
2626
public IList<ResponseContentPart> Content
27-
=> (this as InternalResponsesUserMessage)?.InternalContent
27+
=> (this as ResponsesUserMessage)?.Content
2828
?? (this as InternalResponsesDeveloperMessage)?.InternalContent
2929
?? (this as InternalResponsesSystemMessage)?.InternalContent
3030
?? (this as InternalResponsesAssistantMessage)?.InternalContent

src/Custom/Responses/Items/ResponseItem.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ public partial class ResponseItem
1717
public static MessageResponseItem CreateUserMessageItem(IEnumerable<ResponseContentPart> contentParts)
1818
{
1919
Argument.AssertNotNullOrEmpty(contentParts, nameof(contentParts));
20-
return new InternalResponsesUserMessage(contentParts);
20+
return new ResponsesUserMessage(contentParts);
2121
}
2222

2323
public static MessageResponseItem CreateUserMessageItem(string inputTextContent)
2424
{
2525
Argument.AssertNotNull(inputTextContent, nameof(inputTextContent));
26-
return new InternalResponsesUserMessage(
26+
return new ResponsesUserMessage(
2727
internalContent: [ResponseContentPart.CreateInputTextPart(inputTextContent)]);
2828
}
2929

src/Custom/Responses/OpenAIResponseClient.Protocol.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ namespace OpenAI.Responses;
88

99
[CodeGenSuppress("GetResponse", typeof(string), typeof(string), typeof(IEnumerable<InternalIncludable>), typeof(bool?), typeof(int?), typeof(RequestOptions))]
1010
[CodeGenSuppress("GetResponseAsync", typeof(string), typeof(string), typeof(IEnumerable<InternalIncludable>), typeof(bool?), typeof(int?), typeof(RequestOptions))]
11-
[CodeGenSuppress("GetInputItems", typeof(string), typeof(int?), typeof(string), typeof(string), typeof(string), typeof(RequestOptions))]
12-
[CodeGenSuppress("GetInputItemsAsync", typeof(string), typeof(int?), typeof(string), typeof(string), typeof(string), typeof(RequestOptions))]
1311
[CodeGenSuppress("CancelResponse", typeof(string), typeof(IEnumerable<InternalIncludable>), typeof(bool?), typeof(int?), typeof(RequestOptions))]
1412
[CodeGenSuppress("CancelResponseAsync", typeof(string), typeof(IEnumerable<InternalIncludable>), typeof(bool?), typeof(int?), typeof(RequestOptions))]
1513
[CodeGenSuppress("GetResponse", typeof(string), typeof(IEnumerable<InternalIncludable>), typeof(bool?), typeof(int?), typeof(RequestOptions))]

src/Custom/Responses/OpenAIResponseClient.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ namespace OpenAI.Responses;
1616
[CodeGenSuppress("CreateResponse", typeof(ResponseCreationOptions), typeof(CancellationToken))]
1717
[CodeGenSuppress("GetResponse", typeof(string), typeof(string), typeof(IEnumerable<InternalIncludable>), typeof(bool?), typeof(int?), typeof(CancellationToken))]
1818
[CodeGenSuppress("GetResponseAsync", typeof(string), typeof(string), typeof(IEnumerable<InternalIncludable>), typeof(bool?), typeof(int?), typeof(CancellationToken))]
19-
[CodeGenSuppress("GetInputItems", typeof(string), typeof(int?), typeof(OpenAI.VectorStores.VectorStoreCollectionOrder?), typeof(string), typeof(string), typeof(CancellationToken))]
20-
[CodeGenSuppress("GetInputItemsAsync", typeof(string), typeof(int?), typeof(OpenAI.VectorStores.VectorStoreCollectionOrder?), typeof(string), typeof(string), typeof(CancellationToken))]
2119
[CodeGenSuppress("DeleteResponse", typeof(string), typeof(string), typeof(CancellationToken))]
2220
[CodeGenSuppress("DeleteResponseAsync", typeof(string), typeof(string), typeof(CancellationToken))]
2321
[CodeGenSuppress("CancelResponse", typeof(string), typeof(IEnumerable<InternalIncludable>), typeof(bool?), typeof(int?), typeof(CancellationToken))]

0 commit comments

Comments
 (0)