Skip to content

Commit

Permalink
Update main.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Pylogmon authored Jun 28, 2024
1 parent cf5d0b5 commit da853d4
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
async function recognize(base64, _lang, options) {
async function recognize(base64, lang, options) {
const { config, utils } = options;
const { tauriFetch: fetch } = utils;
let { model = "gpt-4o", apiKey, requestPath } = config;
let { model = "gpt-4o", apiKey, requestPath, customPrompt } = config;

if (!requestPath) {
requestPath = "https://api.openai.com";
}
if (!/https?:\/\/.+/.test(requestPath)) {
requestPath = `https://${requestPath}`;
}
Expand All @@ -12,6 +15,11 @@ async function recognize(base64, _lang, options) {
if (!requestPath.endsWith('/chat/completions')) {
requestPath += '/v1/chat/completions';
}
if (!customPrompt) {
customPrompt = "Just recognize the text in the image. Do not offer unnecessary explanations.";
}else{
customPrompt = customPrompt.replaceAll("$lang", lang);
}

const headers = {
'Content-Type': 'application/json',
Expand All @@ -26,7 +34,7 @@ async function recognize(base64, _lang, options) {
"content": [
{
"type": "text",
"text": "Just recognize the text in the image. Do not offer unnecessary explanations."
"text": customPrompt
}
],
},
Expand Down Expand Up @@ -60,4 +68,4 @@ async function recognize(base64, _lang, options) {
} else {
throw `Http Request Error\nHttp Status: ${res.status}\n${JSON.stringify(res.data)}`;
}
}
}

0 comments on commit da853d4

Please sign in to comment.