Skip to content

Commit dc52464

Browse files
committed
Create FUNDING.yml
Update README.md Update README.md Update FUNDING.yml feat: Remove source language (#7) * remove source language * change home image screenshot support press Esc to hide window (#8) Chord/default model (#9) * set default model * set default model add support for gpt-4o (#10) release v0.0.2
1 parent f3211c1 commit dc52464

File tree

17 files changed

+136
-187
lines changed

17 files changed

+136
-187
lines changed

.github/FUNDING.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
github: [leehuwuj]

README.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ Features:
1212
- [] Windows support.
1313
- [WIP] Custom prompt: Adjust the translation or text refining in different style.
1414

15+
***Note***: This app is still in development
16+
1517
## Screenshots:
1618
- Home:
1719
![Refiner Home](./docs/images/home_sc.png)
@@ -20,9 +22,14 @@ Features:
2022

2123

2224
## Installation
23-
1. Download the released file (.dmg for MacOS) in the Released tab
24-
2. Install the app
25-
3. If you use `Hot key` feature that pressing `Cmd + E` to quick translate the selected text then Accessibility permission for Refiner app must be enable. Here are the steps to enable Accessibility permissions for an app on a Mac:
25+
1. Download the released file (.dmg for MacOS) in the [Released page](https://github.com/leehuwuj/refiner/releases)
26+
2. Install the app.
27+
3. Setting API key (required for OpenAI provider).
28+
- Click the Setting button in the bottom right cornor of the app.
29+
- Chose OpenAI provider and select a model.
30+
- Add your OpenAI's API key
31+
- Click `Save` to save the settings.
32+
5. If you use `Hot key` feature that pressing `Cmd + E` to quick translate the selected text then Accessibility permission for Refiner app must be enable. Here are the steps to enable Accessibility permissions for an app on a Mac:
2633
- Open System Preferences (you can do this by clicking on the Apple logo in the top-left corner of your screen and selecting "System Preferences").
2734
- Click on "Security & Privacy".
2835
- Click on the "Privacy" tab.
@@ -33,3 +40,8 @@ Features:
3340
- Click the lock again to prevent further changes.
3441
Remember to only grant Accessibility permissions to apps you trust, as they will have increased control over your system.
3542

43+
44+
45+
> MacOS users may encounter this problem: "Refiner.app" is damaged and can't be opened. You should move it to the Trash.
46+
open terminal and execute:
47+
`xattr -c /Applications/Refiner.app`

docs/images/home_sc.png

-272 KB
Loading

src-tauri/capabilities/migrated.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"global-shortcut:allow-is-registered",
2222
"global-shortcut:allow-register",
2323
"global-shortcut:allow-unregister",
24-
"shell:default"
24+
"shell:default",
25+
"window:allow-hide"
2526
]
2627
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"migrated":{"identifier":"migrated","description":"permissions that were migrated from v1","local":true,"windows":["main"],"permissions":["path:default","event:default","window:default","app:default","resources:default","menu:default","tray:default","store:default","store:allow-set","store:allow-get","store:allow-save","global-shortcut:default","global-shortcut:allow-is-registered","global-shortcut:allow-register","global-shortcut:allow-unregister","shell:default"]}}
1+
{"migrated":{"identifier":"migrated","description":"permissions that were migrated from v1","local":true,"windows":["main"],"permissions":["path:default","event:default","window:default","app:default","resources:default","menu:default","tray:default","store:default","store:allow-set","store:allow-get","store:allow-save","global-shortcut:default","global-shortcut:allow-is-registered","global-shortcut:allow-register","global-shortcut:allow-unregister","shell:default","window:allow-hide"]}}

src-tauri/src/commands.rs

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ use crate::providers::{self, base::get_provider};
22
use providers::base::Provider;
33

44
const DEFAULT_TRANSLATION_PROMPT: &str = "
5-
You're a good translator.
6-
Only answer the translated text with the following rules and do not showing your thought:
5+
You're a good translator.
6+
Only answer the translated text with the following rules and do not showing your thought:
77
- put your answer in <ans></ans> block and do not include anything else because only the text inside <ans></ans> block will be extracted.
88
Example 1:
99
Original langue: English, Target language: Tiếng Việt
@@ -13,24 +13,24 @@ const DEFAULT_TRANSLATION_PROMPT: &str = "
1313
Original langue: English, Target language: Español
1414
Input: I'm running
1515
Your answer: <ans>Estoy corriendo</ans>
16-
Please translate the text in original language {original_lang} in the the text block below to {target_lang}:
16+
Please translate the text in original language {original_lang} in the the text block below to {target_lang}:
1717
";
1818
const DEFAULT_CORRECTION_PROMPT: &str = "
19-
You're a teacher and you're correcting a student's homework.
20-
Only answer the correct text without explanation,
19+
You're a teacher and you're correcting a student's homework.
20+
Only answer the correct text without explanation,
2121
put your answer in <ans></ans> block and do not include anything else because only the text inside <ans></ans> block will be extracted.
2222
Example:
2323
Input: I running
2424
Your answer: <ans>I'm running</ans>
25-
Please check grammar correct it in the text block below and answer in {original_lang} language: ";
25+
Please check grammar correct it in the text block below and answer in {target_lang} language: ";
2626
const DEFAULT_REFINE_PROMPT: &str = "
27-
You're a good editor.
28-
Only answer the translated text without explanation,
27+
You're a good editor.
28+
Only answer without explanation,
2929
put your answer in <ans></ans> block and do not include anything else because only the text inside <ans></ans> block will be extracted.
3030
Example:
3131
Input: Hello, how are you?
3232
Your answer: <ans>What's up!</ans>
33-
Please refine the text in text block below with conversational style in {original_lang} language:
33+
Please rewrite the text in text block below with conversational style in {target_lang} language:
3434
"
3535
;
3636

@@ -56,7 +56,10 @@ pub async fn translate(
5656
.completion(format!("{}<text>{}<text>. Your answer: ", new_prompt, text).as_str())
5757
.await;
5858
if res.is_err() {
59-
return Ok("Something wrong with LLM provider API. Please check the config and try again!".to_string());
59+
return Ok(
60+
"Something wrong with LLM provider API. Please check the config and try again!"
61+
.to_string(),
62+
);
6063
} else {
6164
let res = res.unwrap();
6265
let ans = res.split("<ans>").collect::<Vec<&str>>()[1]
@@ -88,7 +91,10 @@ pub async fn correct(
8891
.completion(format!("{}<text>{}<text>. Your answer: ", new_prompt, text).as_str())
8992
.await;
9093
if res.is_err() {
91-
return Ok("Something wrong with LLM provider API. Please check the config and try again!".to_string());
94+
return Ok(
95+
"Something wrong with LLM provider API. Please check the config and try again!"
96+
.to_string(),
97+
);
9298
} else {
9399
let res = res.unwrap();
94100
let ans = res.split("<ans>").collect::<Vec<&str>>()[1]
@@ -121,7 +127,10 @@ pub async fn refine(
121127
.await;
122128
// Retrieve the answer from the response and remove all other xml tag in ans
123129
if res.is_err() {
124-
return Ok("Something wrong with LLM provider API. Please check the config and try again!".to_string());
130+
return Ok(
131+
"Something wrong with LLM provider API. Please check the config and try again!"
132+
.to_string(),
133+
);
125134
} else {
126135
let res = res.unwrap();
127136
let ans = res.split("<ans>").collect::<Vec<&str>>()[1]
@@ -132,10 +141,3 @@ pub async fn refine(
132141
return Ok(ans);
133142
}
134143
}
135-
136-
// Save API key to environment variable
137-
#[tauri::command]
138-
pub fn save_api_key(provider: &str, api_key: &str) -> Result<(), String> {
139-
std::env::set_var(format!("{}_API_KEY", "OPENAI"), api_key);
140-
Ok(())
141-
}

src-tauri/src/main.rs

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
33

44
mod commands;
5-
mod selected_text;
65
pub mod providers;
7-
use commands::{correct, refine, save_api_key, translate};
6+
mod selected_text;
7+
use commands::{correct, refine, translate};
88
use tauri::Manager;
99
use tauri::{
1010
menu::{Menu, MenuItem},
@@ -60,28 +60,27 @@ fn main() {
6060
{
6161
use tauri_plugin_global_shortcut::{Code, Modifiers};
6262

63-
app.handle()
64-
.plugin(
65-
tauri_plugin_global_shortcut::Builder::new()
66-
.with_shortcuts(["super+e"])?
67-
.with_handler(|app, shortcut| { // Add 'async' here
68-
if shortcut.matches(Modifiers::SUPER, Code::KeyE) {
69-
// Trigger get selected text
70-
let selected_text = tauri::async_runtime::block_on(async {
71-
get_selected_text(app).await
72-
});
73-
if let Ok(selected_text) = selected_text {
74-
let _ = app.emit("shortcut-quickTranslate", selected_text);
75-
}
76-
let window = app.clone().get_webview_window("main").unwrap();
77-
window.show().unwrap();
78-
window.set_focus().unwrap();
79-
// let _ = app.emit("shortcut-quickTranslate", selected_text);
80-
63+
app.handle().plugin(
64+
tauri_plugin_global_shortcut::Builder::new()
65+
.with_shortcuts(["super+e"])?
66+
.with_handler(|app, shortcut| {
67+
// Add 'async' here
68+
if shortcut.matches(Modifiers::SUPER, Code::KeyE) {
69+
// Trigger get selected text
70+
let selected_text = tauri::async_runtime::block_on(async {
71+
get_selected_text(app).await
72+
});
73+
if let Ok(selected_text) = selected_text {
74+
let _ = app.emit("shortcut-quickTranslate", selected_text);
8175
}
82-
})
83-
.build(),
84-
)?;
76+
let window = app.clone().get_webview_window("main").unwrap();
77+
window.show().unwrap();
78+
window.set_focus().unwrap();
79+
// let _ = app.emit("shortcut-quickTranslate", selected_text);
80+
}
81+
})
82+
.build(),
83+
)?;
8584
}
8685

8786
setup_tray(app).unwrap();
@@ -99,12 +98,7 @@ fn main() {
9998
_ => {}
10099
}
101100
})
102-
.invoke_handler(tauri::generate_handler![
103-
translate,
104-
correct,
105-
refine,
106-
save_api_key
107-
])
101+
.invoke_handler(tauri::generate_handler![translate, correct, refine])
108102
.run(tauri::generate_context!())
109103
.expect("error while running tauri application");
110104
}

src-tauri/src/providers/ollama.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ impl OllamaProvider {
1010
pub fn new(host: Option<String>, port: Option<u16>, model: Option<String>) -> Self {
1111
let default_host = String::from("http://localhost");
1212
let default_port: u16 = 11434;
13-
let default_model = String::from("gpt-3.5-turbo");
13+
let default_model = String::from("llama3");
1414

1515
// Init client
1616
let client = Ollama::new(host.unwrap_or(default_host), port.unwrap_or(default_port));

src-tauri/src/providers/openai.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
use crate::providers::base::Provider;
22
use async_openai::{
33
config::OpenAIConfig,
4-
types::{
5-
ChatCompletionRequestUserMessageArgs, CreateChatCompletionRequestArgs,
6-
},
4+
types::{ChatCompletionRequestUserMessageArgs, CreateChatCompletionRequestArgs},
75
Client,
86
};
97

@@ -21,7 +19,7 @@ impl OpenAIProvider {
2119

2220
Self {
2321
client,
24-
model: model.unwrap_or("gpt-3.5-turbo").to_string(),
22+
model: model.unwrap_or("gpt-4o").to_string(),
2523
}
2624
}
2725
}
@@ -31,7 +29,7 @@ impl Provider for OpenAIProvider {
3129
println!("Prompt: {}", prompt);
3230
let client = self.client.clone();
3331
let request = CreateChatCompletionRequestArgs::default()
34-
.model("gpt-3.5-turbo-0125")
32+
.model(self.model.clone())
3533
.messages([ChatCompletionRequestUserMessageArgs::default()
3634
.content(prompt)
3735
.build()

src-tauri/tauri.conf copy.json

Lines changed: 0 additions & 74 deletions
This file was deleted.

0 commit comments

Comments
 (0)