참고소스 수정본
This commit is contained in:
13
참고/guardrails-main/docs/examples/data/article1.txt
Normal file
13
참고/guardrails-main/docs/examples/data/article1.txt
Normal file
@@ -0,0 +1,13 @@
|
||||
Section. 1.
|
||||
All legislative Powers herein granted shall be vested in a Congress of the United States, which shall consist of a Senate and House of Representatives.
|
||||
|
||||
Section. 2.
|
||||
The House of Representatives shall be composed of Members chosen every second Year by the People of the several States, and the Electors in each State shall have the Qualifications requisite for Electors of the most numerous Branch of the State Legislature.
|
||||
|
||||
No Person shall be a Representative who shall not have attained to the Age of twenty five Years, and been seven Years a Citizen of the United States, and who shall not, when elected, be an Inhabitant of that State in which he shall be chosen.
|
||||
|
||||
Representatives and direct Taxes shall be apportioned among the several States which may be included within this Union, according to their respective Numbers, which shall be determined by adding to the whole Number of free Persons, including those bound to Service for a Term of Years, and excluding Indians not taxed, three fifths of all other Persons. The actual Enumeration shall be made within three Years after the first Meeting of the Congress of the United States, and within every subsequent Term of ten Years, in such Manner as they shall by Law direct. The Number of Representatives shall not exceed one for every thirty Thousand, but each State shall have at Least one Representative; and until such enumeration shall be made, the State of New Hampshire shall be entitled to chuse three, Massachusetts eight, Rhode-Island and Providence Plantations one, Connecticut five, New-York six, New Jersey four, Pennsylvania eight, Delaware one, Maryland six, Virginia ten, North Carolina five, South Carolina five, and Georgia three.
|
||||
|
||||
When vacancies happen in the Representation from any State, the Executive Authority thereof shall issue Writs of Election to fill such Vacancies.
|
||||
|
||||
The House of Representatives shall chuse their Speaker and other Officers; and shall have the sole Power of Impeachment.
|
||||
BIN
참고/guardrails-main/docs/examples/data/chase_card_agreement.pdf
Normal file
BIN
참고/guardrails-main/docs/examples/data/chase_card_agreement.pdf
Normal file
Binary file not shown.
70
참고/guardrails-main/docs/examples/data/config.py
Normal file
70
참고/guardrails-main/docs/examples/data/config.py
Normal file
@@ -0,0 +1,70 @@
|
||||
"""
|
||||
All guards defined here will be initialized, if and only if
|
||||
the application is using in memory guards.
|
||||
|
||||
The application will use in memory guards if pg_host is left
|
||||
undefined. Otherwise, a postgres instance will be started
|
||||
and guards will be persisted into postgres. In that case,
|
||||
these guards will not be initialized.
|
||||
"""
|
||||
|
||||
from typing import Any, Callable, Dict, Optional, Union
|
||||
from guardrails import Guard, OnFailAction
|
||||
from guardrails.validators import (
|
||||
Validator,
|
||||
register_validator,
|
||||
FailResult,
|
||||
PassResult,
|
||||
ValidationResult,
|
||||
)
|
||||
from guardrails.hub import RegexMatch
|
||||
|
||||
name_case = Guard(
|
||||
name="name-case", description="Checks that a string is in Name Case format."
|
||||
).use(RegexMatch(regex="^(?:[A-Z][^\s]*\s?)+$", on_fail=OnFailAction.NOOP))
|
||||
|
||||
all_caps = Guard(
|
||||
name="all-caps", description="Checks that a string is all capital."
|
||||
).use(RegexMatch(regex="^[A-Z\\s]*$", on_fail=OnFailAction.NOOP))
|
||||
|
||||
|
||||
@register_validator(name="custom/dynamic-enum", data_type="all")
|
||||
class DynamicEnum(Validator):
|
||||
def __init__(
|
||||
self,
|
||||
enum_fetcher: Callable,
|
||||
on_fail: Optional[Union[Callable, OnFailAction]] = None,
|
||||
):
|
||||
super().__init__(on_fail=on_fail, enum_fetcher=enum_fetcher)
|
||||
self.enum_fetcher = enum_fetcher
|
||||
|
||||
def validate(self, value: Any, metdata: Optional[Dict] = {}) -> ValidationResult:
|
||||
enum_fetcher_args = metdata.get("enum_fetcher_args", [])
|
||||
dynamic_enum = self.enum_fetcher(*enum_fetcher_args)
|
||||
|
||||
if value not in dynamic_enum:
|
||||
return FailResult(
|
||||
error_message="Value must be in the dynamically chosen enum!",
|
||||
fix_value=dynamic_enum[0],
|
||||
)
|
||||
return PassResult()
|
||||
|
||||
|
||||
valid_topics = ["music", "cooking", "camping", "outdoors"]
|
||||
invalid_topics = ["sports", "work", "ai"]
|
||||
all_topics = [*valid_topics, *invalid_topics]
|
||||
|
||||
|
||||
def custom_enum_fetcher(*args):
|
||||
topic_type = args[0]
|
||||
if topic_type == "valid":
|
||||
return valid_topics
|
||||
elif topic_type == "invalid":
|
||||
return invalid_topics
|
||||
return all_topics
|
||||
|
||||
|
||||
custom_code_guard = Guard(
|
||||
name="custom",
|
||||
description="Uses a custom callable init argument for dynamic enum checks",
|
||||
).use(DynamicEnum(custom_enum_fetcher, on_fail=OnFailAction.NOOP))
|
||||
70
참고/guardrails-main/docs/examples/data/twain.txt
Normal file
70
참고/guardrails-main/docs/examples/data/twain.txt
Normal file
@@ -0,0 +1,70 @@
|
||||
The Humorous Story an American Development.— Its
|
||||
Difference from Comic and Witty Stories.
|
||||
|
||||
DO not claim that I can tell a story as it ought to
|
||||
be told. I only claim to know how a story
|
||||
ought to be told, for I have been almost daily in the
|
||||
company of the most expert story-tellers for many
|
||||
years.
|
||||
|
||||
There are several kinds of stories, but only one
|
||||
difficult kind —the humorous. I will talk mainly
|
||||
about that one. The humorous story is American,
|
||||
the comic story is English, the witty story is French.
|
||||
The humorous story depends for its effect upon the
|
||||
manner of the telling; the comic story and the witty
|
||||
story upon the matter.
|
||||
|
||||
The humorous story may be spun out to great
|
||||
length, and may wander around as much as it
|
||||
pleases, and arrive nowhere in particular; but the
|
||||
comic and witty stories must be brief and end with
|
||||
a point. The humorous story bubbles gently along,
|
||||
the others burst.
|
||||
|
||||
The humorous story is strictly a work of art —
|
||||
high and delicate art — and only an artist can tell it;
|
||||
but no art is necessary in telling the comic and the
|
||||
witty story; anybody can do it. The art of telling
|
||||
a humorous story — understand, I mean by word of
|
||||
mouth, not print — was created in America, and
|
||||
has remained at home.
|
||||
|
||||
The humorous story is told gravely; the teller
|
||||
does his best to conceal the fact that he even dimly
|
||||
suspects that there is anything funny about it; but
|
||||
the teller of the comic story tells you beforehand
|
||||
that it is one of the funniest things he has ever
|
||||
heard, then tells it with eager delight, and is the
|
||||
first person to laugh when he gets through. And
|
||||
sometimes, if he has had good success, he is so glad
|
||||
and happy that he will repeat the ‘‘ nub’’ of it and
|
||||
slance around from face to face, collecting applause,
|
||||
and then repeat it again. It is a pathetic thing to
|
||||
see.
|
||||
|
||||
Very often, of course, the rambling and disjointed
|
||||
humorous story finishes with a nub, point, snapper,
|
||||
or whatever you like to call it. Then the listener
|
||||
must be alert, for in many cases the teller will divert
|
||||
attention from that nub by dropping it in a carefully.
|
||||
casual and indifferent way, with the pretence that he
|
||||
does not know it is a nub.
|
||||
|
||||
Artemus Ward used that trick a good deal; then
|
||||
when the belated audience presently caught the joke
|
||||
he would look up with innocent surprise, as if
|
||||
wondering what they had found to laugh at. Dan
|
||||
Setchell used it before him, Nye and Riley and
|
||||
others use it to-day.
|
||||
|
||||
But the teller of the comic story does not slur
|
||||
the nub; he shouts it at you—every time. And
|
||||
when he prints it, in England, France, Germany,
|
||||
and Italy, he italicizes it, puts some whooping
|
||||
exclamation-points after it, and sometimes explains
|
||||
it in a parenthesis. All of which is very depressing,
|
||||
and makes one want to renounce joking and lead a
|
||||
better life.
|
||||
|
||||
- Mark Twain
|
||||
Reference in New Issue
Block a user