mirror of
https://github.com/kolbytn/mindcraft.git
synced 2025-08-03 13:55:36 +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",
|
||||
|
||||
"model": {
|
||||
"model": "gpt-4o-mini",
|
||||
"model": "gpt-4o",
|
||||
"params": {
|
||||
"temperature": 1,
|
||||
"not_real": true
|
||||
"temperature": 0.5
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
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';
|
||||
|
||||
export class Gemini {
|
||||
|
@ -37,7 +37,7 @@ export class Gemini {
|
|||
let model;
|
||||
const modelConfig = {
|
||||
model: this.model_name || "gemini-1.5-flash",
|
||||
...(this.params || {})
|
||||
// systemInstruction does not work bc google is trash
|
||||
};
|
||||
|
||||
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...');
|
||||
|
||||
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({
|
||||
contents: [
|
||||
{
|
||||
role: 'user',
|
||||
parts: [
|
||||
{
|
||||
text: "Explain how AI works",
|
||||
}
|
||||
],
|
||||
}
|
||||
],
|
||||
generateConfig: {
|
||||
contents,
|
||||
generationConfig: {
|
||||
...(this.params || {})
|
||||
}
|
||||
});
|
||||
const response = await result.response;
|
||||
const text = response.text();
|
||||
console.log('Received.');
|
||||
if (!text.includes(stop_seq)) return text;
|
||||
const idx = text.indexOf(stop_seq);
|
||||
|
||||
return text.slice(0, idx);
|
||||
}
|
||||
|
|
|
@ -26,8 +26,10 @@ export function toSinglePrompt(turns, system=null, stop_seq='***', model_nicknam
|
|||
return prompt;
|
||||
}
|
||||
|
||||
// ensures stricter turn order for anthropic/llama models
|
||||
// combines repeated messages from the same role, separates repeat assistant messages with filler user messages
|
||||
// ensures stricter turn order and roles:
|
||||
// - 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) {
|
||||
let prev_role = null;
|
||||
let messages = [];
|
||||
|
|
Loading…
Add table
Reference in a new issue