From b1cd7d1166a839c42ccabc34c1920a22dc4b003e Mon Sep 17 00:00:00 2001 From: jmansdorfer Date: Tue, 27 Aug 2024 09:33:07 -0400 Subject: [PATCH] checking and fixing all Rust examples --- fern/docs/pages/reference/PII.mdx | 2 +- fern/docs/pages/reference/chat.mdx | 14 +------------- fern/docs/pages/reference/chat_sse.mdx | 20 +++++--------------- fern/docs/pages/reference/chat_vision.mdx | 4 +++- fern/docs/pages/reference/completions.mdx | 2 +- fern/docs/pages/reference/embeddings.mdx | 2 +- fern/docs/pages/reference/factuality.mdx | 4 ++-- fern/docs/pages/reference/toxicity.mdx | 2 +- fern/docs/pages/reference/translate.mdx | 7 ++++--- fern/docs/pages/sdks.mdx | 7 +++---- 10 files changed, 22 insertions(+), 42 deletions(-) diff --git a/fern/docs/pages/reference/PII.mdx b/fern/docs/pages/reference/PII.mdx index 60395cf..1670348 100644 --- a/fern/docs/pages/reference/PII.mdx +++ b/fern/docs/pages/reference/PII.mdx @@ -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 joe@gmail.com and my number is 270-123-4567".to_string(), true, ReplaceMethod::Mask, ); diff --git a/fern/docs/pages/reference/chat.mdx b/fern/docs/pages/reference/chat.mdx index 5c05856..31e43da 100644 --- a/fern/docs/pages/reference/chat.mdx +++ b/fern/docs/pages/reference/chat.mdx @@ -153,21 +153,9 @@ your application. let clt = client::Client::new(pg_env).expect("client value"); let req = chat::Request::::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); diff --git a/fern/docs/pages/reference/chat_sse.mdx b/fern/docs/pages/reference/chat_sse.mdx index c0b50f2..c5c93c1 100644 --- a/fern/docs/pages/reference/chat_sse.mdx +++ b/fern/docs/pages/reference/chat_sse.mdx @@ -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] @@ -149,22 +151,10 @@ method for your application. let clt = client::Client::new(pg_env).expect("client value"); - let req = chat::Request::::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::::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); @@ -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"); diff --git a/fern/docs/pages/reference/chat_vision.mdx b/fern/docs/pages/reference/chat_vision.mdx index 2664818..9df9dba 100644 --- a/fern/docs/pages/reference/chat_vision.mdx +++ b/fern/docs/pages/reference/chat_vision.mdx @@ -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(), ); @@ -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"#; ``` diff --git a/fern/docs/pages/reference/completions.mdx b/fern/docs/pages/reference/completions.mdx index 00b8d15..4d70aa8 100644 --- a/fern/docs/pages/reference/completions.mdx +++ b/fern/docs/pages/reference/completions.mdx @@ -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 diff --git a/fern/docs/pages/reference/embeddings.mdx b/fern/docs/pages/reference/embeddings.mdx index 8f687f5..0a81f72 100644 --- a/fern/docs/pages/reference/embeddings.mdx +++ b/fern/docs/pages/reference/embeddings.mdx @@ -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 { diff --git a/fern/docs/pages/reference/factuality.mdx b/fern/docs/pages/reference/factuality.mdx index c64bc62..ca0693d 100644 --- a/fern/docs/pages/reference/factuality.mdx +++ b/fern/docs/pages/reference/factuality.mdx @@ -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 diff --git a/fern/docs/pages/reference/toxicity.mdx b/fern/docs/pages/reference/toxicity.mdx index b3e228e..2fb0c5b 100644 --- a/fern/docs/pages/reference/toxicity.mdx +++ b/fern/docs/pages/reference/toxicity.mdx @@ -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"); diff --git a/fern/docs/pages/reference/translate.mdx b/fern/docs/pages/reference/translate.mdx index 78b5383..fe26e65 100644 --- a/fern/docs/pages/reference/translate.mdx +++ b/fern/docs/pages/reference/translate.mdx @@ -111,7 +111,7 @@ your preference or requirements, select the appropriate method for your applicat ```rust - extern crate prediction_guard as pg_client; + extern crate prediction_guard as pg_client; use pg_client::{client, translate}; @@ -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"); diff --git a/fern/docs/pages/sdks.mdx b/fern/docs/pages/sdks.mdx index dd352ac..2a38bfe 100644 --- a/fern/docs/pages/sdks.mdx +++ b/fern/docs/pages/sdks.mdx @@ -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() { @@ -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)