-
Notifications
You must be signed in to change notification settings - Fork 877
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): add token logprobs to chat completions (#576)
- Loading branch information
1 parent
465236d
commit f1852f6
Showing
12 changed files
with
184 additions
and
18 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,23 @@ | ||
#!/usr/bin/env -S npm run tsn -T | ||
|
||
import OpenAI from 'openai'; | ||
|
||
// gets API Key from environment variable OPENAI_API_KEY | ||
const openai = new OpenAI(); | ||
|
||
async function main() { | ||
const stream = await openai.beta.chat.completions | ||
.stream({ | ||
model: 'gpt-4', | ||
messages: [{ role: 'user', content: 'Say this is a test' }], | ||
stream: true, | ||
logprobs: true, | ||
}) | ||
.on('logprob', (logprob) => { | ||
console.log(logprob); | ||
}); | ||
|
||
console.dir(await stream.finalChatCompletion(), { depth: null }); | ||
} | ||
|
||
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
Oops, something went wrong.