Skip to content

Commit 8f25f74

Browse files
committed
refactor: rename auth service
1 parent a6b70ac commit 8f25f74

File tree

6 files changed

+15
-13
lines changed

6 files changed

+15
-13
lines changed
File renamed without changes.

packages/agent-api/src/functions/chats-delete.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { HttpRequest, HttpResponseInit, InvocationContext, app } from '@azure/fu
33
import { AzureCosmsosDBNoSQLChatMessageHistory } from '@langchain/azure-cosmosdb';
44
import 'dotenv/config';
55
import { badRequest, ok, notFound } from '../http-response.js';
6-
import { getCredentials, getUserId } from '../security.js';
6+
import { getCredentials, getUserId } from '../auth.js';
77

88
async function deleteChats(request: HttpRequest, context: InvocationContext): Promise<HttpResponseInit> {
99
const azureCosmosDbEndpoint = process.env.AZURE_COSMOSDB_NOSQL_ENDPOINT;

packages/agent-api/src/functions/chats-get.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { HttpRequest, HttpResponseInit, InvocationContext, app } from '@azure/fu
33
import { AzureCosmsosDBNoSQLChatMessageHistory } from '@langchain/azure-cosmosdb';
44
import 'dotenv/config';
55
import { badRequest, ok, notFound } from '../http-response.js';
6-
import { getCredentials, getUserId } from '../security.js';
6+
import { getCredentials, getUserId } from '../auth.js';
77

88
async function getChats(request: HttpRequest, context: InvocationContext): Promise<HttpResponseInit> {
99
const azureCosmosDbEndpoint = process.env.AZURE_COSMOSDB_NOSQL_ENDPOINT;

packages/agent-api/src/functions/chats-post.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ import { AzureChatOpenAI } from '@langchain/openai';
55
import { AzureCosmsosDBNoSQLChatMessageHistory } from '@langchain/azure-cosmosdb';
66
import { BaseChatModel } from '@langchain/core/language_models/chat_models';
77
import { RunnableWithMessageHistory } from '@langchain/core/runnables';
8-
import { ChatPromptTemplate, PromptTemplate } from '@langchain/core/prompts';
8+
import { ChatPromptTemplate } from '@langchain/core/prompts';
99
import { createToolCallingAgent } from "langchain/agents";
1010
import { AgentExecutor } from "langchain/agents";
1111
import { loadMcpTools } from "@langchain/mcp-adapters";
1212
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
1313
import { v4 as uuidv4 } from 'uuid';
1414
import 'dotenv/config';
1515
import { badRequest, data, serviceUnavailable } from '../http-response.js';
16-
import { getAzureOpenAiTokenProvider, getCredentials, getUserId } from '../security.js';
16+
import { getAzureOpenAiTokenProvider, getCredentials, getUserId } from '../auth.js';
1717
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
1818
import { ChainValues } from '@langchain/core/utils/types.js';
1919

@@ -36,6 +36,7 @@ Make sure the last question ends with ">>".
3636
- If you get any errors when trying to use a tool that does not seem related to missing parameters, try again
3737
- If you cannot get the information needed to answer the user's question or perform the specified action, inform the user that you are unable to do so. Never make up information.
3838
- The get_burger tool can help you get informations about the burgers
39+
- Creating or cancelling an order requires the userId, which is provided in the request context
3940
`;
4041

4142
const titleSystemPrompt = `Create a title for this chat session, based on the user question. The title should be less than 32 characters. Do NOT use double-quotes.`;
@@ -112,8 +113,9 @@ export async function postChats(request: HttpRequest, context: InvocationContext
112113

113114
const prompt = ChatPromptTemplate.fromMessages([
114115
["system", agentSystemPrompt],
116+
["human", "userId: {userId}"],
115117
["placeholder", "{chat_history}"],
116-
["human", "{input}"],
118+
["human", "{question}"],
117119
["placeholder", "{agent_scratchpad}"],
118120
]);
119121

@@ -132,14 +134,14 @@ export async function postChats(request: HttpRequest, context: InvocationContext
132134
// Handle chat history
133135
const agentChainWithHistory = new RunnableWithMessageHistory({
134136
runnable: agentExecutor,
135-
inputMessagesKey: 'input',
137+
inputMessagesKey: 'question',
136138
historyMessagesKey: 'chat_history',
137139
getMessageHistory: async () => chatHistory,
138140
});
139141
// Retriever to search for the documents in the database
140142
const question = messages.at(-1)!.content;
141143
const responseStream = await agentChainWithHistory.stream(
142-
{ input: question },
144+
{ userId, question },
143145
{ configurable: { sessionId } },
144146
);
145147
const jsonStream = Readable.from(createJsonStream(responseStream, sessionId));
@@ -148,11 +150,11 @@ export async function postChats(request: HttpRequest, context: InvocationContext
148150
const { title } = await chatHistory.getContext();
149151
if (!title) {
150152
const response = await ChatPromptTemplate.fromMessages([
151-
['system', titleSystemPrompt],
152-
['human', '{input}'],
153-
])
153+
['system', titleSystemPrompt],
154+
['human', '{question}'],
155+
])
154156
.pipe(model)
155-
.invoke({ input: question });
157+
.invoke({ question });
156158
context.log(`Title for session: ${response.content as string}`);
157159
chatHistory.setContext({ title: response.content });
158160
}

packages/agent-api/src/functions/me-get.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
type InvocationContext,
66
} from "@azure/functions";
77
import { UserDbService } from "../user-db-service.js";
8-
import { getUserId } from "../security.js";
8+
import { getUserId } from "../auth.js";
99

1010
app.http("me-get", {
1111
methods: ["GET"],

packages/agent-api/src/minimal.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { AgentExecutor } from "langchain/agents";
66
import { loadMcpTools } from "@langchain/mcp-adapters";
77
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
88
import 'dotenv/config';
9-
import { getAzureOpenAiTokenProvider, getCredentials, getUserId } from './security.js';
9+
import { getAzureOpenAiTokenProvider, getCredentials, getUserId } from './auth.js';
1010
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
1111

1212
const agentSystemPrompt = `

0 commit comments

Comments
 (0)