Skip to content

Commit 01dab54

Browse files
authored
如果用户提供的函数没有description,就应该明确报错,不让他继续使用 (#273)
Fixes #271
2 parents b6961e5 + 462a9f2 commit 01dab54

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

code365scripts.openai/Private/Functions.ps1

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,19 @@ function Get-FunctionJson {
1717

1818
# generate a json object based on the help content of the function
1919
$help = Get-Help $functionName
20+
21+
# if the help doesn't include description, return null
22+
if (-not $help.description) {
23+
Write-Warning "Function $functionName does not have a description."
24+
return $null
25+
}
26+
27+
# if any parameters don't include description, return null
28+
if ($help.parameters.parameter | Where-Object { -not $_.description }) {
29+
Write-Warning "Function $functionName has parameters without description."
30+
return $null
31+
}
32+
2033
$json = [pscustomobject]@{
2134
type = "function"
2235
function = @{

code365scripts.openai/Public/New-ChatGPTConversation.ps1

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,8 @@ function New-ChatGPTConversation {
296296
if ($functions) {
297297
$tools = @(Get-PredefinedFunctions -names $functions)
298298

299-
Write-Verbose ($tools | ConvertTo-Json -Depth 10)
300-
301299
if ($tools.Count -gt 0) {
300+
Write-Verbose ($tools | ConvertTo-Json -Depth 10)
302301
if ($null -eq $config) {
303302
$config = @{}
304303
}

0 commit comments

Comments
 (0)