ai-functions 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -14,12 +14,14 @@ const { ai, gpt, list } = AI({ apiKey: OPENAI_API_KEY })
14
14
  Then you can use magic `ai` functions:
15
15
  ```javascript
16
16
 
17
- const product = await ai.categorizeProduct({ domain: name }, {
17
+ const categorizeProduct = ai.categorizeProduct({
18
18
  productType: 'App | API | Marketplace | Platform | Packaged Service | Professional Service | Website',
19
19
  customer: 'ideal customer profile in 3-5 words',
20
20
  solution: 'describe the offer in 4-10 words',
21
21
  description: 'website meta description',
22
22
  })
23
+
24
+ const product = await (categorizeProduct({ domain: name }))
23
25
  ```
24
26
 
25
27
  you can also use `list` tagged template as a convienence function:
package/example.js CHANGED
@@ -7,32 +7,32 @@ for await (const item of list`synonyms for "fun"`) {
7
7
  }
8
8
 
9
9
 
10
- // for await (const item of list`fun things to do in Miami`) {
11
- // console.log(item)
12
- // }
13
-
14
- // const listBlogPosts = (count, topic) => list`${count} blog post titles about ${topic}`
15
- // const writeBlogPost = title => gpt`write a blog post in markdown starting with "# ${title}"`
16
-
17
- // async function* writeBlog(count, topic) {
18
- // for await (const title of listBlogPosts(count, topic)) {
19
- // const contentPromise = writeBlogPost(title).then(content => {
20
- // console.log({ title, content })
21
- // return { title, content }
22
- // })
23
- // yield { title, contentPromise }
24
- // }
25
- // }
26
-
27
- // for await (const post of writeBlog(3, 'future of car sales')) {
28
- // console.log({ post })
29
- // }
30
-
31
- const product = await ai.categorizeProduct({ domain: 'OpenSaaS.org' }, {
10
+ for await (const item of list`fun things to do in Miami`) {
11
+ console.log(item)
12
+ }
13
+
14
+ const listBlogPosts = (count, topic) => list`${count} blog post titles about ${topic}`
15
+ const writeBlogPost = title => gpt`write a blog post in markdown starting with "# ${title}"`
16
+
17
+ async function* writeBlog(count, topic) {
18
+ for await (const title of listBlogPosts(count, topic)) {
19
+ const contentPromise = writeBlogPost(title).then(content => {
20
+ console.log({ title, content })
21
+ return { title, content }
22
+ })
23
+ yield { title, contentPromise }
24
+ }
25
+ }
26
+
27
+ for await (const post of writeBlog(3, 'future of car sales')) {
28
+ console.log({ post })
29
+ }
30
+
31
+ const product = await ai.categorizeProduct({
32
32
  productType: 'App | API | Marketplace | Platform | Packaged Service | Professional Service | Website',
33
- customer: 'ideal customer profile in 10-20 words',
34
- solution: 'describe the offer in 10-20 words',
33
+ customer: 'ideal customer profile in 3-5 words',
34
+ solution: 'describe the offer in 4-10 words',
35
35
  description: 'website meta description',
36
- })
36
+ })({ domain: 'OpenSaaS.org' })
37
37
 
38
38
  console.log({ product })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-functions",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "Library for Developing and Managing AI Functions (including OpenAI GPT4 / GPT3.5)",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -20,7 +20,13 @@
20
20
  },
21
21
  "homepage": "https://github.com/nathanclevenger/ai-functions#readme",
22
22
  "devDependencies": {
23
- "partial-json-parser": "^1.2.2",
24
23
  "vitest": "^0.33.0"
24
+ },
25
+ "dependencies": {
26
+ "camelcase-keys": "^9.1.0",
27
+ "js-yaml": "^4.1.0",
28
+ "openai": "^4.11.1",
29
+ "partial-json-parser": "^1.2.2",
30
+ "yaml": "^2.3.2"
25
31
  }
26
32
  }
package/proxy.js CHANGED
@@ -1,7 +1,6 @@
1
1
  // import { OpenAI } from 'openai'
2
2
  // import camelcaseKeys from 'camelcase-keys'
3
- // import { dump } from 'js-yaml'
4
- // import { stringify } from 'yaml'
3
+ import { dump } from 'js-yaml'
5
4
  import { schema } from './schema.js'
6
5
 
7
6
  export const AI = opts => {
@@ -29,13 +28,13 @@ export const AI = opts => {
29
28
 
30
29
  const ai = new Proxy({}, {
31
30
  get: (target, functionName, receiver) => {
32
- return async (args, returnSchema, options) => {
31
+ return (returnSchema, options) => async args => {
33
32
  console.log(schema(returnSchema))
34
33
  const { system, description, model = 'gpt-3.5-turbo', meta = false, ...rest } = options || {}
35
34
  const prompt = {
36
35
  model,
37
36
  messages: [
38
- { role: 'user', content: `Call ${functionName} given the context:\n${JSON.stringify(args).replaceAll('"','')}` }, // \nThere is no additional information, so make assumptions/guesses as necessary` },
37
+ { role: 'user', content: `Call ${functionName} given the context:\n${dump(args)}` }, // \nThere is no additional information, so make assumptions/guesses as necessary` },
39
38
  ],
40
39
  functions: [{
41
40
  name: functionName,
@@ -44,7 +43,6 @@ export const AI = opts => {
44
43
  }],
45
44
  ...rest,
46
45
  }
47
- // console.log(prompt.messages)
48
46
  if (system) prompt.messages.unshift({ role: 'system', content: system })
49
47
  const completion = await openaiFetch(prompt)
50
48
  let data, error