-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add: Generate Image by DALL·E 3 (#493)
* add generateImage function * remove debug comment * change command to image * add image command instructions * add n parameter instructions * use the currentProvider.createClient method * display no supported models error * refactor for same key value names
- Loading branch information
1 parent
b12cd30
commit d09c947
Showing
4 changed files
with
83 additions
and
1 deletion.
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
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,30 @@ | ||
import { ChatCraftCommand } from "../ChatCraftCommand"; | ||
import { ChatCraftChat } from "../ChatCraftChat"; | ||
import { ChatCraftHumanMessage } from "../ChatCraftMessage"; | ||
import { generateImage, isGenerateImageSupported } from "../../lib/ai"; | ||
|
||
export class ImageCommand extends ChatCraftCommand { | ||
constructor() { | ||
super("image"); | ||
} | ||
|
||
async execute(chat: ChatCraftChat, user: User | undefined, args?: string[]) { | ||
if (!(await isGenerateImageSupported())) { | ||
throw new Error("Failed to generate image, no image generation models available"); | ||
} | ||
if (!(args && args[0])) { | ||
throw new Error("must include a prompt"); | ||
} | ||
const prompt = args.join(" "); | ||
let imageUrls: string[] = []; | ||
const text = `(DALL·E 3 result of the prompt: ${prompt})`; | ||
|
||
try { | ||
imageUrls = await generateImage(prompt); | ||
} catch (error: any) { | ||
console.error(`Failed to generate image: ${error.message}`); | ||
throw new Error(`Failed to generate image: ${error.message}`); | ||
} | ||
return chat.addMessage(new ChatCraftHumanMessage({ user, text, imageUrls })); | ||
} | ||
} |
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