From c36c03ded5502e7e9909ea4e7429cc87f55bebf9 Mon Sep 17 00:00:00 2001 From: Benjamin Sherriff Date: Fri, 7 Jul 2023 15:39:12 -0400 Subject: [PATCH] Working on thread titles --- Cargo.toml | 6 +++++- Dockerfile | 11 +++++++++++ src/commands/oai.rs | 24 +++++++++++++++++++++++- 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index bd3ba7e..1cdd0af 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,4 +38,8 @@ features = ["json", "rustls-tls"] [dependencies.diesel] version = "2.1.0" default-features = false -features = ["postgres", "32-column-tables", "serde_json", "r2d2", "with-deprecated"] \ No newline at end of file +features = ["postgres", "32-column-tables", "serde_json", "r2d2", "with-deprecated"] + +[dependencies.rust-bert] +version = "0.21.0" +features = ["download-libtorch"] \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 62edc3f..c39cdb8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,10 +13,21 @@ RUN apt-get update && apt-get install -y curl tar xz-utils && \ curl -L https://github.com/yt-dlp/FFmpeg-Builds/releases/download/latest/ffmpeg-master-latest-linux64-gpl.tar.xz > ffmpeg.tar.xz && \ tar -xJf ffmpeg.tar.xz --wildcards */bin/ffmpeg --transform='s/^.*\///' && rm ffmpeg.tar.xz +# FROM debian:bullseye-slim as libraries +# WORKDIR /libraries +# RUN apt-get update && apt-get install -y unzip && \ +# curl -L https://download.pytorch.org/libtorch/cu117/libtorch-cxx11-abi-shared-with-deps-2.0.1%2Bcu117.zip > libtorch.zip && \ +# unzip libtorch.zip && rm libtorch.zip + FROM debian:bullseye-slim as runtime WORKDIR /siren RUN apt-get update && apt-get install -y libopus-dev libpq5 libpq-dev && apt-get auto-remove -y COPY --from=builder /siren/target/release/siren /usr/local/bin/siren COPY --from=packages /packages /usr/bin +# COPY --from=libraries /libraries /usr/lib + +# ARG LIBTORCH=/usr/lib/libtorch +# ARG LD_LIBRARY_PATH=${LIBTORCH}/lib:${LD_LIBRARY_PATH} + # ADD migrations ./ CMD ["siren"] diff --git a/src/commands/oai.rs b/src/commands/oai.rs index 83b1161..9341476 100644 --- a/src/commands/oai.rs +++ b/src/commands/oai.rs @@ -290,7 +290,7 @@ pub async fn generate_response(ctx: &Context, msg: &Message, oai: &OAI, pool: &P // Stop the typing indicator and send the response typing.stop(); match msg.channel_id.create_public_thread(&ctx.http, msg.id, |thread| { - thread.name("Siren Response").kind(ChannelType::PublicThread) + thread.name(truncate(&parsed_content, 99)).kind(ChannelType::PublicThread) }).await { Ok(c) => { if let Err(why) = c.say(&ctx.http, response).await { @@ -304,3 +304,25 @@ pub async fn generate_response(ctx: &Context, msg: &Message, oai: &OAI, pool: &P } }; } + +fn truncate(s: &str, max_chars: usize) -> &str { + match s.char_indices().nth(max_chars) { + None => s, + Some((idx, _)) => &s[..idx], + } +} + +// fn summarization_model() -> Result { +// let config_resource = RemoteResource::from_pretrained(T5ConfigResources::T5_SMALL); +// let vocab_resource = RemoteResource::from_pretrained(T5VocabResources::T5_SMALL); +// let weights_resource = RemoteResource::from_pretrained(T5ModelResources::T5_SMALL); + +// let summarization_config = SummarizationConfig::new( +// ModelType::T5, +// ModelResource::Torch(Box::new(weights_resource)), +// config_resource, +// vocab_resource, +// None +// ); +// return SummarizationModel::new(summarization_config); +// }