Skip to content

Commit

Permalink
updated all references
Browse files Browse the repository at this point in the history
  • Loading branch information
ardan-bkennedy committed Jun 7, 2024
1 parent c4d70d8 commit d0ee9bc
Show file tree
Hide file tree
Showing 10 changed files with 990 additions and 159 deletions.
138 changes: 122 additions & 16 deletions fern/docs/pages/reference/PII.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@
title: PII
---

You can check and replace Personal Identifiable Information (PII) from the `/PII` endpoint or `pii` class in the Python Client. This endpoint/Class takes three parameters:
You can check and replace Personal Identifiable Information (PII) from the `/PII`
REST API endpoint or any of the official SDKs (Python, Go, Rust, JS, or cURL).

- `prompt` - The prompt that you want to check for PII.
- `replace` - A boolean for replacing the PII if any is found.
- `replace_method` - The method you would like to use to replace any found PII. The methods are `random`, `mask`, `category`, and `fake`.

The output will include the replaced PII if any is present, or will tell you if any PII is in the prompt if `replace` is not chosen.
The output will include the replaced PII if any is present, or will tell you if
any PII is in the prompt if `replace` is not chosen.

## Check and Replace PII

To check and replace PII, you can use the following code examples. Depending on your preference or requirements, select the appropriate method for your application.
To check and replace PII, you can use the following code examples. Depending on
your preference or requirements, select the appropriate method for your application.

<CodeBlocks>
<CodeBlock title="Python">
Expand All @@ -29,7 +28,8 @@ To check and replace PII, you can use the following code examples. Depending on

response = client.pii.check(
prompt="Hello, my name is John Doe and my SSN is 111-22-3333.",
replace=False
replace=True,
replace_method="mask"
)

print(json.dumps(
Expand All @@ -43,29 +43,135 @@ To check and replace PII, you can use the following code examples. Depending on

<CodeBlock title="Go">
```go
package main

import (
"context"
"fmt"
"log"
"os"
"time"

"github.com/predictionguard/go-client"
)

func main() {
if err := run(); err != nil {
log.Fatalln(err)
}
}

func run() error {
host := "https://api.predictionguard.com"
apiKey := os.Getenv("PGKEY")

logger := func(ctx context.Context, msg string, v ...any) {
s := fmt.Sprintf("msg: %s", msg)
for i := 0; i < len(v); i = i + 2 {
s = s + fmt.Sprintf(", %s: %v", v[i], v[i+1])
}
log.Println(s)
}

cln := client.New(logger, host, apiKey)

ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()

prompt := "Hello, my name is John Doe and my SSN is 111-22-3333."

resp, err := cln.ReplacePI(ctx, prompt, client.ReplaceMethods.Mask)
if err != nil {
return fmt.Errorf("ERROR: %w", err)
}

fmt.Println(resp.Checks[0].NewPrompt)

return nil
}
```
</CodeBlock>

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

use pg_client::{client, pii};
use pii::ReplaceMethod;

#[tokio::main]
async fn main() {
let pg_env = client::PgEnvironment::from_env().expect("env keys");

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(),
true,
ReplaceMethod::Mask,
);

let result = clt.pii(&req).await.expect("error from pii");

println!("\n\npii response:\n{:?}\n\n", result);
}
```
</CodeBlock>

<CodeBlock title="NodeJS">
```js
import * as pg from '../dist/index.js';

const client = new pg.Client('https://api.predictionguard.com', process.env.PGKEY);

async function ReplacePI() {
const replaceMethod = pg.ReplaceMethods.Mask;
const prompt = `Hello, my name is John Doe and my SSN is 111-22-3333.`;

var [result, err] = await client.ReplacePI(replaceMethod, prompt);
if (err != null) {
console.log('ERROR:' + err.error);
return;
}

console.log('RESULT:' + result.checks[0].new_prompt);
}

ReplacePI();
```
</CodeBlock>

<CodeBlock title="cURL">
```bash
$ curl --location --request POST 'https://api.predictionguard.com/PII' \
--header 'Content-Type: application/json' \
--header 'x-api-key: <api key>' \
--data '{
"prompt": "Hello, my name is John Doe and my SSN is 111-22-3333.",
"replace": true,
"replace_method": "random"
}'
curl -X POST https://api.predictionguard.com/PII \
-H "x-api-key: ${PGKEY}" \
-H "Content-Type: application/json" \
-d '{
"prompt": "Hello, my name is John Doe and my SSN is 111-22-3333.",
"replace": true,
"replace_method": "mask"
}'
```
</CodeBlock>
</CodeBlocks>

The output will look something like:

```json
{
"checks":[
{
"new_prompt":"Hello, my name is * and my SSN is *.",
"index":0,
"status":"success"
}
],
"created":"1717781430",
"id":"pii-jYiO2ToMT0JVICWvrUUlErqwO11lVlHH",
"object":"pii_check"
}
```

This approach presents a straightforward way for readers to choose and apply the
code example that best suits their needs for generating text completions using
either Python, Go, Rust, JS, or cURL.
36 changes: 29 additions & 7 deletions fern/docs/pages/reference/chat.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ title: Chat
---

You can get chat text completions (based on a thread of chat messages) from any
of the chat enabled [models](../models) using the `/chat/completions` REST API
endpoint or `chat.completions` Python client class.
of the chat enabled [models](/options/enumerations) using the `/chat/completions`
REST API endpoint or any of the official SDKs (Python, Go, Rust, JS, or cURL).

## Generate A Chat Text Completion
## Generate a Chat Text Completion

To generate a chat text completion, you can use the following code examples.
Depending on your preference or requirements, select the appropriate method for
Expand Down Expand Up @@ -120,7 +120,7 @@ your application.
Temperature: 0.1,
TopP: 0.1,
Options: &client.ChatInputOptions{
Factuality: true,
Factuality: false,
Toxicity: true,
PII: client.PIIs.Replace,
PIIReplaceMethod: client.ReplaceMethods.Random,
Expand Down Expand Up @@ -212,7 +212,7 @@ your application.
temperature: 0.1,
topP: 0.1,
options: {
factuality: true,
factuality: false,
toxicity: true,
pii: pg.PIIs.Replace,
piiReplaceMethod: pg.ReplaceMethods.Random,
Expand Down Expand Up @@ -246,7 +246,7 @@ your application.
},
{
"role": "user",
"content": "What's up!"
"content": "What''s up!"
},
{
"role": "assistant",
Expand All @@ -261,7 +261,7 @@ your application.
"temperature": 1.1,
"top_p": 0.1,
"output": {
"factuality": true,
"factuality": false,
"toxicity": true
},
"input": {
Expand All @@ -273,6 +273,28 @@ your application.
</CodeBlock>
</CodeBlocks>

The output will look something like this.

```json
{
"id":"chat-SUZNF22Qn7uq22Ciez0AfhmnVlKF0",
"object":"chat_completion",
"created":1717780456,
"model":"Neural-Chat-7B",
"choices":[
{
"index":0,
"message":{
"role":"assistant",
"content":"Thanks, but if you're looking for something more serious, I'm here to help with any questions or tasks you might have. Just let me know!",
"output":null
},
"status":"success"
}
]
}
```

This approach presents a straightforward way for readers to choose and apply the
code example that best suits their needs for generating text completions using
either Python, Go, Rust, JS, or cURL.
21 changes: 19 additions & 2 deletions fern/docs/pages/reference/completions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ title: Completions

You can get privacy-conserving text completions from any of the
[available models](/options/enumerations) using a call to the `/completions` REST
API endpoint or the `completions` class in the Python client.
API endpoint or any of the official SDKs (Python, Go, Rust, JS, or cURL).

## Generate a Text Completion

Expand Down Expand Up @@ -164,9 +164,26 @@ on your preference or requirements, select the appropriate method for your appli
}'
```
</CodeBlock>

</CodeBlocks>

The output will look something like this.

```json
{
"id":"cmpl-IkUw9KPuwrwzseWiOYXCi1TP3I447",
"object":"text_completion",
"created":1717780588,
"choices":[
{
"text":"\n\nA man walks into a bar and says to the bartender, \"If I show you something really weird, will you give me a free drink?\" The bartender, being intrigued, says, \"Sure, I'll give it a look.\" The man reaches into his pocket and pulls out a tiny horse. The bartender is astonished and gives the man a free drink. The man then puts the horse back into his pocket.\n\nThe next day, the same man walks back into the bar and says to the bartender, \"If I show you something even weirder than yesterday and you give me a free drink, will you do it again?\" The bartender, somewhat reluctantly, says, \"Okay, I guess you can show it to me.\" The man reaches into his pocket, pulls out the same tiny horse, and opens the door to reveal the entire bar inside the horse.\n\nThe bartender faints.",
"index":0,
"status":"success",
"model":"Neural-Chat-7B"
}
]
}
```

This approach presents a straightforward way for readers to choose and apply the
code example that best suits their needs for generating text completions using
either Python, Go, Rust, JS, or cURL.
Loading

0 comments on commit d0ee9bc

Please sign in to comment.