mirror of
https://github.com/FranP-code/ChatGPT.git
synced 2025-10-13 00:13:25 +00:00
Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3fe04a244a | ||
|
|
c54aec88c0 | ||
|
|
02fb4dd3b7 | ||
|
|
028ef8bae8 | ||
|
|
e86bf42cc1 | ||
|
|
09b8643d99 | ||
|
|
c07fd1e0b8 | ||
|
|
1b71bf8f26 | ||
|
|
4366b8ee8a | ||
|
|
7505311a2c | ||
|
|
680100801f | ||
|
|
ee0836cb07 | ||
|
|
91cebe82db |
@@ -22,9 +22,9 @@
|
|||||||
|
|
||||||
**最新版:**
|
**最新版:**
|
||||||
|
|
||||||
- `Mac`: [ChatGPT_0.4.0_x64.dmg](https://github.com/lencx/ChatGPT/releases/download/v0.4.0/ChatGPT_0.4.0_x64.dmg)
|
- `Mac`: [ChatGPT_0.5.0_x64.dmg](https://github.com/lencx/ChatGPT/releases/download/v0.5.0/ChatGPT_0.5.0_x64.dmg)
|
||||||
- `Linux`: [chat-gpt_0.4.0_amd64.deb](https://github.com/lencx/ChatGPT/releases/download/v0.4.0/chat-gpt_0.4.0_amd64.deb)
|
- `Linux`: [chat-gpt_0.5.0_amd64.deb](https://github.com/lencx/ChatGPT/releases/download/v0.5.0/chat-gpt_0.5.0_amd64.deb)
|
||||||
- `Windows`: [ChatGPT_0.4.0_x64_en-US.msi](https://github.com/lencx/ChatGPT/releases/download/v0.4.0/ChatGPT_0.4.0_x64_en-US.msi)
|
- `Windows`: [ChatGPT_0.5.0_x64_en-US.msi](https://github.com/lencx/ChatGPT/releases/download/v0.5.0/ChatGPT_0.5.0_x64_en-US.msi)
|
||||||
|
|
||||||
[其他版本...](https://github.com/lencx/ChatGPT/releases)
|
[其他版本...](https://github.com/lencx/ChatGPT/releases)
|
||||||
|
|
||||||
|
|||||||
@@ -23,9 +23,9 @@
|
|||||||
|
|
||||||
**Latest:**
|
**Latest:**
|
||||||
|
|
||||||
- `Mac`: [ChatGPT_0.4.0_x64.dmg](https://github.com/lencx/ChatGPT/releases/download/v0.4.0/ChatGPT_0.4.0_x64.dmg)
|
- `Mac`: [ChatGPT_0.5.0_x64.dmg](https://github.com/lencx/ChatGPT/releases/download/v0.5.0/ChatGPT_0.5.0_x64.dmg)
|
||||||
- `Linux`: [chat-gpt_0.4.0_amd64.deb](https://github.com/lencx/ChatGPT/releases/download/v0.4.0/chat-gpt_0.4.0_amd64.deb)
|
- `Linux`: [chat-gpt_0.5.0_amd64.deb](https://github.com/lencx/ChatGPT/releases/download/v0.5.0/chat-gpt_0.5.0_amd64.deb)
|
||||||
- `Windows`: [ChatGPT_0.4.0_x64_en-US.msi](https://github.com/lencx/ChatGPT/releases/download/v0.4.0/ChatGPT_0.4.0_x64_en-US.msi)
|
- `Windows`: [ChatGPT_0.5.0_x64_en-US.msi](https://github.com/lencx/ChatGPT/releases/download/v0.5.0/ChatGPT_0.5.0_x64_en-US.msi)
|
||||||
|
|
||||||
[Other version...](https://github.com/lencx/ChatGPT/releases)
|
[Other version...](https://github.com/lencx/ChatGPT/releases)
|
||||||
|
|
||||||
@@ -75,6 +75,7 @@ In the chatgpt text input area, type a character starting with `/` to bring up t
|
|||||||
- Common shortcut keys
|
- Common shortcut keys
|
||||||
- System tray hover window
|
- System tray hover window
|
||||||
- Powerful menu items
|
- Powerful menu items
|
||||||
|
- Shortcut command typing chatgpt prompt
|
||||||
|
|
||||||
### MenuItem
|
### MenuItem
|
||||||
|
|
||||||
@@ -103,7 +104,7 @@ In the chatgpt text input area, type a character starting with `/` to bring up t
|
|||||||
## TODO
|
## TODO
|
||||||
|
|
||||||
- Web access capability ([#20](https://github.com/lencx/ChatGPT/issues/20))
|
- Web access capability ([#20](https://github.com/lencx/ChatGPT/issues/20))
|
||||||
- Shortcut command typing chatgpt prompt
|
- `Control Center` - Feature Enhancements
|
||||||
- ...
|
- ...
|
||||||
|
|
||||||
## 👀 Preview
|
## 👀 Preview
|
||||||
|
|||||||
@@ -1,5 +1,18 @@
|
|||||||
# UPDATE LOG
|
# UPDATE LOG
|
||||||
|
|
||||||
|
## v0.5.0
|
||||||
|
|
||||||
|
feat: `Control Center` added `chatgpt-prompts` synchronization
|
||||||
|
|
||||||
|
## v0.4.2
|
||||||
|
|
||||||
|
add chatgpt log (path: `~/.chatgpt/chatgpt.log`)
|
||||||
|
|
||||||
|
## v0.4.1
|
||||||
|
|
||||||
|
fix:
|
||||||
|
- tray window style optimization
|
||||||
|
|
||||||
## v0.4.0
|
## v0.4.0
|
||||||
|
|
||||||
feat:
|
feat:
|
||||||
|
|||||||
@@ -33,6 +33,7 @@
|
|||||||
"@ant-design/icons": "^4.8.0",
|
"@ant-design/icons": "^4.8.0",
|
||||||
"@tauri-apps/api": "^1.2.0",
|
"@tauri-apps/api": "^1.2.0",
|
||||||
"antd": "^5.0.6",
|
"antd": "^5.0.6",
|
||||||
|
"dayjs": "^1.11.7",
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
"react": "^18.2.0",
|
"react": "^18.2.0",
|
||||||
"react-dom": "^18.2.0",
|
"react-dom": "^18.2.0",
|
||||||
|
|||||||
@@ -19,6 +19,14 @@ serde_json = "1.0"
|
|||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
tauri = { version = "1.2.2", features = ["api-all", "devtools", "system-tray", "updater"] }
|
tauri = { version = "1.2.2", features = ["api-all", "devtools", "system-tray", "updater"] }
|
||||||
tauri-plugin-positioner = { version = "1.0.4", features = ["system-tray"] }
|
tauri-plugin-positioner = { version = "1.0.4", features = ["system-tray"] }
|
||||||
|
log = "0.4.17"
|
||||||
|
csv = "1.1.6"
|
||||||
|
thiserror = "1.0.38"
|
||||||
|
|
||||||
|
[dependencies.tauri-plugin-log]
|
||||||
|
git = "https://github.com/tauri-apps/tauri-plugin-log"
|
||||||
|
branch = "dev"
|
||||||
|
features = ["colored"]
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
# by default Tauri runs in production mode
|
# by default Tauri runs in production mode
|
||||||
|
|||||||
@@ -70,4 +70,21 @@ pub fn get_chat_model() -> serde_json::Value {
|
|||||||
let path = utils::chat_root().join("chat.model.json");
|
let path = utils::chat_root().join("chat.model.json");
|
||||||
let content = fs::read_to_string(path).unwrap_or_else(|_| r#"{"data":[]}"#.to_string());
|
let content = fs::read_to_string(path).unwrap_or_else(|_| r#"{"data":[]}"#.to_string());
|
||||||
serde_json::from_str(&content).unwrap()
|
serde_json::from_str(&content).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, serde::Serialize, serde::Deserialize)]
|
||||||
|
pub struct PromptRecord {
|
||||||
|
pub act: String,
|
||||||
|
pub prompt: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[command]
|
||||||
|
pub fn parse_prompt(data: String) -> Vec<PromptRecord> {
|
||||||
|
let mut rdr = csv::Reader::from_reader(data.as_bytes());
|
||||||
|
let mut list = vec![];
|
||||||
|
for result in rdr.deserialize() {
|
||||||
|
let record: PromptRecord = result.unwrap();
|
||||||
|
list.push(record);
|
||||||
|
}
|
||||||
|
list
|
||||||
|
}
|
||||||
|
|||||||
123
src-tauri/src/app/fs_extra.rs
Normal file
123
src-tauri/src/app/fs_extra.rs
Normal file
@@ -0,0 +1,123 @@
|
|||||||
|
// https://github.com/tauri-apps/tauri-plugin-fs-extra/blob/dev/src/lib.rs
|
||||||
|
|
||||||
|
// Copyright 2019-2021 Tauri Programme within The Commons Conservancy
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
use serde::{ser::Serializer, Serialize};
|
||||||
|
use std::{
|
||||||
|
path::PathBuf,
|
||||||
|
time::{SystemTime, UNIX_EPOCH},
|
||||||
|
};
|
||||||
|
use tauri::command;
|
||||||
|
|
||||||
|
#[cfg(unix)]
|
||||||
|
use std::os::unix::fs::{MetadataExt, PermissionsExt};
|
||||||
|
#[cfg(windows)]
|
||||||
|
use std::os::windows::fs::MetadataExt;
|
||||||
|
|
||||||
|
type Result<T> = std::result::Result<T, Error>;
|
||||||
|
|
||||||
|
#[derive(Debug, thiserror::Error)]
|
||||||
|
pub enum Error {
|
||||||
|
#[error(transparent)]
|
||||||
|
Io(#[from] std::io::Error),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Serialize for Error {
|
||||||
|
fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
|
||||||
|
where
|
||||||
|
S: Serializer,
|
||||||
|
{
|
||||||
|
serializer.serialize_str(self.to_string().as_ref())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
struct Permissions {
|
||||||
|
readonly: bool,
|
||||||
|
#[cfg(unix)]
|
||||||
|
mode: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(unix)]
|
||||||
|
#[derive(Serialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
struct UnixMetadata {
|
||||||
|
dev: u64,
|
||||||
|
ino: u64,
|
||||||
|
mode: u32,
|
||||||
|
nlink: u64,
|
||||||
|
uid: u32,
|
||||||
|
gid: u32,
|
||||||
|
rdev: u64,
|
||||||
|
blksize: u64,
|
||||||
|
blocks: u64,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
pub struct Metadata {
|
||||||
|
accessed_at_ms: u64,
|
||||||
|
created_at_ms: u64,
|
||||||
|
modified_at_ms: u64,
|
||||||
|
is_dir: bool,
|
||||||
|
is_file: bool,
|
||||||
|
is_symlink: bool,
|
||||||
|
size: u64,
|
||||||
|
permissions: Permissions,
|
||||||
|
#[cfg(unix)]
|
||||||
|
#[serde(flatten)]
|
||||||
|
unix: UnixMetadata,
|
||||||
|
#[cfg(windows)]
|
||||||
|
file_attributes: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn system_time_to_ms(time: std::io::Result<SystemTime>) -> u64 {
|
||||||
|
time.map(|t| {
|
||||||
|
let duration_since_epoch = t.duration_since(UNIX_EPOCH).unwrap();
|
||||||
|
duration_since_epoch.as_millis() as u64
|
||||||
|
})
|
||||||
|
.unwrap_or_default()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[command]
|
||||||
|
pub async fn metadata(path: PathBuf) -> Result<Metadata> {
|
||||||
|
let metadata = std::fs::metadata(path)?;
|
||||||
|
let file_type = metadata.file_type();
|
||||||
|
let permissions = metadata.permissions();
|
||||||
|
Ok(Metadata {
|
||||||
|
accessed_at_ms: system_time_to_ms(metadata.accessed()),
|
||||||
|
created_at_ms: system_time_to_ms(metadata.created()),
|
||||||
|
modified_at_ms: system_time_to_ms(metadata.modified()),
|
||||||
|
is_dir: file_type.is_dir(),
|
||||||
|
is_file: file_type.is_file(),
|
||||||
|
is_symlink: file_type.is_symlink(),
|
||||||
|
size: metadata.len(),
|
||||||
|
permissions: Permissions {
|
||||||
|
readonly: permissions.readonly(),
|
||||||
|
#[cfg(unix)]
|
||||||
|
mode: permissions.mode(),
|
||||||
|
},
|
||||||
|
#[cfg(unix)]
|
||||||
|
unix: UnixMetadata {
|
||||||
|
dev: metadata.dev(),
|
||||||
|
ino: metadata.ino(),
|
||||||
|
mode: metadata.mode(),
|
||||||
|
nlink: metadata.nlink(),
|
||||||
|
uid: metadata.uid(),
|
||||||
|
gid: metadata.gid(),
|
||||||
|
rdev: metadata.rdev(),
|
||||||
|
blksize: metadata.blksize(),
|
||||||
|
blocks: metadata.blocks(),
|
||||||
|
},
|
||||||
|
#[cfg(windows)]
|
||||||
|
file_attributes: metadata.file_attributes(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// #[command]
|
||||||
|
// pub async fn exists(path: PathBuf) -> bool {
|
||||||
|
// path.exists()
|
||||||
|
// }
|
||||||
@@ -4,7 +4,7 @@ use crate::{
|
|||||||
};
|
};
|
||||||
use tauri::{
|
use tauri::{
|
||||||
AboutMetadata, AppHandle, CustomMenuItem, Manager, Menu, MenuItem, Submenu, SystemTray,
|
AboutMetadata, AppHandle, CustomMenuItem, Manager, Menu, MenuItem, Submenu, SystemTray,
|
||||||
SystemTrayEvent, SystemTrayMenu, WindowMenuEvent, SystemTrayMenuItem,
|
SystemTrayEvent, SystemTrayMenu, SystemTrayMenuItem, WindowMenuEvent,
|
||||||
};
|
};
|
||||||
use tauri_plugin_positioner::{on_tray_event, Position, WindowExt};
|
use tauri_plugin_positioner::{on_tray_event, Position, WindowExt};
|
||||||
|
|
||||||
@@ -138,6 +138,10 @@ pub fn init() -> Menu {
|
|||||||
let help_menu = Submenu::new(
|
let help_menu = Submenu::new(
|
||||||
"Help",
|
"Help",
|
||||||
Menu::new()
|
Menu::new()
|
||||||
|
.add_item(CustomMenuItem::new(
|
||||||
|
"chatgpt_log".to_string(),
|
||||||
|
"ChatGPT Log",
|
||||||
|
))
|
||||||
.add_item(CustomMenuItem::new("update_log".to_string(), "Update Log"))
|
.add_item(CustomMenuItem::new("update_log".to_string(), "Update Log"))
|
||||||
.add_item(CustomMenuItem::new("report_bug".to_string(), "Report Bug"))
|
.add_item(CustomMenuItem::new("report_bug".to_string(), "Report Bug"))
|
||||||
.add_item(
|
.add_item(
|
||||||
@@ -226,6 +230,7 @@ pub fn menu_handler(event: WindowMenuEvent<tauri::Wry>) {
|
|||||||
)
|
)
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
// Help
|
// Help
|
||||||
|
"chatgpt_log" => utils::open_file(utils::chat_root().join("chatgpt.log")),
|
||||||
"update_log" => open(&app, conf::UPDATE_LOG_URL.to_string()),
|
"update_log" => open(&app, conf::UPDATE_LOG_URL.to_string()),
|
||||||
"report_bug" => open(&app, conf::ISSUES_URL.to_string()),
|
"report_bug" => open(&app, conf::ISSUES_URL.to_string()),
|
||||||
"dev_tools" => {
|
"dev_tools" => {
|
||||||
@@ -240,11 +245,20 @@ pub fn menu_handler(event: WindowMenuEvent<tauri::Wry>) {
|
|||||||
pub fn tray_menu() -> SystemTray {
|
pub fn tray_menu() -> SystemTray {
|
||||||
SystemTray::new().with_menu(
|
SystemTray::new().with_menu(
|
||||||
SystemTrayMenu::new()
|
SystemTrayMenu::new()
|
||||||
.add_item(CustomMenuItem::new("control_center".to_string(), "Control Center"))
|
.add_item(CustomMenuItem::new(
|
||||||
.add_item(CustomMenuItem::new("show_dock_icon".to_string(), "Show Dock Icon"))
|
"control_center".to_string(),
|
||||||
.add_item(CustomMenuItem::new("hide_dock_icon".to_string(), "Hide Dock Icon"))
|
"Control Center",
|
||||||
|
))
|
||||||
|
.add_item(CustomMenuItem::new(
|
||||||
|
"show_dock_icon".to_string(),
|
||||||
|
"Show Dock Icon",
|
||||||
|
))
|
||||||
|
.add_item(CustomMenuItem::new(
|
||||||
|
"hide_dock_icon".to_string(),
|
||||||
|
"Hide Dock Icon",
|
||||||
|
))
|
||||||
.add_native_item(SystemTrayMenuItem::Separator)
|
.add_native_item(SystemTrayMenuItem::Separator)
|
||||||
.add_item(CustomMenuItem::new("quit".to_string(), "Quit ChatGPT"))
|
.add_item(CustomMenuItem::new("quit".to_string(), "Quit ChatGPT")),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -276,25 +290,19 @@ pub fn tray_handler(handle: &AppHandle, event: SystemTrayEvent) {
|
|||||||
"control_center" => app.get_window("main").unwrap().show().unwrap(),
|
"control_center" => app.get_window("main").unwrap().show().unwrap(),
|
||||||
"restart" => tauri::api::process::restart(&handle.env()),
|
"restart" => tauri::api::process::restart(&handle.env()),
|
||||||
"show_dock_icon" => {
|
"show_dock_icon" => {
|
||||||
ChatConfJson::amend(
|
ChatConfJson::amend(&serde_json::json!({ "hide_dock_icon": false }), Some(app))
|
||||||
&serde_json::json!({ "hide_dock_icon": false }),
|
.unwrap();
|
||||||
Some(app),
|
}
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
},
|
|
||||||
"hide_dock_icon" => {
|
"hide_dock_icon" => {
|
||||||
let chat_conf = conf::ChatConfJson::get_chat_conf();
|
let chat_conf = conf::ChatConfJson::get_chat_conf();
|
||||||
if !chat_conf.hide_dock_icon {
|
if !chat_conf.hide_dock_icon {
|
||||||
ChatConfJson::amend(
|
ChatConfJson::amend(&serde_json::json!({ "hide_dock_icon": true }), Some(app))
|
||||||
&serde_json::json!({ "hide_dock_icon": true }),
|
.unwrap();
|
||||||
Some(app),
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
"quit" => std::process::exit(0),
|
"quit" => std::process::exit(0),
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
},
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
pub mod cmd;
|
pub mod cmd;
|
||||||
|
pub mod fs_extra;
|
||||||
pub mod menu;
|
pub mod menu;
|
||||||
pub mod setup;
|
pub mod setup;
|
||||||
pub mod window;
|
pub mod window;
|
||||||
|
|||||||
@@ -34,7 +34,8 @@ pub fn init(app: &mut App) -> std::result::Result<(), Box<dyn std::error::Error>
|
|||||||
.initialization_script(include_str!("../assets/export.js"))
|
.initialization_script(include_str!("../assets/export.js"))
|
||||||
.initialization_script(include_str!("../assets/cmd.js"))
|
.initialization_script(include_str!("../assets/cmd.js"))
|
||||||
.user_agent(&chat_conf.ua_window)
|
.user_agent(&chat_conf.ua_window)
|
||||||
.build().unwrap();
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
#[cfg(not(target_os = "macos"))]
|
#[cfg(not(target_os = "macos"))]
|
||||||
WindowBuilder::new(&app, "core", WindowUrl::App(url.into()))
|
WindowBuilder::new(&app, "core", WindowUrl::App(url.into()))
|
||||||
@@ -51,7 +52,8 @@ pub fn init(app: &mut App) -> std::result::Result<(), Box<dyn std::error::Error>
|
|||||||
.initialization_script(include_str!("../assets/export.js"))
|
.initialization_script(include_str!("../assets/export.js"))
|
||||||
.initialization_script(include_str!("../assets/cmd.js"))
|
.initialization_script(include_str!("../assets/cmd.js"))
|
||||||
.user_agent(&chat_conf.ua_window)
|
.user_agent(&chat_conf.ua_window)
|
||||||
.build().unwrap();
|
.build()
|
||||||
|
.unwrap();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
23
src-tauri/src/assets/cmd.js
vendored
23
src-tauri/src/assets/cmd.js
vendored
@@ -7,7 +7,6 @@ function init() {
|
|||||||
}
|
}
|
||||||
.chat-model-cmd-list {
|
.chat-model-cmd-list {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
width: 400px;
|
|
||||||
bottom: 60px;
|
bottom: 60px;
|
||||||
max-height: 100px;
|
max-height: 100px;
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
@@ -31,13 +30,17 @@ function init() {
|
|||||||
}
|
}
|
||||||
.chat-model-cmd-list .cmd-item b {
|
.chat-model-cmd-list .cmd-item b {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
width: 120px;
|
width: 100px;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
margin-right: 10px;
|
margin-right: 10px;
|
||||||
color: #2a2a2a;
|
color: #2a2a2a;
|
||||||
}
|
}
|
||||||
.chat-model-cmd-list .cmd-item i {
|
.chat-model-cmd-list .cmd-item i {
|
||||||
width: 270px;
|
width: 100%;
|
||||||
|
max-width: 200px;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
@@ -59,13 +62,21 @@ function init() {
|
|||||||
|
|
||||||
async function cmdTip() {
|
async function cmdTip() {
|
||||||
const chatModelJson = await invoke('get_chat_model') || {};
|
const chatModelJson = await invoke('get_chat_model') || {};
|
||||||
if (!chatModelJson.data && chatModelJson.data.length <= 0) return;
|
const user_custom = chatModelJson.user_custom || [];
|
||||||
const data = chatModelJson.data || [];
|
const sys_sync_prompts = chatModelJson.sys_sync_prompts || [];
|
||||||
|
const data = [...user_custom, ...sys_sync_prompts];
|
||||||
|
if (data.length <= 0) return;
|
||||||
|
|
||||||
const modelDom = document.createElement('div');
|
const modelDom = document.createElement('div');
|
||||||
modelDom.classList.add('chat-model-cmd-list');
|
modelDom.classList.add('chat-model-cmd-list');
|
||||||
|
|
||||||
|
// fix: tray window
|
||||||
|
if (__TAURI_METADATA__.__currentWindow.label === 'tray') {
|
||||||
|
modelDom.style.bottom = '40px';
|
||||||
|
}
|
||||||
|
|
||||||
document.querySelector('form').appendChild(modelDom);
|
document.querySelector('form').appendChild(modelDom);
|
||||||
const itemDom = (v) => `<div class="cmd-item" data-prompt="${encodeURIComponent(v.prompt)}"><b>/${v.cmd}</b><i>${v.act}</i></div>`;
|
const itemDom = (v) => `<div class="cmd-item" title="${v.prompt}" data-prompt="${encodeURIComponent(v.prompt)}"><b title="${v.cmd}">/${v.cmd}</b><i>${v.act}</i></div>`;
|
||||||
const searchInput = document.querySelector('form textarea');
|
const searchInput = document.querySelector('form textarea');
|
||||||
|
|
||||||
// Enter a command starting with `/` and press a space to automatically fill `chatgpt prompt`.
|
// Enter a command starting with `/` and press a space to automatically fill `chatgpt prompt`.
|
||||||
|
|||||||
@@ -7,15 +7,32 @@ mod app;
|
|||||||
mod conf;
|
mod conf;
|
||||||
mod utils;
|
mod utils;
|
||||||
|
|
||||||
use app::{cmd, menu, setup};
|
use app::{cmd, fs_extra, menu, setup};
|
||||||
use conf::{ChatConfJson, ChatState};
|
use conf::{ChatConfJson, ChatState};
|
||||||
|
use tauri::api::path;
|
||||||
|
use tauri_plugin_log::{fern::colors::ColoredLevelConfig, LogTarget, LoggerBuilder};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
ChatConfJson::init();
|
ChatConfJson::init();
|
||||||
let chat_conf = ChatConfJson::get_chat_conf();
|
let chat_conf = ChatConfJson::get_chat_conf();
|
||||||
let context = tauri::generate_context!();
|
let context = tauri::generate_context!();
|
||||||
|
let colors = ColoredLevelConfig::default();
|
||||||
|
|
||||||
tauri::Builder::default()
|
tauri::Builder::default()
|
||||||
|
// https://github.com/tauri-apps/tauri/pull/2736
|
||||||
|
.plugin(
|
||||||
|
LoggerBuilder::new()
|
||||||
|
// .level(log::LevelFilter::Error)
|
||||||
|
.with_colors(colors)
|
||||||
|
.targets([
|
||||||
|
// LogTarget::LogDir,
|
||||||
|
// LOG PATH: ~/.chatgpt/ChatGPT.log
|
||||||
|
LogTarget::Folder(path::home_dir().unwrap().join(".chatgpt")),
|
||||||
|
LogTarget::Stdout,
|
||||||
|
LogTarget::Webview,
|
||||||
|
])
|
||||||
|
.build(),
|
||||||
|
)
|
||||||
.manage(ChatState::default(chat_conf))
|
.manage(ChatState::default(chat_conf))
|
||||||
.invoke_handler(tauri::generate_handler![
|
.invoke_handler(tauri::generate_handler![
|
||||||
cmd::drag_window,
|
cmd::drag_window,
|
||||||
@@ -28,6 +45,8 @@ fn main() {
|
|||||||
cmd::form_msg,
|
cmd::form_msg,
|
||||||
cmd::open_file,
|
cmd::open_file,
|
||||||
cmd::get_chat_model,
|
cmd::get_chat_model,
|
||||||
|
cmd::parse_prompt,
|
||||||
|
fs_extra::metadata,
|
||||||
])
|
])
|
||||||
.setup(setup::init)
|
.setup(setup::init)
|
||||||
.plugin(tauri_plugin_positioner::init())
|
.plugin(tauri_plugin_positioner::init())
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
use log::info;
|
||||||
use std::{
|
use std::{
|
||||||
fs::{self, File},
|
fs::{self, File},
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
@@ -48,6 +49,7 @@ pub fn user_script() -> String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn open_file(path: PathBuf) {
|
pub fn open_file(path: PathBuf) {
|
||||||
|
info!("open_file: {}", path.to_string_lossy());
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
Command::new("open").arg("-R").arg(path).spawn().unwrap();
|
Command::new("open").arg("-R").arg(path).spawn().unwrap();
|
||||||
|
|
||||||
|
|||||||
@@ -7,11 +7,16 @@
|
|||||||
},
|
},
|
||||||
"package": {
|
"package": {
|
||||||
"productName": "ChatGPT",
|
"productName": "ChatGPT",
|
||||||
"version": "0.4.0"
|
"version": "0.5.0"
|
||||||
},
|
},
|
||||||
"tauri": {
|
"tauri": {
|
||||||
"allowlist": {
|
"allowlist": {
|
||||||
"all": true,
|
"all": true,
|
||||||
|
"http": {
|
||||||
|
"scope": [
|
||||||
|
"https://raw.githubusercontent.com/*"
|
||||||
|
]
|
||||||
|
},
|
||||||
"fs": {
|
"fs": {
|
||||||
"all": true,
|
"all": true,
|
||||||
"scope": [
|
"scope": [
|
||||||
@@ -51,13 +56,19 @@
|
|||||||
"shortDescription": "ChatGPT",
|
"shortDescription": "ChatGPT",
|
||||||
"targets": "all",
|
"targets": "all",
|
||||||
"windows": {
|
"windows": {
|
||||||
"webviewInstallMode": {
|
|
||||||
"silent": true,
|
|
||||||
"type": "downloadBootstrapper"
|
|
||||||
},
|
|
||||||
"certificateThumbprint": null,
|
"certificateThumbprint": null,
|
||||||
"digestAlgorithm": "sha256",
|
"digestAlgorithm": "sha256",
|
||||||
"timestampUrl": ""
|
"timestampUrl": "",
|
||||||
|
"webviewInstallMode": {
|
||||||
|
"silent": true,
|
||||||
|
"type": "embedBootstrapper"
|
||||||
|
},
|
||||||
|
"wix": {
|
||||||
|
"language": [
|
||||||
|
"zh-CN",
|
||||||
|
"en-US"
|
||||||
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"security": {
|
"security": {
|
||||||
|
|||||||
8
src/hooks/useChatModel.ts
vendored
8
src/hooks/useChatModel.ts
vendored
@@ -4,20 +4,20 @@ import { clone } from 'lodash';
|
|||||||
import { CHAT_MODEL_JSON, readJSON, writeJSON } from '@/utils';
|
import { CHAT_MODEL_JSON, readJSON, writeJSON } from '@/utils';
|
||||||
import useInit from '@/hooks/useInit';
|
import useInit from '@/hooks/useInit';
|
||||||
|
|
||||||
export default function useChatModel() {
|
export default function useChatModel(key: string) {
|
||||||
const [modelJson, setModelJson] = useState<Record<string, any>>({});
|
const [modelJson, setModelJson] = useState<Record<string, any>>({});
|
||||||
|
|
||||||
useInit(async () => {
|
useInit(async () => {
|
||||||
const data = await readJSON(CHAT_MODEL_JSON, { name: 'ChatGPT Model', data: [] });
|
const data = await readJSON(CHAT_MODEL_JSON, { name: 'ChatGPT Model', [key]: [] });
|
||||||
setModelJson(data);
|
setModelJson(data);
|
||||||
});
|
});
|
||||||
|
|
||||||
const modelSet = async (data: Record<string, any>[]) => {
|
const modelSet = async (data: Record<string, any>[]) => {
|
||||||
const oData = clone(modelJson);
|
const oData = clone(modelJson);
|
||||||
oData.data = data;
|
oData[key] = data;
|
||||||
await writeJSON(CHAT_MODEL_JSON, oData);
|
await writeJSON(CHAT_MODEL_JSON, oData);
|
||||||
setModelJson(oData);
|
setModelJson(oData);
|
||||||
}
|
}
|
||||||
|
|
||||||
return { modelJson, modelSet, modelData: modelJson?.data || [] }
|
return { modelJson, modelSet, modelData: modelJson?.[key] || [] }
|
||||||
}
|
}
|
||||||
2
src/hooks/useInit.ts
vendored
2
src/hooks/useInit.ts
vendored
@@ -8,5 +8,5 @@ export default function useInit(callback: () => void) {
|
|||||||
callback();
|
callback();
|
||||||
isInit.current = false;
|
isInit.current = false;
|
||||||
}
|
}
|
||||||
}, [])
|
})
|
||||||
}
|
}
|
||||||
5
src/layout/index.scss
vendored
5
src/layout/index.scss
vendored
@@ -8,6 +8,11 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.ant-layout-sider-trigger {
|
||||||
|
user-select: none;
|
||||||
|
-webkit-user-select: none;
|
||||||
|
}
|
||||||
|
|
||||||
.chat-container {
|
.chat-container {
|
||||||
padding: 20px;
|
padding: 20px;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
|||||||
27
src/layout/index.tsx
vendored
27
src/layout/index.tsx
vendored
@@ -17,13 +17,32 @@ const ChatLayout: FC<ChatLayoutProps> = ({ children }) => {
|
|||||||
const go = useNavigate();
|
const go = useNavigate();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Layout style={{ minHeight: '100vh' }}>
|
<Layout style={{ minHeight: '100vh' }} hasSider>
|
||||||
<Sider theme="light" collapsible collapsed={collapsed} onCollapse={(value) => setCollapsed(value)}>
|
<Sider
|
||||||
|
theme="light"
|
||||||
|
collapsible
|
||||||
|
collapsed={collapsed}
|
||||||
|
onCollapse={(value) => setCollapsed(value)}
|
||||||
|
style={{
|
||||||
|
overflow: 'auto',
|
||||||
|
height: '100vh',
|
||||||
|
position: 'fixed',
|
||||||
|
left: 0,
|
||||||
|
top: 0,
|
||||||
|
bottom: 0,
|
||||||
|
zIndex: 999,
|
||||||
|
}}
|
||||||
|
>
|
||||||
<div className="chat-logo"><img src="/logo.png" /></div>
|
<div className="chat-logo"><img src="/logo.png" /></div>
|
||||||
<Menu defaultSelectedKeys={[location.pathname]} mode="vertical" items={menuItems} onClick={(i) => go(i.key)} />
|
<Menu defaultSelectedKeys={[location.pathname]} mode="vertical" items={menuItems} onClick={(i) => go(i.key)} />
|
||||||
</Sider>
|
</Sider>
|
||||||
<Layout className="chat-layout">
|
<Layout className="chat-layout" style={{ marginLeft: collapsed ? 80 : 200, transition: 'margin-left 300ms ease-out' }}>
|
||||||
<Content className="chat-container">
|
<Content
|
||||||
|
className="chat-container"
|
||||||
|
style={{
|
||||||
|
overflow: 'inherit'
|
||||||
|
}}
|
||||||
|
>
|
||||||
<Routes />
|
<Routes />
|
||||||
</Content>
|
</Content>
|
||||||
<Footer style={{ textAlign: 'center' }}>
|
<Footer style={{ textAlign: 'center' }}>
|
||||||
|
|||||||
10
src/routes.tsx
vendored
10
src/routes.tsx
vendored
@@ -2,12 +2,14 @@ import { useRoutes } from 'react-router-dom';
|
|||||||
import {
|
import {
|
||||||
DesktopOutlined,
|
DesktopOutlined,
|
||||||
BulbOutlined,
|
BulbOutlined,
|
||||||
|
SyncOutlined,
|
||||||
} from '@ant-design/icons';
|
} from '@ant-design/icons';
|
||||||
import type { RouteObject } from 'react-router-dom';
|
import type { RouteObject } from 'react-router-dom';
|
||||||
import type { MenuProps } from 'antd';
|
import type { MenuProps } from 'antd';
|
||||||
|
|
||||||
import General from '@view/General';
|
import General from '@view/General';
|
||||||
import LanguageModel from '@/view/LanguageModel';
|
import LanguageModel from '@/view/LanguageModel';
|
||||||
|
import SyncPrompts from '@/view/SyncPrompts';
|
||||||
|
|
||||||
export type ChatRouteObject = {
|
export type ChatRouteObject = {
|
||||||
label: string;
|
label: string;
|
||||||
@@ -31,6 +33,14 @@ export const routes: Array<RouteObject & { meta: ChatRouteObject }> = [
|
|||||||
icon: <BulbOutlined />,
|
icon: <BulbOutlined />,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: '/sync-prompts',
|
||||||
|
element: <SyncPrompts />,
|
||||||
|
meta: {
|
||||||
|
label: 'Sync Prompts',
|
||||||
|
icon: <SyncOutlined />,
|
||||||
|
},
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
type MenuItem = Required<MenuProps>['items'][number];
|
type MenuItem = Required<MenuProps>['items'][number];
|
||||||
|
|||||||
14
src/utils.ts
vendored
14
src/utils.ts
vendored
@@ -1,7 +1,10 @@
|
|||||||
import { readTextFile, writeTextFile, exists } from '@tauri-apps/api/fs';
|
import { readTextFile, writeTextFile, exists } from '@tauri-apps/api/fs';
|
||||||
import { homeDir, join } from '@tauri-apps/api/path';
|
import { homeDir, join } from '@tauri-apps/api/path';
|
||||||
|
import dayjs from 'dayjs';
|
||||||
|
|
||||||
export const CHAT_MODEL_JSON = 'chat.model.json';
|
export const CHAT_MODEL_JSON = 'chat.model.json';
|
||||||
|
export const CHAT_PROMPTS_CSV = 'chat.prompts.csv';
|
||||||
|
export const GITHUB_PROMPTS_CSV_URL = 'https://raw.githubusercontent.com/f/awesome-chatgpt-prompts/main/prompts.csv';
|
||||||
export const DISABLE_AUTO_COMPLETE = {
|
export const DISABLE_AUTO_COMPLETE = {
|
||||||
autoCapitalize: 'off',
|
autoCapitalize: 'off',
|
||||||
autoComplete: 'off',
|
autoComplete: 'off',
|
||||||
@@ -12,10 +15,14 @@ export const chatRoot = async () => {
|
|||||||
return join(await homeDir(), '.chatgpt')
|
return join(await homeDir(), '.chatgpt')
|
||||||
}
|
}
|
||||||
|
|
||||||
export const chatModelPath = async () => {
|
export const chatModelPath = async (): Promise<string> => {
|
||||||
return join(await chatRoot(), CHAT_MODEL_JSON);
|
return join(await chatRoot(), CHAT_MODEL_JSON);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const chatPromptsPath = async (): Promise<string> => {
|
||||||
|
return join(await chatRoot(), CHAT_PROMPTS_CSV);
|
||||||
|
}
|
||||||
|
|
||||||
export const readJSON = async (path: string, defaultVal = {}) => {
|
export const readJSON = async (path: string, defaultVal = {}) => {
|
||||||
const root = await chatRoot();
|
const root = await chatRoot();
|
||||||
const file = await join(root, path);
|
const file = await join(root, path);
|
||||||
@@ -24,7 +31,6 @@ export const readJSON = async (path: string, defaultVal = {}) => {
|
|||||||
writeTextFile(file, JSON.stringify({
|
writeTextFile(file, JSON.stringify({
|
||||||
name: 'ChatGPT',
|
name: 'ChatGPT',
|
||||||
link: 'https://github.com/lencx/ChatGPT/blob/main/chat.model.md',
|
link: 'https://github.com/lencx/ChatGPT/blob/main/chat.model.md',
|
||||||
data: null,
|
|
||||||
...defaultVal,
|
...defaultVal,
|
||||||
}, null, 2))
|
}, null, 2))
|
||||||
}
|
}
|
||||||
@@ -40,4 +46,6 @@ export const writeJSON = async (path: string, data: Record<string, any>) => {
|
|||||||
const root = await chatRoot();
|
const root = await chatRoot();
|
||||||
const file = await join(root, path);
|
const file = await join(root, path);
|
||||||
await writeTextFile(file, JSON.stringify(data, null, 2));
|
await writeTextFile(file, JSON.stringify(data, null, 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const fmtDate = (date: any) => dayjs(date).format('YYYY-MM-DD HH:mm:ss');
|
||||||
14
src/view/LanguageModel/index.tsx
vendored
14
src/view/LanguageModel/index.tsx
vendored
@@ -2,6 +2,7 @@ import { useState, useRef, useEffect } from 'react';
|
|||||||
import { Table, Button, Modal, message } from 'antd';
|
import { Table, Button, Modal, message } from 'antd';
|
||||||
import { invoke } from '@tauri-apps/api';
|
import { invoke } from '@tauri-apps/api';
|
||||||
|
|
||||||
|
import useInit from '@/hooks/useInit';
|
||||||
import useChatModel from '@/hooks/useChatModel';
|
import useChatModel from '@/hooks/useChatModel';
|
||||||
import useColumns from '@/hooks/useColumns';
|
import useColumns from '@/hooks/useColumns';
|
||||||
import useData from '@/hooks/useData';
|
import useData from '@/hooks/useData';
|
||||||
@@ -13,7 +14,7 @@ import './index.scss';
|
|||||||
export default function LanguageModel() {
|
export default function LanguageModel() {
|
||||||
const [isVisible, setVisible] = useState(false);
|
const [isVisible, setVisible] = useState(false);
|
||||||
const [modelPath, setChatModelPath] = useState('');
|
const [modelPath, setChatModelPath] = useState('');
|
||||||
const { modelData, modelSet } = useChatModel();
|
const { modelData, modelSet } = useChatModel('user_custom');
|
||||||
const { opData, opAdd, opRemove, opReplace, opSafeKey } = useData(modelData);
|
const { opData, opAdd, opRemove, opReplace, opSafeKey } = useData(modelData);
|
||||||
const { columns, ...opInfo } = useColumns(modelColumns());
|
const { columns, ...opInfo } = useColumns(modelColumns());
|
||||||
const formRef = useRef<any>(null);
|
const formRef = useRef<any>(null);
|
||||||
@@ -30,6 +31,11 @@ export default function LanguageModel() {
|
|||||||
}
|
}
|
||||||
}, [opInfo.opType, formRef]);
|
}, [opInfo.opType, formRef]);
|
||||||
|
|
||||||
|
useInit(async () => {
|
||||||
|
const path = await chatModelPath();
|
||||||
|
setChatModelPath(path);
|
||||||
|
})
|
||||||
|
|
||||||
const hide = () => {
|
const hide = () => {
|
||||||
setVisible(false);
|
setVisible(false);
|
||||||
opInfo.resetRecord();
|
opInfo.resetRecord();
|
||||||
@@ -53,10 +59,8 @@ export default function LanguageModel() {
|
|||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleOpenFile = async () => {
|
const handleOpenFile = () => {
|
||||||
const path = await chatModelPath();
|
invoke('open_file', { path: modelPath });
|
||||||
setChatModelPath(path);
|
|
||||||
invoke('open_file', { path });
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const modalTitle = `${({ new: 'Create', edit: 'Edit' })[opInfo.opType]} Language Model`;
|
const modalTitle = `${({ new: 'Create', edit: 'Edit' })[opInfo.opType]} Language Model`;
|
||||||
|
|||||||
45
src/view/SyncPrompts/config.tsx
vendored
Normal file
45
src/view/SyncPrompts/config.tsx
vendored
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
import { Tag } from 'antd';
|
||||||
|
|
||||||
|
export const genCmd = (act: string) => act.replace(/\s+|\/+/g, '_').replace(/[^\d\w]/g, '').toLocaleLowerCase();
|
||||||
|
|
||||||
|
export const modelColumns = () => [
|
||||||
|
{
|
||||||
|
title: '/{cmd}',
|
||||||
|
dataIndex: 'cmd',
|
||||||
|
fixed: 'left',
|
||||||
|
// width: 120,
|
||||||
|
key: 'cmd',
|
||||||
|
render: (_: string, row: Record<string, string>) => (
|
||||||
|
<Tag color="#2a2a2a">/{genCmd(row.act)}</Tag>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Act',
|
||||||
|
dataIndex: 'act',
|
||||||
|
key: 'act',
|
||||||
|
// width: 200,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Tags',
|
||||||
|
dataIndex: 'tags',
|
||||||
|
key: 'tags',
|
||||||
|
// width: 150,
|
||||||
|
render: () => <Tag>chatgpt-prompts</Tag>,
|
||||||
|
},
|
||||||
|
// {
|
||||||
|
// title: 'Enable',
|
||||||
|
// dataIndex: 'enable',
|
||||||
|
// key: 'enable',
|
||||||
|
// width: 80,
|
||||||
|
// render: (v: boolean = false) => <Switch checked={v} disabled />,
|
||||||
|
// },
|
||||||
|
{
|
||||||
|
title: 'Prompt',
|
||||||
|
dataIndex: 'prompt',
|
||||||
|
key: 'prompt',
|
||||||
|
// width: 300,
|
||||||
|
// render: (v: string) => (
|
||||||
|
// <Tooltip overlayInnerStyle={{ width: 350 }} title={v}><span className="chat-prompts-val">{v}</span></Tooltip>
|
||||||
|
// ),
|
||||||
|
},
|
||||||
|
];
|
||||||
28
src/view/SyncPrompts/index.scss
vendored
Normal file
28
src/view/SyncPrompts/index.scss
vendored
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
.chat-prompts-tags {
|
||||||
|
.ant-tag {
|
||||||
|
margin: 2px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.add-btn {
|
||||||
|
margin-bottom: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chat-model-path {
|
||||||
|
font-size: 12px;
|
||||||
|
font-weight: bold;
|
||||||
|
color: #888;
|
||||||
|
margin-bottom: 5px;
|
||||||
|
|
||||||
|
span {
|
||||||
|
display: inline-block;
|
||||||
|
// background-color: #d8d8d8;
|
||||||
|
color: #4096ff;
|
||||||
|
padding: 0 8px;
|
||||||
|
height: 20px;
|
||||||
|
line-height: 20px;
|
||||||
|
border-radius: 4px;
|
||||||
|
cursor: pointer;
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
}
|
||||||
71
src/view/SyncPrompts/index.tsx
vendored
Normal file
71
src/view/SyncPrompts/index.tsx
vendored
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
import { useState } from 'react';
|
||||||
|
import { Table, Button, message } from 'antd';
|
||||||
|
import { invoke } from '@tauri-apps/api';
|
||||||
|
import { fetch, ResponseType } from '@tauri-apps/api/http';
|
||||||
|
import { writeTextFile, readTextFile } from '@tauri-apps/api/fs';
|
||||||
|
|
||||||
|
import useColumns from '@/hooks/useColumns';
|
||||||
|
import useChatModel from '@/hooks/useChatModel';
|
||||||
|
import { fmtDate, chatPromptsPath, GITHUB_PROMPTS_CSV_URL } from '@/utils';
|
||||||
|
import { modelColumns, genCmd } from './config';
|
||||||
|
import './index.scss';
|
||||||
|
import useInit from '@/hooks/useInit';
|
||||||
|
|
||||||
|
const promptsURL = 'https://github.com/f/awesome-chatgpt-prompts/blob/main/prompts.csv';
|
||||||
|
|
||||||
|
export default function LanguageModel() {
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [lastUpdated, setLastUpdated] = useState();
|
||||||
|
const { modelSet } = useChatModel('sys_sync_prompts');
|
||||||
|
const [tableData, setTableData] = useState<Record<string, string>[]>([]);
|
||||||
|
const { columns, ...opInfo } = useColumns(modelColumns());
|
||||||
|
|
||||||
|
useInit(async () => {
|
||||||
|
const filename = await chatPromptsPath();
|
||||||
|
const data = await readTextFile(filename);
|
||||||
|
const list: Record<string, string>[] = await invoke('parse_prompt', { data });
|
||||||
|
const fileData: Record<string, any> = await invoke('metadata', { path: filename });
|
||||||
|
setLastUpdated(fileData.accessedAtMs);
|
||||||
|
setTableData(list);
|
||||||
|
})
|
||||||
|
|
||||||
|
const handleSync = async () => {
|
||||||
|
setLoading(true);
|
||||||
|
const res = await fetch(GITHUB_PROMPTS_CSV_URL, {
|
||||||
|
method: 'GET',
|
||||||
|
responseType: ResponseType.Text,
|
||||||
|
});
|
||||||
|
const data = (res.data || '') as string;
|
||||||
|
// const content = data.replace(/"(\s+)?,(\s+)?"/g, '","');
|
||||||
|
await writeTextFile(await chatPromptsPath(), data);
|
||||||
|
const list: Record<string, string>[] = await invoke('parse_prompt', { data });
|
||||||
|
setTableData(list);
|
||||||
|
modelSet(list.map(i => ({ cmd: genCmd(i.act), enable: true, tags: ['chatgpt-prompts'], ...i })));
|
||||||
|
setLoading(false);
|
||||||
|
setLastUpdated(fmtDate(Date.now()) as any);
|
||||||
|
message.success('ChatGPT Prompts data synchronization completed!');
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Button type="primary" loading={loading} onClick={handleSync}>Sync</Button>
|
||||||
|
{lastUpdated && <span style={{ marginLeft: 10, color: '#999' }}>Last updated on {fmtDate(lastUpdated)}</span>}
|
||||||
|
<div className="chat-model-path">URL: <a href={promptsURL} target="_blank">{promptsURL}</a></div>
|
||||||
|
<Table
|
||||||
|
key={lastUpdated}
|
||||||
|
rowKey="act"
|
||||||
|
columns={columns}
|
||||||
|
scroll={{ x: 'auto' }}
|
||||||
|
dataSource={tableData}
|
||||||
|
pagination={{
|
||||||
|
hideOnSinglePage: true,
|
||||||
|
showSizeChanger: true,
|
||||||
|
showQuickJumper: true,
|
||||||
|
defaultPageSize: 5,
|
||||||
|
pageSizeOptions: [5, 10, 15, 20],
|
||||||
|
showTotal: (total) => <span>Total {total} items</span>,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user