|
26 | 26 | " huggingface-cli login --token $HUGGINGFACE_TOKEN\n" |
27 | 27 | ] |
28 | 28 | }, |
| 29 | + { |
| 30 | + "cell_type": "markdown", |
| 31 | + "metadata": {}, |
| 32 | + "source": [ |
| 33 | + "We also need to install the ```HighQualityTranslation``` validator from Guardrails Hub: \n", |
| 34 | + "\n", |
| 35 | + "```guardrails hub install hub://brainlogic/high_quality_translation```" |
| 36 | + ] |
| 37 | + }, |
29 | 38 | { |
30 | 39 | "cell_type": "code", |
31 | 40 | "execution_count": 10, |
|
36 | 45 | "from pydantic import BaseModel, Field\n", |
37 | 46 | "import guardrails as gd\n", |
38 | 47 | "from rich import print\n", |
39 | | - "from guardrails.validators import IsHighQualityTranslation" |
| 48 | + "from guardrails.hub import HighQualityTranslation" |
40 | 49 | ] |
41 | 50 | }, |
42 | 51 | { |
|
130 | 139 | "class HighQualityTranslation(BaseModel):\n", |
131 | 140 | " translated_statement: str = Field(\n", |
132 | 141 | " description=\"Validate the translation quality of the given statement\",\n", |
133 | | - " validators=[IsHighQualityTranslation(on_fail=\"fix\")],\n", |
| 142 | + " validators=[HighQualityTranslation(on_fail=\"fix\")],\n", |
134 | 143 | " )" |
135 | 144 | ] |
136 | 145 | }, |
|
553 | 562 | "source": [ |
554 | 563 | "# Test with validation method 'full'\n", |
555 | 564 | "guard = gd.Guard.from_string(\n", |
556 | | - " validators=[IsHighQualityTranslation(on_fail=\"fix\")],\n", |
| 565 | + " validators=[HighQualityTranslation(on_fail=\"fix\")],\n", |
557 | 566 | " description=\"Validate the translation quality of the given statement\",\n", |
558 | 567 | ")" |
559 | 568 | ] |
|
705 | 714 | "cell_type": "markdown", |
706 | 715 | "metadata": {}, |
707 | 716 | "source": [ |
708 | | - "As you can see, the translation quality is really bad, and the `IsHighQualityTranslation` check failed as the translation quality was below the threshold. The validated response is an empty string.\n", |
| 717 | + "As you can see, the translation quality is really bad, and the `HighQualityTranslation` check failed as the translation quality was below the threshold. The validated response is an empty string.\n", |
709 | 718 | "\n", |
710 | 719 | "## In this way, you can use Guardrails to ensure that the output of your LLM is of high quality.\n" |
711 | 720 | ] |
|
0 commit comments