-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[JS] feat: File download support, vision support, and vision sample (#…
…1018) ## Linked issues closes: #912 fixes: #786, #399 ## NOTE > This PR is identical to #913. The only difference is the person creating the PR. ## Details This change adds 2 key new features to the AI library: - A new file downloader feature lets developers reregister file downloader plugins that can download files relative to the users input. A `TeamsAttachmentDownloader` implementation is provided which simplifies the downloading of files uploaded to a bot. - GPT Vision support is added so that downloaded image files can be sent to GPT as part of the users input. This PR also fixes a couple of prompt related bugs that were identified in the process. #### Change details - Fixed bugs related to prompts not using the override options defined in a prompts config.json file. - Added a new `InputFileDownloader` plugin model to the `Application` class. - Added a `TeamsAttachmentDownloader` class for automatically downloading files uploaded to the bot. - Added a new `state.temp.input_files` variable which is of type `InputFile[]`. - Moved the initialization of `state.temp.input` from the `AI` class to the `Application` class as it made more sense to do this earlier. - Updated the `Message` interface to support the new features needed for the vision API's. - Added a new `UserInputMessage` prompt section that knows how to format "user" messages containing images. - Updated `ConversationHistory` prompt section to count tokens for included images. This is currently hard coded to 85 which is the cost of low detail images. High detail images consume more tokens but it would require more work to count them properly. - Updated `OpenAIModel` class to return the `LLMClient` the input message it sent to the model. This is so the message with the images gets properly added to conversation history. ## 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 (we use [TypeDoc](https://typedoc.org/) to document our code) - 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: Steven Ickman <[email protected]> Co-authored-by: Corina Gum <> Co-authored-by: Lily Du <[email protected]>
- Loading branch information
1 parent
bb711b3
commit a62392b
Showing
62 changed files
with
1,778 additions
and
176 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
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,43 @@ | ||
/** | ||
* @module teams-ai | ||
*/ | ||
/** | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. | ||
*/ | ||
|
||
import { TurnContext } from 'botbuilder'; | ||
import { TurnState } from './TurnState'; | ||
|
||
/** | ||
* A plugin responsible for downloading files relative to the current user's input. | ||
* @template TState Optional. Type of application state. | ||
*/ | ||
export interface InputFileDownloader<TState extends TurnState = TurnState> { | ||
/** | ||
* Download any files relative to the current user's input. | ||
* @param context Context for the current turn of conversation. | ||
* @param state Application state for the current turn of conversation. | ||
*/ | ||
downloadFiles(context: TurnContext, state: TState): Promise<InputFile[]>; | ||
} | ||
|
||
/** | ||
* A file sent by the user to the bot. | ||
*/ | ||
export interface InputFile { | ||
/** | ||
* The downloaded content of the file. | ||
*/ | ||
content: Buffer; | ||
|
||
/** | ||
* The content type of the file. | ||
*/ | ||
contentType: string; | ||
|
||
/** | ||
* Optional. URL to the content of the file. | ||
*/ | ||
contentUrl?: string; | ||
} |
Oops, something went wrong.