-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: make systemPrompt sync and optional (#29)
- Loading branch information
1 parent
c9731e5
commit 287c02b
Showing
12 changed files
with
128 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@callstack/byorg-core': minor | ||
--- | ||
|
||
core: make systemPrompt both optional and sync-only |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { expect, test } from 'vitest'; | ||
import { createMockVercelModel } from '../../mock/vercel-mock-model.js'; | ||
import { createApp } from '../../application.js'; | ||
import { Message } from '../../domain.js'; | ||
import { VercelChatModelAdapter } from '../vercel.js'; | ||
|
||
const messages: Message[] = [{ role: 'user', content: 'Hello' }]; | ||
|
||
test('sends system messages when system prompt is provided', async () => { | ||
const { languageModel, calls } = createMockVercelModel({ text: 'Hello, world!' }); | ||
const app = createApp({ | ||
chatModel: new VercelChatModelAdapter({ languageModel }), | ||
systemPrompt: 'This is system prompt', | ||
}); | ||
|
||
await app.processMessages(messages); | ||
expect(calls.length).toBe(1); | ||
expect(calls[0].prompt).toContainEqual({ | ||
role: 'system', | ||
content: 'This is system prompt', | ||
}); | ||
}); | ||
|
||
test('does not send system message when system prompt is not provided', async () => { | ||
const { languageModel, calls } = createMockVercelModel({ text: 'Hello, world!' }); | ||
const app = createApp({ | ||
chatModel: new VercelChatModelAdapter({ languageModel }), | ||
}); | ||
|
||
await app.processMessages(messages); | ||
expect(calls.length).toBe(1); | ||
expect(calls[0].prompt).not.toContainEqual({ | ||
role: 'system', | ||
}); | ||
}); | ||
|
||
test('does not send system message when system prompt returns null', async () => { | ||
const { languageModel, calls } = createMockVercelModel({ text: 'Hello, world!' }); | ||
const app = createApp({ | ||
chatModel: new VercelChatModelAdapter({ languageModel }), | ||
systemPrompt: () => null, | ||
}); | ||
|
||
await app.processMessages(messages); | ||
expect(calls.length).toBe(1); | ||
expect(calls[0].prompt).not.toContainEqual({ | ||
role: 'system', | ||
}); | ||
}); | ||
|
||
test('does not send system message when system prompt returns empty string', async () => { | ||
const { languageModel, calls } = createMockVercelModel({ text: 'Hello, world!' }); | ||
const app = createApp({ | ||
chatModel: new VercelChatModelAdapter({ languageModel }), | ||
systemPrompt: () => '', | ||
}); | ||
|
||
await app.processMessages(messages); | ||
expect(calls.length).toBe(1); | ||
expect(calls[0].prompt).not.toContainEqual({ | ||
role: 'system', | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { LanguageModelV1CallOptions } from 'ai'; | ||
import { MockLanguageModelV1 } from 'ai/test'; | ||
|
||
export type MockVercelModelOptions = { | ||
text: string; | ||
}; | ||
|
||
export function createMockVercelModel({ text }: MockVercelModelOptions) { | ||
const calls: LanguageModelV1CallOptions[] = []; | ||
const languageModel = new MockLanguageModelV1({ | ||
doGenerate: (options) => { | ||
calls.push(options); | ||
return Promise.resolve({ | ||
rawCall: { rawPrompt: null, rawSettings: {} }, | ||
finishReason: 'stop', | ||
usage: { promptTokens: 10, completionTokens: 20 }, | ||
text, | ||
}); | ||
}, | ||
// TODO: add doStream when needed | ||
}); | ||
|
||
return { languageModel, calls }; | ||
} |