-
Notifications
You must be signed in to change notification settings - Fork 910
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(tests): add query string tests to ecosystem tests
- Loading branch information
1 parent
f870682
commit 36be724
Showing
13 changed files
with
142 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,35 @@ | ||
const openaiKey = "a valid OpenAI key" | ||
const OpenAI = require('openai'); | ||
|
||
console.log(OpenAI) | ||
const openai = new OpenAI(); | ||
|
||
const openai = new OpenAI({ | ||
apiKey: openaiKey, | ||
}); | ||
function assertEqual(actual, expected) { | ||
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-4', | ||
messages: [{ role: 'user', content: 'Say this is a test' }], | ||
}); | ||
if (!completion.choices[0].message.content) { | ||
console.dir(completion, { depth: 4 }); | ||
throw new Error('no response content!'); | ||
} | ||
|
||
assertEqual( | ||
decodeURIComponent(openai.stringifyQuery({ foo: { nested: { a: true, b: 'foo' } } })), | ||
'foo[nested][a]=true&foo[nested][b]=foo', | ||
); | ||
assertEqual( | ||
decodeURIComponent(openai.stringifyQuery({ foo: { nested: { a: ['hello', 'world'] } } })), | ||
'foo[nested][a][]=hello&foo[nested][a][]=world', | ||
); | ||
} | ||
|
||
main(); |
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
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
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
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
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
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