-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 3b3ed50
Showing
232 changed files
with
8,641 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/**/dist/ | ||
/target/ | ||
/Cargo.lock | ||
/.idea | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/src-ui | ||
/public | ||
/Cargo.toml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[workspace] | ||
members = [ | ||
"src-shared", | ||
"src-tauri", | ||
"src-ui", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Enki | ||
A ChatGPT desktop application built with Tauri, Leptos, SQLx, and Tailwind. Support proxy, chat list and customizable parameters. | ||
|
||
### Features | ||
- [x] chat | ||
- [x] image generation | ||
- [x] image edits | ||
- [x] image variations | ||
- [x] audio transcriptions | ||
- [x] audio translations | ||
|
||
![](public/image-generate.png) | ||
|
||
### Getting Started | ||
|
||
```shell | ||
# install tailwindcss | ||
npm install -g tailwindcss | ||
|
||
# install sass | ||
npm install -g sass | ||
|
||
# install nightly | ||
rustup toolchain install nightly | ||
|
||
# install wasm32 | ||
rustup target add wasm32-unknown-unknown | ||
|
||
# install trunk | ||
cargo install --locked trunk | ||
|
||
# install tauri-cli | ||
cargo install tauri-cli --version "^2.0.0-alpha" | ||
|
||
# dev / build | ||
cargo tauri dev / build | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[build] | ||
target = "./src-ui/index.html" | ||
|
||
[watch] | ||
ignore = ["./src-tauri"] | ||
|
||
[serve] | ||
address = "127.0.0.1" | ||
port = 1420 | ||
open = false | ||
|
||
[[hooks]] | ||
stage = "build" | ||
command = "bash" | ||
command_arguments = ["-c", "sass ./src-ui/styles.scss | tailwindcss -c ./src-ui/tailwind.config.js -i - -o $TRUNK_STAGING_DIR/styles.css"] |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[toolchain] | ||
channel = "nightly" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[package] | ||
name = "enki-shared" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
serde = { version = "1.0", features = ["derive"] } | ||
urlencoding = { version = "2.1.2" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)] | ||
pub enum AudioFormat { | ||
TXT, | ||
SRT, | ||
VTT, | ||
} | ||
|
||
pub const AUDIO_FORMATS: &[(AudioFormat, &'static str)] = &[ | ||
(AudioFormat::TXT, "text"), | ||
(AudioFormat::SRT, "srt"), | ||
(AudioFormat::VTT, "vtt"), | ||
]; | ||
|
||
impl ToString for AudioFormat { | ||
fn to_string(&self) -> String { | ||
for &(ref fmt, name) in AUDIO_FORMATS.iter() { | ||
if self == fmt { | ||
return name.to_string(); | ||
} | ||
} | ||
|
||
unreachable!(); | ||
} | ||
} | ||
|
||
impl AudioFormat { | ||
pub fn vec() -> Vec<String> { | ||
AUDIO_FORMATS | ||
.iter() | ||
.map(|&(_, name)| name.to_string()) | ||
.collect() | ||
} | ||
|
||
pub fn value_from_index(index: usize) -> Self { | ||
if index <= AUDIO_FORMATS.len() { | ||
return AUDIO_FORMATS[index].0; | ||
} | ||
|
||
panic!() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)] | ||
pub enum AudioModel { | ||
Whisper1, | ||
} | ||
|
||
pub const AUDIO_MODELS: &[(AudioModel, &'static str)] = &[(AudioModel::Whisper1, "whisper-1")]; | ||
|
||
impl ToString for AudioModel { | ||
fn to_string(&self) -> String { | ||
for &(ref fmt, name) in AUDIO_MODELS.iter() { | ||
if self == fmt { | ||
return name.to_string(); | ||
} | ||
} | ||
|
||
unreachable!(); | ||
} | ||
} | ||
|
||
impl AudioModel { | ||
pub fn vec() -> Vec<String> { | ||
AUDIO_MODELS | ||
.iter() | ||
.map(|&(_, name)| name.to_string()) | ||
.collect() | ||
} | ||
|
||
pub fn value_from_index(index: usize) -> Self { | ||
if index <= AUDIO_MODELS.len() { | ||
return AUDIO_MODELS[index].0; | ||
} | ||
|
||
panic!() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
use crate::{audio_format::AudioFormat, audio_model::AudioModel}; | ||
|
||
#[derive(Deserialize, Serialize)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct AudioParams { | ||
pub file: String, | ||
pub model: AudioModel, | ||
pub prompt: String, | ||
pub fmt: AudioFormat, | ||
pub temperature: f64, | ||
pub language: Option<String>, | ||
pub topic_id: i64, | ||
} | ||
|
||
#[derive(Deserialize, Serialize)] | ||
pub struct AudioRecordParams { | ||
pub id: i64, | ||
} | ||
|
||
#[derive(Clone, Deserialize, Serialize)] | ||
pub struct AudioData { | ||
pub id: i64, | ||
pub file: String, | ||
pub prompt: String, | ||
pub response: String, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Clone, Debug, Default, Serialize, Deserialize)] | ||
pub struct AuthData { | ||
pub token: String, | ||
} | ||
|
||
impl AuthData { | ||
pub fn into_auth_header(self) -> AuthHeader { | ||
AuthHeader { | ||
name: "Authorization".to_owned(), | ||
value: format!("Bearer {}", self.token), | ||
} | ||
} | ||
} | ||
|
||
#[derive(Clone, Debug, Default, Serialize, Deserialize)] | ||
pub struct AuthHeader { | ||
pub name: String, | ||
pub value: String, | ||
} | ||
|
||
impl AuthHeader { | ||
pub fn get_name(&self) -> &str { | ||
self.name.as_str() | ||
} | ||
|
||
pub fn get_value(&self) -> &str { | ||
self.value.as_str() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)] | ||
pub enum ChatModel { | ||
#[serde(rename = "gpt-3.5-turbo")] | ||
GPT, | ||
#[serde(rename = "gpt-3.5-turbo-0301")] | ||
GPT0301, | ||
} | ||
|
||
pub const CHAT_MODELS: &[(ChatModel, &'static str)] = &[ | ||
(ChatModel::GPT, "gpt-3.5-turbo"), | ||
(ChatModel::GPT0301, "gpt-3.5-turbo-0301"), | ||
]; | ||
|
||
impl ToString for ChatModel { | ||
fn to_string(&self) -> String { | ||
for &(ref model, name) in CHAT_MODELS.iter() { | ||
if model == self { | ||
return name.to_string(); | ||
} | ||
} | ||
|
||
unreachable!(); | ||
} | ||
} | ||
|
||
impl ChatModel { | ||
pub fn vec() -> Vec<String> { | ||
CHAT_MODELS | ||
.iter() | ||
.map(|&(_, name)| name.to_string()) | ||
.collect() | ||
} | ||
|
||
pub fn value_from_index(index: usize) -> Self { | ||
if index <= CHAT_MODELS.len() { | ||
return CHAT_MODELS[index].0; | ||
} | ||
|
||
panic!() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
use crate::chat::ChatMessage; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Clone, Debug, Deserialize, Serialize)] | ||
pub struct ChatRecord { | ||
pub speaker: ChatMessage, | ||
pub responder: Vec<ChatMessage>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use crate::chat_model::ChatModel; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Clone, Debug, Serialize, Deserialize)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct NewChat { | ||
pub message: String, | ||
pub model: ChatModel, | ||
pub instruction: Option<String>, | ||
pub temperature: f64, | ||
pub top_p: f64, | ||
pub n: i32, | ||
pub max_tokens: i32, | ||
pub presence_penalty: f64, | ||
pub frequency_penalty: f64, | ||
pub provide_previous_messages: bool, | ||
pub topic_id: i64, | ||
} | ||
|
||
#[derive(Clone, Debug, Serialize, Deserialize)] | ||
pub struct ChatMessage { | ||
pub role: String, | ||
pub content: String, | ||
} | ||
|
||
#[derive(Debug, Serialize, Deserialize)] | ||
#[serde(untagged)] | ||
pub enum ChatResponse { | ||
Ok { choices: Vec<ChatMessageObj> }, | ||
Err { error: ChatResponseError }, | ||
} | ||
|
||
#[derive(Clone, Debug, Serialize, Deserialize)] | ||
pub struct ChatMessageObj { | ||
pub message: ChatMessage, | ||
} | ||
|
||
#[derive(Debug, PartialEq, Serialize, Deserialize)] | ||
pub struct ChatResponseError { | ||
pub message: String, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
use urlencoding::encode; | ||
|
||
pub fn convert_src(src: &str) -> String { | ||
if src.starts_with("asset://localhost/") { | ||
src.to_string() | ||
} else { | ||
let url = encode(src); | ||
|
||
format!("asset://localhost/{}", url) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Debug, PartialEq, Serialize, Deserialize)] | ||
pub enum ImageCategory { | ||
Generate, | ||
Edit, | ||
Variate, | ||
} | ||
|
||
const IMAGE_CATEGORIES: &[(ImageCategory, &'static str)] = &[ | ||
(ImageCategory::Generate, "generate"), | ||
(ImageCategory::Edit, "edit"), | ||
(ImageCategory::Variate, "variate"), | ||
]; | ||
|
||
impl ToString for ImageCategory { | ||
fn to_string(&self) -> String { | ||
for (cate, name) in IMAGE_CATEGORIES.iter() { | ||
if cate == self { | ||
return name.to_string(); | ||
} | ||
} | ||
|
||
unreachable!() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Clone, Debug, Deserialize, Serialize)] | ||
pub struct ImageEditRecord { | ||
pub image: String, | ||
pub mask: Option<String>, | ||
pub prompt: String, | ||
pub images: Vec<String>, | ||
} | ||
|
||
#[derive(Debug, Deserialize, Serialize)] | ||
pub struct ImageEditRecordParams { | ||
pub id: i64, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
use crate::image_category::ImageCategory; | ||
use crate::{image_format::ImageFormat, image_size::ImageSize}; | ||
|
||
#[derive(Debug, serde::Serialize)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct ImageEditParams { | ||
pub image: String, | ||
pub mask: Option<String>, | ||
pub prompt: String, | ||
pub n: usize, | ||
pub size: ImageSize, | ||
pub fmt: ImageFormat, | ||
pub category: ImageCategory, | ||
pub topic_id: i64, | ||
} |
Oops, something went wrong.