Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JS] chore: update setup for ChefBot #1012

Merged
merged 4 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions js/samples/04.ai.a.teamsChefBot/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Microsoft Teams Conversational Bot with AI: Teams Chef

> Please note: this sample is still being tweaked and therefore not setup with Teams Toolkit yet. We'll get it updated ASAP!
This is a conversational bot for Microsoft Teams that thinks it's a Chef to help you cook apps using the Teams AI Library. The bot uses the `gpt-3.5-turbo` model to chat with Teams users and respond in a polite and respectful manner, staying within the scope of the conversation.

<!-- @import "[TOC]" {cmd="toc" depthFrom=1 depthTo=6 orderedList=false} -->

Expand All @@ -23,9 +22,6 @@
<!-- /code_chunk_output -->

## Summary

This is a conversational bot for Microsoft Teams that thinks it's a Chef to help you cook apps using the Teams AI Library. The bot uses the `gpt-3.5-turbo` model to chat with Teams users and respond in a polite and respectful manner, staying within the scope of the conversation.

This sample illustrates how to use [Retrieval Augmented Generation (RAG)](https://en.wikipedia.org/wiki/Prompt_engineering#Retrieval-augmented_generation) to easily inject contextual relevant information into the prompt sent to the model. This results in better and more accurate replies from the bot.

The sample uses a local Vector Database, called [Vectra](https://github.com/Stevenic/vectra), and [Semantic Search](https://en.wikipedia.org/wiki/Semantic_search) to find the most relevant information to include in the prompt for the users input. The index can be found in `./index/teams-ai` and includes all of the projects Getting Started docs and the source code for the Teams AI Library. This means you can ask the Teams Chef Bot anything about the library and it can answer it. You can even ask it to write sample code for you!
Expand All @@ -46,7 +42,7 @@ Open the panel below to learn fine-tuned details on how this sample works.
```javascript
// Create AI components
const planner = new OpenAIPlanner({
apiKey: process.env.OPENAI_API_KEY || '',
apiKey: process.env.OPENAI_KEY || '',
defaultModel: 'gpt-3.5-turbo',
logRequests: true
});
Expand Down Expand Up @@ -149,6 +145,11 @@ Notice that the bot remembered Dave's first message when responding to the secon
```bash
cd teams-ai/js/samples/04.ai.a.teamsChefBot/
```
4. Duplicate the `sample.env` in the `teams-ai/js/samples/04.ai.a.teamsChefBot` folder. Rename the file to `.env`.

5. Add in your `OPENAI_KEY` key.

6. Update `config.json` and `index.ts` with your model deployment name.

## Multiple ways to test

Expand Down
3 changes: 1 addition & 2 deletions js/samples/04.ai.a.teamsChefBot/env/.env.dev
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ RESOURCE_SUFFIX=

# Generated during provision, you can also add your own variables.
BOT_ID=
BOT_PASSWORD=
OPENAI_API_KEY=
BOT_PASSWORD=
2 changes: 2 additions & 0 deletions js/samples/04.ai.a.teamsChefBot/sample.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# This is an example file of how to set up environment variables. You can duplicate this file and add the appropriate keys.
OPENAI_KEY=
8 changes: 1 addition & 7 deletions js/samples/04.ai.a.teamsChefBot/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,25 +113,19 @@ const planner = new ActionPlanner({
defaultPrompt: 'chat',
});

// const moderator = new OpenAIModerator({
// apiKey: process.env.OPENAI_API_KEY || '',
// moderate: 'both'
// });

// Define storage and application
const storage = new MemoryStorage();
const app = new Application<ApplicationTurnState>({
storage,
ai: {
planner,
// moderator
}
});

// Register your data source with planner
planner.prompts.addDataSource(new VectraDataSource({
name: 'teams-ai',
apiKey: process.env.OPENAI_API_KEY!,
apiKey: process.env.OPENAI_KEY!,
indexFolder: path.join(__dirname, '../index'),
}));

Expand Down
18 changes: 4 additions & 14 deletions js/samples/04.ai.a.teamsChefBot/teamsapp.local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,10 @@ provision:
appPackagePath: ./build/appPackage/appPackage.${{TEAMSFX_ENV}}.zip # Relative path to this file. This is the path for built zip file.

deploy:
- uses: script
# Provides the Teams Toolkit .env file values to the apps runtime so they can be accessed with `process.env`.
- uses: file/createOrUpdateEnvironmentFile
with:
run: "yarn install"
timeout: 180000 # timeout in ms

- uses: script
with:
run: "yarn build"
timeout: 180000 # timeout in ms

- uses: file/createOrUpdateEnvironmentFile # Generate runtime environment variables
with:
target: ./.localSettings
target: ./.env
envs:
BOT_ID: ${{BOT_ID}}
BOT_PASSWORD: ${{SECRET_BOT_PASSWORD}}
OPENAI_API_KEY: ${{SECRET_OPENAI_API_KEY}}
BOT_PASSWORD: ${{SECRET_BOT_PASSWORD}}
1 change: 0 additions & 1 deletion js/samples/04.ai.a.teamsChefBot/teamsapp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,3 @@ publish:
writeToEnvironmentFile:
# Write the information of installed dependencies into environment file for the specified environment variable(s).
publishedAppId: TEAMS_APP_PUBLISHED_APP_ID
projectId: f76f76ab-fa47-46f5-a401-5d5deb608718