feat: 修改Langfuse配置
All checks were successful
Egg Server MIflow / build-image (push) Successful in 49s

This commit is contained in:
zhaoyingbo 2024-09-26 06:56:14 +00:00
parent c2088c586f
commit c7adc6f76b
3 changed files with 42 additions and 8 deletions

View File

@ -32,9 +32,23 @@ const getDeepseekApiKey = async () => get("deepseek_api_key")
*/
const getOpenAIApiKey = async () => get("openai_api_key")
/**
* Langfuse的pk
* @returns {string} pk
*/
const getLangfusePk = async () => get("langfuse_pk")
/**
* Langfuse的sk
* @returns {string} sk
*/
const getLangfuseSk = async () => get("langfuse_sk")
const appConfig = {
getOpenAIApiKey,
getDeepseekApiKey,
getLangfusePk,
getLangfuseSk,
}
export default appConfig

13
test/llm.ts Normal file
View File

@ -0,0 +1,13 @@
import { Langfuse } from "langfuse-langchain"
const langfuseParams = {
publicKey: "pk-lf-7328c2f1-595a-4023-994b-78762d3dde9e",
secretKey: "sk-lf-bdf20cd5-ff2c-45c3-9021-8292dbb1bef3",
baseUrl: "https://langfuse.yingbo.im:333",
}
const langfuse = new Langfuse(langfuseParams)
const prompt = await langfuse.getPrompt("summary")
console.log(prompt)

View File

@ -4,16 +4,22 @@ import { z } from "zod"
import db from "../db"
const langfuseParams = {
publicKey: "pk-lf-7328c2f1-595a-4023-994b-78762d3dde9e",
secretKey: "sk-lf-bdf20cd5-ff2c-45c3-9021-8292dbb1bef3",
baseUrl: "https://langfuse.yingbo.im:333",
/**
* Langfuse
* @returns
*/
const getLangfuse = async () => {
const langfuseParams = {
publicKey: await db.appConfig.getLangfusePk(),
secretKey: await db.appConfig.getLangfuseSk(),
baseUrl: "https://langfuse.yingbo.im:333",
}
return {
langfuseHandler: new CallbackHandler(langfuseParams),
langfuse: new Langfuse(langfuseParams),
}
}
const langfuseHandler = new CallbackHandler(langfuseParams)
const langfuse = new Langfuse(langfuseParams)
/**
* Deepseek模型
* @param temperature
@ -65,6 +71,7 @@ const invokeLLM4ChatHistory = async (
promptType: LlmPromptType,
chatHistory: string
) => {
const { langfuseHandler, langfuse } = await getLangfuse()
const prompt = await langfuse.getPrompt(promptType)
const compiled_prompt = prompt.compile({
chatHistory,