feat(group-agent): 大模型监控增加参数
This commit is contained in:
parent
4e08d68af8
commit
ae759108cf
@ -93,7 +93,7 @@ const sendGroupReport = async (
|
|||||||
mentions?: LarkEvent.Mention[]
|
mentions?: LarkEvent.Mention[]
|
||||||
}
|
}
|
||||||
) => {
|
) => {
|
||||||
const { larkService, logger, larkCard } = ctx
|
const { larkService, logger, larkCard, requestId } = ctx
|
||||||
const cardGender = larkCard.child("groupAgent")
|
const cardGender = larkCard.child("groupAgent")
|
||||||
const updateCard = (content: any) =>
|
const updateCard = (content: any) =>
|
||||||
larkService.message.update(messageId, content)
|
larkService.message.update(messageId, content)
|
||||||
@ -117,10 +117,14 @@ const sendGroupReport = async (
|
|||||||
logger.debug(`Chat history: ${JSON.stringify(chatHistory)}`)
|
logger.debug(`Chat history: ${JSON.stringify(chatHistory)}`)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const llmRes = await llm.invoke(functionId, {
|
const llmRes = await llm.invoke(
|
||||||
chatHistory: JSON.stringify(chatHistory),
|
functionId,
|
||||||
time: new Date().toLocaleString("zh-CN", { timeZone: "Asia/Shanghai" }),
|
{
|
||||||
})
|
chatHistory: JSON.stringify(chatHistory),
|
||||||
|
time: new Date().toLocaleString("zh-CN", { timeZone: "Asia/Shanghai" }),
|
||||||
|
},
|
||||||
|
requestId
|
||||||
|
)
|
||||||
// 记录大模型返回结果后的时间戳
|
// 记录大模型返回结果后的时间戳
|
||||||
const processEnd = Date.now()
|
const processEnd = Date.now()
|
||||||
// 计算时间差并存储在processingTime变量中,以秒为单位
|
// 计算时间差并存储在processingTime变量中,以秒为单位
|
||||||
@ -173,6 +177,7 @@ const parseGroupAgentQuery = async (
|
|||||||
larkService,
|
larkService,
|
||||||
larkCard,
|
larkCard,
|
||||||
logger,
|
logger,
|
||||||
|
requestId,
|
||||||
} = ctx
|
} = ctx
|
||||||
const cardGender = larkCard.child("groupAgent")
|
const cardGender = larkCard.child("groupAgent")
|
||||||
|
|
||||||
@ -199,7 +204,7 @@ const parseGroupAgentQuery = async (
|
|||||||
|
|
||||||
// 使用大模型解析用户输入
|
// 使用大模型解析用户输入
|
||||||
const { chatId, chatName, functionName, functionId, startTime, endTime } =
|
const { chatId, chatName, functionName, functionId, startTime, endTime } =
|
||||||
await llm.parseGroupAgentQuery(msgText, groupInfo, functionInfo)
|
await llm.parseGroupAgentQuery(msgText, groupInfo, functionInfo, requestId)
|
||||||
logger.info(
|
logger.info(
|
||||||
`Parsed group agent query: chatId: ${chatId}, chatName: ${chatName}, functionName: ${functionName}, functionId: ${functionId}, startTime: ${startTime}, endTime: ${endTime}`
|
`Parsed group agent query: chatId: ${chatId}, chatName: ${chatName}, functionName: ${functionName}, functionId: ${functionId}, startTime: ${startTime}, endTime: ${endTime}`
|
||||||
)
|
)
|
||||||
|
@ -20,4 +20,6 @@ const functionInfo = JSON.stringify([
|
|||||||
|
|
||||||
const userInput = "你好"
|
const userInput = "你好"
|
||||||
|
|
||||||
llm.parseGroupAgentQuery(userInput, groupInfo, functionInfo).then(console.log)
|
llm
|
||||||
|
.parseGroupAgentQuery(userInput, groupInfo, functionInfo, "localTest")
|
||||||
|
.then(console.log)
|
||||||
|
17
utils/llm.ts
17
utils/llm.ts
@ -9,11 +9,13 @@ import db from "../db"
|
|||||||
* 获取Langfuse
|
* 获取Langfuse
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
const getLangfuse = async () => {
|
const getLangfuse = async (name: string, requestId: string) => {
|
||||||
const langfuseParams = {
|
const langfuseParams = {
|
||||||
publicKey: await db.appConfig.getLangfusePk(),
|
publicKey: await db.appConfig.getLangfusePk(),
|
||||||
secretKey: await db.appConfig.getLangfuseSk(),
|
secretKey: await db.appConfig.getLangfuseSk(),
|
||||||
baseUrl: "http://langfuse.c5-cloudml.xiaomi.srv",
|
baseUrl: "http://langfuse.c5-cloudml.xiaomi.srv",
|
||||||
|
sessionId: requestId,
|
||||||
|
name,
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
langfuseHandler: new CallbackHandler(langfuseParams),
|
langfuseHandler: new CallbackHandler(langfuseParams),
|
||||||
@ -74,14 +76,19 @@ const groupAgentConfig = z.object({
|
|||||||
* @param userInput 用户输入
|
* @param userInput 用户输入
|
||||||
* @param groupInfo 群聊信息
|
* @param groupInfo 群聊信息
|
||||||
* @param functionInfo 功能信息
|
* @param functionInfo 功能信息
|
||||||
|
* @param requestId 请求ID
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
const parseGroupAgentQuery = async (
|
const parseGroupAgentQuery = async (
|
||||||
userInput: string,
|
userInput: string,
|
||||||
groupInfo: string,
|
groupInfo: string,
|
||||||
functionInfo: string
|
functionInfo: string,
|
||||||
|
requestId: string
|
||||||
) => {
|
) => {
|
||||||
const { langfuseHandler } = await getLangfuse()
|
const { langfuseHandler } = await getLangfuse(
|
||||||
|
"parseGroupAgentQuery",
|
||||||
|
requestId
|
||||||
|
)
|
||||||
const model = await getModel("qwen-72b-instruct-int4/v1")
|
const model = await getModel("qwen-72b-instruct-int4/v1")
|
||||||
const structuredLlm = model.withStructuredOutput(groupAgentConfig, {
|
const structuredLlm = model.withStructuredOutput(groupAgentConfig, {
|
||||||
name: "groupAgent",
|
name: "groupAgent",
|
||||||
@ -121,15 +128,17 @@ const parseGroupAgentQuery = async (
|
|||||||
* 调用LLM模型
|
* 调用LLM模型
|
||||||
* @param promptName 提示Key
|
* @param promptName 提示Key
|
||||||
* @param variables 变量
|
* @param variables 变量
|
||||||
|
* @param requestId 请求ID
|
||||||
* @param temperature 温度
|
* @param temperature 温度
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
const invoke = async (
|
const invoke = async (
|
||||||
promptName: string,
|
promptName: string,
|
||||||
variables: Record<string, any>,
|
variables: Record<string, any>,
|
||||||
|
requestId: string,
|
||||||
temperature = 0
|
temperature = 0
|
||||||
) => {
|
) => {
|
||||||
const { langfuse, langfuseHandler } = await getLangfuse()
|
const { langfuse, langfuseHandler } = await getLangfuse("invoke", requestId)
|
||||||
const prompt = await langfuse.getPrompt(promptName)
|
const prompt = await langfuse.getPrompt(promptName)
|
||||||
const config = prompt.config as { modelName: keyof typeof modelMap }
|
const config = prompt.config as { modelName: keyof typeof modelMap }
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user