Skip to content

Commit 6d3ed6c

Browse files
authored
merge-hashtable复杂对象时会报错 (#266)
Fixes #265
2 parents 2f95bf9 + 4ed99d5 commit 6d3ed6c

File tree

4 files changed

+64
-0
lines changed

4 files changed

+64
-0
lines changed

code365scripts.openai/Private/Get-PromptContent.ps1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ function Get-PromptContent {
5959
}
6060

6161
#merge system variables with context
62+
# if context is not hashtable, then convert it to hashtable
63+
if ($context -isnot [hashtable]) {
64+
$context = ConvertTo-Hashtable $context
65+
}
6266
Merge-Hashtable -table1 $systemVariables -table2 $context
6367
$context = $systemVariables
6468
# if user provide the context, inject the data into the prompt by replace the context key with the context value

code365scripts.openai/Public/New-ChatCompletions.ps1

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,16 @@ function New-ChatCompletions {
8484
if ($parsed_env_config.endpoint -and (!$endpoint)) { $endpoint = $parsed_env_config.endpoint }
8585
if ($parsed_env_config.config) {
8686
if ($config) {
87+
# if config is not hashtable, then convert it to hashtable
88+
if ($config -isnot [hashtable]) {
89+
$config = ConvertTo-Hashtable $config
90+
}
91+
92+
# if parsed_env_config.config is not hashtable, then convert it to hashtable
93+
if ($parsed_env_config.config -isnot [hashtable]) {
94+
$parsed_env_config.config = ConvertTo-Hashtable $parsed_env_config.config
95+
}
96+
8797
Merge-Hashtable -table1 $config -table2 $parsed_env_config.config
8898
}
8999
else {
@@ -100,6 +110,16 @@ function New-ChatCompletions {
100110
}
101111

102112
if ($headers) {
113+
# if headers is not hashtable, then convert it to hashtable
114+
if ($headers -isnot [hashtable]) {
115+
$headers = ConvertTo-Hashtable $headers
116+
}
117+
118+
# if parsed_env_config.headers is not hashtable, then convert it to hashtable
119+
if ($parsed_env_config.headers -isnot [hashtable]) {
120+
$parsed_env_config.headers = ConvertTo-Hashtable $parsed_env_config.headers
121+
}
122+
103123
Merge-Hashtable -table1 $headers -table2 $parsed_env_config.headers
104124
}
105125
else {
@@ -196,6 +216,11 @@ function New-ChatCompletions {
196216

197217
# if user provide the headers, merge the headers to the default headers
198218
if ($headers) {
219+
# if headers is not hashtable, then convert it to hashtable
220+
if ($headers -isnot [hashtable]) {
221+
$headers = ConvertTo-Hashtable $headers
222+
}
223+
199224
Merge-Hashtable -table1 $header -table2 $headers
200225
}
201226

@@ -271,6 +296,10 @@ function New-ChatCompletions {
271296
}
272297

273298
if ($config) {
299+
# if config is not hashtable, then convert it to hashtable
300+
if ($config -isnot [hashtable]) {
301+
$config = ConvertTo-Hashtable $config
302+
}
274303
Merge-Hashtable -table1 $body -table2 $config
275304
}
276305

code365scripts.openai/Public/New-ChatGPTConversation.ps1

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,16 @@ function New-ChatGPTConversation {
136136
if ($parsed_env_config.endpoint -and (!$endpoint)) { $endpoint = $parsed_env_config.endpoint }
137137
if ($parsed_env_config.config) {
138138
if ($config) {
139+
# if config is not hashtable, then convert it to hashtable
140+
if ($config -isnot [hashtable]) {
141+
$config = ConvertTo-Hashtable $config
142+
}
143+
144+
# if parsed_env_config.config is not hashtable, then convert it to hashtable
145+
if ($parsed_env_config.config -isnot [hashtable]) {
146+
$parsed_env_config.config = ConvertTo-Hashtable $parsed_env_config.config
147+
}
148+
139149
Merge-Hashtable -table1 $config -table2 $parsed_env_config.config
140150
}
141151
else {
@@ -152,6 +162,15 @@ function New-ChatGPTConversation {
152162
}
153163

154164
if ($headers) {
165+
# if headers is not hashtable, then convert it to hashtable
166+
if ($headers -isnot [hashtable]) {
167+
$headers = ConvertTo-Hashtable $headers
168+
}
169+
170+
# if parsed_env_config.headers is not hashtable, then convert it to hashtable
171+
if ($parsed_env_config.headers -isnot [hashtable]) {
172+
$parsed_env_config.headers = ConvertTo-Hashtable $parsed_env_config.headers
173+
}
155174
Merge-Hashtable -table1 $headers -table2 $parsed_env_config.headers
156175
}
157176
else {
@@ -266,6 +285,10 @@ function New-ChatGPTConversation {
266285

267286
# if user provide the headers, merge the headers to the default headers
268287
if ($headers) {
288+
# if the headers is not hashtable, then convert it to hashtable
289+
if ($headers -isnot [hashtable]) {
290+
$headers = ConvertTo-Hashtable $headers
291+
}
269292
Merge-Hashtable -table1 $header -table2 $headers
270293
}
271294

@@ -497,6 +520,10 @@ function New-ChatGPTConversation {
497520

498521

499522
if ($config) {
523+
#if the config is not hashtable, then convert it to hashtable
524+
if ($config -isnot [hashtable]) {
525+
$config = ConvertTo-Hashtable $config
526+
}
500527
Merge-Hashtable -table1 $body -table2 $config
501528
}
502529
$params.Body = ($body | ConvertTo-Json -Depth 10)

code365scripts.openai/Types/OpenAIClient.ps1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,10 @@ class Assistant:AssistantResource {
348348
}
349349

350350
if ($config) {
351+
#if config is not hashtable, then convert it to hashtable
352+
if ($config -isnot [hashtable]) {
353+
$config = ConvertTo-Hashtable $config
354+
}
351355
Merge-Hashtable -table1 $body -table2 $config
352356
}
353357

0 commit comments

Comments
 (0)