Skip to content

Commit

Permalink
(feat): add format to the x-fern-streaming extension to support s…
Browse files Browse the repository at this point in the history
…se (#3407)
  • Loading branch information
dsinghvi authored Apr 19, 2024
1 parent f5b73f6 commit 2e0f42d
Show file tree
Hide file tree
Showing 22 changed files with 263 additions and 24 deletions.
1 change: 1 addition & 0 deletions packages/cli/openapi-ir-sdk/fern/definition/finalIr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ types:
file: FileResponse
json: JsonResponse
text: TextResponse
streamingSse: JsonResponse
streamingText: TextResponse
streamingJson:
type: JsonResponse
Expand Down
1 change: 1 addition & 0 deletions packages/cli/openapi-ir-sdk/fern/definition/parseIr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ types:
file: finalIr.FileResponse
json: JsonResponseWithExample
text: finalIr.TextResponse
streamingSse: finalIr.JsonResponse
streamingText: finalIr.TextResponse
streamingJson:
type: finalIr.JsonResponse
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export type Response =
| FernOpenapiIr.Response.File_
| FernOpenapiIr.Response.Json
| FernOpenapiIr.Response.Text
| FernOpenapiIr.Response.StreamingSse
| FernOpenapiIr.Response.StreamingText
/**
* Checks if `x-fern-streaming` is present and is true. */
Expand All @@ -26,6 +27,10 @@ export declare namespace Response {
type: "text";
}

interface StreamingSse extends FernOpenapiIr.JsonResponse, _Utils {
type: "streamingSse";
}

interface StreamingText extends FernOpenapiIr.TextResponse, _Utils {
type: "streamingText";
}
Expand All @@ -42,6 +47,7 @@ export declare namespace Response {
file: (value: FernOpenapiIr.FileResponse) => _Result;
json: (value: FernOpenapiIr.JsonResponse) => _Result;
text: (value: FernOpenapiIr.TextResponse) => _Result;
streamingSse: (value: FernOpenapiIr.JsonResponse) => _Result;
streamingText: (value: FernOpenapiIr.TextResponse) => _Result;
streamingJson: (value: FernOpenapiIr.JsonResponse) => _Result;
_other: (value: { type: string }) => _Result;
Expand Down Expand Up @@ -88,6 +94,19 @@ export const Response = {
};
},

streamingSse: (value: FernOpenapiIr.JsonResponse): FernOpenapiIr.Response.StreamingSse => {
return {
...value,
type: "streamingSse",
_visit: function <_Result>(
this: FernOpenapiIr.Response.StreamingSse,
visitor: FernOpenapiIr.Response._Visitor<_Result>
) {
return FernOpenapiIr.Response._visit(this, visitor);
},
};
},

streamingText: (value: FernOpenapiIr.TextResponse): FernOpenapiIr.Response.StreamingText => {
return {
...value,
Expand Down Expand Up @@ -122,6 +141,8 @@ export const Response = {
return visitor.json(value);
case "text":
return visitor.text(value);
case "streamingSse":
return visitor.streamingSse(value);
case "streamingText":
return visitor.streamingText(value);
case "streamingJson":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export type ResponseWithExample =
| FernOpenapiIr.ResponseWithExample.File_
| FernOpenapiIr.ResponseWithExample.Json
| FernOpenapiIr.ResponseWithExample.Text
| FernOpenapiIr.ResponseWithExample.StreamingSse
| FernOpenapiIr.ResponseWithExample.StreamingText
/**
* Checks if `x-fern-streaming` is present and is true. */
Expand All @@ -26,6 +27,10 @@ export declare namespace ResponseWithExample {
type: "text";
}

interface StreamingSse extends FernOpenapiIr.JsonResponse, _Utils {
type: "streamingSse";
}

interface StreamingText extends FernOpenapiIr.TextResponse, _Utils {
type: "streamingText";
}
Expand All @@ -42,6 +47,7 @@ export declare namespace ResponseWithExample {
file: (value: FernOpenapiIr.FileResponse) => _Result;
json: (value: FernOpenapiIr.JsonResponseWithExample) => _Result;
text: (value: FernOpenapiIr.TextResponse) => _Result;
streamingSse: (value: FernOpenapiIr.JsonResponse) => _Result;
streamingText: (value: FernOpenapiIr.TextResponse) => _Result;
streamingJson: (value: FernOpenapiIr.JsonResponse) => _Result;
_other: (value: { type: string }) => _Result;
Expand Down Expand Up @@ -88,6 +94,19 @@ export const ResponseWithExample = {
};
},

streamingSse: (value: FernOpenapiIr.JsonResponse): FernOpenapiIr.ResponseWithExample.StreamingSse => {
return {
...value,
type: "streamingSse",
_visit: function <_Result>(
this: FernOpenapiIr.ResponseWithExample.StreamingSse,
visitor: FernOpenapiIr.ResponseWithExample._Visitor<_Result>
) {
return FernOpenapiIr.ResponseWithExample._visit(this, visitor);
},
};
},

streamingText: (value: FernOpenapiIr.TextResponse): FernOpenapiIr.ResponseWithExample.StreamingText => {
return {
...value,
Expand Down Expand Up @@ -125,6 +144,8 @@ export const ResponseWithExample = {
return visitor.json(value);
case "text":
return visitor.text(value);
case "streamingSse":
return visitor.streamingSse(value);
case "streamingText":
return visitor.streamingText(value);
case "streamingJson":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const Response: core.serialization.Schema<serializers.Response.Raw, FernO
file: core.serialization.lazyObject(async () => (await import("../../..")).FileResponse),
json: core.serialization.lazyObject(async () => (await import("../../..")).JsonResponse),
text: core.serialization.lazyObject(async () => (await import("../../..")).TextResponse),
streamingSse: core.serialization.lazyObject(async () => (await import("../../..")).JsonResponse),
streamingText: core.serialization.lazyObject(async () => (await import("../../..")).TextResponse),
streamingJson: core.serialization.lazyObject(async () => (await import("../../..")).JsonResponse),
})
Expand All @@ -23,6 +24,8 @@ export const Response: core.serialization.Schema<serializers.Response.Raw, FernO
return FernOpenapiIr.Response.json(value);
case "text":
return FernOpenapiIr.Response.text(value);
case "streamingSse":
return FernOpenapiIr.Response.streamingSse(value);
case "streamingText":
return FernOpenapiIr.Response.streamingText(value);
case "streamingJson":
Expand All @@ -35,7 +38,13 @@ export const Response: core.serialization.Schema<serializers.Response.Raw, FernO
});

export declare namespace Response {
type Raw = Response.File | Response.Json | Response.Text | Response.StreamingText | Response.StreamingJson;
type Raw =
| Response.File
| Response.Json
| Response.Text
| Response.StreamingSse
| Response.StreamingText
| Response.StreamingJson;

interface File extends serializers.FileResponse.Raw {
type: "file";
Expand All @@ -49,6 +58,10 @@ export declare namespace Response {
type: "text";
}

interface StreamingSse extends serializers.JsonResponse.Raw {
type: "streamingSse";
}

interface StreamingText extends serializers.TextResponse.Raw {
type: "streamingText";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const ResponseWithExample: core.serialization.Schema<
file: core.serialization.lazyObject(async () => (await import("../../..")).FileResponse),
json: core.serialization.lazyObject(async () => (await import("../../..")).JsonResponseWithExample),
text: core.serialization.lazyObject(async () => (await import("../../..")).TextResponse),
streamingSse: core.serialization.lazyObject(async () => (await import("../../..")).JsonResponse),
streamingText: core.serialization.lazyObject(async () => (await import("../../..")).TextResponse),
streamingJson: core.serialization.lazyObject(async () => (await import("../../..")).JsonResponse),
})
Expand All @@ -26,6 +27,8 @@ export const ResponseWithExample: core.serialization.Schema<
return FernOpenapiIr.ResponseWithExample.json(value);
case "text":
return FernOpenapiIr.ResponseWithExample.text(value);
case "streamingSse":
return FernOpenapiIr.ResponseWithExample.streamingSse(value);
case "streamingText":
return FernOpenapiIr.ResponseWithExample.streamingText(value);
case "streamingJson":
Expand All @@ -42,6 +45,7 @@ export declare namespace ResponseWithExample {
| ResponseWithExample.File
| ResponseWithExample.Json
| ResponseWithExample.Text
| ResponseWithExample.StreamingSse
| ResponseWithExample.StreamingText
| ResponseWithExample.StreamingJson;

Expand All @@ -57,6 +61,10 @@ export declare namespace ResponseWithExample {
type: "text";
}

interface StreamingSse extends serializers.JsonResponse.Raw {
type: "streamingSse";
}

interface StreamingText extends serializers.TextResponse.Raw {
type: "streamingText";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ exports[`open api parser streaming simple 1`] = `
},
"response-stream": {
"docs": "",
"format": "json",
"type": "StreamUser",
},
},
Expand Down Expand Up @@ -127,6 +128,7 @@ exports[`open api parser streaming simple 1`] = `
},
"response-stream": {
"docs": "",
"format": "json",
"type": "StreamUser2",
},
},
Expand Down Expand Up @@ -188,6 +190,7 @@ exports[`open api parser streaming simple 1`] = `
},
"response-stream": {
"docs": "",
"format": "json",
"type": "UserV3StreamResponse",
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -998,6 +998,7 @@ Executes a deployed Workflow and streams back its results.",
},
"response-stream": {
"docs": "",
"format": "json",
"type": "WorkflowStreamEvent",
},
"url": "Predict",
Expand Down Expand Up @@ -1121,6 +1122,7 @@ Generate a stream of completions using a previously defined deployment.
},
"response-stream": {
"docs": "",
"format": "json",
"type": "GenerateStreamResponse",
},
"url": "Predict",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ exports[`x-fern-sdk-group-name-with-streaming x-fern-sdk-group-name-with-streami
},
"response-stream": {
"docs": "",
"format": "json",
"type": "root.StreamUser",
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ exports[`x-fern-global-headers x-fern-global-headers simple 1`] = `
},
"response-stream": {
"docs": "",
"format": "json",
"type": "root.StreamUser",
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ exports[`x-fern-streaming-with-reference x-fern-streaming-with-reference simple
},
"response-stream": {
"docs": "",
"format": "json",
"type": "root.CompletionChunk",
},
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`x-fern-streaming-with-sse x-fern-streaming-with-sse simple 1`] = `
{
"definitionFiles": {
"chatCompletions.yml": {
"service": {
"auth": false,
"base-path": "",
"endpoints": {
"create": {
"auth": false,
"docs": undefined,
"method": "POST",
"path": "/completions/chat",
"request": {
"body": {
"properties": {
"prompt": "string",
"stream": "optional<boolean>",
},
},
"headers": undefined,
"name": "CreateCompletionRequest",
"query-parameters": undefined,
},
"response-stream": {
"docs": "Success!",
"format": "sse",
"type": "string",
},
},
},
},
},
},
"packageMarkerFile": {
"types": {
"Completion": {
"docs": undefined,
"properties": {
"text": "optional<string>",
},
},
"CompletionChunk": {
"docs": undefined,
"properties": {
"text": "optional<string>",
},
},
},
},
"rootApiFile": {
"display-name": "Test extension \`x-fern-audiences\` alongside \`x-fern-streaming\`.",
"error-discrimination": {
"strategy": "status-code",
},
"name": "api",
},
}
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
openapi: 3.1.0
info:
title: Test extension `x-fern-audiences` alongside `x-fern-streaming`.
version: 1.0.0
paths:
"/completions/chat":
post:
x-fern-sdk-group-name: chatCompletions
x-fern-sdk-method-name: create
x-fern-streaming:
format: sse
# stream-condition: $request.stream
# response:
# $ref: "#/components/schemas/Completion"
# response-stream:
# $ref: "#/components/schemas/CompletionChunk"
requestBody:
content:
application/json:
schema:
$ref: "#/components/schemas/CreateCompletionRequest"
responses:
"200":
description: "Success!"
content:
application/json:
schema:
type: string
components:
schemas:
CreateCompletionRequest:
type: object
properties:
stream:
type: boolean
prompt:
type: string
required:
- prompt
Completion:
type: object
properties:
text:
type: string
CompletionChunk:
type: object
properties:
text:
type: string
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { testConvertOpenAPI } from "./testConvertOpenApi";

describe("x-fern-streaming-with-sse", () => {
testConvertOpenAPI("x-fern-streaming-with-sse", "openapi.yml");
});
Loading

0 comments on commit 2e0f42d

Please sign in to comment.