Sure, here's the translation in simplified Chinese, keeping the HTML structure: ```html

一个基本的LangChain.js链,具有提示模板、结构化JSON输出和OpenAI / Ollama LLMs。

``` In this HTML snippet, `

` tags are used to maintain the structure while providing the translated text in simplified Chinese.

Sure, here's the translation in simplified Chinese while keeping the HTML structure: ```html

Typescript开发者的逐步指南

``` This HTML snippet translates "A step-by-step guide for Typescript developers" to "Typescript开发者的逐步指南" in simplified Chinese.

Sure, here is the translation in simplified Chinese, while keeping the HTML structure intact: ```html 这是我AI增强开发系列的第四部分: ``` This HTML snippet maintains the structure you requested while providing the translation in simplified Chinese.

  • Sure, here's the translation in simplified Chinese while keeping the HTML structure: ```html

    介绍总结了最近的变化,使得在TypeScript中轻松进行AI应用原型设计成为可能。

    ```
  • 在第二篇文章中,涵盖了安装 Jupyter Lab IDE 及用于快速原型设计的工具。
  • 在HTML结构中保持不变,将以下英文文本翻译为简体中文: 第三部分讲解了如何使用JupyterLab,并演示了基本的编码工作流程。

Sure, here is the simplified Chinese translation of the provided text, keeping the HTML structure intact: ```html

本文重点介绍“文本审阅者”应用的第一部分。正如我在介绍中所解释的那样,该应用分为两个步骤:

``` This HTML snippet includes the translated text in simplified Chinese.
  1. Sure, here's the translation in simplified Chinese, maintaining the HTML structure: ```html 用户输入文本,由语言模型(LLM)审查并改进。 ``` In this HTML snippet, the Chinese text is inserted between `` and `` tags, following the structure you mentioned.
  2. Certainly! Here is the translated text in simplified Chinese, keeping the HTML structure: ```html 工具将LLM的结果与原始文本进行比较,并显示更改。 ``` This HTML code embeds the translated Chinese text while maintaining the HTML structure as requested.

Sure, here's the simplified Chinese translation while keeping the HTML structure: ```html 我们将在这里介绍第一步,展示一个基本的LangChain链,用于审查和改进文本。 ``` In this translation: - "我们将在这里介绍" corresponds to "We’ll cover here". - "第一步" means "first step". - "基本的LangChain链" translates to "basic LangChain chain". - "用于审查和改进文本" means "that reviews and improves text".

Sure, here is the translated text in simplified Chinese while keeping the HTML structure intact: ```html

第二步不使用语言模型。如果我们要求语言模型列出与原始文本相比的更改,通常会返回不正确或不完整的结果。这些模型可以生成文本输出或改进文本的质量,但它们在算法任务上表现不佳。它们处理提示并尝试预测预期的答案。它们不会“思考”或具备类似人类的逻辑能力。但是,我们可以使用语言模型生成文本比较函数的源代码。在未来的文章中,我们将使用LLM生成文本比较的代码。

``` This HTML snippet contains the translated text in simplified Chinese within a paragraph (`

` tag).

```html

语言模型可以以不同的格式进行响应,例如Markdown、JSON或XML。在下面的示例中,我们要求模型以预定义的架构提供JSON响应。如果架构简单且响应中不包含许多特殊字符,JSON响应效果很好。

```

Sure, here's how you would structure the HTML with the translated text in simplified Chinese: ```html
提示模板
OpenAI 模型
JSON 输出
``` This HTML structure keeps the original English terms as classes for styling purposes while displaying the simplified Chinese translations as content.

在下面的示例中,我们使用以下签名实现了 reviewTextOpenAI 函数。

/**
* Reviews and corrects the input text using OpenAI's GPT-4o model.
*
* @param instruction - Instructions to be given to the model.
* @param inputText - The text to be reviewed and corrected.
* @returns - The reviewed and corrected text, or undefined if the response is invalid.
*/
reviewTextOpenAI(instruction: string, inputText: string): Promise<string | undefined>

Sure, here's how you can structure the HTML to display the text in simplified Chinese: ```html

Example function call and output

示例函数调用和输出

``` In this HTML structure: - `` declares the document type and version. - `` sets the language of the document to simplified Chinese. - `` ensures proper character encoding. - `` adjusts the page's viewport for responsive design. - `Example function call and output` provides the title of the webpage. - `

示例函数调用和输出

` is the heading in simplified Chinese that translates to "Example function call and output".
// Define the instruction and input text for the prompt
const instruction = "Fix the grammar issues in the following text.";
const inputText = "How to stays relevant as the developer in the world of ai?";// Log the result of the review function (OpenAI version)

console.log(await reviewTextOpenAI(instruction, inputText));
// CONSOLE: How to stay relevant as a developer in the world of AI?

Sure, here is the translation in simplified Chinese while maintaining the HTML structure: ```html reviewTextOpenAI 函数的功能如下: ```

  • 在保持HTML结构的前提下,将以下英文文本翻译为简体中文: 创建一个提示模板。
  • Sure, here's how you can express "Defines a JSON schema using Zod" in simplified Chinese while keeping HTML structure: ```html 定义使用 Zod 的 JSON 模式。 ``` This HTML structure surrounds the Chinese text with `` and `` tags: ```html 定义使用 Zod 的 JSON 模式。 ```
  • Sure, here's the translation in simplified Chinese while keeping the HTML structure: ```html

    创建一个语言模型(GPT-4o)包装器,以我们定义的JSON模式返回响应。我们使用 .withStructuredOutput 方法从模型获取JSON输出。

    ``` Translated text in simplified Chinese: ```html

    创建一个语言模型(GPT-4o)包装器,以我们定义的JSON模式返回响应。我们使用 .withStructuredOutput 方法从模型获取JSON输出。

    ```
  • 保持HTML结构,将以下英文文本翻译为简体中文: 连接提示模板与语言模型以创建一个链条。
  • 保持HTML结构,将以下英文文本翻译为简体中文: 使用提供的inputText和instruction调用该链。

To translate the text "Here is the complete code for the function (you can download it in a Jupyter Notebook)" into simplified Chinese while keeping the HTML structure, you can use the following: ```html 这里是函数的完整代码(您可以在 Jupyter Notebook 中下载它): ``` This HTML snippet ensures that the translated Chinese text is formatted and presented clearly within the HTML structure.

/**
* Reviews and corrects the input text using OpenAI's GPT-4o model.
*
* @param instruction - Instructions to be given to the model.
* @param inputText - The text to be reviewed and corrected.
* @returns - The reviewed and corrected text, or undefined if the response is invalid.
*/
async function reviewTextOpenAI(instruction: string, inputText: string): Promise<string | undefined> {
// Create a prompt template using the provided instruction and input text
const prompt = PromptTemplate.fromTemplate(
`{instruction}
---
{inputText}`);
// Initialize the OpenAI chat model with specified options
const llm = new ChatOpenAI({
modelName: "gpt-4o", // Use the GPT-4 model
verbose: false, // Disable verbose logging
});
// Define the schema for the model's output, it contains the reviewed text
const reviewedTextSchema = z.object({
reviewedText: z.string().describe("The reviewed text.") // The reviewed text must be a string
});
type ReviewedTextSchema = z.infer<typeof reviewedTextSchema>; // Infer the TypeScript type from the Zod schema
// We expect structured JSON output, we achieve this using OpenAI's function calling feature
const llmWithStructuredOutput = llm.withStructuredOutput(reviewedTextSchema, {
method: "functionCalling",
name: "withStructuredOutput"
});
// Create a processing chain combining the prompt and the LLM
const chain = prompt.pipe(llmWithStructuredOutput);
// Invoke the chain with the instruction and input text, and wait for the response
const response: ReviewedTextSchema = await chain.invoke({ instruction, inputText });
// Return the reviewed text if present in the response, otherwise undefined
return response?.reviewedText;
}
// Define the instruction and input text for the prompt
const instruction = "Fix the grammar issues in the following text.";
const inputText = "How to stays relevant as the developer in the world of ai?";
// show the reviewed text returned by the LLM
console.log(await reviewTextOpenAI(instruction, inputText));

To translate "Let’s break down each part of the code. The function reviewTextOpenAI takes two parameters: an instruction and the input text. It returns a reviewed and corrected text or undefined if the response is invalid:" into simplified Chinese while keeping the HTML structure intact, you can use the following: ```html 让我们逐步分析代码的每个部分。函数 reviewTextOpenAI 接受两个参数:一个指令和输入文本。它返回一个经过审阅和校正的文本,如果响应无效则返回 undefined: ``` This HTML snippet includes the translated text in simplified Chinese, formatted for display within an HTML document.

async function reviewTextOpenAI(instruction: string, inputText: string): Promise<string | undefined> {

To translate the English text into simplified Chinese and keep the HTML structure intact, you can use the following code snippet: ```html

我们使用声明式LangChain表达语言(LCEL)来组合链条。我们链条的第一个元素是提示模板,具有两个参数:指示和输入文本。在执行链条时,我们为这些参数赋值。

``` This HTML code preserves the structure while presenting the translated Chinese text.
const prompt = PromptTemplate.fromTemplate(
`{instruction}
---
{inputText}`);

在保持HTML结构的情况下,将以下英文文本翻译为简体中文: 我们初始化OpenAI聊天模型封装器。我们使用gpt-4o模型,并禁用详细日志记录。在这里了解更多关于ChatOpenAI模型封装器的信息。

const llm = new ChatOpenAI({
modelName: "gpt-4o",
verbose: false,
});

Sure, here's the translated text in simplified Chinese while keeping the HTML structure: ```html 我们使用 Zod 库定义模型输出的模式。该模式指定输出应具有属性 reviewedText,其必须是一个字符串。然后,我们使用 z.infer 从这个模式创建 TypeScript 类型。这确保我们的代码准确知道要期望的数据类型。 ``` This text maintains the original meaning and structure, suitable for embedding in HTML.

const reviewedTextSchema = z.object({
reviewedText: z.string().describe("The reviewed text.")
});
type ReviewedTextSchema = z.infer<typeof reviewedTextSchema>; // Infer the TypeScript type from the Zod schema

Sure, here's the text translated into simplified Chinese while keeping the HTML structure: ```html

我们使用Langchain的.withStructuredOutput()方法配置模型,以生成结构化的JSON输出:

```
const llmWithStructuredOutput = llm.withStructuredOutput(reviewedTextSchema, {
method: "functionCalling",
name: "withStructuredOutput"
});

Sure, here's the HTML structure with the translated text in simplified Chinese: ```html

我们创建了一个处理链,将提示与配置为结构化输出的模型结合起来。在这里了解更多关于Langchain的LCEL链和pipe()方法。

``` In simplified Chinese, the translation of the text is: "我们创建了一个处理链,将提示与配置为结构化输出的模型结合起来。在这里了解更多关于Langchain的LCEL链和pipe()方法。"
const chain = prompt.pipe(llmWithStructuredOutput);

Sure, here's the translated text in simplified Chinese, while maintaining the HTML structure: ```html

最后,我们使用指令和输入文本调用处理链,然后等待响应。如果响应中存在已审核的文本,我们将返回该文本。否则,我们将返回未定义。

```
const response: ReviewedTextSchema = await chain.invoke({ instruction, inputText });   
return response?.reviewedText;

Sure, here's the translation in simplified Chinese while keeping the HTML structure: ```html

OpenAI API 需要 API 密钥。在 JupyterLab 中,我们通过 OPENAI_API_KEY 环境变量提供此密钥,因此我们需要创建一个带有 OpenAI API 密钥的 .env 文件:

``` This HTML snippet presents the translated text clearly while maintaining the structure for web or document formatting.
OPENAI_API_KEY=[your OpenAI API key]

To translate the given English text into simplified Chinese while keeping the HTML structure intact, you can use the following: ```html 然后我们使用导入语句 "https://deno.land/std@0.215.0/dotenv/load.ts"; 来读取 .env 文件并设置环境变量。 ``` This translation maintains the original structure and effectively conveys the meaning in simplified Chinese.

Sure, here's the translation in simplified Chinese while keeping the HTML structure intact: ```html

提示模板 + Ollama模型 + JSON输出

```

Sure, here's the translated text in simplified Chinese, keeping the HTML structure intact: ```html Ollama-based 模型需要不同的方法来生成 JSON 输出。LangChain 的 .withStructuredOutput 尚不支持 Ollama,因此我们使用 OllamaFunctions 包装器的函数调用功能。 ``` This text preserves the original meaning while translating it into simplified Chinese.

Certainly! Here's how you could structure your HTML while displaying the translated text in simplified Chinese: ```html

Example function call and output

示例函数调用及输出

``` In this example: - `lang="zh-CN"` specifies the language as simplified Chinese. - `

示例函数调用及输出

` is the heading translated to simplified Chinese. Make sure to replace `` with the rest of your HTML content.
// Define the instruction and input text for the prompt
const instruction = "Fix the grammar issues in the following text.";
const inputText = "How to stays relevant as the developer in the world of ai?";

// Log the result of the review function (Ollama version)
console.log(await reviewTextOllama(instruction, inputText));
// CONSOLE: How to stay relevant as a developer in the world of AI?

Sure, here's the translation of the text into simplified Chinese, while maintaining the HTML structure: ```html

步骤与OpenAI实现的步骤类似,只有一个区别:获取JSON输出的方法不同。reviewTextOllama函数执行以下操作:

``` This HTML snippet retains the original English structure and provides the translated text in simplified Chinese.
  • 在保持HTML结构的情况下,将英文文本 "Creates a prompt template." 翻译成简体中文可以是: 创建一个提示模板。
  • 在保留HTML结构的情况下,将以下英文文本翻译为简体中文: 使用Zod定义一个JSON模式。
  • 在保留HTML结构的前提下,将以下英文文本翻译成简体中文: 创建一个LLM(Ollama / Codellama)包装器,按照我们的JSON模式定义的格式返回响应。我们使用函数调用从模型获取JSON输出。
  • 在保持HTML结构的情况下,将以下英文文本翻译为简体中文: 连接提示模板与语言模型以创建一个链条。
  • Sure, here's the translation in simplified Chinese while keeping the HTML structure: ```html Calls the chain with the given inputText and instruction ``` In the translation: - `inputText` and `instruction` are placeholders indicating where the translated text would appear in the HTML structure while specifying the language as simplified Chinese (`zh-CN`).

To translate the English text "Here is the complete code for the function (you can download it in a Jupyter Notebook)" into simplified Chinese while keeping the HTML structure, you would write: ```html 这里是该函数的完整代码(您可以在Jupyter Notebook中下载它): ``` This HTML structure maintains the original English sentence while providing the translated Chinese text.

/**
* Processes a given text using a language model to review and correct it based on the provided instruction.
*
* @param instruction - Instruction for the language model on how to process the text.
* @param inputText - The text that needs to be reviewed and corrected.
* @returns The reviewed text if successful, otherwise undefined.
*/
async function reviewTextOllama(instruction: string, inputText: string): Promise<string | undefined> {
// Create a prompt template by combining the instruction and input text
const prompt = PromptTemplate.fromTemplate(
`{instruction}
---
{inputText}`);
// Define a schema for the expected output using zod
const reviewedTextSchema = z.object({
reviewedText: z.string().describe("The reviewed text.") // Define the structure and description of the reviewed text
});
type ReviewedTextSchema = z.infer<typeof reviewedTextSchema>; // Infer the TypeScript type from the zod schema
// Initialize the language model with specific configuration
const llm = new OllamaFunctions({
baseUrl: "http://localhost:11434", // Base URL for the language model server
model: "codellama:7b-code", // Specify the model to use
verbose: false, // Disable verbose logging
}).bind({
functions: [
{
name: "storeResultTool", // Function name used in the language model
description: "Gets the reviewed text", // Description of the function
parameters: {
type: "object", // Define the type of parameters expected by the function
properties: zodToJsonSchema(reviewedTextSchema), // Convert zod schema to JSON schema
},
},
],
function_call: {
name: "storeResultTool", // Specify the function to be called
},
});
// Create a processing chain: prompt -> language model -> JSON output parser
const chain = prompt.pipe(llm).pipe(new JsonOutputFunctionsParser());
// Invoke the chain with the instruction and input text
const response = await chain.invoke({ instruction, inputText });
// Return the reviewed text if available
return response?.reviewedText;
}
// Define the instruction and input text for the prompt
const instruction = "Fix the grammar issues in the following text.";
const inputText = "How to stays relevant as the developer in the world of ai?";
// Log the result of the review function
console.log(await reviewTextOllama(instruction, inputText));

Sure, here's the translation in simplified Chinese while keeping the HTML structure intact: ```html 让我们看看如何设置 Ollama 包装器以在我们的代码中使用 codellama 模型,并获取 JSON 响应。 ``` In HTML format: ```html 让我们看看如何设置 Ollama 包装器以在我们的代码中使用 codellama 模型,并获取 JSON 响应。 ```

// Initialize the language model with specific configuration
const llm = new OllamaFunctions({
baseUrl: "http://localhost:11434", // Base URL for the language model server
model: "codellama:7b-code", // Specify the model to use
verbose: false, // Enable verbose logging
}).bind({
functions: [
{
name: "storeResultTool", // Function name used in the language model
description: "Gets the reviewed text", // Description of the function
parameters: {
type: "object", // Define the type of parameters expected by the function
properties: zodToJsonSchema(reviewedTextSchema), // Convert zod schema to JSON schema
},
},
],
function_call: {
name: "storeResultTool", // Specify the function to be called
},
});

Sure, here's the translated text in simplified Chinese, formatted within an HTML structure: ```html

当我们创建 Ollama 包装器(OllamaFunctions)时,我们向其传递一个配置对象,其中包含模型的名称和 Ollama 服务器的 baseUrl。我们在创建的 OllamaFunctions 实例上使用 .bind 函数来定义 storeResultTool 函数。这个函数的参数具有 reviewedTextSchema 架构,这是我们期望的响应的架构。function_call.name = 'storeResultTool' 配置选项强制模型将响应发送到 storeResultTool 函数。

``` This HTML snippet preserves the structure while presenting the translated text in simplified Chinese.

Sure, here's the translated text in simplified Chinese while keeping the HTML structure: ```html

我们创建了一个处理链,结合了提示和为结构化输出配置的模型。与OpenAI的实现相比,这个链多了一步:使用JsonOutputFunctionsParser将JSON输出字符串转换为对象:

``` This HTML snippet preserves the translated Chinese text within a paragraph (`

` tag).

// Create a processing chain: prompt -> language model -> JSON output parser
const chain = prompt.pipe(llm).pipe(new JsonOutputFunctionsParser());

Certainly! The translation of "Summary" in simplified Chinese while keeping the HTML structure would be: ```html 总结 ``` This HTML code wraps the Chinese translation in a `` tag, preserving the structure of the document.

```html

恭喜您完成了本教程!在AI增强开发系列的第四部分中,我展示了如何使用LangChain.js创建基本的LLM链。我们使用了提示模板,获得了结构化的JSON输出,并与OpenAI和Ollama LLMs集成。在下一篇文章中,我将展示如何生成一个函数,逐字符比较两个字符串,并返回差异的HTML字符串。非常令人兴奋,请务必订阅!

```

To translate "👨‍💻About the author" into simplified Chinese while keeping the HTML structure intact, you would write: ```html 👨‍💻关于作者 ```

To translate the given English text into simplified Chinese while keeping HTML structure, you can use the following code snippet: ```html

我的名字是Gergely Szerovay,我曾经担任数据科学家和全栈开发人员多年,目前作为前端技术负责人,专注于基于Angular的前端开发。作为我的职责的一部分,我不断关注Angular和整体前端开发领域的发展。

``` This HTML code wraps the translated Chinese text in a paragraph (`

`) tag, preserving the structure of the content while presenting it in simplified Chinese.

Sure, here's the translated text in simplified Chinese while keeping the HTML structure intact: ```html Angular在过去几年中发展迅速,特别是在过去一年,随着生成AI技术的兴起,我们的软件开发工作流也在快速进化。为了紧密跟随AI辅助软件开发的进展,我决定开始在公开场合构建AI工具,并在AIBoosted.dev上发布我的进展。在这里订阅 🚀 ``` This HTML snippet translates the provided English text into simplified Chinese and includes the link with the rocket emoji at the end.

Sure, here's the text translated into simplified Chinese while keeping the HTML structure intact: ```html Follow me on Substack (Angular Addicts), Substack (AIBoosted.dev), Medium, Dev.to, X, or LinkedIn to learn more about Angular, and how to build AI apps with AI, Typescript, React and Angular! ``` Translated text in Chinese: ```html 关注我的 Substack (Angular Addicts), Substack (AIBoosted.dev), Medium, Dev.to, X 或者 LinkedIn,了解更多关于Angular的信息,以及如何使用AI、Typescript、React和Angular构建AI应用! ``` Ensure to replace `"https://example.com"` with the actual URLs of the respective platforms.

2024-06-28 04:27:30 AI中文站翻译自原文