Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

checking and fixing all Rust examples #35

Merged
merged 1 commit into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion fern/docs/pages/reference/PII.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ your preference or requirements, select the appropriate method for your applicat
let clt = client::Client::new(pg_env).expect("client value");

let req = pii::Request::new(
"Hello, my name is John Doe and my SSN is 111-22-3333.".to_string(),
"My email is [email protected] and my number is 270-123-4567".to_string(),
true,
ReplaceMethod::Mask,
);
Expand Down
14 changes: 1 addition & 13 deletions fern/docs/pages/reference/chat.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -153,21 +153,9 @@ your application.
let clt = client::Client::new(pg_env).expect("client value");

let req = chat::Request::<chat::Message>::new(models::Model::NeuralChat7B)
.add_message(
chat::Roles::System,
"You are a helpful assistant that provide clever and sometimes funny responses.".to_string(),
)
.add_message(
chat::Roles::User,
"What's up!".to_string(),
)
.add_message(
chat::Roles::Assistant,
"Well, technically vertically out from the center of the earth.".to_string(),
)
.add_message(
chat::Roles::User,
"Haha. Good one.".to_string(),
"How do you feel about the world in general?".to_string(),
)
.max_tokens(1000)
.temperature(0.85);
Expand Down
20 changes: 5 additions & 15 deletions fern/docs/pages/reference/chat_sse.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ method for your application.
```rust
extern crate prediction_guard as pg_client;

use std::io::Write;

use pg_client::{chat, client, models};

#[tokio::main]
Expand All @@ -149,22 +151,10 @@ method for your application.

let clt = client::Client::new(pg_env).expect("client value");

let req = chat::Request::<chat::Message>::new(models::Model::NeuralChat7B)
.add_message(
chat::Roles::System,
"You are a helpful assistant that provide clever and sometimes funny responses.".to_string(),
)
.add_message(
chat::Roles::User,
"What's up!".to_string(),
)
.add_message(
chat::Roles::Assistant,
"Well, technically vertically out from the center of the earth.".to_string(),
)
let mut req = chat::Request::<chat::Message>::new(models::Model::NeuralChat7B)
.add_message(
chat::Roles::User,
"Haha. Good one.".to_string(),
"How do you feel about the world in general".to_string(),
)
.max_tokens(1000)
.temperature(0.85);
Expand All @@ -178,7 +168,7 @@ method for your application.
};

let result = clt
.generate_chat_completion_events(req, &mut evt_handler)
.generate_chat_completion_events(&mut req, &mut evt_handler)
.await
.expect("error from chat_events");

Expand Down
4 changes: 3 additions & 1 deletion fern/docs/pages/reference/chat_vision.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ images that are base64 encoded represented by a data uri.
.max_tokens(1000)
.add_message(
chat::Roles::User,
"What's in this image?".to_string(),
"What is in this image?".to_string(),
IMAGE.to_string(),
);

Expand All @@ -155,6 +155,8 @@ images that are base64 encoded represented by a data uri.

println!("\nchat completion response:\n\n {:?}", result);
}

const IMAGE: &str = r#"data:image/jpeg;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAFUlEQVR42mP8z8BQz0AEYBxVSF+FABJADveWkH6oAAAAAElFTkSuQmCC"#;
```
</CodeBlock>

Expand Down
2 changes: 1 addition & 1 deletion fern/docs/pages/reference/completions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ on your preference or requirements, select the appropriate method for your appli

let req = completion::Request::new(
models::Model::NeuralChat7B,
"The best joke I know is: ".to_string(),
"Will I lose my hair?".to_string(),
);

let result = clt
Expand Down
2 changes: 1 addition & 1 deletion fern/docs/pages/reference/embeddings.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ encoded in a base64 string.
let pg_env = client::PgEnvironment::from_env().expect("env keys");

let img_str = match image::encode(
"https://farm4.staticflickr.com/3300/3497460990_11dfb95dd1_z.jpg".to_string(),
"https://farm4.staticflickr.com/3300/3497460990_11dfb95dd1_z.jpg".to_string(),
)
.await
{
Expand Down
4 changes: 2 additions & 2 deletions fern/docs/pages/reference/factuality.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ for your application.
let clt = client::Client::new(pg_env).expect("client value");

let req = factuality::Request::new(
"The sky is blue.".to_string(),
"The sky is green".to_string(),
"The President shall receive in full for his services during the term for which he shall have been elected compensation in the aggregate amount of 400,000 a year, to be paid monthly, and in addition an expense allowance of 50,000 to assist in defraying expenses relating to or resulting from the discharge of his official duties. Any unused amount of such expense allowance shall revert to the Treasury pursuant to section 1552 of title 31, United States Code. No amount of such expense allowance shall be included in the gross income of the President. He shall be entitled also to the use of the furniture and other effects belonging to the United States and kept in the Executive Residence at the White House.".to_string(),
"The president of the united states can take a salary of one million dollars".to_string(),
);

let result = clt
Expand Down
2 changes: 1 addition & 1 deletion fern/docs/pages/reference/toxicity.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ on your preference or requirements, select the appropriate method for your appli
let clt = client::Client::new(pg_env).expect("client value");

let req = toxicity::Request::new(
"This is a perfectly fine statement.".to_string(),
"Every flight I have is late and I am very angry. I want to hurt someone.".to_string(),
);

let result = clt.toxicity(&req).await.expect("error from toxicity");
Expand Down
7 changes: 4 additions & 3 deletions fern/docs/pages/reference/translate.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ your preference or requirements, select the appropriate method for your applicat

<CodeBlock title="Rust">
```rust
extern crate prediction_guard as pg_client;
extern crate prediction_guard as pg_client;

use pg_client::{client, translate};

Expand All @@ -122,9 +122,10 @@ your preference or requirements, select the appropriate method for your applicat
let clt = client::Client::new(pg_env).expect("client value");

let req = translate::Request::new(
"The sky is blue".to_string(),
"The rain in Spain stays mainly in the plain".to_string(),
translate::Language::English,
translate::Language::French,
translate::Language::Spanish,
true,
);

let result = clt.translate(&req).await.expect("error from translate");
Expand Down
7 changes: 3 additions & 4 deletions fern/docs/pages/sdks.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,9 @@ You can find the SDK docs and package information using this link.
#### Rust Code Example

```rust copy
use std::env;
extern crate prediction_guard as pg_client;

use pg_rust_client as pg_client;
use pg_client::{client, chat, models};
use pg_client::{chat, client, models};

#[tokio::main]
async fn main() {
Expand All @@ -237,7 +236,7 @@ async fn main() {
"How do you feel about the world in general?".to_string(),
)
.max_tokens(1000)
.temperature(0.8);
.temperature(0.85);

let result = clt
.generate_chat_completion(&req)
Expand Down
Loading