Skip to content

Commit 196e70b

Browse files
Improve Gemini output filtering and update demo workflow
Enhanced filtering of Gemini CLI warnings and informational messages in Invoke-ChatMode.ps1, Invoke-ToolWithCapture.ps1, and Invoke-AITool.ps1. Updated demo-unattended.ipynb to use markdown input for immunization data, streamlined prompts, and improved workflow for schema creation and data extraction. Added runtime validation for -First and -Last parameters in Invoke-AITool.ps1. Fixed path handling in Test-GeminiAuth.ps1. Bumped module version to 1.0.30. Added sample immunization.md for testing and updated unattended.md for clarity.
1 parent cc9e88b commit 196e70b

File tree

8 files changed

+139
-91
lines changed

8 files changed

+139
-91
lines changed

Tests/pdf/immunization.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
Dog Shot Record
2+
3+
2309 Kelley Road, Gulfport, MS, 39501
4+
5+
CLINIC NAME
6+
7+
Phone: 123-1234567 - Email: info@petshopname.com
8+
9+
Dog's Name Chewy
10+
11+
Age 5
12+
13+
Date of Birth February 25, 2014
14+
15+
Gender Male
16+
17+
Breed Labrador
18+
19+
Color Brown
20+
21+
Owner's Name Jane Doe
22+
23+
Address 1375 McDowell Street
24+
Mount Pleasant, TN, 38474
25+
26+
Recommended Immunization Schedule
27+
28+
| Age | Recommended | Optional |
29+
|-------------|--------------------------------------|--------------------------------------|
30+
| 6-8 weeks | Distemper, Measles, Parainfluenza | Bordatella |
31+
| 10-12 weeks | DHPP | Coronavirus, Leptospirosis, Lyme disease |
32+
| 12-24 weeks | Rabies | None |
33+
| 14-16 weeks | DHPP | Coronavirus, Lyme disease, Leptospirosis |
34+
| 12-16 months| Rabies, DHPP | Coronavirus, Leptospirosis, Bordatella, Lyme disease |
35+
| Every 1-2 years | DHPP | Coronavirus, Leptospirosis, Bordatella, Lyme disease |
36+
| Every 1-3 years | Rabies | None |
37+
38+
Immunization Dates
39+
40+
| Vaccine | Immunization Date1 | Immunization Date2 | Immunization Date3 | Veterinarian |
41+
|---------------|--------------------|--------------------|--------------------|----------------|
42+
| Distemper | 02/01/2019 | | | John Smith |
43+
| Measles | 02/01/2019 | | | John Smith |
44+
| Parainfluenza | 02/01/2019 | | | John Smith |
45+
| DHPP | 02/01/2019 | 09/01/2017 | 09/01/2018 | John Smith |
46+
| Bordatella | 02/01/2019 | 09/01/2017 | 09/01/2018 | John Smith |
47+
| Coronavirus | 02/01/2019 | 10/01/2017 | 09/01/2018 | John Smith |
48+
| Leptospirosis | 02/01/2019 | 09/01/2017 | 09/01/2018 | John Smith |
49+
| Lyme disease | 02/01/2019 | 10/01/2017 | 09/01/2018 | John Smith |
50+
51+
Veterinarian Name: John Smith
52+
Veterinarian Signature
53+
54+
Date of Signature: February 25, 2019

aitools.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
RootModule = 'aitools.psm1'
1010

1111
# Version number of this module.
12-
ModuleVersion = '1.0.25'
12+
ModuleVersion = '1.0.30'
1313

1414
# ID used to uniquely identify this module
1515
GUID = 'c90f5001-c492-4fbe-8ab3-f03599951bd0'

demo-unattended.ipynb

Lines changed: 55 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
},
4141
{
4242
"cell_type": "code",
43-
"execution_count": null,
43+
"execution_count": 1,
4444
"metadata": {
4545
"dotnet_interactive": {
4646
"language": "pwsh"
@@ -49,7 +49,48 @@
4949
"kernelName": "pwsh"
5050
}
5151
},
52-
"outputs": [],
52+
"outputs": [
53+
{
54+
"data": {
55+
"text/html": [
56+
"<table><thead><tr><th><i>key</i></th><th>value</th></tr></thead><tbody><tr><td><div class=\"dni-plaintext\"><pre>FullName</pre></div></td><td><div class=\"dni-plaintext\"><pre>AITools.DefaultTool</pre></div></td></tr><tr><td><div class=\"dni-plaintext\"><pre>Value</pre></div></td><td><div class=\"dni-plaintext\"><pre>Copilot</pre></div></td></tr></tbody></table><style>\r\n",
57+
".dni-code-hint {\r\n",
58+
" font-style: italic;\r\n",
59+
" overflow: hidden;\r\n",
60+
" white-space: nowrap;\r\n",
61+
"}\r\n",
62+
".dni-treeview {\r\n",
63+
" white-space: nowrap;\r\n",
64+
"}\r\n",
65+
".dni-treeview td {\r\n",
66+
" vertical-align: top;\r\n",
67+
" text-align: start;\r\n",
68+
"}\r\n",
69+
"details.dni-treeview {\r\n",
70+
" padding-left: 1em;\r\n",
71+
"}\r\n",
72+
"table td {\r\n",
73+
" text-align: start;\r\n",
74+
"}\r\n",
75+
"table tr { \r\n",
76+
" vertical-align: top; \r\n",
77+
" margin: 0em 0px;\r\n",
78+
"}\r\n",
79+
"table tr td pre \r\n",
80+
"{ \r\n",
81+
" vertical-align: top !important; \r\n",
82+
" margin: 0em 0px !important;\r\n",
83+
"} \r\n",
84+
"table th {\r\n",
85+
" text-align: start;\r\n",
86+
"}\r\n",
87+
"</style>"
88+
]
89+
},
90+
"metadata": {},
91+
"output_type": "display_data"
92+
}
93+
],
5394
"source": [
5495
"# Anthropic's having outages. PIVOTTT\n",
5596
"Set-AIToolDefault -Tool Copilot\n",
@@ -64,7 +105,7 @@
64105
},
65106
{
66107
"cell_type": "code",
67-
"execution_count": null,
108+
"execution_count": 2,
68109
"metadata": {
69110
"dotnet_interactive": {
70111
"language": "pwsh"
@@ -105,63 +146,20 @@
105146
"outputs": [],
106147
"source": [
107148
"$designPrompt = @\"\n",
108-
"Review this pet vaccination PDF and design a normalized database schema.\n",
149+
"Review Tests/pdf/immunization.pdf carefully and design a normalized database schema.\n",
109150
"\n",
110151
"Requirements:\n",
111152
"- Create properly normalized tables (at least 2 tables with foreign key relationship)\n",
112153
"- Use best practices for data types, constraints, and indexing\n",
113-
"- Target database: SQL Server tempdb\n",
154+
"- Target DB: SQL Server, localhost, windows auth, tempdb\n",
114155
"\n",
115156
"Output:\n",
116157
"1. First, explain your design decisions (table structure, why you normalized this way)\n",
117158
"2. Then provide the complete T-SQL DDL to create the tables\n",
118-
"3. Format the DDL in a code block so I can execute it\n",
159+
"3. Execute ONLY DDL against local SQL Server\n",
119160
"\"@\n",
120161
"\n",
121-
"Get-ChildItem ./Tests/pdf/immunization.pdf |\n",
122-
" ConvertTo-AITImage |\n",
123-
" Invoke-AITool -Prompt $designPrompt"
124-
]
125-
},
126-
{
127-
"cell_type": "markdown",
128-
"metadata": {},
129-
"source": [
130-
"### Now go check SSMS!\n",
131-
"\n",
132-
"Or... let's have Claude create AND show us what it built:"
133-
]
134-
},
135-
{
136-
"cell_type": "code",
137-
"execution_count": null,
138-
"metadata": {
139-
"dotnet_interactive": {
140-
"language": "pwsh"
141-
},
142-
"polyglot_notebook": {
143-
"kernelName": "pwsh"
144-
}
145-
},
146-
"outputs": [],
147-
"source": [
148-
"$createPrompt = \"Review this pet vaccination PDF and design a normalized database schema.\n",
149-
"\n",
150-
"Requirements:\n",
151-
"- Create properly normalized tables (at least 2 tables with foreign key relationship)\n",
152-
"- Use best practices for data types, constraints, and indexing\n",
153-
"- Target database: tempdb on localhost with windows auth. dbatools is available on the machine, use it.\n",
154-
"\n",
155-
"DO NOT IMPORT DATA, JUST SCHEMA\"\n",
156-
"\n",
157-
"\n",
158-
"Get-ChildItem ./Tests/pdf/immunization.pdf |\n",
159-
" ConvertTo-AITImage |\n",
160-
" Invoke-AITool -Prompt $createPrompt\n",
161-
"\n",
162-
"# Show what was created\n",
163-
"Get-DbaDbTable -SqlInstance $sqlInstance -Database $database -Table Pets, Vaccinations |\n",
164-
" Select-Object Name, RowCount, DataSpaceUsed"
162+
"Invoke-AITool -Prompt $designPrompt"
165163
]
166164
},
167165
{
@@ -189,38 +187,20 @@
189187
},
190188
"outputs": [],
191189
"source": [
192-
"$extractPrompt = \"Extract the data from this pet vaccination PDF.\n",
190+
"$extractPrompt = \"Extract the data from /Tests/pdf/immunization.md\n",
193191
"\n",
194192
"I have vaccine tables in tempdb on localhost (sql server/windows auth),\n",
195193
"figure out the structure, insert the data from the PDF then show me what\n",
196194
"you inserted\"\n",
197195
"\n",
198-
"Get-ChildItem ./Tests/pdf/immunization.pdf |\n",
199-
" ConvertTo-AITImage |\n",
200-
" Invoke-AITool -Prompt $extractPrompt"
201-
]
202-
},
203-
{
204-
"cell_type": "code",
205-
"execution_count": null,
206-
"metadata": {
207-
"dotnet_interactive": {
208-
"language": "pwsh"
209-
},
210-
"polyglot_notebook": {
211-
"kernelName": "pwsh"
212-
}
213-
},
214-
"outputs": [],
215-
"source": [
216-
"# Let's see what we imported in SSMS"
196+
"Invoke-AITool -Prompt $extractPrompt"
217197
]
218198
},
219199
{
220200
"cell_type": "markdown",
221201
"metadata": {},
222202
"source": [
223-
"### Notice anything wrong?\n",
203+
"### Go look in SSMS, notice anything wrong?\n",
224204
"\n",
225205
"The data is in there exactly as the PDF showed it. But there might be problems...\n",
226206
"\n",
@@ -243,9 +223,7 @@
243223
},
244224
"outputs": [],
245225
"source": [
246-
"Get-ChildItem ./Tests/pdf/immunization.pdf |\n",
247-
" ConvertTo-AITImage |\n",
248-
" Invoke-AITool -Prompt C:\\github\\aitools\\unattended.md"
226+
"Invoke-AITool -Prompt C:\\github\\aitools\\unattended.md -Tool Claude"
249227
]
250228
},
251229
{
@@ -274,10 +252,9 @@
274252
"outputs": [],
275253
"source": [
276254
"$reportPrompt = @\"\n",
277-
"Review this pet vaccination PDF and generate a data quality report.\n",
255+
"Review /Tests/pdf/immunization.pdf carefully and generate a data quality report.\n",
278256
"\n",
279257
"Analyze the document thoroughly for:\n",
280-
"- Data inconsistencies (breed vs. physical characteristics, weight ranges, etc.)\n",
281258
"- Missing or incomplete information\n",
282259
"- Suspicious or potentially incorrect values\n",
283260
"- Format issues\n",
@@ -292,9 +269,7 @@
292269
"Be thorough - this report helps humans catch shit data before it pollutes the database.\n",
293270
"\"@\n",
294271
"\n",
295-
"$report = Get-ChildItem ./Tests/pdf/immunization.pdf |\n",
296-
" ConvertTo-AITImage |\n",
297-
" Invoke-AITool -Prompt $reportPrompt\n",
272+
"$report = Invoke-AITool -Prompt $reportPrompt\n",
298273
"\n",
299274
"# Save the report\n",
300275
"$report | Set-Content ./Tests/pdf/data_quality_report.md\n",
@@ -343,7 +318,7 @@
343318
"\n",
344319
"\"Labrador\" is a valid breed. Traditional validation would pass it.\n",
345320
"\n",
346-
"But AI looks at the *whole picture* and says \"wait, this doesn't add up.\""
321+
"But AI looks at the *whole picture* and knows it doesn't quite add up."
347322
]
348323
}
349324
],

private/Invoke-ChatMode.ps1

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,9 +368,13 @@ function Invoke-ChatMode {
368368
$capturedOutput = Get-Content -Path $tempOutputFile -Raw -Encoding utf8
369369
Remove-Item -Path $tempOutputFile -Force -ErrorAction SilentlyContinue
370370

371-
# Filter out misleading Gemini warnings
371+
# Filter out misleading Gemini warnings and informational stderr messages
372372
if ($ToolName -eq 'Gemini') {
373373
$capturedOutput = $capturedOutput -replace '(?m)^\s*\[WARN\]\s+Skipping unreadable directory:.*?\n', ''
374+
# Filter out informational messages that Gemini CLI writes to stderr
375+
$capturedOutput = $capturedOutput -replace '(?m)^.*YOLO mode is enabled\..*\n?', ''
376+
$capturedOutput = $capturedOutput -replace '(?m)^.*All tool calls will be automatically approved\..*\n?', ''
377+
$capturedOutput = $capturedOutput -replace '(?m)^.*Loaded cached credentials\..*\n?', ''
374378
}
375379
}
376380

private/Invoke-ToolWithCapture.ps1

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,13 @@ function Invoke-ToolWithCapture {
227227

228228
$capturedOutput = Get-Content -Path $tempOutputFile -Raw -Encoding utf8
229229

230-
# Filter out misleading Gemini warnings about unreadable directories
230+
# Filter out misleading Gemini warnings and informational stderr messages
231231
if ($ToolName -eq 'Gemini') {
232232
$capturedOutput = $capturedOutput -replace '(?m)^\s*\[WARN\]\s+Skipping unreadable directory:.*?\n', ''
233+
# Filter out informational messages that Gemini CLI writes to stderr
234+
$capturedOutput = $capturedOutput -replace '(?m)^.*YOLO mode is enabled\..*\n?', ''
235+
$capturedOutput = $capturedOutput -replace '(?m)^.*All tool calls will be automatically approved\..*\n?', ''
236+
$capturedOutput = $capturedOutput -replace '(?m)^.*Loaded cached credentials\..*\n?', ''
233237
}
234238
}
235239

private/Test-GeminiAuth.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function Test-GeminiAuth {
1616
$geminiKey = [Environment]::GetEnvironmentVariable('GEMINI_API_KEY')
1717
$vertexAI = [Environment]::GetEnvironmentVariable('GOOGLE_GENAI_USE_VERTEXAI')
1818
$gca = [Environment]::GetEnvironmentVariable('GOOGLE_GENAI_USE_GCA')
19-
$settingsPath = Join-Path $HOME '.gemini' 'settings.json'
19+
$settingsPath = Join-Path -Path "$HOME/.gemini" -ChildPath 'settings.json'
2020

2121
if ($geminiKey -or $vertexAI -or $gca) {
2222
Write-PSFMessage -Level Verbose -Message "Gemini auth found via environment variable"

public/Invoke-AITool.ps1

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ function Invoke-AITool {
311311
[Parameter()]
312312
[string]$Model,
313313
[Parameter()]
314-
[ValidateSet('low', 'medium', 'high')]
314+
[ValidateSet('low', 'medium', 'high', '')]
315315
[string]$ReasoningEffort,
316316
[Parameter()]
317317
[string[]]$Attachment,
@@ -339,10 +339,8 @@ function Invoke-AITool {
339339
[ValidateRange(0, [int]::MaxValue)]
340340
[int]$Skip,
341341
[Parameter()]
342-
[ValidateRange(1, [int]::MaxValue)]
343342
[int]$First,
344343
[Parameter()]
345-
[ValidateRange(1, [int]::MaxValue)]
346344
[int]$Last,
347345
[Parameter()]
348346
[ValidateRange(1, 50)]
@@ -366,6 +364,14 @@ function Invoke-AITool {
366364
$script:originalLocation = Get-Location
367365
Write-PSFMessage -Level Verbose -Message "Saved original location: $script:originalLocation"
368366

367+
# Validate First and Last at runtime (can't use ValidateRange due to GetNewClosure() capturing default 0)
368+
if ($PSBoundParameters.ContainsKey('First') -and $First -lt 1) {
369+
Stop-PSFFunction -Message "-First must be at least 1" -EnableException $true
370+
}
371+
if ($PSBoundParameters.ContainsKey('Last') -and $Last -lt 1) {
372+
Stop-PSFFunction -Message "-Last must be at least 1" -EnableException $true
373+
}
374+
369375
# BatchSize > 1 automatically disables parallel processing
370376
if ($BatchSize -gt 1) {
371377
Write-PSFMessage -Level Verbose -Message "BatchSize set to $BatchSize - parallel processing will be automatically disabled for batch mode"
@@ -1004,9 +1010,13 @@ function Invoke-AITool {
10041010
$capturedOutput = Get-Content -Path $tempOutputFile -Raw -Encoding utf8
10051011
Remove-Item -Path $tempOutputFile -Force -ErrorAction SilentlyContinue
10061012

1007-
# Filter out misleading Gemini warnings
1013+
# Filter out misleading Gemini warnings and informational stderr messages
10081014
if ($currentTool -eq 'Gemini') {
10091015
$capturedOutput = $capturedOutput -replace '(?m)^\s*\[WARN\]\s+Skipping unreadable directory:.*?\n', ''
1016+
# Filter out informational messages that Gemini CLI writes to stderr
1017+
$capturedOutput = $capturedOutput -replace '(?m)^.*YOLO mode is enabled\..*\n?', ''
1018+
$capturedOutput = $capturedOutput -replace '(?m)^.*All tool calls will be automatically approved\..*\n?', ''
1019+
$capturedOutput = $capturedOutput -replace '(?m)^.*Loaded cached credentials\..*\n?', ''
10101020
}
10111021

10121022
# Strip result to JSON boundaries if single JSON context mode

unattended.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
$prompt = "Review this pet vaccination PDF carefully for data quality issues.
1+
Review /Tests/pdf/immunization.pdf carefully for data quality issues.
22

33
I've already imported the data exactly as shown in the PDF into tempdb tables
4-
(look it up on localhost).
4+
(look it up on localhost using windows credentials).
5+
56
Now I need you to:
67

78
1. ANALYZE the document for inconsistencies, errors, or suspicious data:
@@ -13,4 +14,4 @@ Now I need you to:
1314

1415
2. Generate T-SQL UPDATE statements to correct any issues you find
1516

16-
3. List ALL data inconsistencies you discovered"
17+
3. List ALL data inconsistencies you discovered

0 commit comments

Comments
 (0)