@genkit-ai/express 1.19.2 → 1.19.3

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.
@@ -0,0 +1,110 @@
1
+ Genkit's Express integration makes it easy to expose Genkit flows as Express API endpoints:
2
+
3
+ ```ts
4
+ import express from 'express';
5
+ import { expressHandler } from '@genkit-ai/express';
6
+ import { simpleFlow } from './flows/simple-flow.js';
7
+
8
+ const app = express();
9
+ app.use(express.json());
10
+
11
+ app.post('/simpleFlow', expressHandler(simpleFlow));
12
+
13
+ app.listen(8080);
14
+ ```
15
+
16
+ You can also handle auth using context providers:
17
+
18
+ ```ts
19
+ import { UserFacingError } from 'genkit';
20
+ import { ContextProvider, RequestData } from 'genkit/context';
21
+
22
+ const context: ContextProvider<Context> = (req: RequestData) => {
23
+ if (req.headers['authorization'] !== 'open sesame') {
24
+ throw new UserFacingError('PERMISSION_DENIED', 'not authorized');
25
+ }
26
+ return {
27
+ auth: {
28
+ user: 'Ali Baba',
29
+ },
30
+ };
31
+ };
32
+
33
+ app.post(
34
+ '/simpleFlow',
35
+ authMiddleware,
36
+ expressHandler(simpleFlow, { context })
37
+ );
38
+ ```
39
+
40
+ Flows and actions exposed using the `expressHandler` function can be accessed using `genkit/beta/client` library:
41
+
42
+ ```ts
43
+ import { runFlow, streamFlow } from 'genkit/beta/client';
44
+
45
+ const result = await runFlow({
46
+ url: `http://localhost:${port}/simpleFlow`,
47
+ input: 'say hello',
48
+ });
49
+
50
+ console.log(result); // hello
51
+ ```
52
+
53
+ ```ts
54
+ // set auth headers (when using auth policies)
55
+ const result = await runFlow({
56
+ url: `http://localhost:${port}/simpleFlow`,
57
+ headers: {
58
+ Authorization: 'open sesame',
59
+ },
60
+ input: 'say hello',
61
+ });
62
+
63
+ console.log(result); // hello
64
+ ```
65
+
66
+ ```ts
67
+ // and streamed
68
+ const result = streamFlow({
69
+ url: `http://localhost:${port}/simpleFlow`,
70
+ input: 'say hello',
71
+ });
72
+ for await (const chunk of result.stream) {
73
+ console.log(chunk);
74
+ }
75
+ console.log(await result.output);
76
+ ```
77
+
78
+ You can use `startFlowServer` to quickly expose multiple flows and actions:
79
+
80
+ ```ts
81
+ import { startFlowServer } from '@genkit-ai/express';
82
+ import { genkit } from 'genkit';
83
+
84
+ const ai = genkit({});
85
+
86
+ export const menuSuggestionFlow = ai.defineFlow(
87
+ {
88
+ name: 'menuSuggestionFlow',
89
+ },
90
+ async (restaurantTheme) => {
91
+ // ...
92
+ }
93
+ );
94
+
95
+ startFlowServer({
96
+ flows: [menuSuggestionFlow],
97
+ });
98
+ ```
99
+
100
+ You can also configure the server:
101
+
102
+ ```ts
103
+ startFlowServer({
104
+ flows: [menuSuggestionFlow],
105
+ port: 4567,
106
+ cors: {
107
+ origin: '*',
108
+ },
109
+ });
110
+ ```
package/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  This plugin provides utilities for conveninetly exposing Genkit flows and actions via Express HTTP server as REST APIs.
4
4
 
5
+ See [official documentation](https://genkit.dev/docs/frameworks/express/) for more.
6
+
5
7
  ## Installation
6
8
 
7
9
  To use this plugin, install it in your project:
@@ -129,7 +131,7 @@ startFlowServer({
129
131
 
130
132
  The sources for this package are in the main [Genkit](https://github.com/firebase/genkit) repo. Please file issues and pull requests against that repo.
131
133
 
132
- Usage information and reference details can be found in [Genkit documentation](https://genkit.dev/docs/get-started).
134
+ Usage information and reference details can be found in [official Genkit documentation](https://genkit.dev/docs/get-started/).
133
135
 
134
136
  ## License
135
137
 
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "genai",
10
10
  "generative-ai"
11
11
  ],
12
- "version": "1.19.2",
12
+ "version": "1.19.3",
13
13
  "type": "commonjs",
14
14
  "repository": {
15
15
  "type": "git",
@@ -24,7 +24,7 @@
24
24
  },
25
25
  "peerDependencies": {
26
26
  "express": "^4.21.1",
27
- "genkit": "^1.19.2"
27
+ "genkit": "^1.19.3"
28
28
  },
29
29
  "devDependencies": {
30
30
  "get-port": "^5.1.0",