Skip to content

Commit 620fc1e

Browse files
committed
feature: special command for image generation
1 parent 70be76a commit 620fc1e

File tree

4 files changed

+35
-12
lines changed

4 files changed

+35
-12
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ Some companies offer free API access. Check their terms and conditions before yo
6969
# Special Commands
7070
Use special commands to perform an action quickly and easily.
7171

72+
### Image generation with Google Gemini
73+
74+
- `pic: image of a dog having fun on the beach`
75+
- `imagine: image of a cat playing with a basket`
76+
77+
Both commands above are equivalent, by using "imagine:" or "pic" you will be sending your prompt to the Google Gemini image generation model.
78+
It will only work when the currently active model is any of Google Gemini.
79+
7280
### Grounding with Google Search
7381
- `g: what's the main news today`
7482

index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@
7575
<script src="js/md5.js?v=1.0.1"></script>
7676
<script src="js/google_cse.js?v=1.1.1"></script>
7777
<script src="js/4devs.js?v=1.0.1"></script>
78-
<script src="js/prompts.js?v=1.0.8"></script>
78+
<script src="js/prompts.js?v=1.1.0"></script>
7979
<script src="js/tools_list.js?v=1.2.0"></script>
80-
<script src="js/script.js?v=3.2.2"></script>
80+
<script src="js/script.js?v=3.2.3"></script>
8181
<script src="js/search_chats.js?v=0.0.3"></script>
8282
<script src="js/voice_rec.js?v=1.0.6"></script>
8383
<script src="js/nuggets.js?v=0.0.1"></script>

js/prompts.js

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/script.js

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,6 +1086,7 @@ function createDialog(text, duration_seconds = 0, add_class_name = '', can_delet
10861086
}
10871087

10881088
function geminiChat(fileUri = '', with_stream = true, the_data = '') {
1089+
let gemini_model = model;
10891090
let all_parts = [];
10901091
let system_prompt = getSystemPrompt();
10911092
addFileToPrompt();
@@ -1179,18 +1180,23 @@ function geminiChat(fileUri = '', with_stream = true, the_data = '') {
11791180
// "maxOutputTokens": 8192,
11801181
};
11811182

1182-
if(model.includes("image")){
1183-
with_stream = false;
1184-
if(data.systemInstruction){
1185-
delete data.systemInstruction;
1186-
}
1187-
data.generationConfig.responseModalities = ["IMAGE", "TEXT"];
1188-
}
11891183

11901184
let pog = whichTool(last_user_input);
11911185
if(pog === 'dt'){
11921186
data.generationConfig.thinkingConfig = { thinkingBudget: 8000 };
11931187
}
1188+
if(pog === 'pic' || pog === 'imagine'){
1189+
console.log('image generation command activated');
1190+
gemini_model = "gemini-2.0-flash-preview-image-generation";
1191+
}
1192+
1193+
if(gemini_model.includes("image")){
1194+
with_stream = false;
1195+
if(data.systemInstruction){
1196+
delete data.systemInstruction;
1197+
}
1198+
data.generationConfig.responseModalities = ["IMAGE", "TEXT"];
1199+
}
11941200

11951201
if (the_data) {
11961202
data = the_data;
@@ -1230,7 +1236,7 @@ function geminiChat(fileUri = '', with_stream = true, the_data = '') {
12301236
return geminiStreamChat(fileUri, data, allow_tool_use);
12311237
}
12321238

1233-
let gemini_endpoint = endpoint.replaceAll("{{model}}", model);
1239+
let gemini_endpoint = endpoint.replaceAll("{{model}}", gemini_model);
12341240
gemini_endpoint = gemini_endpoint.replaceAll("{{api_key}}", api_key);
12351241
gemini_endpoint = gemini_endpoint.replaceAll("{{gen_mode}}", "generateContent");
12361242

@@ -2009,7 +2015,8 @@ function needToolUse(last_user_input) {
20092015
'search:', 's:',
20102016
'javascript:', 'js:',
20112017
'youtube:', 'yt:',
2012-
'dt:'
2018+
'dt:',
2019+
'pic:','imagine:'
20132020
]
20142021
if (cmd_list.includes(cmd)) {
20152022
return true;
@@ -2038,6 +2045,8 @@ function whichTool(last_user_input) {
20382045
}else if(cmd === 'dt:'){
20392046
// Activate extend thinking for Claude
20402047
return 'dt';
2048+
}else if(cmd.trim() !== ''){
2049+
return cmd.replaceAll(":","");
20412050
}
20422051
return '';
20432052
}

0 commit comments

Comments
 (0)