-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpatch-code6.cjs
More file actions
23 lines (18 loc) · 1.63 KB
/
Copy pathpatch-code6.cjs
File metadata and controls
23 lines (18 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
const fs = require('fs');
const file = 'src/ai/circuitChatAI.js';
let code = fs.readFileSync(file, 'utf8');
// We are currently on v1beta because of patch-code5.cjs. We need to change it to v1 AND change systemInstruction to system_instruction.
const r1 = ` const response = await fetch(\`https://generativelanguage.googleapis.com/v1/models/gemini-1.5-flash:generateContent?key=\${apiKey}\`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
system_instruction: { parts: [{ text: systemPrompt }] },
contents: geminiHistory
})
});`;
// Replace using regex to match both v1/v1beta and systemInstruction
code = code.replace(/const response = await fetch\(`https:\/\/generativelanguage\.googleapis\.com\/v1beta\/models\/gemini-1\.5-flash:generateContent\?key=\$\{apiKey\}`,\s*{\s*method:\s*'POST',\s*headers:\s*{\s*'Content-Type':\s*'application\/json'\s*},\s*body:\s*JSON\.stringify\({\s*systemInstruction:\s*{\s*parts:\s*\[{\s*text:\s*systemPrompt\s*}\]\s*},\s*contents:\s*geminiHistory\s*}\)\s*}\);/g, r1);
// Just in case it's v1 right now
code = code.replace(/const response = await fetch\(`https:\/\/generativelanguage\.googleapis\.com\/v1\/models\/gemini-1\.5-flash:generateContent\?key=\$\{apiKey\}`,\s*{\s*method:\s*'POST',\s*headers:\s*{\s*'Content-Type':\s*'application\/json'\s*},\s*body:\s*JSON\.stringify\({\s*systemInstruction:\s*{\s*parts:\s*\[{\s*text:\s*systemPrompt\s*}\]\s*},\s*contents:\s*geminiHistory\s*}\)\s*}\);/g, r1);
fs.writeFileSync(file, code, 'utf8');
console.log("Patched URL and system_instruction successfully.");