Skip to content

Commit

Permalink
Replace all repeated newlines in the chat input.
Browse files Browse the repository at this point in the history
  • Loading branch information
cedruszhang committed Oct 30, 2023
1 parent 2c4a277 commit bfce88a
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/oai/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use axum::{
};
use futures_util::{Stream, StreamExt};
use itertools::Itertools;
use regex::Regex;
use serde::{Deserialize, Serialize};

use crate::{
Expand Down Expand Up @@ -92,10 +93,12 @@ impl From<ChatRequest> for GenerateRequest {
..
} = value;

let re = Regex::new(r"\n(\s*\n)+").unwrap();
let prompt = Vec::from(messages.clone())
.into_iter()
.map(|ChatRecord { role, content }| {
let role = names.get(&role).cloned().unwrap_or(role.to_string());
let content = re.replace_all(&content, "\n");
let content = content.trim();
format!("{role}: {content}")
})
Expand Down

0 comments on commit bfce88a

Please sign in to comment.