摘要: Creational patterns provide object creation mechanisms that increase flexibility and reuse of existing code. Factory method: Provides an interface for 阅读全文
posted @ 2024-01-23 15:11 Zhentiw 阅读(10) 评论(0) 推荐(0)
摘要: Just for fun... Given a number (always positive) as a type. Your type should return the number decreased by one. For example: type Zero = MinusOne<1> 阅读全文
posted @ 2022-10-07 22:57 Zhentiw 阅读(54) 评论(0) 推荐(0)
摘要: Blog: https://www.geeksforgeeks.org/es6-trampoline-function/ Stackoverflow problem for recursion: const sumBelow = (number, sum = 0) => ( number 0 ? s 阅读全文
posted @ 2022-08-18 14:32 Zhentiw 阅读(43) 评论(0) 推荐(0)
摘要: Serverless framework with AWS Link to each sections Table of Content: Part 0: Serverless Project structure Part 1: DynamoDB & ApiGateway Part 2: Event 阅读全文
posted @ 2021-05-17 15:15 Zhentiw 阅读(158) 评论(0) 推荐(0)
摘要: Storage Services: S3 Glacier CloudFront Elastic Block Store (EBS) Storage Gateway Snow family Database Overview Block storage: Used on local networks 阅读全文
posted @ 2021-03-15 03:06 Zhentiw 阅读(154) 评论(0) 推荐(0)
摘要: S3 Features Prefiees and delimiters For example: the file name in S3 can be: `marking/plans/kpi_2021_1.pdf`. The point is make it looks like a folder 阅读全文
posted @ 2021-03-12 17:34 Zhentiw 阅读(148) 评论(0) 推荐(0)
摘要: In our previous code, we have seen this partten for operators: // #region operators const concat = curry((broadcaster, listener) => { let string = ''; 阅读全文
posted @ 2020-10-25 21:54 Zhentiw 阅读(157) 评论(0) 推荐(0)
该文被密码保护。 阅读全文
posted @ 2020-05-07 18:22 Zhentiw 阅读(0) 评论(0) 推荐(0)
摘要: Generators can yield promises which can work with the "for await of" loop syntax. This lesson shows how all the pieces fit together and explains why t 阅读全文
posted @ 2020-03-22 02:59 Zhentiw 阅读(168) 评论(0) 推荐(0)
摘要: In this post, we are going to see how to use Ramda Lens. For example, we have data: R.lens: R.lens takes a getter and a setter: R.lensProp: There is a 阅读全文
posted @ 2019-02-24 20:12 Zhentiw 阅读(714) 评论(0) 推荐(0)
摘要: Just like the State ADT an Array is also an Applicative Functor. That means we can do the same tricks with liftA2 with Array that we have been doing w 阅读全文
posted @ 2019-01-16 16:30 Zhentiw 阅读(714) 评论(0) 推荐(0)
摘要: Use custom Cypress command for reusable assertions We’re duplicating quite a few commands between the registration and login of our user for assertion 阅读全文
posted @ 2018-12-06 21:13 Zhentiw 阅读(435) 评论(0) 推荐(0)
摘要: Use Cypress to test user registration Let’s write a test to fill out our registration form. Because we’ll be running this against a live backend, we n 阅读全文
posted @ 2018-12-05 15:54 Zhentiw 阅读(360) 评论(0) 推荐(0)
摘要: Despite the fact that Cypress is an application that runs natively on your machine, you can install it and add it as a dependency just like all other 阅读全文
posted @ 2018-12-05 02:38 Zhentiw 阅读(573) 评论(0) 推荐(0)
摘要: Ensure Functions are Called Correctly with JavaScript Mocks Often when writing JavaScript tests and mocking dependencies, you’ll want to verify that t 阅读全文
posted @ 2018-11-06 04:25 Zhentiw 阅读(433) 评论(0) 推荐(0)
摘要: 1. Color Picker (Chrome) You might know how to use color picker in Chrome, recently there is a feature inside color picker which is "Contrast Ratio", 阅读全文
posted @ 2018-07-15 18:41 Zhentiw 阅读(244) 评论(0) 推荐(0)
摘要: We'll examine how to unnest function calls, capture assignment, and create a linear data flow with a type we call Box. This is our introduction to wor 阅读全文
posted @ 2016-12-11 21:47 Zhentiw 阅读(332) 评论(0) 推荐(0)
摘要: Well, this stuff will be a little bit strange if you deal with it first time. Container Object: Just a wrapper / contianer for values No Method No Nou 阅读全文
posted @ 2016-09-06 04:23 Zhentiw 阅读(344) 评论(0) 推荐(0)
摘要: First, what is 'High Order function', basic just a function, inside the function return another fuction. For example: Decorators is a subset of high o 阅读全文
posted @ 2016-06-14 03:10 Zhentiw 阅读(381) 评论(0) 推荐(0)
摘要: Somehow it looks like reflect in Java. For example: We define an mothod on the Object, it called defineMethod(). It accepts two arguements, one is met 阅读全文
posted @ 2016-05-02 03:06 Zhentiw 阅读(384) 评论(0) 推荐(0)
import { ollama } from "ollama-ai-provider";
import { generateObject, generateText } from "ai";
import { z } from "zod";
import { globby } from "globby";
import { parseArgs } from "node:util";
import { readFile } from "node:fs/promises";
import path from "node:path";

const { positionals } = parseArgs({
  allowPositionals: true,
});

const model = ollama("gemma3:latest");

const objectPrompt = positionals[0];

const fileTypes = ["md", "txt"] as const;
// generateObject to pull out the file type
const { object: fileTypeObject } = await generateObject({
  model,
  schema: z.object({
    fileType: z
      .string()
      .describe(
        `The file type to process. My file types are: ${fileTypes.join(", ")}}`
      )
      .optional(),
  }),
  prompt: `
  Based on the following user request, determine the most relevant file type to search.
  If no file type if mentioned or implied, please return an empty string.
  User Request: "${objectPrompt}"
  `,
});

if (!fileTypeObject.fileType) {
  console.error(
    `No file type found. Only one of the following file types is allowed: ${fileTypes.join(
      ", "
    )}`
  );
  process.exit(1);
}

const files = await globby(`*.${fileTypeObject.fileType}`, { gitignore: true });
console.log(files);
const isNonEmpty = (files: string[]): files is [string, ...string[]] => {
  return files.length > 0;
};

if (!isNonEmpty(files)) {
  console.error("No files found");
  process.exit(1);
}

const commandFilePaths = await globby("commands/*.md", {
  gitignore: true,
});

const commandMap = new Map<string, string>();

for (const commandFilePath of commandFilePaths) {
  const commandName = path.parse(commandFilePath).name;
  const commandContent = await readFile(commandFilePath, "utf-8");
  commandMap.set(commandName, commandContent);
}

const validCommands = Array.from(commandMap.keys()) as [string, ...string[]];

const { object } = await generateObject({
  model,
  schema: z.object({
    command: z.enum(validCommands).describe(`The command to execute}`),
    filePath: z.enum(files).describe("The path to the files to prcess"),
  }),
  prompt: objectPrompt,
}).catch((err) => {
  console.error(`Model generated an invalid reponse for ${objectPrompt}`);
  process.exit(1);
});

type Command = (typeof validCommands)[number];
const isValidCommand = (cmd: unknown): cmd is Command => {
  return (
    typeof cmd === "string" &&
    (validCommands as readonly string[]).includes(cmd)
  );
};

if (!isValidCommand(object.command)) {
  console.error("Invalid command");
  process.exit(1);
}

const content = await readFile(object.filePath, "utf-8");

const textPrompt = `
<command>
${object.command}
</command>

<instructions>
${commandMap.get(object.command)}
</instructions>

<content>
${content}
</content>
`;

const { text } = await generateText({
  model,
  prompt: textPrompt,
});
console.log(text);

 

posted @ 2025-07-19 21:32 Zhentiw 阅读(7) 评论(0) 推荐(0)
摘要: import { ollama } from "ollama-ai-provider"; import { generateObject, generateText } from "ai"; import { z } from "zod"; import { globby } from "globb 阅读全文
posted @ 2025-07-19 21:06 Zhentiw 阅读(8) 评论(0) 推荐(0)
摘要: NLP 发展的4个阶段: 阶段 时间 方法 / 模型 类型 主要用途 是否考虑词序 / 语义 规则阶段 1950s–1970s 语法规则、人工模板 人工构建规则系统 机器翻译、问答系统 ✅ 语法结构,❌语义 统计阶段 1970s–2010s Bag-of-Words (BoW) 特征表示方法 文本分 阅读全文
posted @ 2025-07-19 20:53 Zhentiw 阅读(10) 评论(0) 推荐(0)
摘要: How vue-router solve the problem: function changeLocation( to: HistoryLocation, state: StateEntry, replace: boolean ): void { /** * if a base tag is p 阅读全文
posted @ 2025-07-18 14:14 Zhentiw 阅读(6) 评论(0) 推荐(0)
摘要: history 是浏览器环境中所支持的一个对象,该对象用于管理当前创建最近访问过的 URL 历史记录,所有的 URL 会被存储在一个名为 histroy 的对象里面,回头就可以通过 JS 脚本调用 history 对象的方法从而控制浏览器前进或者后退。 例如打开浏览器,新创建一个标签页会话,然后在控 阅读全文
posted @ 2025-07-16 14:24 Zhentiw 阅读(8) 评论(0) 推荐(0)
摘要: Overriding a function lets you wrap a third-party method with your own logic while still invoking its original behavior. Example code: const unmountAp 阅读全文
posted @ 2025-07-15 13:50 Zhentiw 阅读(7) 评论(0) 推荐(0)
摘要: import { ollama } from "ollama-ai-provider"; import { generateObject, generateText } from "ai"; import { z } from "zod"; import { globby } from "globb 阅读全文
posted @ 2025-07-05 19:06 Zhentiw 阅读(6) 评论(0) 推荐(0)
摘要: import { ollama } from "ollama-ai-provider"; import { generateObject } from "ai"; import { z } from "zod"; import { globby } from "globby"; import { p 阅读全文
posted @ 2025-07-05 18:55 Zhentiw 阅读(3) 评论(0) 推荐(0)
摘要: import { ollama } from "ollama-ai-provider"; import { generateObject } from "ai"; import { z } from "zod"; import { parseArgs } from "node:util"; cons 阅读全文
posted @ 2025-07-05 18:40 Zhentiw 阅读(4) 评论(0) 推荐(0)
摘要: Run: ollama run gemma3 import { ollama } from "ollama-ai-provider"; import { generateObject } from "ai"; import { z } from "zod"; const model = ollama 阅读全文
posted @ 2025-07-05 18:37 Zhentiw 阅读(9) 评论(0) 推荐(0)
点击右上角即可分享
微信分享提示