Browse Source

feat: restrict title gen output to 50 tokens

Jun Siang Cheah 1 year ago
parent
commit
b8c97fa012
2 changed files with 8 additions and 2 deletions
  1. 5 1
      src/lib/apis/ollama/index.ts
  2. 3 1
      src/lib/apis/openai/index.ts

+ 5 - 1
src/lib/apis/ollama/index.ts

@@ -159,7 +159,11 @@ export const generateTitle = async (
 		body: JSON.stringify({
 			model: model,
 			prompt: template,
-			stream: false
+			stream: false,
+			options: {
+				// Restrict the number of tokens generated to 50
+				num_predict: 50,
+			}
 		})
 	})
 		.then(async (res) => {

+ 3 - 1
src/lib/apis/openai/index.ts

@@ -295,7 +295,9 @@ export const generateTitle = async (
 					content: template
 				}
 			],
-			stream: false
+			stream: false,
+			// Restricting the max tokens to 50 to avoid long titles
+			max_tokens: 50,
 		})
 	})
 		.then(async (res) => {