-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added unit tests for UserTokenAccess, DataSourceSection, FunctionCall…
…Message, FunctionResponseMessage
- Loading branch information
Showing
4 changed files
with
162 additions
and
4 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
39 changes: 39 additions & 0 deletions
39
js/packages/teams-ai/src/prompts/DataSourceSection.spec.ts
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,39 @@ | ||
import assert from 'assert'; | ||
import { TextDataSource } from '../dataSources/TextDataSource'; | ||
import { DataSourceSection } from './DataSourceSection'; | ||
import { TestAdapter } from 'botbuilder-core'; | ||
import { TestTurnState } from '../TestTurnState'; | ||
import { GPT3Tokenizer } from '../tokenizers'; | ||
import { TestPromptManager } from './TestPromptManager'; | ||
|
||
describe('DataSourceSection', () => { | ||
const textDataSource = new TextDataSource('testname', 'Hello World!'); | ||
const adapter = new TestAdapter(); | ||
const functions = new TestPromptManager(); | ||
const tokenizer = new GPT3Tokenizer(); | ||
|
||
describe('constructor', () => { | ||
it('should create a DataSourceSection', () => { | ||
const section = new DataSourceSection(textDataSource, -2); | ||
assert.notEqual(section, undefined); | ||
assert.equal(section.tokens, -2); | ||
assert.equal(section.required, true); | ||
assert.equal(section.separator, '\n\n'); | ||
assert.equal(section.textPrefix, ''); | ||
}); | ||
}); | ||
|
||
describe('renderAsMessages', () => { | ||
it('should render a DataSourceSection', async () => { | ||
await adapter.sendTextToBot('test', async (context) => { | ||
const state = await TestTurnState.create(context); | ||
const section = new DataSourceSection(textDataSource, -2); | ||
const rendered = await section.renderAsMessages(context, state, functions, tokenizer, 100); | ||
|
||
assert.deepEqual(rendered.output, [{ role: 'system', content: 'Hello World!' }]); | ||
assert.equal(rendered.length, 3); | ||
assert.equal(rendered.tooLong, false); | ||
}); | ||
}); | ||
}); | ||
}); |
46 changes: 46 additions & 0 deletions
46
js/packages/teams-ai/src/prompts/FunctionCallMessage.spec.ts
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,46 @@ | ||
import assert from 'assert'; | ||
import { FunctionCallMessage } from './FunctionCallMessage'; | ||
import { FunctionCall } from './Message'; | ||
import { TestAdapter } from 'botbuilder-core'; | ||
import { TestTurnState } from '../TestTurnState'; | ||
import { GPT3Tokenizer } from '../tokenizers'; | ||
import { TestPromptManager } from './TestPromptManager'; | ||
|
||
describe('FunctionCallMessage', () => { | ||
const functionCall: FunctionCall = { | ||
name: 'test', | ||
arguments: '{"foo":"bar"}' | ||
}; | ||
const adapter = new TestAdapter(); | ||
const functions = new TestPromptManager(); | ||
const tokenizer = new GPT3Tokenizer(); | ||
|
||
describe('constructor', () => { | ||
it('should create a FunctionCallMessage', () => { | ||
const section = new FunctionCallMessage(functionCall); | ||
|
||
assert.notEqual(section, undefined); | ||
assert.equal(section.tokens, -1); | ||
assert.equal(section.required, true); | ||
assert.equal(section.separator, '\n'); | ||
assert.equal(section.textPrefix, 'assistant: '); | ||
assert.equal(section.function_call, functionCall); | ||
}); | ||
}); | ||
|
||
describe('renderAsMessages', () => { | ||
it('should render a FunctionCallMessage', async () => { | ||
await adapter.sendTextToBot('test', async (context) => { | ||
const state = await TestTurnState.create(context); | ||
const section = new FunctionCallMessage(functionCall); | ||
const rendered = await section.renderAsMessages(context, state, functions, tokenizer, 100); | ||
|
||
assert.deepEqual(rendered.output, [ | ||
{ role: 'assistant', content: undefined, function_call: functionCall } | ||
]); | ||
assert.equal(rendered.length, 17); | ||
assert.equal(rendered.tooLong, false); | ||
}); | ||
}); | ||
}); | ||
}); |
42 changes: 42 additions & 0 deletions
42
js/packages/teams-ai/src/prompts/FunctionResponseMessage.spec.ts
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,42 @@ | ||
import assert from 'assert'; | ||
import { FunctionResponseMessage } from './FunctionResponseMessage'; | ||
import { TestAdapter } from 'botbuilder-core'; | ||
import { TestTurnState } from '../TestTurnState'; | ||
import { GPT3Tokenizer } from '../tokenizers'; | ||
import { TestPromptManager } from './TestPromptManager'; | ||
|
||
describe('FunctionResponseMessage', () => { | ||
const functionName = 'foo'; | ||
const response = 'bar'; | ||
const adapter = new TestAdapter(); | ||
const functions = new TestPromptManager(); | ||
const tokenizer = new GPT3Tokenizer(); | ||
|
||
describe('constructor', () => { | ||
it('should create a FunctionResponseMessage', () => { | ||
const section = new FunctionResponseMessage(functionName, response); | ||
|
||
assert.notEqual(section, undefined); | ||
assert.equal(section.name, functionName); | ||
assert.equal(section.response, response); | ||
assert.equal(section.tokens, -1); | ||
assert.equal(section.required, true); | ||
assert.equal(section.separator, '\n'); | ||
assert.equal(section.textPrefix, 'user: '); | ||
}); | ||
}); | ||
|
||
describe('renderAsMessages', () => { | ||
it('should render a FunctionResponseMessage', async () => { | ||
await adapter.sendTextToBot('test', async (context) => { | ||
const state = await TestTurnState.create(context); | ||
const section = new FunctionResponseMessage(functionName, response); | ||
const rendered = await section.renderAsMessages(context, state, functions, tokenizer, 100); | ||
|
||
assert.deepEqual(rendered.output, [{ role: 'function', name: functionName, content: response }]); | ||
assert.equal(rendered.length, 2); | ||
assert.equal(rendered.tooLong, false); | ||
}); | ||
}); | ||
}); | ||
}); |