|
17 | 17 | import { ModelMiddleware, modelRef } from '@genkit-ai/ai/model';
|
18 | 18 | import * as assert from 'assert';
|
19 | 19 | import { beforeEach, describe, it } from 'node:test';
|
| 20 | +import { stripUndefinedProps } from '../../core/src'; |
20 | 21 | import { GenkitBeta, genkit } from '../src/beta';
|
21 | 22 | import { PromptAction, z } from '../src/index';
|
22 | 23 | import {
|
@@ -61,7 +62,7 @@ const wrapResponse: ModelMiddleware = async (req, next) => {
|
61 | 62 | };
|
62 | 63 | };
|
63 | 64 |
|
64 |
| -describe('definePrompt - functional', () => { |
| 65 | +describe('definePrompt', () => { |
65 | 66 | let ai: GenkitBeta;
|
66 | 67 |
|
67 | 68 | beforeEach(() => {
|
@@ -172,7 +173,7 @@ describe('definePrompt - functional', () => {
|
172 | 173 | });
|
173 | 174 | });
|
174 | 175 |
|
175 |
| -describe('definePrompt - dotprompt', () => { |
| 176 | +describe.only('definePrompt', () => { |
176 | 177 | describe('default model', () => {
|
177 | 178 | let ai: GenkitBeta;
|
178 | 179 |
|
@@ -309,14 +310,15 @@ describe('definePrompt - dotprompt', () => {
|
309 | 310 | });
|
310 | 311 | });
|
311 | 312 |
|
312 |
| - describe('default model ref', () => { |
| 313 | + describe.only('default model ref', () => { |
313 | 314 | let ai: GenkitBeta;
|
314 | 315 |
|
315 | 316 | beforeEach(() => {
|
316 | 317 | ai = genkit({
|
317 | 318 | model: modelRef({
|
318 | 319 | name: 'echoModel',
|
319 | 320 | }),
|
| 321 | + promptDir: './tests/prompts', |
320 | 322 | });
|
321 | 323 | defineEchoModel(ai);
|
322 | 324 | });
|
@@ -400,6 +402,52 @@ describe('definePrompt - dotprompt', () => {
|
400 | 402 | assert.deepStrictEqual(foo, { bar: 'baz' });
|
401 | 403 | });
|
402 | 404 |
|
| 405 | + it('defaults to json format from a loaded prompt', async () => { |
| 406 | + defineStaticResponseModel(ai, { |
| 407 | + role: 'model', |
| 408 | + content: [ |
| 409 | + { |
| 410 | + text: '```json\n{bar: "baz"}\n```', |
| 411 | + }, |
| 412 | + ], |
| 413 | + }); |
| 414 | + const hi = ai.prompt('output'); |
| 415 | + |
| 416 | + const response = await hi({ name: 'Genkit' }); |
| 417 | + const foo = response.output; |
| 418 | + assert.deepStrictEqual(stripUndefinedProps(response.request), { |
| 419 | + config: {}, |
| 420 | + messages: [ |
| 421 | + { |
| 422 | + content: [ |
| 423 | + { |
| 424 | + text: 'Hi Genkit', |
| 425 | + }, |
| 426 | + ], |
| 427 | + role: 'user', |
| 428 | + }, |
| 429 | + ], |
| 430 | + output: { |
| 431 | + constrained: true, |
| 432 | + contentType: 'application/json', |
| 433 | + format: 'json', |
| 434 | + schema: { |
| 435 | + additionalProperties: false, |
| 436 | + properties: { |
| 437 | + bar: { |
| 438 | + type: 'string', |
| 439 | + }, |
| 440 | + }, |
| 441 | + required: ['bar'], |
| 442 | + type: 'object', |
| 443 | + }, |
| 444 | + }, |
| 445 | + tools: [], |
| 446 | + }); |
| 447 | + |
| 448 | + assert.deepStrictEqual(foo, { bar: 'baz' }); |
| 449 | + }); |
| 450 | + |
403 | 451 | it('streams dotprompt with default model', async () => {
|
404 | 452 | const hi = ai.definePrompt({
|
405 | 453 | name: 'hi',
|
|
0 commit comments