Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd6d809e

Browse files
committed
Add CI job to run lint (tests will come later) and resolve lint issues
1 parent7bdf8a9 commitd6d809e

File tree

57 files changed

+713
-670
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+713
-670
lines changed

‎.github/workflows/ci.yml‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name:CI
2+
3+
on:
4+
push:
5+
branches:[main]
6+
pull_request:
7+
8+
jobs:
9+
lint-and-test:
10+
runs-on:ubuntu-latest
11+
strategy:
12+
matrix:
13+
python-version:["3.11", "3.12", "3.13"]
14+
steps:
15+
-name:Checkout repository
16+
uses:actions/checkout@v4
17+
18+
-name:Set up Python
19+
uses:actions/setup-python@v5
20+
with:
21+
python-version:${{ matrix.python-version }}
22+
23+
-name:Install dependencies
24+
run:make sync
25+
26+
-name:Lint with ruff
27+
run:make lint
28+
29+
# TODO: enable this once all the tests pass
30+
# - name: Run tests
31+
# run: make tests

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ For full details, advanced usage, and API reference, see here: [OpenAI Guardrail
1717
2.**Install dependencies**
1818
-**Install from this repo:**
1919
```bash
20-
pip install -e .[presidio]
20+
pip install -e'.[presidio]'
2121
```
2222
-**Eventually this will be:**
2323
```bash

‎examples/basic/azure_implementation.py‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88

99
importasyncio
1010
importos
11+
12+
fromdotenvimportload_dotenv
1113
fromopenaiimportBadRequestError
14+
1215
fromguardrailsimport (
1316
GuardrailsAsyncAzureOpenAI,
1417
GuardrailTripwireTriggered,
1518
)
16-
fromdotenvimportload_dotenv
1719

1820
load_dotenv()
1921

@@ -72,14 +74,14 @@ async def process_input(
7274
exceptGuardrailTripwireTriggeredase:
7375
# Extract information from the triggered guardrail
7476
triggered_result=e.guardrail_result
75-
print(f" Input blocked. Please try a different message.")
77+
print(" Input blocked. Please try a different message.")
7678
print(f" Full result:{triggered_result}")
7779
raise
7880
exceptBadRequestErrorase:
7981
# Handle Azure's built-in content filter errors
8082
# Will be triggered not when the guardrail is tripped, but when the LLM is filtered by Azure.
8183
if"content_filter"instr(e):
82-
print(f"\n🚨 Third party content filter triggered during LLM call.")
84+
print("\n🚨 Third party content filter triggered during LLM call.")
8385
print(f" Error:{e}")
8486
raise
8587
else:

‎examples/basic/custom_context.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
fromguardrailsimportGuardrailsAsyncOpenAI,GuardrailTripwireTriggered
1212
fromguardrails.contextimportGuardrailsContext,set_context
1313

14-
1514
# Pipeline config with an LLM-based guardrail using Gemma3 via Ollama
1615
PIPELINE_CONFIG= {
1716
"version":1,

‎examples/basic/hello_world.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
importasyncio
44
fromcontextlibimportsuppress
5+
56
fromrich.consoleimportConsole
67
fromrich.panelimportPanel
78

@@ -55,7 +56,7 @@ async def process_input(
5556

5657
returnresponse.llm_response.id
5758

58-
exceptGuardrailTripwireTriggeredasexc:
59+
exceptGuardrailTripwireTriggered:
5960
raise
6061

6162

‎examples/basic/local_model.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
importasyncio
44
fromcontextlibimportsuppress
5-
fromrich.consoleimportConsole
6-
fromrich.panelimportPanel
75

86
fromopenai.types.chatimportChatCompletionMessageParam
7+
fromrich.consoleimportConsole
8+
fromrich.panelimportPanel
99

1010
fromguardrailsimportGuardrailsAsyncOpenAI,GuardrailTripwireTriggered
1111

@@ -55,7 +55,7 @@ async def process_input(
5555
input_data.append({"role":"user","content":user_input})
5656
input_data.append({"role":"assistant","content":response_content})
5757

58-
exceptGuardrailTripwireTriggeredasexc:
58+
exceptGuardrailTripwireTriggered:
5959
# Handle guardrail violations
6060
raise
6161

‎examples/basic/multi_bundle.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
fromrich.consoleimportConsole
77
fromrich.liveimportLive
88
fromrich.panelimportPanel
9+
910
fromguardrailsimportGuardrailsAsyncOpenAI,GuardrailTripwireTriggered
1011

1112
console=Console()
@@ -79,7 +80,7 @@ async def process_input(
7980

8081
returnresponse_id_to_return
8182

82-
exceptGuardrailTripwireTriggeredasexc:
83+
exceptGuardrailTripwireTriggered:
8384
# Clear the live display when output guardrail is triggered
8485
live.update("")
8586
console.clear()

‎examples/basic/multiturn_chat_with_alignment.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
from __future__importannotations
2020

2121
importargparse
22-
importjson
23-
fromtypingimportIterable
2422
importasyncio
23+
importjson
24+
fromcollections.abcimportIterable
2525

2626
fromrich.consoleimportConsole
2727
fromrich.panelimportPanel
@@ -177,10 +177,10 @@ def _stage_lines(stage_name: str, stage_results: Iterable) -> list[str]:
177177
# Add interpretation
178178
ifr.tripwire_triggered:
179179
lines.append(
180-
f" ⚠️ PROMPT INJECTION DETECTED: Action does not serve user's goal!"
180+
" ⚠️ PROMPT INJECTION DETECTED: Action does not serve user's goal!"
181181
)
182182
else:
183-
lines.append(f" ✨ ALIGNED: Action serves user's goal")
183+
lines.append(" ✨ ALIGNED: Action serves user's goal")
184184
else:
185185
# Other guardrails - show basic info
186186
forkey,valueininfo.items():

‎examples/basic/pii_mask_example.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
importasyncio
1313
fromcontextlibimportsuppress
14+
1415
fromrich.consoleimportConsole
1516
fromrich.panelimportPanel
1617

‎examples/basic/structured_outputs_example.py‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Simple example demonstrating structured outputs with GuardrailsClient."""
22

33
importasyncio
4+
45
frompydanticimportBaseModel,Field
56

67
fromguardrailsimportGuardrailsAsyncOpenAI,GuardrailTripwireTriggered
@@ -37,13 +38,13 @@ async def extract_user_info(guardrails_client: GuardrailsAsyncOpenAI, text: str)
3738
model="gpt-4.1-nano",
3839
text_format=UserInfo
3940
)
40-
41+
4142
# Access the parsed structured output
4243
user_info=response.llm_response.output_parsed
4344
print(f"✅ Successfully extracted:{user_info.name},{user_info.age},{user_info.email}")
44-
45+
4546
returnuser_info
46-
47+
4748
exceptGuardrailTripwireTriggeredasexc:
4849
print(f"❌ Guardrail triggered:{exc}")
4950
raise
@@ -75,4 +76,4 @@ async def main() -> None:
7576

7677

7778
if__name__=="__main__":
78-
asyncio.run(main())
79+
asyncio.run(main())

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp