Versions
- Open: VersionChanges from v5 to v6+8-7export async function getModelBuilder(spec: {type?: "llm" | "chat" | "embedding";provider?: "openai" | "huggingface";} = { type: "llm", provider: "openai" }, options?: any) {
// Use dynamic imports to ensure compatibilityconst { extend, cond, matches } = await import("https://esm.sh/lodash-es");// Since Val Town doesn't support direct environment variable access,// we'll modify the approach to require API keys to be passed inconst args = extend({callbacks: options?.verbose !== false ? [] : undefined}, options);// Simplified model builder setupconst setup = cond([[⦚ 36 unchanged lines ⦚]);// Return function to prevent serialization errorsreturn () => setup(spec);}// Add a default export to make the val more flexibleexport default getModelBuilder;// 1. 定義一個異步函數 getModelBuilderexport async function getModelBuilder(spec: {type?: "llm" | "chat" | "embedding";provider?: "openai" | "huggingface";} = { type: "llm", provider: "openai" }, options?: any) {// 2. 使用動態導入以確保兼容性const { extend, cond, matches } = await import("https://esm.sh/lodash-es");// 3. 由於 Val Town 不支持直接訪問環境變量,// 我們將修改方法以要求傳遞 API 密鑰const args = extend({callbacks: options?.verbose !== false ? [] : undefined}, options);// 4. 簡化的模型構建器設置const setup = cond([[⦚ 36 unchanged lines ⦚]);// 5. 返回函數以防止序列化錯誤return () => setup(spec);}// 6. 添加默認導出以使 val 更靈活export default getModelBuilder; - Open: VersionChanges from v4 to v5+20-36
// 1. 從 node 中導入 process 模組import process from "node:process";// 2. 導出一個異步函數 getModelBuilderexport async function getModelBuilder(spec: {type?: "llm" | "chat" | "embedding";provider?: "openai" | "huggingface";} = { type: "llm", provider: "openai" }, options?: any) {// 3. 從 lodash-es 中導入函數const { extend, cond, matches, invoke } = await import("npm:lodash-es");// 4. 設置 LangSmith 追蹤器const { Client } = await import("npm:langsmith");const { LangChainTracer } = await import("npm:langchain/callbacks");const client = new Client({apiUrl: "https://api.smith.langchain.com",apiKey: process.env.LANGSMITH,});const tracer = new LangChainTracer({ client });const callbacks = options?.verbose !== false ? [tracer] : [];// 5. 為每個提供者設置 API 密鑰const args = extend({ callbacks }, options);if (spec?.provider === "openai")args.openAIApiKey = process.env.OPENAI;else if (spec?.provider === "huggingface")args.apiKey = process.env.HUGGINGFACE;// 6. 填充模型構建器const setup = cond([[matches({ type: "llm", provider: "openai" }),async () => {const { OpenAI } = await import("npm:langchain/llms/openai");return new OpenAI(args);},export async function getModelBuilder(spec: {type?: "llm" | "chat" | "embedding";provider?: "openai" | "huggingface";} = { type: "llm", provider: "openai" }, options?: any) {// Use dynamic imports to ensure compatibilityconst { extend, cond, matches } = await import("https://esm.sh/lodash-es");// Since Val Town doesn't support direct environment variable access,// we'll modify the approach to require API keys to be passed inconst args = extend({callbacks: options?.verbose !== false ? [] : undefined}, options);// Simplified model builder setupconst setup = cond([[matches({ type: "llm", provider: "openai" }),async () => {const { OpenAI } = await import("https://esm.sh/langchain/llms/openai");return new OpenAI(args);},],[matches({ type: "chat", provider: "openai" }),async () => {const { ChatOpenAI } = await import("https://esm.sh/langchain/chat_models/openai");return new ChatOpenAI(args);},],[matches({ type: "embedding", provider: "openai" }),async () => {const { OpenAIEmbeddings } = await import("https://esm.sh/langchain/embeddings/openai");return new OpenAIEmbeddings(args);},], - Open: VersionChanges from v3 to v4+0-1
//從 webup 而來// 1. 從 node 中導入 process 模組import process from "node:process";⦚ 75 unchanged lines ⦚// 1. 從 node 中導入 process 模組import process from "node:process";⦚ 75 unchanged lines ⦚ - Open: VersionChanges from v2 to v3+1-0// 1. 從 node 中導入 process 模組import process from "node:process";⦚ 75 unchanged lines ⦚//從 webup 而來// 1. 從 node 中導入 process 模組import process from "node:process";⦚ 75 unchanged lines ⦚
- Open: VersionChanges from v1 to v2+12-5import process from "node:process";export async function getModelBuilder(spec: {type?: "llm" | "chat" | "embedding";provider?: "openai" | "huggingface";} = { type: "llm", provider: "openai" }, options?: any) {
const { extend, cond, matches, invoke } = await import("npm:lodash-es");// Set up LangSmith tracerconst { Client } = await import("npm:langsmith");const { LangChainTracer } = await import("npm:langchain/callbacks");⦚ 4 unchanged lines ⦚const tracer = new LangChainTracer({ client });const callbacks = options?.verbose !== false ? [tracer] : [];// Set up API key for each providersconst args = extend({ callbacks }, options);if (spec?.provider === "openai")args.openAIApiKey = process.env.OPENAI;else if (spec?.provider === "huggingface")args.apiKey = process.env.HUGGINGFACE;// Populate model buildersconst setup = cond([[⦚ 39 unchanged lines ⦚],]);// Return function to prevent "Serialization Error"return () => setup(spec);}// 1. 從 node 中導入 process 模組import process from "node:process";// 2. 導出一個異步函數 getModelBuilderexport async function getModelBuilder(spec: {type?: "llm" | "chat" | "embedding";provider?: "openai" | "huggingface";} = { type: "llm", provider: "openai" }, options?: any) {// 3. 從 lodash-es 中導入函數const { extend, cond, matches, invoke } = await import("npm:lodash-es");// 4. 設置 LangSmith 追蹤器const { Client } = await import("npm:langsmith");const { LangChainTracer } = await import("npm:langchain/callbacks");⦚ 4 unchanged lines ⦚const tracer = new LangChainTracer({ client });const callbacks = options?.verbose !== false ? [tracer] : [];// 5. 為每個提供者設置 API 密鑰const args = extend({ callbacks }, options);if (spec?.provider === "openai")args.openAIApiKey = process.env.OPENAI;else if (spec?.provider === "huggingface")args.apiKey = process.env.HUGGINGFACE;// 6. 填充模型構建器const setup = cond([[⦚ 39 unchanged lines ⦚],]);// 7. 返回函數以防止 "Serialization Error"return () => setup(spec); - Open: VersionChanges from v0 to v1+69-0import process from "node:process";export async function getModelBuilder(spec: {type?: "llm" | "chat" | "embedding";provider?: "openai" | "huggingface";} = { type: "llm", provider: "openai" }, options?: any) {const { extend, cond, matches, invoke } = await import("npm:lodash-es");// Set up LangSmith tracerconst { Client } = await import("npm:langsmith");const { LangChainTracer } = await import("npm:langchain/callbacks");const client = new Client({apiUrl: "https://api.smith.langchain.com",apiKey: process.env.LANGSMITH,});const tracer = new LangChainTracer({ client });const callbacks = options?.verbose !== false ? [tracer] : [];// Set up API key for each providersconst args = extend({ callbacks }, options);if (spec?.provider === "openai")args.openAIApiKey = process.env.OPENAI;else if (spec?.provider === "huggingface")args.apiKey = process.env.HUGGINGFACE;// Populate model buildersconst setup = cond([[matches({ type: "llm", provider: "openai" }),async () => {const { OpenAI } = await import("npm:langchain/llms/openai");return new OpenAI(args);},],[matches({ type: "chat", provider: "openai" }),async () => {const { ChatOpenAI } = await import("npm:langchain/chat_models/openai");return new ChatOpenAI(args);
- Open: Version+0-0
Updated: December 20, 2024