mirror of
https://github.com/kolbytn/mindcraft.git
synced 2025-08-06 07:15:45 +02:00
updated gemini, cleaned gpt profile
This commit is contained in:
parent
be780cba27
commit
0c3ba9a383
3 changed files with 21 additions and 22 deletions
|
@ -2,10 +2,9 @@
|
||||||
"name": "gpt",
|
"name": "gpt",
|
||||||
|
|
||||||
"model": {
|
"model": {
|
||||||
"model": "gpt-4o-mini",
|
"model": "gpt-4o",
|
||||||
"params": {
|
"params": {
|
||||||
"temperature": 1,
|
"temperature": 0.5
|
||||||
"not_real": true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
import { GoogleGenerativeAI } from '@google/generative-ai';
|
import { GoogleGenerativeAI } from '@google/generative-ai';
|
||||||
import { toSinglePrompt } from '../utils/text.js';
|
import { toSinglePrompt, strictFormat } from '../utils/text.js';
|
||||||
import { getKey } from '../utils/keys.js';
|
import { getKey } from '../utils/keys.js';
|
||||||
|
|
||||||
export class Gemini {
|
export class Gemini {
|
||||||
|
@ -37,7 +37,7 @@ export class Gemini {
|
||||||
let model;
|
let model;
|
||||||
const modelConfig = {
|
const modelConfig = {
|
||||||
model: this.model_name || "gemini-1.5-flash",
|
model: this.model_name || "gemini-1.5-flash",
|
||||||
...(this.params || {})
|
// systemInstruction does not work bc google is trash
|
||||||
};
|
};
|
||||||
|
|
||||||
if (this.url) {
|
if (this.url) {
|
||||||
|
@ -53,29 +53,27 @@ export class Gemini {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const stop_seq = '***';
|
|
||||||
const prompt = toSinglePrompt(turns, systemMessage, stop_seq, 'model');
|
|
||||||
console.log('Awaiting Google API response...');
|
console.log('Awaiting Google API response...');
|
||||||
|
|
||||||
|
turns.unshift({ role: 'system', content: systemMessage });
|
||||||
|
turns = strictFormat(turns);
|
||||||
|
let contents = [];
|
||||||
|
for (let turn of turns) {
|
||||||
|
contents.push({
|
||||||
|
role: turn.role === 'assistant' ? 'model' : 'user',
|
||||||
|
parts: [{ text: turn.content }]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const result = await model.generateContent({
|
const result = await model.generateContent({
|
||||||
contents: [
|
contents,
|
||||||
{
|
generationConfig: {
|
||||||
role: 'user',
|
|
||||||
parts: [
|
|
||||||
{
|
|
||||||
text: "Explain how AI works",
|
|
||||||
}
|
|
||||||
],
|
|
||||||
}
|
|
||||||
],
|
|
||||||
generateConfig: {
|
|
||||||
...(this.params || {})
|
...(this.params || {})
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
const response = await result.response;
|
const response = await result.response;
|
||||||
const text = response.text();
|
const text = response.text();
|
||||||
console.log('Received.');
|
console.log('Received.');
|
||||||
if (!text.includes(stop_seq)) return text;
|
|
||||||
const idx = text.indexOf(stop_seq);
|
|
||||||
|
|
||||||
return text.slice(0, idx);
|
return text.slice(0, idx);
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,8 +26,10 @@ export function toSinglePrompt(turns, system=null, stop_seq='***', model_nicknam
|
||||||
return prompt;
|
return prompt;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ensures stricter turn order for anthropic/llama models
|
// ensures stricter turn order and roles:
|
||||||
// combines repeated messages from the same role, separates repeat assistant messages with filler user messages
|
// - system messages are treated as user messages and prefixed with SYSTEM:
|
||||||
|
// - combines repeated messages from users
|
||||||
|
// - separates repeat assistant messages with filler user messages
|
||||||
export function strictFormat(turns) {
|
export function strictFormat(turns) {
|
||||||
let prev_role = null;
|
let prev_role = null;
|
||||||
let messages = [];
|
let messages = [];
|
||||||
|
|
Loading…
Add table
Reference in a new issue