87 lines
2.8 KiB
Go
87 lines
2.8 KiB
Go
/*
|
|
Copyright © 2024 Matteo Schiff <matteo@underdesk.net>
|
|
|
|
*/
|
|
|
|
package llm
|
|
|
|
/*import (
|
|
"context"
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
"time"
|
|
|
|
"git.underdesk.net/Matte23/transcriber/utils"
|
|
"github.com/sashabaranov/go-openai"
|
|
)
|
|
|
|
func RewriteTextLarge(client *openai.Client, transcription string) {
|
|
splittedTranscription = transcription
|
|
|
|
outputFile, err := os.Create("output.md")
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
// close output file on exit and check for its returned error
|
|
defer func() {
|
|
if err := outputFile.Close(); err != nil {
|
|
panic(err)
|
|
}
|
|
}()
|
|
|
|
systemPrompt := openai.ChatCompletionMessage{
|
|
Role: openai.ChatMessageRoleSystem,
|
|
Content: `You will receive a part of a transcription in English that you have to rewrite. Your task is to:
|
|
|
|
Rewrite the transcription, ensuring that the content is clearly presented and properly structured.
|
|
Correct any English errors, including grammar, spelling, and punctuation.
|
|
Organize the discourse by adding appropriate headings, subheadings, and bullet points where needed. Use titles and subtitles to logically separate sections and make the content easy to follow.
|
|
Do not add any new information that is not present in the original transcription (for example don't insert a conclusion paragraph if it's not present in the original text). Do not change the meaning of the text.
|
|
Each response will be formatted in Markdown. Use the following guidelines:
|
|
Use #, ##, ### for titles and subtitles.
|
|
Use bullet points, numbered lists, and other Markdown formatting to present information clearly.
|
|
Use ** for bold.
|
|
Use paragraphs to separate distinct ideas or topics.
|
|
|
|
Each message you receive will be a part of a larger transcription, so please ensure that the content flows naturally and coherently. You should revise the transcription as if it were a section of a longer document, but avoid duplicating any content.`,
|
|
}
|
|
|
|
var messages []openai.ChatCompletionMessage
|
|
|
|
log.Println("Starting rewriting text")
|
|
for _, currentMessage := range splittedTranscription {
|
|
startTime := time.Now()
|
|
messages = append(messages, openai.ChatCompletionMessage{
|
|
Role: openai.ChatMessageRoleUser,
|
|
Content: currentMessage,
|
|
})
|
|
|
|
if len(messages) > 4 {
|
|
messages = messages[2:]
|
|
}
|
|
|
|
resp1, err := client.CreateChatCompletion(
|
|
context.Background(),
|
|
openai.ChatCompletionRequest{
|
|
Model: "mistral-small-instruct",
|
|
Messages: append([]openai.ChatCompletionMessage{systemPrompt}, messages...),
|
|
},
|
|
)
|
|
|
|
if err != nil {
|
|
fmt.Printf("LLM process error: %v\n", err)
|
|
return
|
|
}
|
|
result := resp1.Choices[0].Message.Content
|
|
|
|
outputFile.Write([]byte(result + "\n"))
|
|
|
|
messages = append(messages, openai.ChatCompletionMessage{
|
|
Role: openai.ChatMessageRoleAssistant,
|
|
Content: result,
|
|
})
|
|
utils.MeasureTime(startTime, "Text rewrite iteration")
|
|
}
|
|
} */
|