Skip to content

Commit

Permalink
feat: v0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
DrackRamoray committed Mar 22, 2023
0 parents commit 3b3ed50
Show file tree
Hide file tree
Showing 232 changed files with 8,641 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/**/dist/
/target/
/Cargo.lock
/.idea
.DS_Store
3 changes: 3 additions & 0 deletions .taurignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/src-ui
/public
/Cargo.toml
6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[workspace]
members = [
"src-shared",
"src-tauri",
"src-ui",
]
37 changes: 37 additions & 0 deletions README.md
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
```
15 changes: 15 additions & 0 deletions Trunk.toml
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"]
Binary file added public/image-generate.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[toolchain]
channel = "nightly"
10 changes: 10 additions & 0 deletions src-shared/Cargo.toml
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" }
43 changes: 43 additions & 0 deletions src-shared/src/audio-format.rs
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!()
}
}
37 changes: 37 additions & 0 deletions src-shared/src/audio-model.rs
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!()
}
}
28 changes: 28 additions & 0 deletions src-shared/src/audio.rs
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,
}
31 changes: 31 additions & 0 deletions src-shared/src/auth.rs
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()
}
}
43 changes: 43 additions & 0 deletions src-shared/src/chat-model.rs
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!()
}
}
8 changes: 8 additions & 0 deletions src-shared/src/chat-record.rs
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>,
}
41 changes: 41 additions & 0 deletions src-shared/src/chat.rs
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,
}
11 changes: 11 additions & 0 deletions src-shared/src/convert-src.rs
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)
}
}
26 changes: 26 additions & 0 deletions src-shared/src/image-category.rs
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!()
}
}
14 changes: 14 additions & 0 deletions src-shared/src/image-edit-record.rs
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,
}
15 changes: 15 additions & 0 deletions src-shared/src/image-edit.rs
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,
}
Loading

0 comments on commit 3b3ed50

Please sign in to comment.