Skip to content

Commit

Permalink
Bump models
Browse files Browse the repository at this point in the history
  • Loading branch information
pbernet committed May 21, 2024
1 parent e59f281 commit f949f3e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/main/scala/tools/OpenAICompletions.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public static void main(String[] args) throws IOException {
LOGGER.info("Chat total tokens: {}", resultRawChat.getRight());
}

// Use for models < 4
public ImmutablePair<String, Integer> runCompletions(String model, String prompt) {
JSONObject requestParams = new JSONObject();
requestParams.put("model", model);
Expand Down
10 changes: 4 additions & 6 deletions src/main/scala/tools/SubtitleTranslator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ object SubtitleTranslator extends App {
private val targetFilePath = "DE_challenges.srt"
private val targetLanguage = "German"

private val defaultModel = "gpt-3.5-turbo"
private val fallbackModel = "gpt-3.5-turbo-instruct"
private val defaultModel = "gpt-4o"
private val fallbackModel = "gpt-4-turbo"

private val maxGapSeconds = 1 // gap time between two scenes (= session windows)
private val endLineTag = "\n"
Expand Down Expand Up @@ -108,13 +108,11 @@ object SubtitleTranslator extends App {
val toTranslate = generateTranslationPrompt(allLines)
logger.info(s"Translation prompt: $toTranslate")

// First try with the cheaper 'gpt-3.5-turbo' model
// Also possible to use 'gpt-4'
val translatedCheap = new OpenAICompletions().runChatCompletions(defaultModel, toTranslate)
val translated = translatedCheap match {
case translatedCheap if !isTranslationPlausible(translatedCheap.getLeft, sceneOrig.size) =>
logger.info(s"Translation with: $defaultModel is not plausible, lines do not match. Fallback to: $fallbackModel")
new OpenAICompletions().runCompletions(fallbackModel, toTranslate)
new OpenAICompletions().runChatCompletions(fallbackModel, toTranslate)
case _ => translatedCheap
}

Expand Down Expand Up @@ -188,7 +186,7 @@ object SubtitleTranslator extends App {
logger.warn(s"Translated block text is too long (${textCleaned.length} chars). Try to shorten via API call. Check result manually")
val toShorten = generateShortenPrompt(textCleaned)
logger.info(s"Shorten prompt: $toShorten")
val responseShort = new OpenAICompletions().runCompletions(fallbackModel, toShorten)
val responseShort = new OpenAICompletions().runChatCompletions(defaultModel, toShorten)
splitSentence(clean(responseShort.getLeft))
}
else splitSentence(textCleaned)
Expand Down

0 comments on commit f949f3e

Please sign in to comment.