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

Updating Translate docs to include third party translation parameter. #24

Merged
merged 7 commits into from
Jul 16, 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
31 changes: 21 additions & 10 deletions fern/docs/pages/reference/translate.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ The /translate endpoint will return a JSON object response with two fields:
- `Best translation` - The translated text.
- `Score` - A score from -1.0 to 1.0 representing the translation quality. Higher the score better the quality.

Additionally, you can opt to use third-party translation engines such as OpenAI, DeepL, and Google.
By default, the use of these commercial engines is set to false.

Our translation API supports a wide range of [languages](/options/enumerations),
including but not limited to English, Hindi, French, Spanish, German, and more.

Expand All @@ -42,7 +45,8 @@ your preference or requirements, select the appropriate method for your applicat
result = client.translate.create(
text="The sky is blue",
source_lang="eng",
target_lang="fra"
target_lang="fra",
use_third_party_engine=True
)

print(json.dumps(
Expand Down Expand Up @@ -93,7 +97,7 @@ your preference or requirements, select the appropriate method for your applicat

text := "The sky is blue"

resp, err := cln.Translate(ctx, text, client.Languages.English, client.Languages.French)
resp, err := cln.Translate(ctx, text, client.Languages.English, client.Languages.French, true)
if err != nil {
return fmt.Errorf("ERROR: %w", err)
}
Expand Down Expand Up @@ -137,11 +141,12 @@ your preference or requirements, select the appropriate method for your applicat
const client = new pg.Client('https://api.predictionguard.com', process.env.PGKEY);

async function Translate() {
const text = `The sky is blue`;
const sourceLang = pg.Languages.English;
const targetLang = pg.Languages.French;
const text = `The sky is blue`;
const useThirdPartyEngine = true;

var [result, err] = await client.Translate(text, sourceLang, targetLang);
var [result, err] = await client.Translate(text, sourceLang, targetLang, useThirdPartyEngine);
if (err != null) {
console.log('ERROR:' + err.error);
return;
Expand Down Expand Up @@ -182,31 +187,37 @@ The output will look something like:
{
"score": 0.8694148659706116,
"translation": "Le ciel est bleu",
"model": "deepl",
"model": "hermes_2_pro_mistral_7b",
"status": "success"
},
{
"score": 0.8694148659706116,
"translation": "Le ciel est bleu",
"model": "google",
"model": "openai",
"status": "success"
},
{
"score": 0.8694148659706116,
"translation": "Le ciel est bleu",
"model": "hermes_2_pro_mistral_7b",
"model": "deepl",
"status": "success"
},
{
"score": 0.8694148659706116,
"translation": "Le ciel est bleu",
"model": "google",
"status": "success"
}
],
"best_translation": "Le ciel est bleu",
"best_score": 0.8694148659706116,
"best_translation_model": "hermes_2_pro_llama_3_8b",
"created": 1720121297,
"id": "translation-21834cb75f1d4d13958506371d47c232",
"created": 1721136682,
"id": "translation-52929bae5c2c44c9b5177921958cb5f7",
"object": "translation"
}
```

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.
either Python, Go, Rust, JS, or cURL.
151 changes: 125 additions & 26 deletions fern/openapi/Prediction-Guard-Prediction-Guard-API-1.0-resolved.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,19 @@ paths:
stream:
type: boolean
description: Turn streaming on.
input:
type: object
description: Options to affect the input of the request.
properties:
block_prompt_injection:
type: boolean
description: Set to true to turn on factuality processing.
pii:
type: string
description: Set to either 'block' or 'replace'.
pii_replace_method:
type: string
description: Set to either 'random', 'fake', 'category', 'mask'.
examples:
basic:
summary: A basic example of using the API.
Expand All @@ -270,7 +283,13 @@ paths:
temperature: 1.0,
top_p: 1.0,
top_k: 50,
stream: true
stream: true,
input: [
{
pii: "replace",
pii_replace_method: "random"
}
]
}
responses:
'403':
Expand Down Expand Up @@ -449,6 +468,29 @@ paths:
top_k:
type: integer
description: The diversity of the generated text based on top-k sampling.
output:
type: object
description: Options to affect the output of the response.
properties:
factuality:
type: boolean
description: Set to true to turn on factuality processing.
toxicity:
type: boolean
description: Set to true to turn on toxicity processing.
input:
type: object
description: Options to affect the input of the request.
properties:
block_prompt_injection:
type: boolean
description: Set to true to turn on factuality processing.
pii:
type: string
description: Set to either 'block' or 'replace'.
pii_replace_method:
type: string
description: Set to either 'random', 'fake', 'category', 'mask'.
examples:
basic:
summary: A basic example of using the API.
Expand All @@ -474,7 +516,19 @@ paths:
max_tokens: 1000,
temperature: 1.0,
top_p: 1.0,
top_k: 50
top_k: 50,
output: [
{
factuality: true,
toxicity: true
}
],
input: [
{
pii: "replace",
pii_replace_method: "random"
}
]
}
responses:
'403':
Expand Down Expand Up @@ -598,6 +652,29 @@ paths:
top_k:
type: integer
description: The diversity of the generated text based on top-k sampling.
output:
type: object
description: Options to affect the output of the response.
properties:
factuality:
type: boolean
description: Set to true to turn on factuality processing.
toxicity:
type: boolean
description: Set to true to turn on toxicity processing.
input:
type: object
description: Options to affect the input of the request.
properties:
block_prompt_injection:
type: boolean
description: Set to true to turn on factuality processing.
pii:
type: string
description: Set to either 'block' or 'replace'.
pii_replace_method:
type: string
description: Set to either 'random', 'fake', 'category', 'mask'.
examples:
basic:
summary: A basic example of using the API.
Expand All @@ -607,7 +684,19 @@ paths:
max_tokens: 1000,
temperature: 1.0,
top_p: 1.0,
top_k: 50
top_k: 50,
output: [
{
factuality: true,
toxicity: true
}
],
input: [
{
pii: "replace",
pii_replace_method: "random"
}
]
}
responses:
'403':
Expand Down Expand Up @@ -1224,13 +1313,17 @@ paths:
target_lang:
type: string
description: The target language for the translation.
use_third_party_engine:
type: boolean
description: Enables/disables third party translations.
examples:
basic:
summary: A basic example of using the API.
value: {
text: "The rain in Spain stays mainly in the plain",
text: "The sky is blue.",
source_lang: "eng",
target_lang: "spa"
target_lang: "spa",
use_third_party_engine: true
}
responses:
'403':
Expand Down Expand Up @@ -1303,36 +1396,42 @@ paths:
type: string
description: The status of using the model for this translation.
example: {
id: "translation-9b2c6f43cf7d4fe69cb9b9e6a4478999",
id: "translation-52929bae5c2c44c9b5177921958cb5f7",
object: "translation",
created: 1717676604,
best_translation: "La lluvia en España permanece principalmente en la llanura",
best_score: 0.5381202101707458,
best_translation_model: "google",
created: 1721136682,
best_translation: "Le ciel est bleu.",
best_score: 0.8694148659706116,
best_translation_model: "hermes_2_pro_llama_3_8b",
translations: [
{
score: -100,
translation: "",
model: "openai",
status: "error: couldn’t get translation"
"score": 0.8694148659706116,
"translation": "Le ciel est bleu.",
"model": "hermes_2_pro_llama_3_8b",
"status": "success"
},
{
score: 0.5008216500282288,
translation: "La lluvia en España se queda principalmente en la llanura",
model: "deepl",
status: "success"
"score": 0.8694148659706116,
"translation": "Le ciel est bleu.",
"model": "hermes_2_pro_mistral_7b",
"status": "success"
},
{
score: 0.5381202101707458,
translation: "La lluvia en España permanece principalmente en la llanura",
model: "google",
status: "success"
"score": 0.8694148659706116,
"translation": "Le ciel est bleu.",
"model": "openai",
"status": "success"
},
{
score: 0.4843788146972656,
translation: "La lluvia en España se queda principalmente en la llanura.",
model: "nous_hermes_llama2",
status: "success"
"score": 0.8694148659706116,
"translation": "Le ciel est bleu.",
"model": "deepl",
"status": "success"
},
{
"score": 0.8694148659706116,
"translation": "Le ciel est bleu.",
"model": "google",
"status": "success"
}
]
}
Expand Down
Loading