-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.rs
78 lines (71 loc) · 2.16 KB
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
use rustyline::error::ReadlineError;
use rustyline::DefaultEditor;
use std::{
io::{BufReader, Read, Write},
process::{Command, Stdio},
};
fn main() {
let mut rl = DefaultEditor::new().unwrap();
loop {
let readline = rl.readline(">> ");
match readline {
Ok(line) => {
post_form("hello".to_string());
if false {
Command::new("stdbuf")
.current_dir("../llama.cpp")
.arg("-o0")
.arg("./main")
.arg("-m")
// .arg("./models/7B/ggml-model-f16.bin")
.arg("./models/7B/ggml-model-q4_0.bin")
.arg("-t")
.arg("12")
.arg("-n")
.arg("32")
.arg("-p")
.arg(line.trim())
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.output()
.expect("Failed to execute command");
}
}
Err(ReadlineError::Interrupted) => {
println!("CTRL-C");
break;
}
Err(ReadlineError::Eof) => {
println!("CTRL-D");
break;
}
Err(err) => {
println!("Error: {:?}", err);
break;
}
}
}
}
pub fn post_form(prompt: String) {
std::thread::spawn(move || {
let client = reqwest::blocking::Client::new();
let response = client
.get("http://localhost:4277/stream_output")
.body(format!(
r#"
{{
"prompt": "{}",
}}
"#,
prompt
))
.send();
let response = response.unwrap();
let mut reader = BufReader::new(response);
let mut buf = [0u8];
while let Ok(()) = reader.read_exact(&mut buf) {
print!("{}", buf[0] as char);
std::io::stdout().flush().unwrap();
}
});
}