Skip to content

Commit

Permalink
chore: updated samples for 0.9 (#1262)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelgj authored Nov 13, 2024
1 parent 0fecc43 commit 711b728
Show file tree
Hide file tree
Showing 36 changed files with 331 additions and 657 deletions.
3 changes: 2 additions & 1 deletion samples/chatbot/genkit-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"prismjs": "^1.29.0",
"rxjs": "~7.8.0",
"tslib": "^2.3.0",
"zone.js": "~0.14.3"
"zone.js": "~0.14.3",
"genkit": "^0.9.0-rc || ^0.9"
},
"devDependencies": {
"@angular-devkit/build-angular": "^18.0.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ import { MatIconModule } from '@angular/material/icon';
import { MatInputModule } from '@angular/material/input';
import { MatProgressBarModule } from '@angular/material/progress-bar';
import { MatRadioModule } from '@angular/material/radio';
import { streamFlow } from 'genkit/client';
import { MarkdownModule } from 'ngx-markdown';
import { streamFlow } from '../../../utils/flow';

const url = 'http://127.0.0.1:3400/chatbotFlow';

Expand Down Expand Up @@ -109,7 +109,7 @@ export class ChatbotComponent {
try {
const response = await streamFlow({
url,
payload: {
input: {
prompt: input,
conversationId: this.id,
llmIndex: this.llmIndex,
Expand Down
150 changes: 0 additions & 150 deletions samples/chatbot/genkit-app/src/utils/flow.ts

This file was deleted.

12 changes: 3 additions & 9 deletions samples/chatbot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@
"scripts": {
"start": "concurrently npm:start:server npm:start:ng",
"setup": "npm i && cd server && npm i && cd ../genkit-app && npm i",
"start:server": "cd server && genkit start",
"start:ng": "cd genkit-app && npm run start",
"build": "tsc",
"build:watch": "tsc --watch",
"test": "echo \"Error: no test specified\" && exit 1"
"start:server": "cd server && npm run genkit:dev",
"start:ng": "cd genkit-app && npm start"
},
"name": "js-angular",
"version": "1.0.0",
Expand All @@ -15,9 +12,6 @@
"author": "",
"license": "ISC",
"devDependencies": {
"genkit": "^0.5.8",
"@angular/cli": "^18.0.2",
"concurrently": "^8.2.2",
"typescript": "^5.4.5"
"concurrently": "^8.2.2"
}
}
15 changes: 8 additions & 7 deletions samples/chatbot/server/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"main": "lib/index.js",
"scripts": {
"start": "npx genkit start",
"start": "node lib/index.js",
"genkit:dev": "genkit start -- npm run dev",
"dev": "tsx --watch src/index.ts",
"build": "tsc",
"build:watch": "tsc --watch",
"test": "echo \"Error: no test specified\" && exit 1"
Expand All @@ -13,16 +15,15 @@
"author": "",
"license": "ISC",
"dependencies": {
"@genkit-ai/ai": "^0.6.0",
"@genkit-ai/core": "^0.6.0",
"@genkit-ai/dotprompt": "^0.6.0",
"@genkit-ai/vertexai": "^0.6.0",
"genkit": "^0.9.0-rc || ^0.9",
"@genkit-ai/vertexai": "^0.9.0-rc || ^0.9",
"express": "^4.21.0",
"partial-json": "^0.1.7",
"zod": "^3.23.8"
},
"devDependencies": {
"genkit": "^0.6.0",
"typescript": "^5.4.5"
"genkit-cli": "^0.9.0-rc || ^0.9",
"typescript": "^5.4.5",
"tsx": "^4.19.2"
}
}
47 changes: 24 additions & 23 deletions samples/chatbot/server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,14 @@
* limitations under the License.
*/

import { generate } from '@genkit-ai/ai';
import {
GenerateResponseChunkSchema,
ModelReference,
PartSchema,
} from '@genkit-ai/ai/model';
import { genkit, run } from '@genkit-ai/core';
import { gemini15Flash, vertexAI } from '@genkit-ai/vertexai';
import {
VertexAIEvaluationMetricType,
gemini15Flash,
llama3,
vertexAI,
} from '@genkit-ai/vertexai';
vertexAIEvaluation,
} from '@genkit-ai/vertexai/evaluation';
import { llama31, vertexAIModelGarden } from '@genkit-ai/vertexai/modelgarden';
import { ModelReference, PartSchema, genkit, run } from 'genkit';
import { GenerateResponseChunkSchema } from 'genkit/model';
import { z } from 'zod';
import { inMemoryStore } from './memory.js';

Expand All @@ -41,20 +36,22 @@ const ai = genkit({
plugins: [
vertexAI({
location: 'us-central1',
modelGardenModels: [llama3],
evaluation: {
metrics: [
VertexAIEvaluationMetricType.SAFETY,
VertexAIEvaluationMetricType.FLUENCY,
],
},
}),
vertexAIModelGarden({
location: 'us-central1',
models: [llama31],
}),
vertexAIEvaluation({
location: 'us-central1',
metrics: [
VertexAIEvaluationMetricType.SAFETY,
VertexAIEvaluationMetricType.FLUENCY,
],
}),
],
logLevel: 'debug',
enableTracingAndMetrics: true,
});

const llms: ModelReference<any>[] = [gemini15Flash, llama3];
const llms: ModelReference<any>[] = [gemini15Flash, llama31];

const historyStore = inMemoryStore();

Expand All @@ -76,9 +73,9 @@ export const chatbotFlow = ai.defineStreamingFlow(
);

// Run the user prompt (with history) through the primary LLM.
const mainResp = await generate({
const mainResp = await ai.generate({
prompt: request.prompt,
history: history,
messages: history,
model: llms[request.llmIndex],
streamingCallback,
});
Expand All @@ -97,3 +94,7 @@ export const chatbotFlow = ai.defineStreamingFlow(
return mainResp.text;
}
);

ai.startFlowServer({
flows: [chatbotFlow],
});
2 changes: 1 addition & 1 deletion samples/chatbot/server/src/memory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { MessageData } from '@genkit-ai/ai/model';
import { MessageData } from 'genkit';

const chatHistory: Record<string, MessageData[]> = {};

Expand Down
3 changes: 2 additions & 1 deletion samples/js-angular/genkit-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"@angular/router": "^18.0.0",
"rxjs": "~7.8.0",
"tslib": "^2.3.0",
"zone.js": "~0.14.3"
"zone.js": "~0.14.3",
"genkit": "^0.9.0-rc || ^0.9"
},
"devDependencies": {
"@angular-devkit/build-angular": "^18.0.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import { MatFormFieldModule } from '@angular/material/form-field';
import { MatIconModule } from '@angular/material/icon';
import { MatInputModule } from '@angular/material/input';
import { MatProgressBarModule } from '@angular/material/progress-bar';
import { streamFlow } from '../../../utils/flow';
import { streamFlow } from 'genkit/client';

const url = 'http://127.0.0.1:3400/chatbotFlow';

Expand Down Expand Up @@ -102,7 +102,7 @@ export class ChatbotComponent {
try {
const response = await streamFlow({
url,
payload: {
input: {
prompt: input,
conversationId: this.id,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { CommonModule } from '@angular/common';
import { Component } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { MatButtonModule } from '@angular/material/button';
import { streamFlow } from '../../../utils/flow';
import { streamFlow } from 'genkit/client';

const url = 'http://127.0.0.1:3400/streamCharacters';

Expand All @@ -42,7 +42,7 @@ export class StreamingJSONComponent {
try {
const response = streamFlow({
url,
payload: parseInt(this.count),
input: parseInt(this.count),
});
for await (const chunk of response.stream()) {
this.characters = chunk;
Expand Down
Loading

0 comments on commit 711b728

Please sign in to comment.