generated from joyqi/typescript-module-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
182 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { Usage } from "."; | ||
import { ApiClient } from ".."; | ||
|
||
type EditRequest = { | ||
model: string; | ||
input?: string; | ||
instruction: string; | ||
n?: number; | ||
temperature?: number; | ||
top_p?: number; | ||
}; | ||
|
||
type Choice = { | ||
index: number; | ||
text: string; | ||
} | ||
|
||
type Edit = { | ||
object: string; | ||
created: number; | ||
choices: Choice[]; | ||
usage: Usage; | ||
} | ||
|
||
export function createEdit(client: ApiClient) { | ||
return async (request: EditRequest): Promise<Edit> => { | ||
return await client("edits", { method: "POST", data: request }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { createReadStream } from "fs"; | ||
import { ApiClient } from ".."; | ||
import FormData from "form-data"; | ||
|
||
type ImageSize = '256x256' | '512x512' | '1024x1024'; | ||
|
||
type ImageResponseFormat = 'url' | 'b64_json'; | ||
|
||
type CreateImageRequest = { | ||
prompt: string; | ||
n?: number; | ||
size?: ImageSize; | ||
response_format?: ImageResponseFormat; | ||
user?: string; | ||
}; | ||
|
||
type EditImageRequest = { | ||
prompt: string; | ||
n?: number; | ||
size?: ImageSize; | ||
response_format?: ImageResponseFormat; | ||
user?: string; | ||
}; | ||
|
||
type CreateImageVariationRequest = { | ||
n?: number; | ||
size?: ImageSize; | ||
response_format?: ImageResponseFormat; | ||
user?: string; | ||
}; | ||
|
||
type UrlImage = { | ||
url: string; | ||
}; | ||
|
||
type B64JsonImage = { | ||
b64_json: string; | ||
}; | ||
|
||
type ImageData = UrlImage | B64JsonImage; | ||
|
||
type Image = { | ||
created: number; | ||
data: ImageData[]; | ||
}; | ||
|
||
export function createImage(client: ApiClient) { | ||
return async (request: CreateImageRequest): Promise<Image> => { | ||
return await client("images/generations", { method: "POST", data: request }); | ||
} | ||
} | ||
|
||
export function editImage(client: ApiClient) { | ||
return async (request: EditImageRequest, image: string, mask?: string): Promise<Image> => { | ||
const form = new FormData(); | ||
|
||
for (const key in request) { | ||
form.append(key, '' + request[key as keyof EditImageRequest]); | ||
} | ||
|
||
form.append('image', createReadStream(image)); | ||
|
||
if (mask) { | ||
form.append('mask', createReadStream(mask)); | ||
} | ||
|
||
return await client("images/edits", { method: "POST", data: form }); | ||
} | ||
} | ||
|
||
export function createImageVariation(client: ApiClient) { | ||
return async (request: CreateImageVariationRequest, image: string): Promise<Image> => { | ||
const form = new FormData(); | ||
|
||
for (const key in request) { | ||
form.append(key, '' + request[key as keyof CreateImageVariationRequest]); | ||
} | ||
|
||
form.append('image', createReadStream(image)); | ||
|
||
return await client("images/variations", { method: "POST", data: form }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters