forked from openai/openai-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
liuchuanhe
committed
Nov 15, 2023
1 parent
09127e8
commit 1b2774d
Showing
17 changed files
with
1,605 additions
and
54 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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/usr/bin/env -S npm run tsn -T | ||
|
||
import OpenAI from '../src'; | ||
import { ChatCompletionStream } from '../src/lib/BaseChatCompletionStream'; | ||
const openai = new OpenAI({ | ||
apiKey: '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', // defaults to process.env["OPENAI_API_KEY"] | ||
baseURL: 'http://llm-engine-test.cf8025269a251437fa494ea5f9c8a924c.cn-beijing.alicontainer.com', | ||
}); | ||
|
||
async function main() { | ||
const stream2 = await openai.baseChat.completions | ||
.createBase({ | ||
model_name: 'Baichuan2', | ||
prompt: { | ||
data: '写一篇100字的小说', | ||
from: 0, | ||
created_at: 12312344, | ||
}, | ||
stream: true, | ||
history: [], | ||
}) | ||
.asResponse(); | ||
const { body } = stream2; | ||
const runner = ChatCompletionStream.fromReadableStream(body as any); | ||
runner.on('content', (delta, snapshot) => { | ||
console.log(snapshot, 'yyyy'); | ||
console.log(delta, '*****'); | ||
}); | ||
} | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,27 @@ | ||
#!/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(); | ||
import OpenAI from '../src'; | ||
import { ChatCompletionStream } from '../src/lib/ChatCompletionStream'; | ||
|
||
const openai = new OpenAI({ | ||
apiKey: '96d6c41139d2efc5c25d7c0b93ad69a3', // defaults to process.env["OPENAI_API_KEY"] | ||
baseURL: 'https://api.baichuan-ai.com/v1', | ||
}); | ||
async function main() { | ||
// Non-streaming: | ||
const completion = await openai.chat.completions.create({ | ||
model: 'gpt-4', | ||
messages: [{ role: 'user', content: 'Say this is a test' }], | ||
}); | ||
console.log(completion.choices[0]?.message?.content); | ||
|
||
// Streaming: | ||
const stream = await openai.chat.completions.create({ | ||
model: 'gpt-4', | ||
messages: [{ role: 'user', content: 'Say this is a test' }], | ||
const stream = openai.beta.chat.completions.stream({ | ||
model: 'Baichuan2', | ||
stream: true, | ||
messages: [{ role: 'user', content: '写一篇200字的小学生作文' }], | ||
}); | ||
for await (const part of stream) { | ||
process.stdout.write(part.choices[0]?.delta?.content || ''); | ||
console.log(part.choices[0]?.delta?.content, '****'); | ||
} | ||
process.stdout.write('\n'); | ||
} | ||
|
||
main(); | ||
|
||
// const runner = ChatCompletionStream.fromReadableStream(stream.toReadableStream()); | ||
|
||
// runner.on('content', (delta, snapshot) => { | ||
// console.log(delta, 'testtest'); | ||
// }); |
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 |
---|---|---|
@@ -1,12 +1,12 @@ | ||
{ | ||
"name": "openai", | ||
"version": "4.18.0", | ||
"name": "openailchgpt", | ||
"version": "1.0.0", | ||
"description": "Client library for the OpenAI API", | ||
"author": "OpenAI <[email protected]>", | ||
"author": "", | ||
"types": "dist/index.d.ts", | ||
"main": "dist/index.js", | ||
"type": "commonjs", | ||
"repository": "github:openai/openai-node", | ||
"repository": "github:lch000/openai-node", | ||
"license": "Apache-2.0", | ||
"private": false, | ||
"sideEffects": [ | ||
|
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.