Skip to content

Commit 5b2c05c

Browse files
code improvements for langchain.js quest
1 parent 037452e commit 5b2c05c

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

.github/steps/5-frameworks.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ The current api code uses the Azure REST SDK directly. By switching to LangChain
3838
Open `server.js` and replace:
3939

4040
```javascript
41-
import ModelClient, { isUnexpected } from "@azure-rest/ai-inference";
4241
import { AzureKeyCredential } from "@azure/core-auth";
42+
import { isUnexpected } from "@azure-rest/ai-inference";
4343
```
4444

4545
with:
@@ -71,6 +71,9 @@ const chatModel = new AzureChatOpenAI({
7171
});
7272
```
7373

74+
> [!Note]
75+
> Update your `.env` with the missing variables
76+
7477
### Update chat endpoint
7578

7679
Replace the Azure REST SDK api call logic in the try-catch block (_app.post("/chat")_) with the following code:
@@ -124,7 +127,7 @@ import { ChatMessageHistory } from "langchain/stores/message/in_memory";
124127
Store session histories, allowing you to maintain separate chat histories for different users or sessions.
125128

126129
```javascript
127-
const sessionHistories = {};
130+
const sessionMemories = {};
128131
```
129132

130133
### Add a helper function to get/create a session history
@@ -170,8 +173,7 @@ app.post("/chat", async (req, res) => {
170173
? {
171174
role: "system",
172175
content: sources.length > 0
173-
? `You are a helpful assistant for Contoso Electronics. You must ONLY use the information provided below to answer.\n\n--- EMPLOYEE HANDBOOK EXCERPTS ---\n${sources.join('\n\n')}\n--- END OF EXCERPTS ---`
174-
: `You are a helpful assistant for Contoso Electronics. The excerpts do not contain relevant information for this question. Reply politely: "I'm sorry, I don't know. The employee handbook does not contain information about that."`,
176+
? `You are a helpful assistant for Contoso Electronics. You must ONLY use the information provided below to answer.\\n\\n--- EMPLOYEE HANDBOOK EXCERPTS ---\\n${sources.join('\\n\\n')}\\n--- END OF EXCERPTS ---`\n : `You are a helpful assistant for Contoso Electronics. The excerpts do not contain relevant information for this question. Reply politely: \"I'm sorry, I don't know. The employee handbook does not contain information about that.\"`,
175177
}
176178
: {
177179
role: "system",
@@ -233,5 +235,8 @@ To complete this quest and **AUTOMATICALLY UPDATE** your progress, you MUST push
233235
## 📚 Further Reading
234236

235237
Here are some additional resources to help you learn more about LangChain.js and its features:
236-
- [Serverless AI Chat with RAG using LangChain.js sample](https://github.com/Azure-Samples/serverless-chat-langchainjs)
238+
- [Get started with Serverless AI Chat with RAG using LangChain.js](https://github.com/Azure-Samples/serverless-chat-langchainjs)
239+
- [LangChain.js x Microsoft docs](https://js.langchain.com/docs/integrations/platforms/microsoft/)
240+
- [Ask YouTube: LangChain.js + Azure Quickstart](https://github.com/Azure-Samples/langchainjs-quickstart-demo)
241+
- [LangChain.js + Azure: A Generative AI App Journey](https://techcommunity.microsoft.com/blog/educatordeveloperblog/langchain-js--azure-a-generative-ai-app-journey/4101258)
237242
- [LangChain.js docs](https://js.langchain.com/docs/introduction/)

0 commit comments

Comments
 (0)