kopia lustrzana https://github.com/transitive-bullshit/chatgpt-api
feat: exploring potential declarative api designs
rodzic
2974d1415c
commit
b8ba8df1cf
10
.eslintrc
10
.eslintrc
|
@ -8,7 +8,7 @@
|
||||||
},
|
},
|
||||||
"parserOptions": {
|
"parserOptions": {
|
||||||
"ecmaFeatures": {
|
"ecmaFeatures": {
|
||||||
"jsx": false
|
"jsx": true
|
||||||
},
|
},
|
||||||
"ecmaVersion": "latest",
|
"ecmaVersion": "latest",
|
||||||
"sourceType": "module",
|
"sourceType": "module",
|
||||||
|
@ -24,6 +24,14 @@
|
||||||
"@typescript-eslint/no-non-null-assertion": "off",
|
"@typescript-eslint/no-non-null-assertion": "off",
|
||||||
"@typescript-eslint/no-explicit-any": "off"
|
"@typescript-eslint/no-explicit-any": "off"
|
||||||
},
|
},
|
||||||
|
"overrides": [
|
||||||
|
{
|
||||||
|
"files": ["*.tsx"],
|
||||||
|
"rules": {
|
||||||
|
"no-undef": "off"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
"settings": {},
|
"settings": {},
|
||||||
"globals": {
|
"globals": {
|
||||||
"__DEV__": true
|
"__DEV__": true
|
||||||
|
|
|
@ -0,0 +1,53 @@
|
||||||
|
/* eslint-disable */
|
||||||
|
import { z } from 'zod'
|
||||||
|
|
||||||
|
// framework mocks
|
||||||
|
function htm(...params: any[]) {
|
||||||
|
return (...p: any[]) => ``
|
||||||
|
}
|
||||||
|
htm.System = function System() {}
|
||||||
|
htm.User = function User() {}
|
||||||
|
htm.Assistant = function Assistant() {}
|
||||||
|
htm.Example = function Example() {}
|
||||||
|
const $: any = {}
|
||||||
|
|
||||||
|
async function ExampleLLMQuery({ texts }: { texts: string[] }) {
|
||||||
|
const examples = [
|
||||||
|
{ input: 'The food was digusting', output: 'negative' },
|
||||||
|
{ input: 'We had a fantastic night', output: 'positive' },
|
||||||
|
{ input: 'Recommended', output: 'positive' },
|
||||||
|
{ input: 'The waiter was rude', output: 'negative' }
|
||||||
|
]
|
||||||
|
|
||||||
|
// TODO: this doesn't handle type inference
|
||||||
|
const prompt = htm`
|
||||||
|
<System>You are an expert sentiment-labelling assistant</System>
|
||||||
|
|
||||||
|
<User>
|
||||||
|
Label the following texts as positive or negative:
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
${texts.map((text) => htm`<li>${text}</li>`)}
|
||||||
|
</ul>
|
||||||
|
</User>
|
||||||
|
|
||||||
|
<System>
|
||||||
|
${examples.map((example) => htm`<${htm.Example} ...${example} />`)}
|
||||||
|
</System>
|
||||||
|
|
||||||
|
<Output schema=${z.array(
|
||||||
|
z.object({ text: z.string(), label: z.string() })
|
||||||
|
)} />
|
||||||
|
`
|
||||||
|
|
||||||
|
return $.gpt4(prompt)
|
||||||
|
}
|
||||||
|
|
||||||
|
ExampleLLMQuery({
|
||||||
|
texts: [
|
||||||
|
'I went to this place and it was just so awful.',
|
||||||
|
'I had a great time.',
|
||||||
|
'I had a terrible time.',
|
||||||
|
'Food poisoning...'
|
||||||
|
]
|
||||||
|
})
|
|
@ -0,0 +1,59 @@
|
||||||
|
/* eslint-disable */
|
||||||
|
import React from 'react'
|
||||||
|
import { z } from 'zod'
|
||||||
|
|
||||||
|
// framework mocks
|
||||||
|
function LLMCall() {}
|
||||||
|
function System() {}
|
||||||
|
function User() {}
|
||||||
|
function Assistant() {}
|
||||||
|
function Example() {}
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
// - [ ] handle reactive state?
|
||||||
|
// - [ ] handle side effects?
|
||||||
|
// - [ ] handle async?
|
||||||
|
|
||||||
|
async function ExampleLLMQuery({ texts }: { texts: string[] }) {
|
||||||
|
const examples = [
|
||||||
|
{ input: 'The food was digusting', output: 'negative' },
|
||||||
|
{ input: 'We had a fantastic night', output: 'positive' },
|
||||||
|
{ input: 'Recommended', output: 'positive' },
|
||||||
|
{ input: 'The waiter was rude', output: 'negative' }
|
||||||
|
]
|
||||||
|
|
||||||
|
return (
|
||||||
|
<LLMCall
|
||||||
|
model='gpt-4'
|
||||||
|
temperature={0.1}
|
||||||
|
output={z.array(z.object({ text: z.string(), label: z.string() }))}
|
||||||
|
>
|
||||||
|
<System>You are an expert sentiment-labelling assistant</System>
|
||||||
|
|
||||||
|
<User>
|
||||||
|
Label the following texts as positive or negative:
|
||||||
|
{/* {texts.map((text) => `- ${text}\n`)} */}
|
||||||
|
<ul>
|
||||||
|
{texts.map((text, index) => (
|
||||||
|
<li key={index}>{text}</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
</User>
|
||||||
|
|
||||||
|
<System>
|
||||||
|
{examples.map((example) => (
|
||||||
|
<Example {...example} />
|
||||||
|
))}
|
||||||
|
</System>
|
||||||
|
</LLMCall>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
ExampleLLMQuery({
|
||||||
|
texts: [
|
||||||
|
'I went to this place and it was just so awful.',
|
||||||
|
'I had a great time.',
|
||||||
|
'I had a terrible time.',
|
||||||
|
'Food poisoning...'
|
||||||
|
]
|
||||||
|
})
|
|
@ -73,6 +73,7 @@
|
||||||
"npm-run-all": "^4.1.5",
|
"npm-run-all": "^4.1.5",
|
||||||
"p-memoize": "^7.1.1",
|
"p-memoize": "^7.1.1",
|
||||||
"prettier": "^2.8.8",
|
"prettier": "^2.8.8",
|
||||||
|
"react": "^18.2.0",
|
||||||
"serpapi": "^1.1.1",
|
"serpapi": "^1.1.1",
|
||||||
"sinon": "^15.1.0",
|
"sinon": "^15.1.0",
|
||||||
"tsup": "^6.7.0",
|
"tsup": "^6.7.0",
|
||||||
|
|
|
@ -106,6 +106,9 @@ devDependencies:
|
||||||
prettier:
|
prettier:
|
||||||
specifier: ^2.8.8
|
specifier: ^2.8.8
|
||||||
version: 2.8.8
|
version: 2.8.8
|
||||||
|
react:
|
||||||
|
specifier: ^18.2.0
|
||||||
|
version: 18.2.0
|
||||||
serpapi:
|
serpapi:
|
||||||
specifier: ^1.1.1
|
specifier: ^1.1.1
|
||||||
version: 1.1.1
|
version: 1.1.1
|
||||||
|
@ -2540,6 +2543,13 @@ packages:
|
||||||
wrap-ansi: 6.2.0
|
wrap-ansi: 6.2.0
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
|
/loose-envify@1.4.0:
|
||||||
|
resolution: {integrity: sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==}
|
||||||
|
hasBin: true
|
||||||
|
dependencies:
|
||||||
|
js-tokens: 4.0.0
|
||||||
|
dev: true
|
||||||
|
|
||||||
/lru-cache@6.0.0:
|
/lru-cache@6.0.0:
|
||||||
resolution: {integrity: sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==}
|
resolution: {integrity: sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==}
|
||||||
engines: {node: '>=10'}
|
engines: {node: '>=10'}
|
||||||
|
@ -3098,6 +3108,13 @@ packages:
|
||||||
engines: {node: '>=12'}
|
engines: {node: '>=12'}
|
||||||
dev: false
|
dev: false
|
||||||
|
|
||||||
|
/react@18.2.0:
|
||||||
|
resolution: {integrity: sha512-/3IjMdb2L9QbBdWiW5e3P2/npwMBaU9mHCSCUzNln0ZCYbcfTsGbTJrU/kGemdH2IWmB2ioZ+zkxtmq6g09fGQ==}
|
||||||
|
engines: {node: '>=0.10.0'}
|
||||||
|
dependencies:
|
||||||
|
loose-envify: 1.4.0
|
||||||
|
dev: true
|
||||||
|
|
||||||
/read-pkg-up@8.0.0:
|
/read-pkg-up@8.0.0:
|
||||||
resolution: {integrity: sha512-snVCqPczksT0HS2EC+SxUndvSzn6LRCwpfSvLrIfR5BKDQQZMaI6jPRC9dYvYFDRAuFEAnkwww8kBBNE/3VvzQ==}
|
resolution: {integrity: sha512-snVCqPczksT0HS2EC+SxUndvSzn6LRCwpfSvLrIfR5BKDQQZMaI6jPRC9dYvYFDRAuFEAnkwww8kBBNE/3VvzQ==}
|
||||||
engines: {node: '>=12'}
|
engines: {node: '>=12'}
|
||||||
|
|
|
@ -12,10 +12,11 @@
|
||||||
"moduleResolution": "node",
|
"moduleResolution": "node",
|
||||||
"resolveJsonModule": true,
|
"resolveJsonModule": true,
|
||||||
"isolatedModules": true,
|
"isolatedModules": true,
|
||||||
|
"jsx": "preserve",
|
||||||
"baseUrl": ".",
|
"baseUrl": ".",
|
||||||
"outDir": "build",
|
"outDir": "build",
|
||||||
"noEmit": true
|
"noEmit": true
|
||||||
},
|
},
|
||||||
"exclude": ["node_modules", "build"],
|
"exclude": ["node_modules", "build"],
|
||||||
"include": ["**/*.ts"]
|
"include": ["**/*.ts", "**/*.tsx"]
|
||||||
}
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue