Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/revmischa/openai-stream-mini
OpenAI client with no dependencies that supports streaming responses
https://github.com/revmischa/openai-stream-mini
Last synced: 3 days ago
JSON representation
OpenAI client with no dependencies that supports streaming responses
- Host: GitHub
- URL: https://github.com/revmischa/openai-stream-mini
- Owner: revmischa
- License: mit
- Created: 2023-03-09T22:17:55.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2023-06-01T01:11:45.000Z (over 1 year ago)
- Last Synced: 2024-10-18T07:53:15.406Z (3 months ago)
- Language: TypeScript
- Size: 37.1 KB
- Stars: 4
- Watchers: 3
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# openai-stream-mini
OpenAI client with **no dependencies** (except Node 18 or browser) that supports streaming completion text.
## Usage
```ts
import { OnTextCallback, streamCompletion } from "openai-stream-mini";
import type { CreateCompletionRequest } from "openai";const apiKey = process.env.OPENAI_API_KEY;
const args: CreateCompletionRequest = {
prompt: "What is the greatest toilet in the world?",
model: "text-davinci-003",
max_tokens: 2500,
temperature: 0.9,
};
const handleText: OnTextCallback = async (text) => {
if (!text) return;
console.log(text);
};const text = await streamCompletion({ args, apiKey, onText: handleText });
```