Skip to content

Commit

Permalink
lint, fix tests and timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
lilyydu committed Nov 14, 2024
1 parent be7579b commit 0580cb5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 26 deletions.
5 changes: 3 additions & 2 deletions js/packages/teams-ai/src/StreamingResponse.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,15 @@ describe('StreamingResponse', function () {
const adapter = new TestAdapter();
await adapter.sendTextToBot('test', async (context) => {
const response = new StreamingResponse(context);
response.queueTextChunk('first', [
response.setCitations([
{ content: 'test-content', url: 'https://example.com', title: 'test', filepath: 'test' } as Citation
]);
response.queueTextChunk('first');
response.queueTextChunk('second');
await response.waitForQueue();
await response.endStream();
assert(response.updatesSent == 2, 'updatesSent should be 2');
assert(response.citations == undefined, 'no citations matched');
assert(response.citations?.length == 1, 'added 1 citation');

// Validate sent activities
const activities = adapter.activeQueue;
Expand Down
46 changes: 22 additions & 24 deletions js/packages/teams-ai/src/StreamingResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,28 +155,27 @@ export class StreamingResponse {
* @param {Citation[]} citations Citations to be included in the message.
*/
public setCitations(citations: Citation[]): void {
if (citations.length > 0) {
if (!this._citations) {
this._citations = [];
}
let currPos = this._citations.length;

for (const citation of citations) {
const clientCitation: ClientCitation = {
'@type': 'Claim',
position: `${currPos + 1}`,
appearance: {
'@type': 'DigitalDocument',
name: citation.title || `Document #${currPos + 1}`,
abstract: Utilities.snippet(citation.content, 477)
}
};
currPos++;
this._citations.push(clientCitation);
}
if (citations.length > 0) {
if (!this._citations) {
this._citations = [];
}
let currPos = this._citations.length;

for (const citation of citations) {
const clientCitation: ClientCitation = {
'@type': 'Claim',
position: `${currPos + 1}`,
appearance: {
'@type': 'DigitalDocument',
name: citation.title || `Document #${currPos + 1}`,
abstract: Utilities.snippet(citation.content, 477)
}
};
currPos++;
this._citations.push(clientCitation);
}
}
}


/**
* Sets the Feedback Loop in Teams that allows a user to
Expand Down Expand Up @@ -314,17 +313,16 @@ export class StreamingResponse {
} as Entity
];

if (this._citations && !this._ended) {
if (this._citations && this._citations.length > 0 && !this._ended) {
// Filter out the citations unused in content.
const currCitations = Utilities.getUsedCitations(this._message, this._citations) ?? undefined;
activity.entities.push({
type: 'https://schema.org/Message',
'@type': 'Message',
'@context': 'https://schema.org',
'@id': '',
citation: currCitations && currCitations.length > 0 ? currCitations : [],
citation: currCitations
} as AIEntity);

}

// Add in Powered by AI feature flags
Expand All @@ -350,7 +348,7 @@ export class StreamingResponse {

// Send activity
const response = await this._context.sendActivity(activity);
await new Promise((resolve) => setTimeout(resolve, 1.5));
await new Promise((resolve) => setTimeout(resolve, 1500));

// Save assigned stream ID
if (!this._streamId) {
Expand Down

0 comments on commit 0580cb5

Please sign in to comment.