kopia lustrzana https://github.com/transitive-bullshit/chatgpt-api
pull/3/head
rodzic
82a5232333
commit
eb1f3aa2b1
|
@ -36,7 +36,7 @@
|
||||||
|
|
||||||
#### Defined in
|
#### Defined in
|
||||||
|
|
||||||
chatgpt-api.ts:20
|
[chatgpt-api.ts:20](https://github.com/transitive-bullshit/chatgpt-api/blob/82a5232/src/chatgpt-api.ts#L20)
|
||||||
|
|
||||||
## Methods
|
## Methods
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ chatgpt-api.ts:20
|
||||||
|
|
||||||
#### Defined in
|
#### Defined in
|
||||||
|
|
||||||
chatgpt-api.ts:175
|
[chatgpt-api.ts:175](https://github.com/transitive-bullshit/chatgpt-api/blob/82a5232/src/chatgpt-api.ts#L175)
|
||||||
|
|
||||||
___
|
___
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ ___
|
||||||
|
|
||||||
#### Defined in
|
#### Defined in
|
||||||
|
|
||||||
chatgpt-api.ts:88
|
[chatgpt-api.ts:88](https://github.com/transitive-bullshit/chatgpt-api/blob/82a5232/src/chatgpt-api.ts#L88)
|
||||||
|
|
||||||
___
|
___
|
||||||
|
|
||||||
|
@ -78,7 +78,7 @@ ___
|
||||||
|
|
||||||
#### Defined in
|
#### Defined in
|
||||||
|
|
||||||
chatgpt-api.ts:93
|
[chatgpt-api.ts:93](https://github.com/transitive-bullshit/chatgpt-api/blob/82a5232/src/chatgpt-api.ts#L93)
|
||||||
|
|
||||||
___
|
___
|
||||||
|
|
||||||
|
@ -92,7 +92,7 @@ ___
|
||||||
|
|
||||||
#### Defined in
|
#### Defined in
|
||||||
|
|
||||||
chatgpt-api.ts:113
|
[chatgpt-api.ts:113](https://github.com/transitive-bullshit/chatgpt-api/blob/82a5232/src/chatgpt-api.ts#L113)
|
||||||
|
|
||||||
___
|
___
|
||||||
|
|
||||||
|
@ -106,7 +106,7 @@ ___
|
||||||
|
|
||||||
#### Defined in
|
#### Defined in
|
||||||
|
|
||||||
chatgpt-api.ts:103
|
[chatgpt-api.ts:103](https://github.com/transitive-bullshit/chatgpt-api/blob/82a5232/src/chatgpt-api.ts#L103)
|
||||||
|
|
||||||
___
|
___
|
||||||
|
|
||||||
|
@ -127,7 +127,7 @@ ___
|
||||||
|
|
||||||
#### Defined in
|
#### Defined in
|
||||||
|
|
||||||
chatgpt-api.ts:48
|
[chatgpt-api.ts:48](https://github.com/transitive-bullshit/chatgpt-api/blob/82a5232/src/chatgpt-api.ts#L48)
|
||||||
|
|
||||||
___
|
___
|
||||||
|
|
||||||
|
@ -147,4 +147,4 @@ ___
|
||||||
|
|
||||||
#### Defined in
|
#### Defined in
|
||||||
|
|
||||||
chatgpt-api.ts:151
|
[chatgpt-api.ts:151](https://github.com/transitive-bullshit/chatgpt-api/blob/82a5232/src/chatgpt-api.ts#L151)
|
||||||
|
|
|
@ -2,13 +2,14 @@ chatgpt / [Exports](modules.md)
|
||||||
|
|
||||||
# ChatGPT API <!-- omit in toc -->
|
# ChatGPT API <!-- omit in toc -->
|
||||||
|
|
||||||
> Node.js wrapper around [ChatGPT](https://openai.com/blog/chatgpt/). Uses headless Chrome as a temporary solution until the official API is released.
|
> Node.js TS wrapper around [ChatGPT](https://openai.com/blog/chatgpt/). Uses headless Chrome until the official API is released.
|
||||||
|
|
||||||
[](https://www.npmjs.com/package/chatgpt) [](https://github.com/transitive-bullshit/chatgpt-api/actions/workflows/test.yml) [](https://github.com/transitive-bullshit/chatgpt-api/blob/main/license) [](https://prettier.io)
|
[](https://www.npmjs.com/package/chatgpt) [](https://github.com/transitive-bullshit/chatgpt-api/actions/workflows/test.yml) [](https://github.com/transitive-bullshit/chatgpt-api/blob/main/license) [](https://prettier.io)
|
||||||
|
|
||||||
- [Intro](#intro)
|
- [Intro](#intro)
|
||||||
- [Auth](#auth)
|
- [Auth](#auth)
|
||||||
- [Usage](#usage)
|
- [Usage](#usage)
|
||||||
|
- [Example](#example)
|
||||||
- [Docs](#docs)
|
- [Docs](#docs)
|
||||||
- [Todo](#todo)
|
- [Todo](#todo)
|
||||||
- [Related](#related)
|
- [Related](#related)
|
||||||
|
@ -18,15 +19,19 @@ chatgpt / [Exports](modules.md)
|
||||||
|
|
||||||
This package is a Node.js TypeScript wrapper around [ChatGPT](https://openai.com/blog/chatgpt) by [OpenAI](https://openai.com).
|
This package is a Node.js TypeScript wrapper around [ChatGPT](https://openai.com/blog/chatgpt) by [OpenAI](https://openai.com).
|
||||||
|
|
||||||
|
You can use it to start experimenting with ChatGPT by integrating it into websites, chatbots, etc...
|
||||||
|
|
||||||
## Auth
|
## Auth
|
||||||
|
|
||||||
It uses headless Chromium via [Playwright](https://playwright.dev) under the hood, so **you still need to have access to ChatGPT**, but it makes it much easier to build experiments with until OpenAPI's official API for ChatGPT is released.
|
It uses headless Chromium via [Playwright](https://playwright.dev) under the hood, so **you still need to have access to ChatGPT**, but it makes it much easier to access programatically.
|
||||||
|
|
||||||
The first time you run `ChatGPTAPI`.init, Chromium will be opened in non-headless mode so you can log in manually. After the first time, Chromium is launched with a persistent context, so you shouldn't need to keep re-logging in.
|
Chromium is opened in non-headless mode by default, which is important because the first time you run `ChatGPTAPI`.init, you'll need to log in manually. Chromium is launched with a persistent context, so you shouldn't need to keep re-logging in after the first time.
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
|
import { ChatGPTAPI } from 'chatgpt'
|
||||||
|
|
||||||
async function example() {
|
async function example() {
|
||||||
const api = new ChatGPTAPI()
|
const api = new ChatGPTAPI()
|
||||||
|
|
||||||
|
@ -37,37 +42,11 @@ await api.init({ auth: 'blocking' })
|
||||||
const response = await api.sendMessage(
|
const response = await api.sendMessage(
|
||||||
'Write a python version of bubble sort. Do not include example usage.'
|
'Write a python version of bubble sort. Do not include example usage.'
|
||||||
)
|
)
|
||||||
|
console.log(response)
|
||||||
/* // response
|
}
|
||||||
Here is an implementation of bubble sort in Python:
|
|
||||||
|
|
||||||
\`\`\`python
|
|
||||||
def bubble_sort(lst):
|
|
||||||
# Set the initial flag to True to start the loop
|
|
||||||
swapped = True
|
|
||||||
|
|
||||||
# Keep looping until there are no more swaps
|
|
||||||
while swapped:
|
|
||||||
# Set the flag to False initially
|
|
||||||
swapped = False
|
|
||||||
|
|
||||||
# Loop through the list
|
|
||||||
for i in range(len(lst) - 1):
|
|
||||||
# If the current element is greater than the next element,
|
|
||||||
# swap them and set the flag to True
|
|
||||||
if lst[i] > lst[i + 1]:
|
|
||||||
lst[i], lst[i + 1] = lst[i + 1], lst[i]
|
|
||||||
swapped = True
|
|
||||||
|
|
||||||
# Return the sorted list
|
|
||||||
return lst
|
|
||||||
\`\`\`
|
|
||||||
*/
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Here's the same response rendered as markdown:
|
Which outputs a similar reponse to this (as a markdown string, including the _```python_ code block prefix):
|
||||||
|
|
||||||
Here is an implementation of bubble sort in Python:
|
|
||||||
|
|
||||||
```python
|
```python
|
||||||
def bubble_sort(lst):
|
def bubble_sort(lst):
|
||||||
|
@ -91,20 +70,33 @@ def bubble_sort(lst):
|
||||||
return lst
|
return lst
|
||||||
```
|
```
|
||||||
|
|
||||||
Note that the default functionality is to parse ChatGPT responses as markdown using [html-to-md](https://github.com/stonehank/html-to-md). I've found the markdown quality to be excellent in my testing, but if you'd rather output plaintext, just pass `{ markdown: false }` to the `ChatGPTAPI` constructor.
|
The default functionality is to parse ChatGPT responses as markdown using [html-to-md](https://github.com/stonehank/html-to-md). I've found the markdown parsing to work really well during my testing, but if you'd rather output plaintext, you can use:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const api = new ChatGPTAPI({ markdown: false })
|
||||||
|
```
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
A full example is included for testing purposes:
|
||||||
|
|
||||||
|
```
|
||||||
|
npx tsx src/example.ts
|
||||||
|
```
|
||||||
|
|
||||||
## Docs
|
## Docs
|
||||||
|
|
||||||
See the [auto-generated docs](./docs/modules.md).
|
See the [auto-generated docs](./docs/classes/ChatGPTAPI.md) for more info on methods parameters.
|
||||||
|
|
||||||
## Todo
|
## Todo
|
||||||
|
|
||||||
- [ ] Add message and conversation IDs
|
- [ ] Add message and conversation IDs
|
||||||
- [ ] Add support for streaming responses
|
- [ ] Add support for streaming responses
|
||||||
|
- [ ] Add basic unit tests
|
||||||
|
|
||||||
## Related
|
## Related
|
||||||
|
|
||||||
- Inspired by the [Go module](https://github.com/danielgross/whatsapp-gpt) by [Daniel Gross](https://github.com/danielgross)
|
- Inspired by this [Go module](https://github.com/danielgross/whatsapp-gpt) by [Daniel Gross](https://github.com/danielgross)
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue