Skip to content

Commit

Permalink
feat: init project
Browse files Browse the repository at this point in the history
  • Loading branch information
lxfriday committed Mar 4, 2023
0 parents commit b55a979
Show file tree
Hide file tree
Showing 16 changed files with 1,855 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
.key.ts
11 changes: 11 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
singleQuote: true,
jsxSingleQuote: true,
semi: false,
useTabs: false,
tabWidth: 2,
bracketSpacing: true,
bracketSameLine: false,
arrowParens: 'always',
trailingComma: 'all',
}
26 changes: 26 additions & 0 deletions demo/a.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const Keyv = require('keyv')
const Lru = require('lru-cache')

class ConversationStore {
constructor() {
const lru = new Lru({ max: 5000 })
this.store = new Keyv({ store: lru })
}
async get(id) {
return await this.store.get(id)
}
async set(msg) {
return await this.store.set(msg.id, msg)
}
}

async function run() {
const store = new ConversationStore()
await store.set({ id: 'a', v: '111' })
await store.set({ id: 'b', v: '222' })
await store.set({ id: 'c', v: '333' })
console.log(store)
console.log(await store.get('a'))
}

run()
44 changes: 44 additions & 0 deletions demo/cmd.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { stdin, stdout } from 'process'
import { createInterface } from 'readline'
import ChatGPT from '../src/Chatgpt'
import apiKey from './.key'

function getReadLine() {
const rl = createInterface({ input: stdin, output: stdout })
const iter = rl[Symbol.asyncIterator]()
return async () => (await iter.next()).value
}

void (async function () {
let prevRes: any
let line = ''
const readline = getReadLine()
console.log('---------------------提出你的问题------------------')
while ((line = await readline())) {
prevRes = await basicRunner(line, prevRes?.id)
console.log('---------------------答案------------------------')
console.log(prevRes.text)
console.log('---------------------提出你的问题------------------')
}
})()

const api = new ChatGPT({
apiKey,
debug: true,
requestConfig: {
timeout: 1000 * 60,
proxy: {
protocol: 'http',
host: '127.0.0.1',
port: 33210,
},
},
})

async function basicRunner(text: string, parentMessageId?: string) {
const res = await api.createChatCompletion({
text,
parentMessageId,
})
return res
}
31 changes: 31 additions & 0 deletions demo/run.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import ChatGPT from './../src/Chatgpt'
import apiKey from './.key'

const api = new ChatGPT({
apiKey,
debug: true,
requestConfig: {
timeout: 1000 * 60,
proxy: {
protocol: 'http',
host: '127.0.0.1',
port: 33210,
},
},
})

async function run() {
try {
const res = await api.createChatCompletion({
text: '说说成都有哪些好玩的地方',
systemPrompt: '假定你是一个旅游博主'
})
console.log(res.text)
} catch (e) {
console.log('err', e)
}
}

run()

// '用Vue3设计一个类似 ExcalDraw 的画布应用,写出比较详细的代码',
27 changes: 27 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "chatgpt-api-yunyuv",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"r": "npx tsx demo/run.ts"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@trivago/prettier-plugin-sort-imports": "^4.1.1",
"@types/node": "^18.14.2",
"@types/uuid": "^9.0.1",
"prettier": "^2.8.4",
"tsup": "^6.6.3",
"tsx": "^3.12.3",
"typescript": "^4.9.5"
},
"dependencies": {
"axios": "^1.3.4",
"keyv": "^4.5.2",
"lru-cache": "^7.18.1",
"uuid": "^9.0.0"
}
}
Loading

0 comments on commit b55a979

Please sign in to comment.