ai-functions 0.0.2 → 0.0.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
@@ -40,11 +40,10 @@ for await (const thing of list`fun things to do in Miami`) {
40
40
  Or in a more complex example:
41
41
 
42
42
  ```javascript
43
+ const listBlogPosts = (count, topic) => list`${count} blog post titles about ${topic}`
44
+ const writeBlogPost = title => gpt`write a blog post in markdown starting with "# ${title}"`
43
45
 
44
- const listBlogPosts => (count, topic) => list`${count} blog post titles about ${topic}`
45
- const writeBlogPost => title => gpt`write a blog post in markdown starting with "# ${title}"`
46
-
47
- const writeBlog = async (count, topic) => {
46
+ async function* writeBlog(count, topic) {
48
47
  for await (const title of listBlogPosts(count, topic)) {
49
48
  const content = await writeBlogPost(title)
50
49
  yield { title, content }
package/ai.js CHANGED
@@ -101,5 +101,5 @@ export const AI = opts => {
101
101
 
102
102
  }
103
103
 
104
- return { ai, list, gpt }
104
+ return { ai, list, gpt, openai }
105
105
  }
package/example.js CHANGED
@@ -10,3 +10,17 @@ for await (const item of list`synonyms for "fun"`) {
10
10
  for await (const item of list`fun things to do in Miami`) {
11
11
  console.log(item)
12
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 content = await writeBlogPost(title)
20
+ yield { title, content }
21
+ }
22
+ }
23
+
24
+ for await (const post of writeBlog(5, 'future of car sales')) {
25
+ console.log({ post })
26
+ }
package/index.js CHANGED
@@ -0,0 +1,3 @@
1
+ export * from './ai.js'
2
+ export * from './schema.js'
3
+ export * from './withAI.js'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-functions",
3
- "version": "0.0.2",
3
+ "version": "0.0.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",
package/withAI.js ADDED
@@ -0,0 +1,8 @@
1
+ import { AI } from './ai.js'
2
+
3
+ export const withAI = options => (req, env) => {
4
+ const { ai, gpt, list } = AI({ apiKey: env.OPENAI_API_KEY, ...options })
5
+ env.ai = ai
6
+ env.gpt = gpt
7
+ env.list = list
8
+ }