Skip to content

Commit

Permalink
feat: MAJOR BREAKING CHANGE; moved from browser to official completio…
Browse files Browse the repository at this point in the history
…n API with unofficial chatgpt model
  • Loading branch information
transitive-bullshit committed Feb 1, 2023
1 parent babaab3 commit 21dd9d5
Show file tree
Hide file tree
Showing 52 changed files with 655 additions and 6,333 deletions.
5 changes: 2 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
# ------------------------------------------------------------------------------

# -----------------------------------------------------------------------------
# ChatGPT
# OpenAI
# -----------------------------------------------------------------------------

OPENAI_EMAIL=
OPENAI_PASSWORD=
OPENAI_API_KEY=
31 changes: 11 additions & 20 deletions demos/demo-conversation.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import dotenv from 'dotenv-safe'
import { oraPromise } from 'ora'

import { ChatGPTAPIBrowser } from '../src'
import { ChatGPTAPI } from '../src'

dotenv.config()

Expand All @@ -13,66 +13,57 @@ dotenv.config()
* ```
*/
async function main() {
const email = process.env.OPENAI_EMAIL
const password = process.env.OPENAI_PASSWORD

const api = new ChatGPTAPIBrowser({
email,
password,
debug: false,
minimize: true
const api = new ChatGPTAPI({
apiKey: process.env.OPENAI_API_KEY,
debug: false
})
await api.initSession()

const prompt = 'Write a poem about cats.'

let res = await oraPromise(api.sendMessage(prompt), {
text: prompt
})

console.log('\n' + res.response + '\n')
console.log('\n' + res.text + '\n')

const prompt2 = 'Can you make it cuter and shorter?'

res = await oraPromise(
api.sendMessage(prompt2, {
conversationId: res.conversationId,
parentMessageId: res.messageId
parentMessageId: res.id
}),
{
text: prompt2
}
)
console.log('\n' + res.response + '\n')
console.log('\n' + res.text + '\n')

const prompt3 = 'Now write it in French.'

res = await oraPromise(
api.sendMessage(prompt3, {
conversationId: res.conversationId,
parentMessageId: res.messageId
parentMessageId: res.id
}),
{
text: prompt3
}
)
console.log('\n' + res.response + '\n')
console.log('\n' + res.text + '\n')

const prompt4 = 'What were we talking about again?'

res = await oraPromise(
api.sendMessage(prompt4, {
conversationId: res.conversationId,
parentMessageId: res.messageId
parentMessageId: res.id
}),
{
text: prompt4
}
)
console.log('\n' + res.response + '\n')

// close the browser at the end
await api.closeSession()
console.log('\n' + res.text + '\n')
}

main().catch((err) => {
Expand Down
43 changes: 0 additions & 43 deletions demos/demo-google-auth.ts

This file was deleted.

21 changes: 4 additions & 17 deletions demos/demo-on-progress.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import dotenv from 'dotenv-safe'

import { ChatGPTAPIBrowser } from '../src'
import { ChatGPTAPI } from '../src'

dotenv.config()

Expand All @@ -12,31 +12,18 @@ dotenv.config()
* ```
*/
async function main() {
const email = process.env.OPENAI_EMAIL
const password = process.env.OPENAI_PASSWORD

const api = new ChatGPTAPIBrowser({
email,
password,
debug: false,
minimize: true
})
await api.initSession()
const api = new ChatGPTAPI({ apiKey: process.env.OPENAI_API_KEY })

const prompt =
'Write a python version of bubble sort. Do not include example usage.'

console.log(prompt)
const res = await api.sendMessage(prompt, {
onProgress: (partialResponse) => {
console.log('p')
console.log('progress', partialResponse?.response)
console.log(partialResponse.text)
}
})
console.log(res.response)

// close the browser at the end
await api.closeSession()
console.log(res.text)
}

main().catch((err) => {
Expand Down
18 changes: 3 additions & 15 deletions demos/demo.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import dotenv from 'dotenv-safe'
import { oraPromise } from 'ora'

import { ChatGPTAPIBrowser } from '../src'
import { ChatGPTAPI } from '../src'

dotenv.config()

Expand All @@ -13,27 +13,15 @@ dotenv.config()
* ```
*/
async function main() {
const email = process.env.OPENAI_EMAIL
const password = process.env.OPENAI_PASSWORD

const api = new ChatGPTAPIBrowser({
email,
password,
debug: false,
minimize: true
})
await api.initSession()
const api = new ChatGPTAPI({ apiKey: process.env.OPENAI_API_KEY })

const prompt =
'Write a python version of bubble sort. Do not include example usage.'

const res = await oraPromise(api.sendMessage(prompt), {
text: prompt
})
console.log(res.response)

// close the browser at the end
await api.closeSession()
console.log(res)
}

main().catch((err) => {
Expand Down
22 changes: 5 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
}
},
"files": [
"build",
"third-party"
"build"
],
"engines": {
"node": ">=18"
Expand All @@ -36,18 +35,10 @@
"test:prettier": "prettier '**/*.{js,jsx,ts,tsx}' --check"
},
"dependencies": {
"delay": "^5.0.0",
"eventsource-parser": "^0.0.5",
"expiry-map": "^2.0.0",
"html-to-md": "^0.8.3",
"gpt-3-encoder": "^1.1.4",
"p-timeout": "^6.0.0",
"puppeteer-extra": "^3.3.4",
"puppeteer-extra-plugin-recaptcha": "npm:@fisch0920/puppeteer-extra-plugin-recaptcha@^3.6.6",
"puppeteer-extra-plugin-stealth": "^2.11.1",
"random": "^4.1.0",
"remark": "^14.0.2",
"strip-markdown": "^5.0.0",
"tempy": "^3.0.0",
"quick-lru": "^6.1.1",
"uuid": "^9.0.0"
},
"devDependencies": {
Expand All @@ -62,16 +53,12 @@
"npm-run-all": "^4.1.5",
"ora": "^6.1.2",
"prettier": "^2.8.0",
"puppeteer": "^19.4.0",
"tsup": "^6.5.0",
"tsx": "^3.12.1",
"typedoc": "^0.23.21",
"typedoc-plugin-markdown": "^3.13.6",
"typescript": "^4.9.3"
},
"peerDependencies": {
"puppeteer": "*"
},
"lint-staged": {
"*.{ts,tsx}": [
"prettier --write"
Expand All @@ -88,11 +75,12 @@
"keywords": [
"openai",
"chatgpt",
"chat",
"gpt",
"gpt-3",
"gpt3",
"gpt4",
"chatbot",
"chat",
"machine learning",
"conversation",
"conversational ai",
Expand Down
Loading

0 comments on commit 21dd9d5

Please sign in to comment.