Skip to content

Commit

Permalink
saving work
Browse files Browse the repository at this point in the history
  • Loading branch information
ardan-bkennedy committed Jun 6, 2024
1 parent 4b2834d commit f0c5dbe
Show file tree
Hide file tree
Showing 2 changed files with 569 additions and 0 deletions.
290 changes: 290 additions & 0 deletions fern/docs/pages/quick_start.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,290 @@
---
title: Quick Start
description: Reliable, future proof AI predictions
---

Technical teams need to figure out how to integrate the latest Large Language
Models (LLMs), but:

- You can’t build robust systems with inconsistent, unvalidated outputs; and
- LLM integrations scare corporate lawyers, finance departments, and security
professionals due to hallucinations, cost, lack of compliance (e.g., HIPAA),
leaked IP/PII, and “injection” vulnerabilities.

Some companies are moving forward anyway by investing tons of engineering time/money
in their own wrappers around LLMs and expensive hosting with OpenAI/Azure. Others
are ignoring these issues and pressing forward with fragile and risky LLM integrations.

At Prediction Guard, we think that you should get useful output from compliant
AI systems (without crazy implementation/ hosting costs), so our solution lets you:

1. **De-risk LLM inputs** to remove PII and prompt injections;
2. **Validate and check LLM outputs** to guard against hallucination, toxicity and
inconsistencies; and
3. **Implement private and compliant LLM systems** (HIPAA and self-hosted) that
give your legal counsel warm fuzzy feeling while still delighting your customers
with AI features.

Sounds pretty great right? Follow the steps below to starting leveraging
trustworthy LLMs:

## 1. Get access to Prediction Guard Enterprise

We host and control the latest LLMs for you in our secure and privacy-conserving
enterprise platform, so you can focus on your prompts and chains. To access the
hosted LLMs, contact us [here](https://mailchi.mp/predictionguard/getting-started)
to get an enterprise access token. You will need this access token to continue.

## 2. Start using one of our LLMs!

Suppose you want to prompt an LLM to answer a user query from a chat application.
You can setup a message thread, which includes a system prompt (that instructs
the LLM how to behave in responding) as follows:

```
[
{
"role": "system",
"content": "You are a helpful assistant. Your model is hosted by Prediction Guard, a leading AI company."
},
{
"role": "user",
"content": "Where can I access the LLMs in a safe and secure environment?"
}
]
```

## 3. Download the SDK for your favorite language

You can then use any of our official SDKs or REST API to prompt one of our LLMs!

<CodeBlocks>

<CodeBlock title="Python">
```python copy
import json
import os

from predictionguard import PredictionGuard

# You can set you Prediction Guard API Key as an env variable,
# or when creating the client object
os.environ["PREDICTIONGUARD_API_KEY"]

client = PredictionGuard(
api_key="<your Prediction Guard API Key"
)

messages = [
{
"role": "system",
"content": "You are a helpful chatbot that helps people learn."
},
{
"role": "user",
"content": "What is a good way to learn to code?"
}
]

result = client.chat.completions.create(
"model": "Hermes-2-Pro-Llama-3-8B",
"messages": messages,
"max_tokens": 100
)

print(json.dumps(
result,
sort_keys=True,
indent=4,
separators=(',', ': ')
))
````
</CodeBlock>

<CodeBlock title="Go">
```go copy
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()

input := client.ChatInput{
Model: client.Models.NeuralChat7B,
Messages: []client.ChatInputMessage{
{
Role: client.Roles.System,
Content: "You are a helpful assistant. Your model is hosted by Prediction Guard, a leading AI company.",
},
{
Role: client.Roles.User,
Content: "Where can I access the LLMs in a safe and secure environment?",
},
},
MaxTokens: 1000,
Temperature: 0.1,
TopP: 0.1,
Options: &client.ChatInputOptions{
Factuality: true,
Toxicity: true,
PII: client.PIIs.Replace,
PIIReplaceMethod: client.ReplaceMethods.Random,
},
}

resp, err := cln.Chat(ctx, input)
if err != nil {
return fmt.Errorf("ERROR: %w", err)
}

fmt.Println(resp.Choices[0].Message.Content)

return nil
}
````
</CodeBlock>

<CodeBlock title="Rust">
```rust copy
use std::env;

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

#[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 = chat::Request::<chat::Message>::new(models::Model::NeuralChat7B)
.add_message(
chat::Roles::System,
"You are a helpful assistant. Your model is hosted by Prediction Guard, a leading AI company.".to_string(),
)
.add_message(
chat::Roles::User,
"Where can I access the LLMs in a safe and secure environment?".to_string(),
)
.max_tokens(1000)
.temperature(0.8);

let result = clt
.generate_chat_completion(&req)
.await
.expect("error from generate chat completion");

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

<CodeBlock title="NodeJS">
```js copy
import * as pg from 'predictionguard';

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

async function Chat() {
const input = {
model: pg.Models.NeuralChat7B,
messages: [
{
role: pg.Roles.System,
content: 'You are a helpful assistant. Your model is hosted by Prediction Guard, a leading AI company.',
},
{
role: pg.Roles.User,
content: 'Where can I access the LLMs in a safe and secure environment?',
}
],
maxTokens: 1000,
temperature: 0.1,
topP: 0.1,
options: {
factuality: true,
toxicity: true,
pii: pg.PIIs.Replace,
piiReplaceMethod: pg.ReplaceMethods.Random,
},
};

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

console.log('RESULT:' + result.createdDate() + ': ' + result.model + ': ' + result.choices[0].message.content);
}

Chat();
````
</CodeBlock>

<CodeBlock title="cURL">
```bash copy
curl -il -X POST https://api.predictionguard.com/chat/completions \
-H "x-api-key: ${PGKEY}" \
-H "Content-Type: application/json" \
-d '{ \
"model": "Neural-Chat-7B", \
"messages": [ \
{ \
"role": "system", \
"content": "You are a helpful assistant. Your model is hosted by Prediction Guard, a leading AI company." \
}, \
{ \
"role": "user", \
"content": "Where can I access the LLMs in a safe and secure environment?" \
} \
], \
"max_tokens": 1000, \
"temperature": 1.1, \
"top_p": 0.1, \
"output": { \
"factuality": true, \
"toxicity": true \
}, \
"input": { \
"pii": "replace", \
"pii_replace_method": "random" \
} \
}'
````
</CodeBlock>

</CodeBlocks>

<Callout type="info" emoji="ℹ️">
Note, you will need to replace `<your api key>` in the above examples with your actual access token.
</Callout>
Loading

0 comments on commit f0c5dbe

Please sign in to comment.