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 3ea1d25 commit 5be93ef
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 22 deletions.
2 changes: 1 addition & 1 deletion fern/docs/pages/input/injection.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ With Prediction Guard, you have the ability to assess whether an incoming prompt
might be an injection attempt before it reaches the LLM. Get a probability score
and the option to block it, safeguarding against potential attacks. Below, you
can see the feature in action, demonstrated with a modified version of a known
prompt injection:
prompt injection.

```python copy
import os
Expand Down
29 changes: 19 additions & 10 deletions fern/docs/pages/output/factuality.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,16 @@ title: Factuality
description: Controlled and compliant AI applications
---

Navigating the llm landscape can be tricky, especially with hallucinations or inaccurate answers. Whether you're integrating llms into customer-facing products or using them for internal data processing, ensuring the accuracy of the information provided is essential. Prediction Guard used SOTA models for factuality check to evaluate the outputs of LLMs against the context of the prompts. You can either add factuality=True or use /factuality endpoint to directly access this functionality.
Navigating the LLM landscape can be tricky, especially with hallucinations or
inaccurate answers. Whether you're integrating LLMs into customer-facing products
or using them for internal data processing, ensuring the accuracy of the information
provided is essential. Prediction Guard uses State Of The Art (SOTA) models for
factuality check to evaluate the outputs of LLMs against the context of the prompts.

Let's use the following prompt template to determine some features of an instragram post announcing new products. First, we can define a prompt template:
You can either add factuality=True or use /factuality endpoint to directly access
this functionality. Let's use the following prompt template to determine some
features of an instragram post announcing new products. First, we can define a
prompt template.

```python copy
import os
Expand Down Expand Up @@ -46,7 +53,8 @@ result = client.completions.create(
)
```

We can then check the factulaity score of the answer that is generated by the llm:
We can then check the factulaity score of the answer that is generated by the
LLM.

```python copy
fact_score = client.factuality.check(
Expand All @@ -58,14 +66,15 @@ print("COMPLETION:", result['choices'][0]['text'])
print("FACT SCORE:", fact_score['checks'][0]['score'])
```

This outputs something similar to:
This outputs something similar to.

```
COMPLETION: California is a state located in the western region of the United States. It is the most populous state in the country, with over 38.9 million residents, and the third-largest state by area, covering approximately 163,696 square miles (423,970 km2). California shares its borders with Oregon to the north, Nevada and Arizona to the east, and the Mexican state of Baja California to the south. It also
FACT SCORE: 0.8541514873504639
```

Now, we could try to make the model hallucinate. However, the hallucination is caught and Prediction Guard returns an error status:
Now, we could try to make the model hallucinate. However, the hallucination is
caught and Prediction Guard returns an error status.

```python copy
result = client.completions.create(
Expand All @@ -85,15 +94,15 @@ print("COMPLETION:", result['choices'][0]['text'])
print("FACT SCORE:", fact_score['checks'][0]['score'])
```

This outputs something similar to:
This outputs something similar to.

```
COMPLETION: California is the smallest state in the United States.
FACT SCORE: 0.12891793251037598
```

## Standalone Factuality Functionality


## Standalone Factuality functionality

You can also call the factuality checking functionality directly using the [`/factuality`](../reference/factuality) endpoint, which will enable you to configure thresholds and score arbitrary inputs.
You can also call the factuality checking functionality directly using the
[`/factuality`](/reference/factuality) endpoint, which will enable you to
configure thresholds and score arbitrary inputs.
33 changes: 22 additions & 11 deletions fern/docs/pages/output/toxicity.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,18 @@ title: Toxicity
description: Controlled and compliant AI applications
---

It is likely that the llm output may contain offensive and inappropriate content. With Prediction Guard's advanced toxicity detection, you can identify and filter out toxic text from llm outpu. Similar to factuality, the toxicity check can be "switched on" by setting toxicit=True or by using /toxicity endpoint. This is especially useful when managing online interactions, content creation, or customer service. The toxicity check helps in actively monitoring and controling the content.
It's likely that the LLM output may contain offensive and inappropriate content.
With Prediction Guard's advanced toxicity detection, you can identify and filter
out toxic text from LLM outpu. Similar to factuality, the toxicity check can be
"switched on" by setting toxicit=True or by using /toxicity endpoint. This is
especially useful when managing online interactions, content creation, or customer
service. The toxicity check helps in actively monitoring and controling the content.

## Toxicity on Text Completions
## Toxicity On Text Completions

Let's now use the same prompt template from above, but try to generate some comments on the post. These could potentially be toxic, so let's enable Prediction Guard's `toxicity` check:
Let's now use the same prompt template from above, but try to generate some
comments on the post. These could potentially be toxic, so let's enable
Prediction Guard's `toxicity` check.

```python copy
import os
Expand Down Expand Up @@ -48,11 +55,12 @@ print(json.dumps(
))
```

**Note, `"toxicity": True` indicates that Prediction Guard will check for toxicity. It does NOT mean that you want the output to be toxic.**
**Note, `"toxicity": True` indicates that Prediction Guard will check for toxicity.
It does NOT mean that you want the output to be toxic.**

The above code, generates something like:
The above code, generates something like.

```json
```json copy
{
"choices": [
{
Expand All @@ -68,7 +76,8 @@ The above code, generates something like:
}
```

If we try to make the prompt generate toxic comments, then Predition Guard catches this and prevents the toxic output:
If we try to make the prompt generate toxic comments, then Predition Guard
catches this and prevents the toxic output.

```python copy
result = client.completions.create(
Expand All @@ -87,9 +96,9 @@ print(json.dumps(
))
```

This results in:
This outputs something similar to.

```json
```json copy
{
"choices": [
{
Expand All @@ -105,6 +114,8 @@ This results in:
}
```

## Standalone Toxicity functionality
## Standalone Toxicity Functionality

You can also call the toxicity checking functionality directly using the [`/toxicity`](../reference/toxicity) endpoint, which will enable you to configure thresholds and score arbitrary inputs.
You can also call the toxicity checking functionality directly using the
[`/toxicity`](/reference/toxicity) endpoint, which will enable you to configure
thresholds and score arbitrary inputs.

0 comments on commit 5be93ef

Please sign in to comment.