-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55 from intelligentnode/52-add-chat-context-function
Upgrade npm release
- Loading branch information
Showing
5 changed files
with
58 additions
and
10 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,49 @@ | ||
const { ChatContext } = require('intellinode'); | ||
require("dotenv").config(); | ||
const assert = require('assert'); | ||
|
||
const apiKey = process.env.OPENAI_API_KEY; | ||
|
||
async function testGetSimpleContext() { | ||
|
||
const context = new ChatContext(apiKey); | ||
const userMessage = "Hello"; | ||
const historyMessages = ["Good morning", "Dinner time", "How can I help you?", "Hello"]; | ||
const n = 3; | ||
|
||
const resultContext = await context.getStringContext(userMessage, historyMessages, n); | ||
|
||
console.log('result: ', resultContext) | ||
|
||
assert.strictEqual(resultContext.length, n); | ||
} | ||
|
||
// Test for getRoleContext | ||
async function testGetRoleContext() { | ||
|
||
const context = new ChatContext(apiKey); | ||
const userMessage = "Hello"; | ||
const historyMessages = [ | ||
{ role: 'user', content: 'Dinner time' }, | ||
{ role: 'user', content: 'Good Morning' }, | ||
{ role: 'assistant', content: 'How can I help you?' }, | ||
{ role: 'user', content: 'Hello' } | ||
]; | ||
const n = 3; | ||
|
||
const resultContext = await context.getRoleContext(userMessage, historyMessages, n); | ||
|
||
console.log('resultContext: ', resultContext) | ||
|
||
assert.strictEqual(resultContext.length, n); | ||
|
||
} | ||
|
||
|
||
(async () => { | ||
console.log('### execute the string context history ###') | ||
await testGetSimpleContext(); | ||
|
||
console.log('### execute the role dictionary context history ###') | ||
await testGetRoleContext(); | ||
})(); |