-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgemini.ts
More file actions
87 lines (79 loc) · 3.78 KB
/
Copy pathgemini.ts
File metadata and controls
87 lines (79 loc) · 3.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
const UseGPT = false;
import { HarmBlockThreshold, HarmCategory } from "@google/generative-ai";
import OpenAI from "openai";
const { GoogleGenerativeAI } = require("@google/generative-ai");
const genAI = new GoogleGenerativeAI(process.env.API_GEMINI,
);
const client = new OpenAI({
apiKey: process.env.API_GPT
});
const safetySettings = [
{
category: HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT,
threshold: HarmBlockThreshold.BLOCK_NONE,
},
{
category: HarmCategory.HARM_CATEGORY_HARASSMENT,
threshold: HarmBlockThreshold.BLOCK_NONE,
},
{
category: HarmCategory.HARM_CATEGORY_HATE_SPEECH,
threshold: HarmBlockThreshold.BLOCK_NONE,
},
{
category: HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT,
threshold: HarmBlockThreshold.BLOCK_NONE,
},
];
const systemInstruction = "You are an advanced fact checking ai. You will recive a chunk of text from a debate, and return a JSON list of the statements and if they are true, false, or not should not answer. When separating statements, ensure each statement is a complete thought and not an incomplete statement. For statements that are too minor to answer, are opinions, or are not verifiable respond with 'should not answer' for their vaildity. Ignore text that appears as if it was said by a debate moderator. Error on the side of answering with true or false even if the statement is vague, but do not rely on what the speakers say to prove your statement. Consider the surronding statements when making you decision. Additonally, include a third key that includes your reasoning. For example [{statement: '...', validity: 'true', reason: '...'} ] "
const model = genAI.getGenerativeModel({ model: "gemini-1.5-flash", systemInstruction : systemInstruction, generationConfig: {
responseMimeType: "application/json"
}, safetySettings: safetySettings });
const splitterSystem = "You are a formating AI. Given a chunk of text from a debate, split the text into groups by statements or claims. If a statement appears cut off still respond it. Format your response with | as a delimiter between statements, and always respond with a rehash of the original, never give reasoning. For example statement1|statement2|statement3";
const splitterModel = genAI.getGenerativeModel({ model: "gemini-1.5-flash", systemInstruction : splitterSystem });
async function splitByStatement(text: any) {
const prompt = `${text}`;
try {
const result = await splitterModel.generateContent(prompt);
const responseText = result.response.text();
return responseText.split("|");
} catch (error) {
console.error('Error splitting cotent:', error);
throw error;
}
}
async function getResponse(sentence: any) {
const prompt = `${sentence}`;
try {
const result = await model.generateContent(prompt);
const responseText = result.response.text();
console.log(responseText);
return JSON.stringify({value: responseText});
} catch (error) {
console.error('Error generating content:', error);
throw error;
}
}
export default {
getResponse: getResponse,
splitByStatement: splitByStatement,
getResponseBulk: async (text: any, title : any) => {
try {
if(UseGPT) {
const chatCompletion = await client.chat.completions.create({
messages: [{ role: 'system', content: systemInstruction + " The title of the video being factchecked is" + title}, { role: 'user', content: text }],
model: 'gpt-4o',
});
console.log(chatCompletion.choices[0].message.content)
return chatCompletion.choices[0].message.content
}
let response = await model.generateContent(title + ":" + text)
let r = response.response.text()
console.log(r)
return r
} catch (error) {
console.log(error)
console.log(text)
}
}
}