-
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
Krzysztof Filipów
committed
Apr 9, 2024
1 parent
3f485bd
commit 48684fd
Showing
12 changed files
with
120 additions
and
205 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,63 +1,19 @@ | ||
import { z } from "zod"; | ||
import { makeGetEndpoint } from "../middleware/validation/makeGetEndpoint.js"; | ||
import { fileReader, parseFileReaderResponse } from "../util/fileReader.js"; | ||
import { OPENAI_MODEL, PROMPT_FILE_NAME, RESPONSE_FORMAT, openai } from "./index.js"; | ||
|
||
//TODO: Rework type inference of fileReader | ||
export const init = makeGetEndpoint(z.any(), async (_request, response) => { | ||
let messages: string[] = [] | ||
const promptFile = await fileReader(PROMPT_FILE_NAME); | ||
let jsonPrompt; | ||
|
||
if(RESPONSE_FORMAT.type === "json_object"){ | ||
|
||
jsonPrompt = await fileReader('json-format-prompt.docx'); | ||
if(parseFileReaderResponse(jsonPrompt)){ | ||
messages.push(jsonPrompt.content); | ||
} | ||
else{ | ||
return response.status(500).send({ | ||
status: 500, | ||
message: jsonPrompt.error | ||
}) | ||
} | ||
} | ||
|
||
if(parseFileReaderResponse(promptFile)){ | ||
messages.push(promptFile.content); | ||
} | ||
else{ | ||
return response.status(500).send({ | ||
status: 500, | ||
message: promptFile.error | ||
}) | ||
} | ||
|
||
|
||
const completion = await openai.chat.completions.create({ | ||
messages: messages.map(message => ({role: "system", content: message})), | ||
model: OPENAI_MODEL, | ||
response_format: RESPONSE_FORMAT | ||
}); | ||
console.log(completion.choices[0]?.message); | ||
return response | ||
.status(200) | ||
.send([ | ||
{ | ||
role: "system", | ||
content: promptFile.content | ||
}, | ||
{ | ||
role: "system", | ||
content: jsonPrompt?.content !== undefined ? jsonPrompt.content : "" | ||
}, | ||
{ | ||
role: 'system', | ||
content: "Don't make assumptions about what values to plug into functions. Ask for clarification if a user request is ambiguous. Do not call functions until all arguments are provided by the user. Include all arguments in the response." | ||
content: "Ask the user to provide the content of the file they want to chat about. Talk only about the content of the provided file." | ||
}, | ||
{ | ||
role: "assistant", | ||
content: "Hallo! Als virtueller Assistent beantworte ich gerne Ihre Fragen rund um die Baufinanzierung und helfe Ihnen bei der Berechnung der Kreditsumme anhand des Zeitpunkts und der Höhe der monatlichen Rate bzw. der Kreditlaufzeit anhand der Höhe und der Höhe der monatlichen Rate." | ||
content: "Hallo! Bitte laden Sie die Datei hoch, über die Sie chatten möchten." | ||
} | ||
]); | ||
}); |
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
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.