@genkit-ai/express 1.15.1 → 1.15.2
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 +49 -1
- package/package.json +2 -3
- package/tests/express_test.ts +1 -2
package/README.md
CHANGED
|
@@ -2,6 +2,16 @@
|
|
|
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
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
To use this plugin, install it in your project:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm i @genkit-ai/express
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
5
15
|
```ts
|
|
6
16
|
import { expressHandler } from '@genkit-ai/express';
|
|
7
17
|
import express from 'express';
|
|
@@ -81,8 +91,46 @@ for await (const chunk of result.stream) {
|
|
|
81
91
|
console.log(await result.output);
|
|
82
92
|
```
|
|
83
93
|
|
|
94
|
+
You can also use `startFlowServer` to quickly expose multiple flows and actions:
|
|
95
|
+
|
|
96
|
+
```ts
|
|
97
|
+
import { startFlowServer } from '@genkit-ai/express';
|
|
98
|
+
import { genkit } from 'genkit';
|
|
99
|
+
|
|
100
|
+
const ai = genkit({});
|
|
101
|
+
|
|
102
|
+
export const menuSuggestionFlow = ai.defineFlow(
|
|
103
|
+
{
|
|
104
|
+
name: 'menuSuggestionFlow',
|
|
105
|
+
},
|
|
106
|
+
async (restaurantTheme) => {
|
|
107
|
+
// ...
|
|
108
|
+
}
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
startFlowServer({
|
|
112
|
+
flows: [menuSuggestionFlow],
|
|
113
|
+
});
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
You can also configure the server:
|
|
117
|
+
|
|
118
|
+
```ts
|
|
119
|
+
startFlowServer({
|
|
120
|
+
flows: [menuSuggestionFlow],
|
|
121
|
+
port: 4567,
|
|
122
|
+
cors: {
|
|
123
|
+
origin: '*',
|
|
124
|
+
},
|
|
125
|
+
});
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## Contributing
|
|
129
|
+
|
|
84
130
|
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.
|
|
85
131
|
|
|
86
132
|
Usage information and reference details can be found in [Genkit documentation](https://genkit.dev/docs/get-started).
|
|
87
133
|
|
|
88
|
-
License
|
|
134
|
+
## License
|
|
135
|
+
|
|
136
|
+
Licensed under the Apache 2.0 License.
|
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"genai",
|
|
10
10
|
"generative-ai"
|
|
11
11
|
],
|
|
12
|
-
"version": "1.15.
|
|
12
|
+
"version": "1.15.2",
|
|
13
13
|
"type": "commonjs",
|
|
14
14
|
"repository": {
|
|
15
15
|
"type": "git",
|
|
@@ -24,8 +24,7 @@
|
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
26
|
"express": "^4.21.1",
|
|
27
|
-
"
|
|
28
|
-
"genkit": "^1.15.1"
|
|
27
|
+
"genkit": "^1.15.2"
|
|
29
28
|
},
|
|
30
29
|
"devDependencies": {
|
|
31
30
|
"get-port": "^5.1.0",
|
package/tests/express_test.ts
CHANGED
|
@@ -14,7 +14,6 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
import type { RequestData } from '@genkit-ai/core';
|
|
18
17
|
import * as assert from 'assert';
|
|
19
18
|
import express from 'express';
|
|
20
19
|
import {
|
|
@@ -25,7 +24,7 @@ import {
|
|
|
25
24
|
type Genkit,
|
|
26
25
|
} from 'genkit';
|
|
27
26
|
import { runFlow, streamFlow } from 'genkit/beta/client';
|
|
28
|
-
import type { ContextProvider } from 'genkit/context';
|
|
27
|
+
import type { ContextProvider, RequestData } from 'genkit/context';
|
|
29
28
|
import type { GenerateResponseChunkData, ModelAction } from 'genkit/model';
|
|
30
29
|
import getPort from 'get-port';
|
|
31
30
|
import type * as http from 'http';
|