39 lines
811 B
TypeScript
39 lines
811 B
TypeScript
import { ChatOpenAI } from "@langchain/openai"
|
|
import CallbackHandler, { Langfuse } from "langfuse-langchain"
|
|
|
|
/**
|
|
* 获取模型
|
|
* @param temperature 温度
|
|
* @returns
|
|
*/
|
|
export const getModel = (temperature = 0) => {
|
|
return new ChatOpenAI(
|
|
{
|
|
temperature,
|
|
model: Bun.env.LLM_MODEL,
|
|
apiKey: Bun.env.LLM_API_KEY,
|
|
},
|
|
{
|
|
baseURL: Bun.env.LLM_BASE_URL,
|
|
}
|
|
)
|
|
}
|
|
|
|
/**
|
|
* 获取Langfuse
|
|
* @returns
|
|
*/
|
|
export const getLangfuse = async (name: string, requestId: string) => {
|
|
const langfuseParams = {
|
|
publicKey: Bun.env.LANGFUSE_PK,
|
|
secretKey: Bun.env.LANGFUSE_SK,
|
|
baseUrl: Bun.env.LANGFUSE_BASE_URL,
|
|
sessionId: requestId,
|
|
name,
|
|
}
|
|
return {
|
|
langfuseHandler: new CallbackHandler(langfuseParams),
|
|
langfuse: new Langfuse(langfuseParams),
|
|
}
|
|
}
|