Versions

  • v6

    12/20/2024
    Open: Version
    Changes from v5 to v6
    +8
    -7
    export async function getModelBuilder(spec: {
    type?: "llm" | "chat" | "embedding";
    provider?: "openai" | "huggingface";
    } = { type: "llm", provider: "openai" }, options?: any) {
    // Use dynamic imports to ensure compatibility
    const { 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 in
    const args = extend({
    callbacks: options?.verbose !== false ? [] : undefined
    }, options);

    // Simplified model builder setup
    const setup = cond([
    [
    ⦚ 36 unchanged lines ⦚
    ]);

    // Return function to prevent serialization errors
    return () => setup(spec);
    }

    // Add a default export to make the val more flexible
    export default getModelBuilder;
    // 1. 定義一個異步函數 getModelBuilder
    export 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;

  • v5

    12/19/2024
    Open: Version
    Changes from v4 to v5
    +20
    -36
    // 1. 從 node 中導入 process 模組
    import process from "node:process";

    // 2. 導出一個異步函數 getModelBuilder
    export 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 compatibility
    const { 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 in
    const args = extend({
    callbacks: options?.verbose !== false ? [] : undefined
    }, options);

    // Simplified model builder setup
    const 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);
    },
    ],
  • v4

    12/19/2024
    Open: Version
    Changes 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 ⦚
  • v3

    12/19/2024
    Open: Version
    Changes 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 ⦚
  • v2

    12/19/2024
    Open: Version
    Changes from v1 to v2
    +12
    -5
    import 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 tracer
    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] : [];
    // Set up API key for each providers
    const 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 builders
    const setup = cond([
    [
    ⦚ 39 unchanged lines ⦚
    ],
    ]);
    // Return function to prevent "Serialization Error"
    return () => setup(spec);
    }
    // 1. 從 node 中導入 process 模組
    import process from "node:process";

    // 2. 導出一個異步函數 getModelBuilder
    export 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);
  • v1

    12/19/2024
    Open: Version
    Changes from v0 to v1
    +69
    -0

    import 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 tracer
    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] : [];
    // Set up API key for each providers
    const 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 builders
    const 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);
  • v0

    12/19/2024
    Open: Version
    +0
    -0


1
Next
Updated: December 20, 2024