-
Notifications
You must be signed in to change notification settings - Fork 1
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
0 parents
commit b55a979
Showing
16 changed files
with
1,855 additions
and
0 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,2 @@ | ||
node_modules | ||
.key.ts |
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,11 @@ | ||
module.exports = { | ||
singleQuote: true, | ||
jsxSingleQuote: true, | ||
semi: false, | ||
useTabs: false, | ||
tabWidth: 2, | ||
bracketSpacing: true, | ||
bracketSameLine: false, | ||
arrowParens: 'always', | ||
trailingComma: 'all', | ||
} |
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,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() |
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,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 | ||
} |
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,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 的画布应用,写出比较详细的代码', |
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,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" | ||
} | ||
} |
Oops, something went wrong.