-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
147 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,20 @@ | ||
import { askDok } from "./llmDocSearchUtils.js"; | ||
// import { askDok, askDokOpenAI } from "./utils/docChatUtilsLangchain.js"; | ||
// import { askRag, showThread, createNewThread, runAssistant } from "./utils/docChatUtilsTemp.js"; | ||
import { createSpeech, createNewThread, askDok } from "./utils/docChatUtilsOpenAI.js"; | ||
|
||
// console.log(askDok("html", "https://snl.no/Vestfold_og_Telemark", "Finnes det noen stavkirker i fylket?")); | ||
console.log(askDok("md", "docs/delingsinfo.md", "Hvem er primærkontakter i Vestfold?")) | ||
|
||
const artikkel = "https://www.utdanningsnytt.no/eksamen-karakterer-kvalitetsvurderingssystem/utvalg-foreslar-a-avvikle-dagens-nasjonale-prover/380387" | ||
const spørsmål = "Hva er den kommunitative lov? Forklar på en enkel måte"; | ||
|
||
|
||
// console.log(askDok("html", artikkel, spørsmål)); | ||
// console.log(askDok("pdf", "./docs/MB_bm.pdf", spørsmål)); | ||
|
||
// console.log(createNewThread()); | ||
// console.log(askRag()); | ||
// console.log(showThread()); | ||
// console.log(runAssistant()); | ||
// console.log(createSpeech(Hei hei.`)); | ||
|
||
// console.log(createNewThread()); | ||
console.log(await askDok("asst_PP9eODyAvv3Qtd7VJYTfmKEL", "thread_xGR6QNsAbB6LZIOBoHYoN6QE", "Punkt 2 var spennende. Kan du si mer om det?")) |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import OpenAI from "openai"; | ||
import fs from "fs"; | ||
import path from "path"; | ||
import dotenv from "dotenv"; | ||
dotenv.config(); | ||
|
||
const openai = new OpenAI(process.env.OPENAI_API_KEY); | ||
const speechFile = path.resolve("./speech.mp3"); | ||
|
||
export const createNewThread = async () => { | ||
const thread = await openai.beta.threads.create(); | ||
console.log(thread); | ||
return thread; | ||
}; | ||
|
||
export const askDok = async (assistantID, threadID, prompt) => { | ||
console.log(assistantID || process.env.ASSISTANT, threadID, prompt); | ||
const message = await openai.beta.threads.messages.create(threadID, { | ||
role: "user", | ||
content: prompt, | ||
}); | ||
const run = await openai.beta.threads.runs.create(threadID, { | ||
assistant_id: assistantID, | ||
instructions: "Svar på norsk.", | ||
}); | ||
|
||
let response = new Promise((resolve, reject) => { | ||
let intervalId = setInterval(async () => { | ||
const updatedRun = await openai.beta.threads.runs.retrieve( | ||
threadID, | ||
run.id | ||
); // Replace with actual function to fetch updated run status | ||
console.log("Waiting for completion: ", updatedRun.status); | ||
if (updatedRun.status === "completed") { | ||
clearInterval(intervalId); | ||
resolve(await openai.beta.threads.messages.list(threadID).data[0].content[0].text.value); | ||
} | ||
}, 1000); | ||
}); | ||
return response; | ||
}; | ||
export const createSpeech = async (speech) => { | ||
const mp3 = await openai.audio.speech.create({ | ||
model: "tts-1", | ||
voice: "alloy", | ||
input: speech, | ||
voice: "shimmer", | ||
}); | ||
console.log(speechFile); | ||
const buffer = Buffer.from(await mp3.arrayBuffer()); | ||
await fs.promises.writeFile(speechFile, buffer); | ||
// Her kan vi returnere noe | ||
return true; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import OpenAI from "openai"; | ||
import dotenv from "dotenv"; | ||
dotenv.config(); | ||
|
||
const openai = new OpenAI(); | ||
|
||
export const askRag = async () => { | ||
const message = await openai.beta.threads.messages.create( | ||
'thread_UQI9QX4rs0CHMJNwMVey6F0Z', | ||
{ | ||
role: "user", | ||
content: "Hvilke kjerneelementer er det?" | ||
} | ||
) | ||
console.log(message.content); | ||
return message | ||
} | ||
|
||
export const createNewThread = async () => { | ||
const thread = await openai.beta.threads.create(); | ||
console.log(thread); | ||
return thread; | ||
} | ||
|
||
export const showThread = async () => { | ||
const threadMessages = await openai.beta.threads.messages.list('thread_UQI9QX4rs0CHMJNwMVey6F0Z') | ||
|
||
for ( const m of threadMessages.data ) { | ||
console.log(m.content); | ||
} | ||
console.log(threadMessages); | ||
return threadMessages; | ||
} | ||
|
||
export const runAssistant = async () => { | ||
const run = await openai.beta.threads.runs.create( | ||
'thread_UQI9QX4rs0CHMJNwMVey6F0Z', | ||
{ | ||
assistant_id: 'asst_PP9eODyAvv3Qtd7VJYTfmKEL', | ||
instructions: "Svar på norsk." | ||
} | ||
) | ||
console.log(run); | ||
}; |