Skip to content

Commit

Permalink
ollama update
Browse files Browse the repository at this point in the history
  • Loading branch information
unclemcz committed Mar 4, 2024
1 parent 186eebd commit 56d8b2c
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion html/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
</nav>
</div>
<div class="col-6">
<input type="text" class="form-control" id="ollama-url" placeholder="http://127.0.0.1:11434/">
<input type="text" class="form-control" id="ollama-url" placeholder="http://127.0.0.1:11434/ 留空则用默认值">
</div>
<div class="col-6">
<input type="text" class="form-control" id="ollama-model" placeholder="model">
Expand Down
9 changes: 6 additions & 3 deletions lib/engine/ollama.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ const apiurl = 'http://127.0.0.1:11434/';


async function translate(query,engine,win,controller) {
const appid = engine.url;
//console.log(engine);
let appid = engine.url;
const key = engine.model;
const name = engine.name;
let result = {};
Expand All @@ -25,6 +26,8 @@ async function translate(query,engine,win,controller) {
if (!utils.isUrl(appid)) {
appid = apiurl
}

//console.log(appid,key);
//大模型反应较慢,先加一个提醒让用户等待
win.webContents.send('update-text', {"origintext":origin,"resulttext":"等待大模型["+key+"]翻译中......","done":false});
const reqdata = {
Expand Down Expand Up @@ -63,14 +66,14 @@ async function translate(query,engine,win,controller) {
result.done = true;
}
win.webContents.send('update-text', result);
console.log(result);
//console.log(result);
});
parser.on('error', error => {
console.error('Error parsing JSON', error);
});
})
.catch(error => {
//console.error('Error during request:', error);
//console.error('Error during request:', JSON.stringify(error));
result = {"origintext":origin,"resulttext":error.address+':'+error.port+' '+ error.syscall + ' ' + error.code,"done":true};
win.webContents.send('update-text', result);
console.log(result);
Expand Down
2 changes: 1 addition & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ app.whenReady().then(() => {
}
}
}else{
console.log("无需隐入,当前状态:",cfgobj.wininto);
//console.log("无需隐入,当前状态:",cfgobj.wininto);
}

});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wodict",
"version": "0.1.5",
"version": "0.1.7",
"description": "A translator based on Electron",
"main": "main.js",
"scripts": {
Expand Down
5 changes: 4 additions & 1 deletion renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ const audiosource = document.getElementById('audiosource')
const btnaudio = document.getElementById('btnaudio')
window.electronAPI.onUpdateText((value) => {
console.log("renderer.js onUpdateText:",value,value.done);
origintext.value = value.origintext.toString();
if (value.origintext && value.origintext.toString() != ''){
origintext.value = value.origintext.toString();
}

resulttext.value = value.resulttext.toString();
if (value.voice && value.voice.toString() != '') {
audiosource.setAttribute('src', value.voice.toString());
Expand Down
4 changes: 1 addition & 3 deletions test/httpurl.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ function isUrl(s) {
}

console.log(isUrl("http://www.example.com")); // true
console.log(isUrl("https://example.com/test")); // true
console.log(isUrl("example.com")); // true
console.log(isUrl("not a url")); // false
console.log(isUrl("http://127.0.0.1:11434/")); //true
console.log(isUrl("http://localhost:11434/")); //true
console.log(isUrl("")); //false

0 comments on commit 56d8b2c

Please sign in to comment.