Bullpen
Bullpen is an unofficial async Rust library that allows you to interact with the Pplx API and Modelfarm APIs.
You can use the Modelfarm client without any api keys, but you will need to provide an api key for the Pplx client.
Modelfarm supports Chat, Completions, and Embeddings. Pplx supports Chat and Completions.
I'll be adding bitcoin and ecash payments as a payment option for the Pplx client soon, then you won't need an api key.
For Developers and Contributors: Contributions
Forked from OpenAI Dive: https://github.com/tjardoo/pplx-client
You can run any of the examples in the examples dir with cargo run --example <example_name>
Modelfarm Example
#[tokio::main]
async fn main() {
let modelfarm = Modelfarm::new();
let chat_session = ChatSession {
context: "You are a programmer bot".to_string(),
examples: vec![ChatExample {
input: ChatMessage {
content: "1 + 1".to_string(),
author: "user".to_string(),
},
output: ChatMessage {
content: "2".to_string(),
author: "assistant".to_string(),
},
}],
messages: vec![ChatMessage {
content: "How do I write a nix flake for a rust project?".to_string(),
author: "user".to_string(),
}],
};
let req = ModelfarmChatCompletionRequest {
model: ModelfarmChatModel::ChatBison,
parameters: ModelfarmChatParameters {
prompts: vec![chat_session],
temperature: 0.2,
max_output_tokens: 1024,
},
};
let result = modelfarm.chat(req).await.unwrap();
println!("{:?}", result);
}
Pplx Example
#[tokio::main]
async fn main() {
dotenv().ok();
let api_key = env::var("PPLX_API_KEY").expect("$PPLX_API_KEY is not set");
let client = Pplx::new(api_key);
let parameters = PplxChatCompletionParameters {
model: PplxChatModel::Mistral7bInstruct,
messages: vec![
ChatMessage {
role: Role::User,
content: "Hello!".to_string(),
..Default::default()
},
ChatMessage {
role: Role::User,
content: "Tell me a story?".to_string(),
..Default::default()
},
],
temperature: None,
top_p: None,
top_k: None,
max_tokens: Some(1000),
presence_penalty: None,
frequency_penalty: None,
};
let mut stream = client.stream_chat(parameters).await.unwrap();
while let Some(response) = stream.next().await {
match response {
Ok(chat_response) => chat_response.choices.iter().for_each(|choice| {
if let Some(content) = choice.delta.content.as_ref() {
print!("{}", content);
}
}),
Err(e) => eprintln!("{}", e),
}
}
}
Contributions
Contributions are welcome! Please open an issue or submit a pull request.
Developer Environment
This is a stable rust 2021 project. You can install the latest stable rust toolchain with rustup:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
This project also uses Nix Flakes to manage the development environment. You can install Nix with:
curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install
After installing Nix, you can enter the development environment with:
nix develop
Then build the project and run commands using just:
build *ARGS="--workspace --all-targets" b *ARGS="--workspace --all-targets" check *ARGS="--workspace --all-targets" c *ARGS="--workspace --all-targets" clippy *ARGS="--locked --offline --workspace --all-targets" clippy-fix *ARGS="--locked --offline --workspace --all-targets" final-check format lint semgrep test t typos *PARAMS typos-fix-all watch *ARGS="-x run"