-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support Perplexity chat completion
- Loading branch information
Showing
11 changed files
with
645 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,11 @@ | ||
[package] | ||
name = "perplexity-chat-completion" | ||
version = "0.1.0" | ||
edition = "2021" | ||
publish = false | ||
|
||
[dependencies] | ||
perplexity = { path = "../../perplexity" } | ||
futures-util = "0.3.30" | ||
tokio = { version = "1.39.2", features = ["full"] } | ||
serde_json = "1.0.128" |
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 @@ | ||
# Perplexity chat completion Example |
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,17 @@ | ||
use perplexity::{ | ||
client::{Client, CreateChatCompletion, Model}, | ||
config::Config, | ||
}; | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
let api_key = std::env::var("PERPLEXITY_API_KEY") | ||
.expect("environment variable PERPLEXITY_API_KEY should be defined"); | ||
|
||
let config = Config::new(api_key); | ||
let client = Client::new(config).unwrap(); | ||
|
||
let message = CreateChatCompletion::new(Model::Llama31SonarLargeOnline); | ||
let result = client.create_completion(message).await.unwrap(); | ||
println!("{:?}", result); | ||
} |
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,23 @@ | ||
[package] | ||
name = "perplexity" | ||
version = "0.1.0" | ||
edition.workspace = true | ||
authors.workspace = true | ||
description = "Perplexity Rust SDK" | ||
homepage.workspace = true | ||
documentation.workspace = true | ||
repository = "https://github.com/roushou/mesh" | ||
readme = "README.md" | ||
license.workspace = true | ||
keywords = ["ai", "chat", "perplexity"] | ||
|
||
[dependencies] | ||
futures-util = "0.3.30" | ||
reqwest = { version = "0.12.5", features = ["json", "stream"] } | ||
serde = { version = "1.0.206", features = ["derive"] } | ||
serde_json = "1.0.124" | ||
thiserror = "1.0.63" | ||
tokio = { version = "1.39.2", features = ["full"] } | ||
|
||
[dev-dependencies] | ||
pretty_assertions = "1.4.0" |
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,55 @@ | ||
# Perplexity Rust SDK | ||
|
||
[![Crates.io][crates-badge]][crates-url] | ||
[![MIT licensed][mit-badge]][mit-url] | ||
[![APACHE-2.0 licensed][apache-badge]][apache-url] | ||
[![Build Status][actions-badge]][actions-url] | ||
|
||
[crates-badge]: https://img.shields.io/crates/v/perplexity.svg | ||
[crates-url]: https://crates.io/crates/perplexity | ||
[mit-badge]: https://img.shields.io/badge/license-MIT-blue.svg | ||
[mit-url]: https://github.com/roushou/mesh/blob/master/LICENSE-MIT | ||
[apache-badge]: https://img.shields.io/badge/license-apache-blue.svg | ||
[apache-url]: https://github.com/roushou/mesh/blob/master/LICENSE-APACHE | ||
[actions-badge]: https://github.com/roushou/mesh/workflows/CI/badge.svg | ||
[actions-url]: https://github.com/roushou/mesh/actions?query=workflow%3ACI+branch%3Amaster | ||
|
||
This is an unofficial Rust SDK for the Perplexity API. | ||
|
||
More information about this crate can be found in the [crate documentation](https://crates.io/crates/perplexity). | ||
|
||
## Installation | ||
|
||
Add `perplexity` as a dependency to your `Cargo.toml` | ||
|
||
```sh | ||
$ cargo add perplexity | ||
``` | ||
|
||
## Usage | ||
|
||
An example to create a completion. | ||
|
||
```rust,ignore | ||
use perplexity::{ | ||
client::{Client, CreateChatCompletion, Model}, | ||
config::Config, | ||
}; | ||
#[tokio::main] | ||
async fn main() { | ||
let api_key = std::env::var("PERPLEXITY_API_KEY") | ||
.expect("environment variable PERPLEXITY_API_KEY should be defined"); | ||
let config = Config::new(api_key); | ||
let client = Client::new(config).unwrap(); | ||
let message = CreateChatCompletion::new(Model::Llama31SonarLargeOnline); | ||
let result = client.create_completion(message.clone()).await.unwrap(); | ||
println!("{:?}", result); | ||
} | ||
``` | ||
|
||
## License | ||
|
||
This project is licensed under the [MIT license](../LICENSE-MIT) and [Apache-2.0](../LICENSE-APACHE) license. |
Oops, something went wrong.