Skip to content

Commit

Permalink
feat: dall-e plugin upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
Hk-Gosuto committed Dec 29, 2023
1 parent 568ffed commit 4551abd
Showing 1 changed file with 33 additions and 4 deletions.
37 changes: 33 additions & 4 deletions app/api/langchain-tools/dalle_image_generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,32 @@ export class DallEAPIWrapper extends StructuredTool {
prompt: z
.string()
.describe(
'input must be a english prompt. you can set `quality: "hd"` for enhanced detail.',
"A text description of the desired image(s). input must be a english prompt.",
),
size: z
.enum(["1024x1024", "1024x1792", "1792x1024"])
.default("1024x1024")
.describe("images size"),
quality: z
.enum(["standard", "hd"])
.default("standard")
.describe(
"hd increases image detail and clarity at the cost of doubled consumption, and should not be used unless specified by the user.",
),
style: z
.enum(["vivid", "natural"])
.default("vivid")
.describe(
"vivid leads to the creation of more intense and dramatic images, while Natural results in images that look more realistic and less exaggerated.",
),
});

/** @ignore */
async _call({ prompt, size }: z.infer<typeof this.schema>) {
async _call({ prompt, size, quality, style }: z.infer<typeof this.schema>) {
let imageUrl;
const apiUrl = `${this.baseURL}/images/generations`;
try {
const requestOptions = {
let requestOptions = {
method: "POST",
headers: {
"Content-Type": "application/json",
Expand All @@ -65,8 +77,25 @@ export class DallEAPIWrapper extends StructuredTool {
prompt: prompt,
n: this.n,
size: size,
quality: quality,
style: style,
}),
};
if (this.model != "dall-e-3") {
requestOptions = {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${this.apiKey}`,
},
body: JSON.stringify({
model: this.model,
prompt: prompt,
n: this.n,
size: size,
}),
};
}
console.log(requestOptions);
const response = await fetch(apiUrl, requestOptions);
const json = await response.json();
Expand Down Expand Up @@ -98,5 +127,5 @@ export class DallEAPIWrapper extends StructuredTool {
}
}

description = `openai's dall-e 3 image generator.`;
description = `openai's dall-e image generator.`;
}

0 comments on commit 4551abd

Please sign in to comment.