Skip to content

Commit

Permalink
[JS] chore: Begin to move typings to typings folder (#2120)
Browse files Browse the repository at this point in the history
## Linked issues

#minor  

## Details

We are beginning an effort to better organize the JS package. One step
is moving types to a `/types` folder. This is a partial implementation
of that. This change does not affect users of the Teams AI library.

## Attestation Checklist

- [x] My code follows the style guidelines of this project

- I have checked for/fixed spelling, linting, and other errors
- I have commented my code for clarity
- I have made corresponding changes to the documentation (updating the
doc strings in the code is sufficient)
- My changes generate no new warnings
- I have added tests that validates my changes, and provides sufficient
test coverage. I have tested with:
  - Local testing
  - E2E testing in Teams
- New and existing unit tests pass locally with my changes

### Additional information

> Feel free to add other relevant information below

---------

Co-authored-by: Corina Gum <>
  • Loading branch information
corinagum authored Oct 17, 2024
1 parent d4bf9cc commit fcc6227
Show file tree
Hide file tree
Showing 27 changed files with 369 additions and 320 deletions.
6 changes: 4 additions & 2 deletions js/packages/teams-ai/src/AI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@

import { TurnContext } from 'botbuilder';

import { TooManyStepsParameters } from './types';

import * as actions from './actions';
import { DefaultModerator } from './moderators';
import { Moderator } from './moderators/Moderator';
import { PredictedDoCommand, Planner, Plan } from './planners';
import { Plan, Planner, PredictedDoCommand } from './planners';
import { TurnState } from './TurnState';

/**
Expand Down Expand Up @@ -393,7 +395,7 @@ export class AI<TState extends TurnState = TurnState> {
// Check for timeout
if (Date.now() - start_time! > max_time || ++step_count! > max_steps) {
completed = false;
const parameters: actions.TooManyStepsParameters = {
const parameters: TooManyStepsParameters = {
max_steps,
max_time,
start_time: start_time!,
Expand Down
2 changes: 1 addition & 1 deletion js/packages/teams-ai/src/Utilities.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { strict as assert } from 'assert';

import { ClientCitation } from './actions';
import { ClientCitation } from './types';
import { GPTTokenizer } from './tokenizers';
import { Utilities } from './Utilities';

Expand Down
2 changes: 1 addition & 1 deletion js/packages/teams-ai/src/Utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import { stringify } from 'yaml';

import { ClientCitation } from './actions';
import { ClientCitation } from './types';
import { Tokenizer } from './tokenizers';

/**
Expand Down
169 changes: 17 additions & 152 deletions js/packages/teams-ai/src/actions/SayCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,150 +6,12 @@
* Licensed under the MIT License.
*/

import { ActivityTypes, Channels, TurnContext } from 'botbuilder';
import { Activity, ActivityTypes, Channels, TurnContext } from 'botbuilder';

import { PredictedSayCommand } from '../planners';
import { TurnState } from '../TurnState';
import { Utilities } from '../Utilities';

export interface AIEntity {
/**
* Required as 'https://schema.org/Message'
*/
type: 'https://schema.org/Message';

/**
* Required as 'Message
*/
'@type': 'Message';

/**
* Required as 'https://schema.org
*/
'@context': 'https://schema.org';

/**
* Must be left blank. This is for Bot Framework schema.
*/
'@id': '';

/**
* Indicate that the content was generated by AI.
*/
additionalType: ['AIGeneratedContent'];

/**
* Optional; if citations object is included, the sent activity will include the citations, referenced in the activity text.
*/
citation?: ClientCitation[];
}
export interface ClientCitation {
/**
* Required; must be "Claim"
*/
'@type': 'Claim';

/**
* Required. Number and position of the citation.
*/
position: string;
appearance: {
/**
* Required; Must be 'DigitalDocument'
*/
'@type': 'DigitalDocument';

/**
* Name of the document.
*/
name: string;

/**
* Optional; ignored in Teams
*/
text?: string;

/**
* URL of the document. This will make the name of the citation clickable and direct the user to the specified URL.
*/
url?: string;

/**
* Content of the citation. Must be clipped if longer than 480 characters.
*/
abstract: string;

/**
* Used for icon; for now it is ignored.
*/
encodingFormat?: 'text/html';

/**
* For now ignored, later used for icon
*/
image?: string;

/**
* Optional; set by developer
*/
keywords?: string[];

/**
* Optional sensitivity content information.
*/
usageInfo?: SensitivityUsageInfo;
};
}

/**
* Sensitivity usage info for content sent to the user. This is used to provide information about the content to the user.
*/
export interface SensitivityUsageInfo {
/**
* Must be "https://schema.org/Message"
*/
type: 'https://schema.org/Message';

/**
* Required; Set to CreativeWork;
*/
'@type': 'CreativeWork';

/**
* Sensitivity description of the content
*/
description?: string;

/**
* Sensitivity title of the content
*/
name: string;

/**
* Optional; ignored in Teams.
*/
position?: number;

pattern?: {
/**
* Set to DefinedTerm
*/
'@type': 'DefinedTerm';

inDefinedTermSet: string;

/**
* Color
*/
name: string;

/**
* e.g. #454545
*/
termCode: string;
};
}

import { AIEntity, ClientCitation } from '../types';
/**
* @private
* @param {boolean} feedbackLoopEnabled - If true, the feedback loop UI for Teams will be enabled.
Expand Down Expand Up @@ -193,21 +55,24 @@ export function sayCommand<TState extends TurnState = TurnState>(feedbackLoopEna
// If there are citations, filter out the citations unused in content.
const referencedCitations = citations ? Utilities.getUsedCitations(contentText, citations) : undefined;

await context.sendActivity({
const entities: AIEntity[] = [
{
type: 'https://schema.org/Message',
'@type': 'Message',
'@context': 'https://schema.org',
'@id': '',
additionalType: ['AIGeneratedContent'],
...(referencedCitations ? { citation: referencedCitations } : {})
}
];
const activity: Partial<Activity> = {
type: ActivityTypes.Message,
text: contentText,
...(isTeamsChannel ? { channelData: { feedbackLoopEnabled } } : {}),
entities: [
{
type: 'https://schema.org/Message',
'@type': 'Message',
'@context': 'https://schema.org',
'@id': '',
additionalType: ['AIGeneratedContent'],
...(referencedCitations ? { citation: referencedCitations } : {})
}
] as AIEntity[]
});
entities: entities
};

await context.sendActivity(activity);

return '';
};
Expand Down
26 changes: 1 addition & 25 deletions js/packages/teams-ai/src/actions/TooManySteps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,7 @@
import { TurnContext } from 'botbuilder-core';

import { TurnState } from '../TurnState';

/**
* Parameters passed to the AI.TooManyStepsActionName action.
*/
export interface TooManyStepsParameters {
/**
* Configured maximum number of steps allowed.
*/
max_steps: number;

/**
* Configured maximum amount of time allowed.
*/
max_time: number;

/**
* Time the AI system started processing the current activity.
*/
start_time: number;

/**
* Number of steps that have been executed.
*/
step_count: number;
}
import { TooManyStepsParameters } from '../types';

/**
* @private
Expand Down
4 changes: 2 additions & 2 deletions js/packages/teams-ai/src/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
*/

export * from './Action';
export * from './Unknown';
export * from './DoCommand';
export * from './FlaggedInput';
export * from './FlaggedOutput';
export * from './HttpError';
export * from './PlanReady';
export * from './DoCommand';
export * from './SayCommand';
export * from './TooManySteps';
export * from './Unknown';
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import { TurnContext } from 'botbuilder';
import { Schema } from 'jsonschema';
import { stringify } from 'yaml';

import { Memory } from '../MemoryFork';
import { ChatCompletionAction } from '../models';
import { Memory } from '../MemoryFork';
import { Message, PromptFunctions, RenderedPromptSection, PromptSectionBase } from '../prompts';
import { Tokenizer } from '../tokenizers';

Expand Down
7 changes: 4 additions & 3 deletions js/packages/teams-ai/src/augmentations/Augmentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
*/

import { TurnContext } from 'botbuilder-core';
import { PromptResponseValidator } from '../validators';
import { Plan } from '../planners';
import { PromptSection } from '../prompts';

import { Memory } from '../MemoryFork';
import { Plan } from '../planners';
import { PromptResponse } from '../types';
import { PromptResponseValidator } from '../validators';
import { PromptSection } from '../prompts';

/**
* An augmentation is a component that can be added to a prompt template to add additional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import { TurnContext } from 'botbuilder-core';

import { Memory } from '../MemoryFork';
import { Plan, PredictedSayCommand } from '../planners';
import { PromptResponse } from '../types';
import { PromptSection } from '../prompts';
import { Tokenizer } from '../tokenizers';
import { PromptResponse } from '../types';
import { Validation } from '../validators';

import { Augmentation } from './Augmentation';
Expand Down
Loading

0 comments on commit fcc6227

Please sign in to comment.