-
Notifications
You must be signed in to change notification settings - Fork 863
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(internal): add ecosystem test for qs reproduction
- Loading branch information
1 parent
1ec41a7
commit 0199dd8
Showing
6 changed files
with
2,168 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { OpenAI } from 'openai'; | ||
|
||
const openai = new OpenAI(); | ||
|
||
function assertEqual(actual: any, expected: any) { | ||
if (actual === expected) { | ||
return; | ||
} | ||
|
||
console.error('expected', expected); | ||
console.error('actual ', actual); | ||
throw new Error('expected values to be equal'); | ||
} | ||
|
||
async function main() { | ||
const completion = await openai.chat.completions.create({ | ||
model: 'gpt-4o-mini', | ||
messages: [ | ||
{ | ||
role: 'user', | ||
content: 'What is the capital of the United States?', | ||
}, | ||
], | ||
}); | ||
// smoke test for responses | ||
if (!completion.choices[0]?.message.content) { | ||
console.dir(completion, { depth: 4 }); | ||
throw new Error('no response content!'); | ||
} | ||
|
||
assertEqual( | ||
decodeURIComponent((openai as any).stringifyQuery({ foo: { nested: { a: true, b: 'foo' } } })), | ||
'foo[nested][a]=true&foo[nested][b]=foo', | ||
); | ||
assertEqual( | ||
decodeURIComponent((openai as any).stringifyQuery({ foo: { nested: { a: ['hello', 'world'] } } })), | ||
'foo[nested][a][]=hello&foo[nested][a][]=world', | ||
); | ||
} | ||
|
||
main(); |
Oops, something went wrong.