Skip to content

Commit

Permalink
Remove unused features
Browse files Browse the repository at this point in the history
  • Loading branch information
SagenKoder committed Dec 26, 2023
1 parent fd14db7 commit e6c3b5a
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 63 deletions.
56 changes: 0 additions & 56 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 4 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ description = "A GPT client making it easy to use ChatGPT by exposing a simple A

[dependencies]
byteorder = "1.5"
tokio = { version = "1.35.1", features = ["full"] }
chatgpt_rs = { version = "1.2.3", features = ["default", "streams"] }
futures-util = { version = "0.3.17", features = ["default"] }
futures = "0.3.30"
tokio = { version = "1.35.1", features = ["macros", "rt-multi-thread", "signal"] }
chatgpt_rs = { version = "1.2.3", features = ["json", "streams"] }
futures = { version = "0.3.30", features = ["async-await", "std", "executor"] }
clap = { version = "4.4.11", features = ["derive", "env"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
serde_json = { version = "1.0", features = ["std"] }

[[bin]]
name = "gpt_for_uds"
Expand Down
6 changes: 6 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
gpt-for-uds (1.0-20231229222702) unstable; urgency=medium

* Remove unused features

-- Alexander Sagen <alexander.sagen@visma.com> Wed, 28 Dec 2023 23:26:02 +0100

gpt-for-uds (1.0-20231229222602) unstable; urgency=medium

* Make binary a lot smaller
Expand Down
2 changes: 1 addition & 1 deletion src/client_handler.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use tokio::net::UnixStream;
use std::error::Error;
use std::io::Cursor;
use futures_util::StreamExt;
use futures::StreamExt;
use byteorder::{BigEndian, ReadBytesExt};
use tokio::io::{AsyncReadExt, AsyncWriteExt};
use crate::gpt_client::{GptEngine, GptMessage, stream_gpt_response};
Expand Down
9 changes: 9 additions & 0 deletions src/gpt_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,30 @@ use chatgpt::prelude::Conversation;
use chatgpt::types::{ChatMessage, ResponseChunk};
use serde::{Deserialize, Serialize};

#[allow(dead_code)]
#[derive(Clone)]
pub enum GptEngine {
Gpt35Turbo(String),
Gpt4(String),
Gpt4_32k(String),
}

#[allow(dead_code)]
#[derive(Clone, Deserialize, Serialize)]
pub enum GptActor {
System,
User,
Assistant
}

#[allow(dead_code)]
#[derive(Clone, Deserialize, Serialize)]
pub struct GptMessage {
pub(crate) actor: GptActor,
pub(crate) message: String,
}

#[allow(dead_code)]
fn get_client_engine(engine: GptEngine) -> ChatGPTEngine {
match engine {
GptEngine::Gpt35Turbo(_) => ChatGPTEngine::Gpt35Turbo,
Expand All @@ -34,6 +38,7 @@ fn get_client_engine(engine: GptEngine) -> ChatGPTEngine {
}
}

#[allow(dead_code)]
fn get_client_actor(actor: GptActor) -> chatgpt::types::Role {
match actor {
GptActor::System => chatgpt::types::Role::System,
Expand All @@ -42,6 +47,7 @@ fn get_client_actor(actor: GptActor) -> chatgpt::types::Role {
}
}

#[allow(dead_code)]
pub fn create_gpt_client(engine: GptEngine) -> Result<ChatGPT, String> {
let (token, client_engine) = match engine {
GptEngine::Gpt35Turbo(token) => (token, ChatGPTEngine::Gpt35Turbo),
Expand All @@ -59,12 +65,14 @@ pub fn create_gpt_client(engine: GptEngine) -> Result<ChatGPT, String> {
Ok(client)
}

#[allow(dead_code)]
fn create_client_conversation(engine: GptEngine, history: Vec<GptMessage>) -> Result<Conversation, String> {
let map = get_client_messages(history);
let conversation = Conversation::new_with_history(create_gpt_client(engine)?, map);
Ok(conversation)
}

#[allow(dead_code)]
pub async fn stream_gpt_response(
engine: GptEngine,
mut history: Vec<GptMessage>
Expand All @@ -88,6 +96,7 @@ pub async fn stream_gpt_response(
Ok(Box::pin(stream))
}

#[allow(dead_code)]
fn get_client_messages(history: Vec<GptMessage>) -> Vec<ChatMessage> {
history.iter().map(|message| ChatMessage {
role: get_client_actor(message.clone().actor),
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ fn get_configuration() -> Result<(String, String), String> {
None => return Err("Socket directory must be a valid UTF-8 string!".to_string()),
};

if (!socket_dir_string.ends_with("/")) {
if !socket_dir_string.ends_with("/") {
socket_dir_string = socket_dir_string + "/";
}

Expand Down

0 comments on commit e6c3b5a

Please sign in to comment.