참고소스 수정본

This commit is contained in:
LASTA_DEV01\lasta
2026-05-12 19:40:31 +09:00
parent 0f34a451fc
commit 2e9204243d
8708 changed files with 3259488 additions and 869 deletions

View File

@@ -0,0 +1,46 @@
# ruff: noqa: E501
import os
from .validator_parallelism_reask_1 import VALIDATOR_PARALLELISM_REASK_1 # noqa: F401
from .validator_parallelism_reask_2 import VALIDATOR_PARALLELISM_REASK_2 # noqa: F401
DATA_DIR = os.path.join(os.path.abspath(os.path.dirname(__file__)))
reader = (
lambda filename: open(os.path.join(DATA_DIR, filename)).read().replace("\r", "")
)
COMPILED_PROMPT_1_WITHOUT_INSTRUCTIONS = reader("compiled_prompt_1.txt")
COMPILED_PROMPT_1_PYDANTIC_2_WITHOUT_INSTRUCTIONS = reader(
"compiled_prompt_1_pydantic_2.txt"
)
COMPILED_PROMPT_2_WITHOUT_INSTRUCTIONS = reader("compiled_prompt_2.txt")
COMPILED_INSTRUCTIONS = reader("compiled_instructions.txt")
LLM_OUTPUT_1_FAIL_GUARDRAILS_VALIDATION = reader(
"llm_output_1_fail_guardrails_validation.txt"
)
LLM_OUTPUT_2_SUCCEED_GUARDRAILS_BUT_FAIL_PYDANTIC_VALIDATION = reader(
"llm_output_2_succeed_gd_but_fail_pydantic_validation.txt"
)
LLM_OUTPUT_3_SUCCEED_GUARDRAILS_AND_PYDANTIC = reader(
"llm_output_3_succeed_gd_and_pydantic.txt"
)
RAIL_SPEC_WITH_VALIDATOR_PARALLELISM = reader("validator_parallelism.rail")
VALIDATOR_PARALLELISM_PROMPT_1 = reader("validator_parallelism_prompt_1.txt")
VALIDATOR_PARALLELISM_RESPONSE_1 = reader("validator_parallelism_1.txt")
VALIDATOR_PARALLELISM_PROMPT_2 = reader("validator_parallelism_prompt_2.txt")
VALIDATOR_PARALLELISM_RESPONSE_2 = reader("validator_parallelism_2.txt")
VALIDATOR_PARALLELISM_PROMPT_3 = reader("validator_parallelism_prompt_3.txt")
VALIDATOR_PARALLELISM_RESPONSE_3 = reader("validator_parallelism_3.txt")
__all__ = [
"COMPILED_PROMPT_1_WITHOUT_INSTRUCTIONS",
"COMPILED_PROMPT_2_WITHOUT_INSTRUCTIONS",
"COMPILED_INSTRUCTIONS",
"LLM_OUTPUT_1_FAIL_GUARDRAILS_VALIDATION",
"LLM_OUTPUT_2_SUCCEED_GUARDRAILS_BUT_FAIL_PYDANTIC_VALIDATION",
"LLM_OUTPUT_3_SUCCEED_GUARDRAILS_AND_PYDANTIC",
]

View File

@@ -0,0 +1,9 @@
You are a helpful assistant only capable of communicating with valid JSON, and no other text.
ONLY return a valid JSON object (no other text is necessary), where the key of the field in JSON is the `name` attribute of the corresponding XML, and the value is of the type specified by the corresponding XML's tag. The JSON MUST conform to the XML format, including any types and format requests e.g. requests for lists, objects and specific types. Be correct and concise. If you are unsure anywhere, enter `null`.
Here are examples of simple (XML, JSON) pairs that show the expected behavior:
- `<string name='foo' format='two-words lower-case' />` => `{'foo': 'example one'}`
- `<list name='bar'><string format='upper-case' /></list>` => `{"bar": ['STRING ONE', 'STRING TWO', etc.]}`
- `<object name='baz'><string name="foo" format="capitalize two-words" /><integer name="index" format="1-indexed" /></object>` => `{'baz': {'foo': 'Some String', 'index': 1}}`

View File

@@ -0,0 +1,34 @@
Provide detailed information about the top 5 grossing movies from Christopher Nolan including release date, duration, budget, whether it's a sequel, website, and contact email.
Given below is XML that describes the information to extract from this document and the tags to extract it into.
<output>
<string name="name" format="is-valid-director"/>
<list name="movies">
<object>
<integer name="rank"/>
<string name="title"/>
<object name="details">
<date name="release_date"/>
<time name="duration"/>
<float name="budget"/>
<bool name="is_sequel" required="false"/>
<string name="website" format="length: min=9 max=100"/>
<string name="contact_email"/>
<choice name="revenue" discriminator="revenue_type">
<case name="box_office">
<float name="gross" format="validate_gross"/>
<float name="opening_weekend"/>
</case>
<case name="streaming">
<integer name="subscriptions"/>
<float name="subscription_fee"/>
</case>
</choice>
</object>
</object>
</list>
</output>
ONLY return a valid JSON object (no other text is necessary), where the key of the field in JSON is the `name` attribute of the corresponding XML, and the value is of the type specified by the corresponding XML's tag. The JSON MUST conform to the XML format, including any types and format requests e.g. requests for lists, objects and specific types. Be correct and concise. If you are unsure anywhere, enter `null`.

View File

@@ -0,0 +1,33 @@
Provide detailed information about the top 5 grossing movies from Christopher Nolan including release date, duration, budget, whether it's a sequel, website, and contact email.
Given below is XML that describes the information to extract from this document and the tags to extract it into.
<output>
<string format="is-valid-director" name="name" required="true"></string>
<list name="movies" required="true">
<object required="true">
<integer name="rank" required="true"></integer>
<string name="title" required="true"></string>
<object name="details" required="true">
<date name="release_date" required="true"></date>
<time name="duration" required="true"></time>
<float name="budget" required="true"></float>
<bool name="is_sequel" required="false"></bool>
<string format="length: 9 100" name="website" required="true"></string>
<string name="contact_email" required="true"></string>
<choice discriminator="revenue_type" name="revenue" required="true">
<case name="box_office">
<float name="gross" required="true"></float>
<float name="opening_weekend" required="true"></float>
</case>
<case name="streaming">
<integer name="subscriptions" required="true"></integer>
<float name="subscription_fee" required="true"></float>
</case>
</choice>
</object>
</object>
</list>
</output>
ONLY return a valid JSON object (no other text is necessary), where the key of the field in JSON is the `name` attribute of the corresponding XML, and the value is of the type specified by the corresponding XML's tag. The JSON MUST conform to the XML format, including any types and format requests e.g. requests for lists, objects and specific types. Be correct and concise. If you are unsure anywhere, enter `null`.

View File

@@ -0,0 +1,51 @@
I was given the following JSON response, which had problems due to incorrect values.
{
"movies": [
{
"details": {
"website": {
"incorrect_value": "a.b.c",
"error_messages": [
"Value has length less than 9. Please return a longer output, that is shorter than 100 characters."
]
}
}
}
]
}
Help me correct the incorrect values based on the given error messages.
Given below is XML that describes the information to extract from this document and the tags to extract it into.
<output>
<string format="is-valid-director" name="name" required="true"></string>
<list name="movies" required="true">
<object required="true">
<integer name="rank" required="true"></integer>
<string name="title" required="true"></string>
<object name="details" required="true">
<date name="release_date" required="true"></date>
<time name="duration" required="true"></time>
<float name="budget" required="true"></float>
<bool name="is_sequel" required="false"></bool>
<string format="length: 9 100" name="website" required="true"></string>
<string name="contact_email" required="true"></string>
<choice discriminator="revenue_type" name="revenue" required="true">
<case name="box_office">
<float name="gross" required="true"></float>
<float name="opening_weekend" required="true"></float>
</case>
<case name="streaming">
<integer name="subscriptions" required="true"></integer>
<float name="subscription_fee" required="true"></float>
</case>
</choice>
</object>
</object>
</list>
</output>
ONLY return a valid JSON object (no other text is necessary), where the key of the field in JSON is the `name` attribute of the corresponding XML, and the value is of the type specified by the corresponding XML's tag. The JSON MUST conform to the XML format, including any types and format requests e.g. requests for lists, objects and specific types. Be correct and concise. If you are unsure anywhere, enter `null`.

View File

@@ -0,0 +1,90 @@
{
"name": "Christopher Nolan",
"movies": [
{
"rank": 1,
"title": "Inception",
"details": {
"release_date": "2010-07-16",
"duration": "02:28:00",
"budget": 160000000.0,
"is_sequel": false,
"website": "a.b.c",
"contact_email": "info@inceptionmovie.com",
"revenue": {
"revenue_type": "box_office",
"gross": 829895144.0,
"opening_weekend": 62785337.0
}
}
},
{
"rank": 2,
"title": "The Dark Knight",
"details": {
"release_date": "2008-07-18",
"duration": "02:32:00",
"budget": 185000000.0,
"is_sequel": true,
"website": "https://www.thedarkknightmovie.com",
"contact_email": "info@thedarkknightmovie.com",
"revenue": {
"revenue_type": "box_office",
"gross": 1004558444.0,
"opening_weekend": 158411483.0
}
}
},
{
"rank": 3,
"title": "The Dark Knight Rises",
"details": {
"release_date": "2012-07-20",
"duration": "02:44:00",
"budget": 250000000.0,
"is_sequel": true,
"website": "https://www.thedarkknightrises.com",
"contact_email": "info@thedarkknightrises.com",
"revenue": {
"revenue_type": "streaming",
"subscriptions": 15000000,
"subscription_fee": 9.99
}
}
},
{
"rank": 4,
"title": "Interstellar",
"details": {
"release_date": "2014-11-07",
"duration": "02:49:00",
"budget": 165000000.0,
"is_sequel": false,
"website": "https://www.interstellarmovie.com",
"contact_email": "info@interstellarmovie.com",
"revenue": {
"revenue_type": "box_office",
"gross": 115000000.0,
"opening_weekend": 47510360.0
}
}
},
{
"rank": 5,
"title": "Dunkirk",
"details": {
"release_date": "2017-07-21",
"duration": "01:46:00",
"budget": 100000000.0,
"is_sequel": false,
"website": "https://www.dunkirkmovie.com",
"contact_email": "info@dunkirkmovie.com",
"revenue": {
"revenue_type": "box_office",
"gross": 526940665.0,
"opening_weekend": 50513488.0
}
}
}
]
}

View File

@@ -0,0 +1,90 @@
{
"name": "Christopher Nolan",
"movies": [
{
"rank": 1,
"title": "Inception",
"details": {
"release_date": "2010-07-16",
"duration": "02:28:00",
"budget": 160000000.0,
"is_sequel": false,
"website": "https://www.inceptionmovie.com",
"contact_email": "info@inceptionmovie.com",
"revenue": {
"revenue_type": "box_office",
"gross": 829895144.0,
"opening_weekend": 62785337.0
}
}
},
{
"rank": 2,
"title": "The Dark Knight",
"details": {
"release_date": "2008-07-18",
"duration": "02:32:00",
"budget": 185000000.0,
"is_sequel": true,
"website": "https://www.thedarkknightmovie.com",
"contact_email": "info@thedarkknightmovie.com",
"revenue": {
"revenue_type": "box_office",
"gross": 1004558444.0,
"opening_weekend": 158411483.0
}
}
},
{
"rank": 3,
"title": "The Dark Knight Rises",
"details": {
"release_date": "2012-07-20",
"duration": "02:44:00",
"budget": 250000000.0,
"is_sequel": true,
"website": "https://www.thedarkknightrises.com",
"contact_email": "info@thedarkknightrises.com",
"revenue": {
"revenue_type": "streaming",
"subscriptions": 15000000,
"subscription_fee": 9.99
}
}
},
{
"rank": 4,
"title": "Interstellar",
"details": {
"release_date": "2014-11-07",
"duration": "02:49:00",
"budget": 165000000.0,
"is_sequel": false,
"website": "https://www.interstellarmovie.com",
"contact_email": "info@interstellarmovie.com",
"revenue": {
"revenue_type": "box_office",
"gross": 115000000.0,
"opening_weekend": 47510360.0
}
}
},
{
"rank": 5,
"title": "Dunkirk",
"details": {
"release_date": "2017-07-21",
"duration": "01:46:00",
"budget": 100000000.0,
"is_sequel": false,
"website": "https://www.dunkirkmovie.com",
"contact_email": "info@dunkirkmovie.com",
"revenue": {
"revenue_type": "box_office",
"gross": 526940665.0,
"opening_weekend": 50513488.0
}
}
}
]
}

View File

@@ -0,0 +1,90 @@
{
"name": "Christopher Nolan",
"movies": [
{
"rank": 1,
"title": "Inception",
"details": {
"release_date": "2010-07-16",
"duration": "02:28:00",
"budget": 160000000.0,
"is_sequel": false,
"website": "https://www.inceptionmovie.com",
"contact_email": "info@inceptionmovie.com",
"revenue": {
"revenue_type": "box_office",
"gross": 829895144.0,
"opening_weekend": 62785337.0
}
}
},
{
"rank": 2,
"title": "The Dark Knight",
"details": {
"release_date": "2008-07-18",
"duration": "02:32:00",
"budget": 185000000.0,
"is_sequel": true,
"website": "https://www.thedarkknightmovie.com",
"contact_email": "info@thedarkknightmovie.com",
"revenue": {
"revenue_type": "box_office",
"gross": 1004558444.0,
"opening_weekend": 158411483.0
}
}
},
{
"rank": 3,
"title": "The Dark Knight Rises",
"details": {
"release_date": "2012-07-20",
"duration": "02:44:00",
"budget": 250000000.0,
"is_sequel": true,
"website": "https://www.thedarkknightrises.com",
"contact_email": "info@thedarkknightrises.com",
"revenue": {
"revenue_type": "streaming",
"subscriptions": 15000000,
"subscription_fee": 9.99
}
}
},
{
"rank": 4,
"title": "Interstellar",
"details": {
"release_date": "2014-11-07",
"duration": "02:49:00",
"budget": 165000000.0,
"is_sequel": false,
"website": "https://www.interstellarmovie.com",
"contact_email": "info@interstellarmovie.com",
"revenue": {
"revenue_type": "box_office",
"gross": 677471339.0,
"opening_weekend": 47510360.0
}
}
},
{
"rank": 5,
"title": "Dunkirk",
"details": {
"release_date": "2017-07-21",
"duration": "01:46:00",
"budget": 100000000.0,
"is_sequel": false,
"website": "https://www.dunkirkmovie.com",
"contact_email": "info@dunkirkmovie.com",
"revenue": {
"revenue_type": "box_office",
"gross": 526940665.0,
"opening_weekend": 50513488.0
}
}
}
]
}

View File

@@ -0,0 +1,22 @@
<rail version="0.1">
<output
type="string"
name="greeting"
validators="two-words; lower-case; one-line; valid-url; valid-choices: {['a']}; length: 1 10"
on-fail-two-words="reask"
on-fail-lower-case="reask"
on-fail-one-line="fix"
on-fail-valid-url="noop"
on-fail-valid-choices="noop"
on-fail-length="reask"
/>
<messages>
<message role="user">
Say hullo to my little friend
${gr.complete_string_suffix}
</message>
</messages>
</rail>

View File

@@ -0,0 +1,16 @@
Say hullo to my little friend
Your generated response should satisfy the following properties:
- two-words
- lower-case
- one-line
- valid-url
- valid-choices: choices=['a']
- length: min=1 max=10
Don't talk; just go.

View File

@@ -0,0 +1,24 @@
This was a previous response you generated:
======
Hello a you
and me
======
Generate a new response that corrects your old response such that the following issues are fixed
- must be exactly two words
- Value Hello a you
and me is not lower case.
- Value has length greater than 10. Please return a shorter output, that is shorter than 10 characters.
Your generated response should satisfy the following properties:
- two-words
- lower-case
- one-line
- valid-url
- valid-choices: choices=['a']
- length: min=1 max=10
Don't talk; just go.

View File

@@ -0,0 +1,20 @@
This was a previous response you generated:
======
hi theremynameispete
======
Generate a new response that corrects your old response such that the following issues are fixed
- Value has length greater than 10. Please return a shorter output, that is shorter than 10 characters.
Your generated response should satisfy the following properties:
- two-words
- lower-case
- one-line
- valid-url
- valid-choices: choices=['a']
- length: min=1 max=10
Don't talk; just go.

View File

@@ -0,0 +1,23 @@
from guardrails.actions.reask import FieldReAsk
from guardrails_ai.types import FailResult
VALIDATOR_PARALLELISM_REASK_1 = FieldReAsk(
incorrect_value="Hello a you\nand me",
fail_results=[
FailResult(
outcome="fail",
error_message="must be exactly two words",
fix_value="Hello a",
),
FailResult(
outcome="fail",
error_message="Value Hello a you\nand me is not lower case.",
fix_value="hello a you\nand me",
),
FailResult(
outcome="fail",
error_message="Value has length greater than 10. Please return a shorter output, that is shorter than 10 characters.", # noqa: E501
fix_value="Hello a yo",
),
],
)

View File

@@ -0,0 +1,16 @@
from guardrails.actions.reask import FieldReAsk
from guardrails_ai.types import FailResult
VALIDATOR_PARALLELISM_REASK_2 = FieldReAsk(
incorrect_value="hi theremynameispete",
fail_results=[
FailResult(
outcome="fail",
metadata=None,
error_message="Value has length greater than 10. "
"Please return a shorter output, "
"that is shorter than 10 characters.",
fix_value="hi theremy",
)
],
)