-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1.0.4 - made spiner into ActivityIndicator and part of the API
- Loading branch information
Showing
8 changed files
with
69 additions
and
12 deletions.
There are no files selected for viewing
File renamed without changes.
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,53 @@ | ||
# Description | ||
|
||
This is a more advanced example that generates an image using the DALL-E-3 model. The model is capable of generating images from textual prompts. The prompt is a description of the image you want to generate. The model will generate an image based on the description. | ||
|
||
This demonstrates using the OpenAI Client Library directly in javaScript code to interact with the OpenAI API. | ||
|
||
# Template Code | ||
|
||
```javascript | ||
<%* | ||
const selectedText = tp.file.selection(); | ||
if (selectedText === null || selectedText.length === 0) { | ||
new Notice("Select text that will serve as the prompt.", 10000); | ||
return; | ||
} | ||
|
||
// More info for parameters to the API: https://platform.openai.com/docs/api-reference/images/create | ||
const model = "dall-e-3"; | ||
const size = "1024x1024"; // for dall-e-3: 1024x1024, 1792x1024, or 1024x1792 for dall-e-3 models. | ||
const style = "vivid"; // for dall-e-3: vivid or natural | ||
const quality = "standard"; // for dall-e-3: hd or standard | ||
|
||
const openai = new ait.OpenAI({ | ||
apiKey: ait.defaultClientSettings.defaultApiKey, | ||
dangerouslyAllowBrowser: true | ||
}); | ||
|
||
const activityIndicator = new ait.ActivityIndicator(); | ||
|
||
try { | ||
activityIndicator.add(); | ||
const imageB64 = await openai.images.generate({ | ||
model: model, | ||
prompt: selectedText, | ||
response_format: "b64_json", | ||
size: size, | ||
style: style, | ||
quality: quality | ||
}); | ||
const now = new Date(); | ||
const dateString = now.getFullYear() + '-' + (now.getMonth() + 1) + '-' + now.getDate() + '_' + now.getHours() + now.getMinutes() + now.getSeconds(); | ||
const fileName = "/dalle_" + dateString + ".jpg"; | ||
const imageBuffer = tp.obsidian.base64ToArrayBuffer(imageB64.data[0].b64_json) | ||
app.vault.adapter.writeBinary(fileName, imageBuffer) | ||
activityIndicator.remove(); | ||
return `${selectedText}\n\n\n\n`; | ||
} catch (error) { | ||
new Notice("Error: " + error.message, 10000); | ||
activityIndicator.remove(); | ||
return selectedText; | ||
} | ||
%> | ||
``` |
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
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 |
---|---|---|
|
@@ -2,5 +2,6 @@ | |
"1.0.0": "1.5.11", | ||
"1.0.1": "1.5.11", | ||
"1.0.2": "1.5.11", | ||
"1.0.3": "1.5.11" | ||
"1.0.3": "1.5.11", | ||
"1.0.4": "1.5.11" | ||
} |