참고소스 수정본

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,52 @@
# ruff: noqa: E501
import os
from .msg_validated_output_reask import MSG_VALIDATED_OUTPUT_REASK
from .validated_output_reask import VALIDATED_OUTPUT_REASK
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_INSTRUCTIONS = reader("compiled_instructions.txt")
COMPILED_PROMPT = reader("compiled_prompt.txt")
COMPILED_LIST_PROMPT = reader("compiled_list_prompt.txt")
LLM_OUTPUT = reader("llm_output.txt")
LIST_LLM_OUTPUT = reader("llm_list_output.txt")
RAIL_SPEC_FOR_STRING = reader("string.rail")
RAIL_SPEC_FOR_LIST = reader("list.rail")
COMPILED_PROMPT_REASK = reader("compiled_prompt_reask.txt")
RAIL_SPEC_FOR_STRING_REASK = reader("string_reask.rail")
LLM_OUTPUT_REASK = reader("llm_output_reask.txt")
RAIL_SPEC_FOR_MSG_HISTORY = reader("message_history.rail")
MSG_LLM_OUTPUT_INCORRECT = reader("message_history_output.txt")
MSG_LLM_OUTPUT_CORRECT = reader("message_history_reask_output.txt")
MOVIE_MSG_HISTORY = [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Can you give me your favorite movie?"},
]
MSG_COMPILED_PROMPT_REASK = reader("msg_compiled_prompt_reask.txt")
MSG_COMPILED_INSTRUCTIONS_REASK = reader("msg_compiled_instructions_reask.txt")
PARSE_COMPILED_PROMPT_REASK = reader("parse_compiled_prompt_reask.txt")
__all__ = [
"COMPILED_PROMPT",
"RAIL_SPEC_FOR_LIST",
"LIST_LLM_OUTPUT",
"LLM_OUTPUT",
"RAIL_SPEC_FOR_STRING",
"COMPILED_PROMPT_REASK",
"RAIL_SPEC_FOR_STRING_REASK",
"LLM_OUTPUT_REASK",
"VALIDATED_OUTPUT_REASK",
"RAIL_SPEC_FOR_MSG_HISTORY",
"MSG_LLM_OUTPUT_INCORRECT",
"MSG_LLM_OUTPUT_CORRECT",
"MOVIE_MSG_HISTORY",
"MSG_COMPILED_PROMPT_REASK",
"MSG_COMPILED_INSTRUCTIONS_REASK",
"MSG_VALIDATED_OUTPUT_REASK",
]

View File

@@ -0,0 +1,11 @@
You are a helpful assistant, and you are helping me come up with a name for a pizza.
Here's a description of what I want you to generate: Name for the pizza
Your generated response should satisfy the following properties:
- two-words
Don't talk; just go.

View File

@@ -0,0 +1,24 @@
Generate a dataset of fake user orders. Each row of the dataset should be valid.
Given below is XML that describes the information to extract from this document and the tags to extract it into.
<output>
<list name="user_orders" description="Generate a list of user, and how many orders they have placed in the past." format="length: min=10 max=10">
<object>
<string name="user_id" description="The user's id." format="1-indexed"/>
<string name="user_name" description="The user's first name and last name" format="two-words"/>
<integer name="num_orders" description="The number of orders the user has placed" format="valid-range: min=0 max=50"/>
<date name="last_order_date" description="Date of last order"/>
</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`.
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,4 @@
Given the following ingredients, what would you call this pizza?
tomato, cheese, sour cream

View File

@@ -0,0 +1,15 @@
This was a previous response you generated:
======
Tomato Cheese Pizza
======
Generate a new response that corrects your old response such that the following issues are fixed
- must be exactly two words
Here's a description of what I want you to generate: Name for the pizza
Your generated response should satisfy the following properties:
- two-words
Don't talk; just go.

View File

@@ -0,0 +1,18 @@
<rail version="0.1">
<output>
<list name="user_orders" description="Generate a list of user, and how many orders they have placed in the past." format="length: 10 10" on-fail-length="noop">
<object>
<string name="user_id" description="The user's id." format="1-indexed" />
<string name="user_name" description="The user's first name and last name" validators="two-words" />
<integer name="num_orders" description="The number of orders the user has placed" validators="valid-range: 0 50" />
<date name="last_order_date" description="Date of last order" />
</object>
</list>
</output>
<prompt>
Generate a dataset of fake user orders. Each row of the dataset should be valid.
${gr.complete_json_suffix}
</prompt>
</rail>

View File

@@ -0,0 +1,14 @@
{
'user_orders': [
{'user_id': 1, 'user_name': 'John Smith', 'num_orders': 10, 'last_order_date': '2020-01-01'},
{'user_id': 2, 'user_name': 'Jane Doe', 'num_orders': 20, 'last_order_date': '2020-02-01'},
{'user_id': 3, 'user_name': 'Bob Jones', 'num_orders': 30, 'last_order_date': '2020-03-01'},
{'user_id': 4, 'user_name': 'Alice Smith', 'num_orders': 40, 'last_order_date': '2020-04-01'},
{'user_id': 5, 'user_name': 'John Doe', 'num_orders': 50, 'last_order_date': '2020-05-01'},
{'user_id': 6, 'user_name': 'Jane Jones', 'num_orders': 0, 'last_order_date': '2020-06-01'},
{'user_id': 7, 'user_name': 'Bob Smith', 'num_orders': 10, 'last_order_date': '2020-07-01'},
{'user_id': 8, 'user_name': 'Alice Doe', 'num_orders': 20, 'last_order_date': '2020-08-01'},
{'user_id': 9, 'user_name': 'John Jones', 'num_orders': 30, 'last_order_date': '2020-09-01'},
{'user_id': 10, 'user_name': 'Jane Smith', 'num_orders': 40, 'last_order_date': '2020-10-01'}
]
}

View File

@@ -0,0 +1 @@
Tomato Cheese Pizza

View File

@@ -0,0 +1,8 @@
<rail version="0.1">
<output
type="string"
description="Generate a movie"
validators="two-words"
on-fail-two-words="reask">
</output>
</rail>

View File

@@ -0,0 +1 @@
You are a helpful assistant.

View File

@@ -0,0 +1,15 @@
This was a previous response you generated:
======
The Matrix Reloaded
======
Generate a new response that corrects your old response such that the following issues are fixed
- must be exactly two words
Here's a description of what I want you to generate: Generate a movie
Your generated response should satisfy the following properties:
- two-words
Don't talk; just go.

View File

@@ -0,0 +1,12 @@
from guardrails.actions.reask import FieldReAsk
from guardrails_ai.types import FailResult
MSG_VALIDATED_OUTPUT_REASK = FieldReAsk(
incorrect_value="The Matrix Reloaded",
fail_results=[
FailResult(
error_message="must be exactly two words",
fix_value="The Matrix",
)
],
)

View File

@@ -0,0 +1,15 @@
This was a previous response you generated:
======
Tomato Cheese Pizza
======
Generate a new response that corrects your old response such that the following issues are fixed
- Value Tomato Cheese Pizza should fail.
Your generated response should satisfy the following properties:
- always_fail
Don't talk; just go.

View File

@@ -0,0 +1,20 @@
<rail version="0.1">
<output
type="string"
description="Name for the pizza"
/>
<messages>
<message role="system">
You are a helpful assistant, and you are helping me come up with a name for a pizza.
${complete_string_suffix}
</message>
<message role="user">
Given the following ingredients, what would you call this pizza?
${ingredients}
</message>
</messages>
</rail>

View File

@@ -0,0 +1,21 @@
<rail version="0.1">
<output
type="string"
description="Name for the pizza"
validators="two-words"
on-fail-two-words="reask"
/>
<messages>
<message role="system">
You are a helpful assistant, and you are helping me come up with a name for a pizza.
${gr.complete_string_suffix}
</message>
<message role="user">
Given the following ingredients, what would you call this pizza?
${ingredients}
</message>
</messages>
</rail>

View File

@@ -0,0 +1,12 @@
from guardrails.actions.reask import FieldReAsk
from guardrails_ai.types import FailResult
VALIDATED_OUTPUT_REASK = FieldReAsk(
incorrect_value="Tomato Cheese Pizza",
fail_results=[
FailResult(
error_message="must be exactly two words",
fix_value="Tomato Cheese",
)
],
)