-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* twitch chat interactive mode - twitch chat is interactive. - stable diffusion token count to avoid crashing. - better prompt segmentation. - STT doesn't make awful sounds. - Pad NDI audio output and remove funny characters. * add cabextract dep and fonts extraction - less history in twitch bot. * unpack fonts fixes * twitch chat info added to readme * v0.5.2 * build without needing fonts extracted allow building without fonts extracted for docs.rs. * add build info for fonts inclusion --------- Co-authored-by: Chris Kennedy <[email protected]>
- Loading branch information
1 parent
5f1e079
commit 01fd037
Showing
17 changed files
with
830 additions
and
401 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 |
---|---|---|
@@ -1,25 +1,27 @@ | ||
name: Rust | ||
|
||
on: | ||
push: | ||
branches: [ "main", "staging" ] | ||
pull_request: | ||
branches: [ "main", "staging" ] | ||
push: | ||
branches: ["main", "staging"] | ||
pull_request: | ||
branches: ["main", "staging"] | ||
|
||
env: | ||
CARGO_TERM_COLOR: always | ||
CARGO_TERM_COLOR: always | ||
|
||
jobs: | ||
build: | ||
runs-on: macos-latest # Changed from ubuntu-latest to macos-latest | ||
build: | ||
runs-on: macos-latest # Changed from ubuntu-latest to macos-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Install dependencies | ||
run: | | ||
brew update | ||
brew install libpcap zmq capnp | ||
- name: Build | ||
run: cargo build --verbose | ||
- name: Run tests | ||
run: cargo test --verbose | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Install dependencies | ||
run: | | ||
brew update | ||
brew install libpcap zmq capnp cabextract | ||
- name: Build | ||
run: | | ||
cd fonts && sh unpack_fonts.sh && cd ../ | ||
cargo build --verbose | ||
- name: Run tests | ||
run: cargo test --verbose |
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
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
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
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
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,70 @@ | ||
#!/bin/bash | ||
# | ||
# Alice's AI Wonderland Character: | ||
# - Parody of walt-disney's original Alice animations, the first ones that got published. | ||
# | ||
# RsLLM configuration script: | ||
# - @2024 Christi Kennedy - This is not related to any known alices or wonderlands. | ||
# | ||
# | ||
|
||
# === CONFIGURATION === | ||
BUILD_TYPE=release | ||
MODEL=gemma | ||
MODEL_ID=2b-it | ||
MAX_TOKENS=800 | ||
ALIGNMENT=center | ||
TEMPERATURE=0.8 | ||
CONTINUOUS=0 | ||
POLL_INTERVAL=0 | ||
PIPELINE_CONCURRENCY=3 | ||
CONTEXT_SIZE=3000 | ||
SUBTITLES=1 | ||
DAEMON=1 | ||
KEEP_HISTORY=1 | ||
GREETING="Hi I'm Alice, ask me a question!" | ||
# === END OF CONFIGURATION === | ||
# | ||
# | ||
SUBTITLE_CMD= | ||
DAEMON_CMD= | ||
NO_HISTORY_CMD= | ||
if [ "$SUBTITLES" == 1 ]; then | ||
SUBTITLE_CMD="--subtitles" | ||
fi | ||
if [ "$DAEMON" == 1 ]; then | ||
DAEMON_CMD="--daemon" | ||
fi | ||
if [ "$CONTINUOUS" == 1 ]; then | ||
CONTINUOUS_CMD="--continuous" | ||
fi | ||
if [ "$KEEP_HISTORY" == 0 ]; then | ||
NO_HISTORY_CMD="--no-history" | ||
fi | ||
|
||
SYSTEM_PROMPT="you are Alice and run Alice's AI Wonderland twitch streaming channel, you chat with twitch users in your twitch channel who ask you questions and have discussions. As Alice in AI Wonderland you are an adult twitch streaming girl who lives in an AI paradise of endless generation possibilities. Always talk in first person as the character speaking. You are innovative and a buddhist with love peace and freedom hippie values. Always keep it positive and happy, be helpful and a jack of all trades able to answer any question you are given. If you don't know for sure, just make up something funny." | ||
PROMPT="create a story based on an anime About Alice an adult twitch streaming girl who lives in AI Wonderland. Have it vary off the title 'Alice in AI Wonderland' with a random plotline you create based on classic anime characters appearing in the wonderland. Alices AI Wonderland is a happy fun show where Alice goes through experiences similar to Alice in Wonderland where she grows small or large depending one what she eats. Add in AI technology twists. Have it fully formatted like a transcript with the character speaking parts mostly speaking in first person, minimal narration. create a whole episode full length with classic anime characters with Alice the main character of AI Wonderland." | ||
|
||
|
||
DYLD_LIBRARY_PATH=`pwd`:/usr/local/lib:$DYLD_LIBRARY_PATH \ | ||
RUST_BACKTRACE=full target/${BUILD_TYPE}/rsllm \ | ||
--query "$PROMPT" \ | ||
--system-prompt "$SYSTEM_PROMPT" \ | ||
--candle-llm $MODEL \ | ||
--twitch-client \ | ||
--sd-image \ | ||
--ndi-audio \ | ||
--ndi-images \ | ||
--mimic3-tts \ | ||
--model-id $MODEL_ID \ | ||
--image-alignment $ALIGNMENT \ | ||
--temperature $TEMPERATURE \ | ||
--pipeline-concurrency $PIPELINE_CONCURRENCY \ | ||
--poll-interval $POLL_INTERVAL \ | ||
--llm-history-size $CONTEXT_SIZE \ | ||
--greeting "$GREETING" \ | ||
$SUBTITLE_CMD \ | ||
$DAEMON_CMD \ | ||
$CONTINUOUS_CMD \ | ||
$NO_HISTORY_CMD \ | ||
--max-tokens $MAX_TOKENS $@ |
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
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,69 @@ | ||
use minimp3::{Decoder, Frame}; | ||
use std::io::Cursor; | ||
use std::io::Result; | ||
|
||
/// Converts WAV PCM data to f32 samples without explicitly handling error cases in the return type. | ||
/// | ||
/// # Arguments | ||
/// * `wav_data` - The bytes of a WAV file. | ||
/// | ||
/// # Returns | ||
/// A `Result` containing a `Vec<f32>` of normalized audio samples, or an `Error`. | ||
pub fn wav_to_f32(wav_data: Vec<u8>) -> Result<Vec<f32>> { | ||
let cursor = Cursor::new(wav_data); | ||
let reader_result = hound::WavReader::new(cursor); | ||
|
||
// Check if the reader was successfully created | ||
let reader = match reader_result { | ||
Ok(r) => r, | ||
Err(_) => return Ok(Vec::new()), // In case of an error, return an empty vector to match the mp3_to_f32 strategy | ||
}; | ||
|
||
// Depending on the sample format, process the samples differently | ||
let spec = reader.spec(); | ||
let sample_format = spec.sample_format; | ||
let bits_per_sample = spec.bits_per_sample; | ||
|
||
let samples = match sample_format { | ||
hound::SampleFormat::Float => reader | ||
.into_samples::<f32>() | ||
.filter_map(|result_sample| result_sample.ok()) // Convert Result<f32, hound::Error> to Option<f32>, and then filter_map will filter out the None values | ||
.collect(), | ||
|
||
hound::SampleFormat::Int => match bits_per_sample { | ||
16 => reader | ||
.into_samples::<i16>() | ||
.filter_map(|result_sample| result_sample.ok()) // Convert Result<i16, hound::Error> to Option<i16> | ||
.map(|sample| sample as f32 / i16::MAX as f32) // Normalize | ||
.collect(), | ||
|
||
24 => reader | ||
.into_samples::<i32>() | ||
.filter_map(|result_sample| result_sample.ok()) // Convert Result<i32, hound::Error> to Option<i32> | ||
.map(|sample| (sample >> 8) as f32 / i16::MAX as f32) // Shift and normalize for 24-bit stored in i32 | ||
.collect(), | ||
|
||
// In case of an unsupported bit depth, return an empty vector | ||
_ => Vec::new(), | ||
}, | ||
}; | ||
|
||
Ok(samples) | ||
} | ||
|
||
pub fn mp3_to_f32(mp3_data: Vec<u8>) -> Result<Vec<f32>> { | ||
let cursor = Cursor::new(mp3_data); | ||
let mut decoder = Decoder::new(cursor); | ||
let mut samples_f32 = Vec::new(); | ||
|
||
while let Ok(Frame { data, .. }) = decoder.next_frame() { | ||
for &sample in &data { | ||
// Convert each sample to f32; MP3 samples are typically s16. | ||
// Normalize the s16 sample to the range [-1.0, 1.0]. | ||
let sample_f32 = sample as f32 / i16::MAX as f32; | ||
samples_f32.push(sample_f32); | ||
} | ||
} | ||
|
||
Ok(samples_f32) | ||
} |
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
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
Oops, something went wrong.