@leonardo-ai/sdk 4.5.3 → 4.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.speakeasy/gen.lock +16 -5
- package/README.md +5 -0
- package/docs/sdks/prompt/README.md +90 -0
- package/lib/config.d.ts +3 -3
- package/lib/config.js +3 -3
- package/package.json +1 -1
- package/sdk/models/operations/index.d.ts +2 -0
- package/sdk/models/operations/index.d.ts.map +1 -1
- package/sdk/models/operations/index.js +2 -0
- package/sdk/models/operations/index.js.map +1 -1
- package/sdk/models/operations/promptimprove.d.ts +97 -0
- package/sdk/models/operations/promptimprove.d.ts.map +1 -0
- package/sdk/models/operations/promptimprove.js +141 -0
- package/sdk/models/operations/promptimprove.js.map +1 -0
- package/sdk/models/operations/promptrandom.d.ts +77 -0
- package/sdk/models/operations/promptrandom.d.ts.map +1 -0
- package/sdk/models/operations/promptrandom.js +123 -0
- package/sdk/models/operations/promptrandom.js.map +1 -0
- package/sdk/prompt.d.ts +22 -0
- package/sdk/prompt.d.ts.map +1 -0
- package/sdk/prompt.js +181 -0
- package/sdk/prompt.js.map +1 -0
- package/sdk/sdk.d.ts +3 -0
- package/sdk/sdk.d.ts.map +1 -1
- package/sdk/sdk.js +5 -0
- package/sdk/sdk.js.map +1 -1
- package/src/lib/config.ts +3 -3
- package/src/sdk/models/operations/index.ts +2 -0
- package/src/sdk/models/operations/promptimprove.ts +206 -0
- package/src/sdk/models/operations/promptrandom.ts +177 -0
- package/src/sdk/prompt.ts +190 -0
- package/src/sdk/sdk.ts +6 -0
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import * as z from "zod";
|
|
6
|
+
|
|
7
|
+
export type PromptRandomPromptGenerationOutput = {
|
|
8
|
+
/**
|
|
9
|
+
* API Credits Cost for Random Prompt Generation. Available for Production API Users.
|
|
10
|
+
*/
|
|
11
|
+
apiCreditCost?: number | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* The random prompt generated.
|
|
14
|
+
*/
|
|
15
|
+
prompt?: string | undefined;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Responses for POST /prompt/random
|
|
20
|
+
*/
|
|
21
|
+
export type PromptRandomResponseBody = {
|
|
22
|
+
promptGeneration?: PromptRandomPromptGenerationOutput | undefined;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export type PromptRandomResponse = {
|
|
26
|
+
/**
|
|
27
|
+
* HTTP response content type for this operation
|
|
28
|
+
*/
|
|
29
|
+
contentType: string;
|
|
30
|
+
/**
|
|
31
|
+
* HTTP response status code for this operation
|
|
32
|
+
*/
|
|
33
|
+
statusCode: number;
|
|
34
|
+
/**
|
|
35
|
+
* Raw HTTP response; suitable for custom response parsing
|
|
36
|
+
*/
|
|
37
|
+
rawResponse: Response;
|
|
38
|
+
/**
|
|
39
|
+
* Responses for POST /prompt/random
|
|
40
|
+
*/
|
|
41
|
+
object?: PromptRandomResponseBody | undefined;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/** @internal */
|
|
45
|
+
export namespace PromptRandomPromptGenerationOutput$ {
|
|
46
|
+
export type Inbound = {
|
|
47
|
+
apiCreditCost?: number | undefined;
|
|
48
|
+
prompt?: string | undefined;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export const inboundSchema: z.ZodType<
|
|
52
|
+
PromptRandomPromptGenerationOutput,
|
|
53
|
+
z.ZodTypeDef,
|
|
54
|
+
Inbound
|
|
55
|
+
> = z
|
|
56
|
+
.object({
|
|
57
|
+
apiCreditCost: z.number().int().default(4),
|
|
58
|
+
prompt: z.string().default("The random prompt generated."),
|
|
59
|
+
})
|
|
60
|
+
.transform((v) => {
|
|
61
|
+
return {
|
|
62
|
+
apiCreditCost: v.apiCreditCost,
|
|
63
|
+
prompt: v.prompt,
|
|
64
|
+
};
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
export type Outbound = {
|
|
68
|
+
apiCreditCost: number;
|
|
69
|
+
prompt: string;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export const outboundSchema: z.ZodType<
|
|
73
|
+
Outbound,
|
|
74
|
+
z.ZodTypeDef,
|
|
75
|
+
PromptRandomPromptGenerationOutput
|
|
76
|
+
> = z
|
|
77
|
+
.object({
|
|
78
|
+
apiCreditCost: z.number().int().default(4),
|
|
79
|
+
prompt: z.string().default("The random prompt generated."),
|
|
80
|
+
})
|
|
81
|
+
.transform((v) => {
|
|
82
|
+
return {
|
|
83
|
+
apiCreditCost: v.apiCreditCost,
|
|
84
|
+
prompt: v.prompt,
|
|
85
|
+
};
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** @internal */
|
|
90
|
+
export namespace PromptRandomResponseBody$ {
|
|
91
|
+
export type Inbound = {
|
|
92
|
+
promptGeneration?: PromptRandomPromptGenerationOutput$.Inbound | undefined;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
export const inboundSchema: z.ZodType<PromptRandomResponseBody, z.ZodTypeDef, Inbound> = z
|
|
96
|
+
.object({
|
|
97
|
+
promptGeneration: z
|
|
98
|
+
.lazy(() => PromptRandomPromptGenerationOutput$.inboundSchema)
|
|
99
|
+
.optional(),
|
|
100
|
+
})
|
|
101
|
+
.transform((v) => {
|
|
102
|
+
return {
|
|
103
|
+
...(v.promptGeneration === undefined
|
|
104
|
+
? null
|
|
105
|
+
: { promptGeneration: v.promptGeneration }),
|
|
106
|
+
};
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
export type Outbound = {
|
|
110
|
+
promptGeneration?: PromptRandomPromptGenerationOutput$.Outbound | undefined;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
export const outboundSchema: z.ZodType<Outbound, z.ZodTypeDef, PromptRandomResponseBody> = z
|
|
114
|
+
.object({
|
|
115
|
+
promptGeneration: z
|
|
116
|
+
.lazy(() => PromptRandomPromptGenerationOutput$.outboundSchema)
|
|
117
|
+
.optional(),
|
|
118
|
+
})
|
|
119
|
+
.transform((v) => {
|
|
120
|
+
return {
|
|
121
|
+
...(v.promptGeneration === undefined
|
|
122
|
+
? null
|
|
123
|
+
: { promptGeneration: v.promptGeneration }),
|
|
124
|
+
};
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** @internal */
|
|
129
|
+
export namespace PromptRandomResponse$ {
|
|
130
|
+
export type Inbound = {
|
|
131
|
+
ContentType: string;
|
|
132
|
+
StatusCode: number;
|
|
133
|
+
RawResponse: Response;
|
|
134
|
+
object?: PromptRandomResponseBody$.Inbound | undefined;
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
export const inboundSchema: z.ZodType<PromptRandomResponse, z.ZodTypeDef, Inbound> = z
|
|
138
|
+
.object({
|
|
139
|
+
ContentType: z.string(),
|
|
140
|
+
StatusCode: z.number().int(),
|
|
141
|
+
RawResponse: z.instanceof(Response),
|
|
142
|
+
object: z.lazy(() => PromptRandomResponseBody$.inboundSchema).optional(),
|
|
143
|
+
})
|
|
144
|
+
.transform((v) => {
|
|
145
|
+
return {
|
|
146
|
+
contentType: v.ContentType,
|
|
147
|
+
statusCode: v.StatusCode,
|
|
148
|
+
rawResponse: v.RawResponse,
|
|
149
|
+
...(v.object === undefined ? null : { object: v.object }),
|
|
150
|
+
};
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
export type Outbound = {
|
|
154
|
+
ContentType: string;
|
|
155
|
+
StatusCode: number;
|
|
156
|
+
RawResponse: never;
|
|
157
|
+
object?: PromptRandomResponseBody$.Outbound | undefined;
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
export const outboundSchema: z.ZodType<Outbound, z.ZodTypeDef, PromptRandomResponse> = z
|
|
161
|
+
.object({
|
|
162
|
+
contentType: z.string(),
|
|
163
|
+
statusCode: z.number().int(),
|
|
164
|
+
rawResponse: z.instanceof(Response).transform(() => {
|
|
165
|
+
throw new Error("Response cannot be serialized");
|
|
166
|
+
}),
|
|
167
|
+
object: z.lazy(() => PromptRandomResponseBody$.outboundSchema).optional(),
|
|
168
|
+
})
|
|
169
|
+
.transform((v) => {
|
|
170
|
+
return {
|
|
171
|
+
ContentType: v.contentType,
|
|
172
|
+
StatusCode: v.statusCode,
|
|
173
|
+
RawResponse: v.rawResponse,
|
|
174
|
+
...(v.object === undefined ? null : { object: v.object }),
|
|
175
|
+
};
|
|
176
|
+
});
|
|
177
|
+
}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { SDKHooks } from "../hooks";
|
|
6
|
+
import { SDK_METADATA, SDKOptions, serverURLFromOptions } from "../lib/config";
|
|
7
|
+
import * as enc$ from "../lib/encodings";
|
|
8
|
+
import { HTTPClient } from "../lib/http";
|
|
9
|
+
import * as schemas$ from "../lib/schemas";
|
|
10
|
+
import { ClientSDK, RequestOptions } from "../lib/sdks";
|
|
11
|
+
import * as errors from "./models/errors";
|
|
12
|
+
import * as operations from "./models/operations";
|
|
13
|
+
|
|
14
|
+
export class Prompt extends ClientSDK {
|
|
15
|
+
private readonly options$: SDKOptions & { hooks?: SDKHooks };
|
|
16
|
+
|
|
17
|
+
constructor(options: SDKOptions = {}) {
|
|
18
|
+
const opt = options as unknown;
|
|
19
|
+
let hooks: SDKHooks;
|
|
20
|
+
if (
|
|
21
|
+
typeof opt === "object" &&
|
|
22
|
+
opt != null &&
|
|
23
|
+
"hooks" in opt &&
|
|
24
|
+
opt.hooks instanceof SDKHooks
|
|
25
|
+
) {
|
|
26
|
+
hooks = opt.hooks;
|
|
27
|
+
} else {
|
|
28
|
+
hooks = new SDKHooks();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
super({
|
|
32
|
+
client: options.httpClient || new HTTPClient(),
|
|
33
|
+
baseURL: serverURLFromOptions(options),
|
|
34
|
+
hooks,
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
this.options$ = { ...options, hooks };
|
|
38
|
+
void this.options$;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Improve a Prompt
|
|
43
|
+
*
|
|
44
|
+
* @remarks
|
|
45
|
+
* This endpoint returns a improved prompt
|
|
46
|
+
*/
|
|
47
|
+
async promptImprove(
|
|
48
|
+
input: operations.PromptImproveRequestBody,
|
|
49
|
+
options?: RequestOptions
|
|
50
|
+
): Promise<operations.PromptImproveResponse> {
|
|
51
|
+
const headers$ = new Headers();
|
|
52
|
+
headers$.set("user-agent", SDK_METADATA.userAgent);
|
|
53
|
+
headers$.set("Content-Type", "application/json");
|
|
54
|
+
headers$.set("Accept", "application/json");
|
|
55
|
+
|
|
56
|
+
const payload$ = schemas$.parse(
|
|
57
|
+
input,
|
|
58
|
+
(value$) => operations.PromptImproveRequestBody$.outboundSchema.parse(value$),
|
|
59
|
+
"Input validation failed"
|
|
60
|
+
);
|
|
61
|
+
const body$ = enc$.encodeJSON("body", payload$, { explode: true });
|
|
62
|
+
|
|
63
|
+
const path$ = this.templateURLComponent("/prompt/improve")();
|
|
64
|
+
|
|
65
|
+
const query$ = "";
|
|
66
|
+
|
|
67
|
+
let security$;
|
|
68
|
+
if (typeof this.options$.bearerAuth === "function") {
|
|
69
|
+
security$ = { bearerAuth: await this.options$.bearerAuth() };
|
|
70
|
+
} else if (this.options$.bearerAuth) {
|
|
71
|
+
security$ = { bearerAuth: this.options$.bearerAuth };
|
|
72
|
+
} else {
|
|
73
|
+
security$ = {};
|
|
74
|
+
}
|
|
75
|
+
const context = {
|
|
76
|
+
operationID: "promptImprove",
|
|
77
|
+
oAuth2Scopes: [],
|
|
78
|
+
securitySource: this.options$.bearerAuth,
|
|
79
|
+
};
|
|
80
|
+
const securitySettings$ = this.resolveGlobalSecurity(security$);
|
|
81
|
+
|
|
82
|
+
const doOptions = { context, errorCodes: [] };
|
|
83
|
+
const request = this.createRequest$(
|
|
84
|
+
{
|
|
85
|
+
security: securitySettings$,
|
|
86
|
+
method: "POST",
|
|
87
|
+
path: path$,
|
|
88
|
+
headers: headers$,
|
|
89
|
+
query: query$,
|
|
90
|
+
body: body$,
|
|
91
|
+
},
|
|
92
|
+
options
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
const response = await this.do$(request, doOptions);
|
|
96
|
+
|
|
97
|
+
const responseFields$ = {
|
|
98
|
+
ContentType: response.headers.get("content-type") ?? "application/octet-stream",
|
|
99
|
+
StatusCode: response.status,
|
|
100
|
+
RawResponse: response,
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
if (this.matchResponse(response, 200, "application/json")) {
|
|
104
|
+
const responseBody = await response.json();
|
|
105
|
+
const result = schemas$.parse(
|
|
106
|
+
responseBody,
|
|
107
|
+
(val$) => {
|
|
108
|
+
return operations.PromptImproveResponse$.inboundSchema.parse({
|
|
109
|
+
...responseFields$,
|
|
110
|
+
object: val$,
|
|
111
|
+
});
|
|
112
|
+
},
|
|
113
|
+
"Response validation failed"
|
|
114
|
+
);
|
|
115
|
+
return result;
|
|
116
|
+
} else {
|
|
117
|
+
const responseBody = await response.text();
|
|
118
|
+
throw new errors.SDKError("Unexpected API response", response, responseBody);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Generate a Random prompt
|
|
124
|
+
*
|
|
125
|
+
* @remarks
|
|
126
|
+
* This endpoint returns a random prompt
|
|
127
|
+
*/
|
|
128
|
+
async promptRandom(options?: RequestOptions): Promise<operations.PromptRandomResponse> {
|
|
129
|
+
const headers$ = new Headers();
|
|
130
|
+
headers$.set("user-agent", SDK_METADATA.userAgent);
|
|
131
|
+
headers$.set("Accept", "application/json");
|
|
132
|
+
|
|
133
|
+
const path$ = this.templateURLComponent("/prompt/random")();
|
|
134
|
+
|
|
135
|
+
const query$ = "";
|
|
136
|
+
|
|
137
|
+
let security$;
|
|
138
|
+
if (typeof this.options$.bearerAuth === "function") {
|
|
139
|
+
security$ = { bearerAuth: await this.options$.bearerAuth() };
|
|
140
|
+
} else if (this.options$.bearerAuth) {
|
|
141
|
+
security$ = { bearerAuth: this.options$.bearerAuth };
|
|
142
|
+
} else {
|
|
143
|
+
security$ = {};
|
|
144
|
+
}
|
|
145
|
+
const context = {
|
|
146
|
+
operationID: "promptRandom",
|
|
147
|
+
oAuth2Scopes: [],
|
|
148
|
+
securitySource: this.options$.bearerAuth,
|
|
149
|
+
};
|
|
150
|
+
const securitySettings$ = this.resolveGlobalSecurity(security$);
|
|
151
|
+
|
|
152
|
+
const doOptions = { context, errorCodes: [] };
|
|
153
|
+
const request = this.createRequest$(
|
|
154
|
+
{
|
|
155
|
+
security: securitySettings$,
|
|
156
|
+
method: "POST",
|
|
157
|
+
path: path$,
|
|
158
|
+
headers: headers$,
|
|
159
|
+
query: query$,
|
|
160
|
+
},
|
|
161
|
+
options
|
|
162
|
+
);
|
|
163
|
+
|
|
164
|
+
const response = await this.do$(request, doOptions);
|
|
165
|
+
|
|
166
|
+
const responseFields$ = {
|
|
167
|
+
ContentType: response.headers.get("content-type") ?? "application/octet-stream",
|
|
168
|
+
StatusCode: response.status,
|
|
169
|
+
RawResponse: response,
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
if (this.matchResponse(response, 200, "application/json")) {
|
|
173
|
+
const responseBody = await response.json();
|
|
174
|
+
const result = schemas$.parse(
|
|
175
|
+
responseBody,
|
|
176
|
+
(val$) => {
|
|
177
|
+
return operations.PromptRandomResponse$.inboundSchema.parse({
|
|
178
|
+
...responseFields$,
|
|
179
|
+
object: val$,
|
|
180
|
+
});
|
|
181
|
+
},
|
|
182
|
+
"Response validation failed"
|
|
183
|
+
);
|
|
184
|
+
return result;
|
|
185
|
+
} else {
|
|
186
|
+
const responseBody = await response.text();
|
|
187
|
+
throw new errors.SDKError("Unexpected API response", response, responseBody);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
package/src/sdk/sdk.ts
CHANGED
|
@@ -11,6 +11,7 @@ import { Element } from "./element";
|
|
|
11
11
|
import { Generation } from "./generation";
|
|
12
12
|
import { InitImage } from "./initimage";
|
|
13
13
|
import { Model } from "./model";
|
|
14
|
+
import { Prompt } from "./prompt";
|
|
14
15
|
import { User } from "./user";
|
|
15
16
|
import { Variation } from "./variation";
|
|
16
17
|
|
|
@@ -71,6 +72,11 @@ export class Leonardo extends ClientSDK {
|
|
|
71
72
|
return (this._model ??= new Model(this.options$));
|
|
72
73
|
}
|
|
73
74
|
|
|
75
|
+
private _prompt?: Prompt;
|
|
76
|
+
get prompt() {
|
|
77
|
+
return (this._prompt ??= new Prompt(this.options$));
|
|
78
|
+
}
|
|
79
|
+
|
|
74
80
|
private _variation?: Variation;
|
|
75
81
|
get variation() {
|
|
76
82
|
return (this._variation ??= new Variation(this.options$));
|