LLMs 集成
了解如何使用 Nuxt Content 和 Nuxt LLMs 模块生成 AI 就绪的内容文件。
为 AI 准备的内容文件 (llms.txt)。
Nuxt Content 模块与 nuxt-llms 无缝集成,以准备你的内容以供大型语言模型 (LLM) 使用。当检测到 nuxt-llms 时,Content 模块会自动扩展 LLMs 模块并将 page 类型的集合注入到 LLMs 模块中。
设置指南
- 首先,安装所需的模块:
npm install nuxt-llms # or yarn add nuxt-llms - 配置你的
nuxt.config.ts:// nuxt.config.ts export default defineNuxtConfig({ modules: ['@nuxt/content', 'nuxt-llms'], llms: { domain: 'https://your-site.com', title: 'Your Site Name', description: 'A brief description of your site', }, })
就是这样!
Nuxt Content 将自动检测 Nuxt LLMs 模块,并将为每个 page 集合创建一个 section。
Sections
在生成内容时,您可以创建自定义 分段(sections),将内容处理成适合 LLM(大型语言模型)的格式。
您可以在 llms.sections 数组中创建自定义分段,并为每个分段定义 contentCollection(内容集合)和 contentFilters(内容过滤器)选项。
如果在
contentCollection 选项中没有定义任何分段,该模块将仅向 LLMs 模块添加页面类型的集合。contentCollection
该选项指定要用作来源的内容集合。
// nuxt.config.ts
export default defineNuxtConfig({
modules: ['@nuxt/content', 'nuxt-llms'],
llms: {
domain: 'https://your-site.com',
title: 'Your Site Name',
description: 'A brief description of your site',
sections: [
{
title: 'Documentation',
description: 'Technical documentation and guides',
// Specify which content collection to use
contentCollection: 'docs',
// Filter content as needed
contentFilters: [
{ field: 'extension', operator: '=', value: 'md' },
// You can add more filters here
]
},
],
},
})
如果没有使用
contentCollection 选项定义任何 section,该模块会将 page 集合添加到 LLMs 模块。contentFilters
你可以使用 contentFilters 精确控制包含哪些内容。每个过滤器包含:
field: 要检查的内容属性operator: 比较运算符 (=,<>,>,<,LIKE,IN,NOT IN,IS NULL,IS NOT NULL等)value: 要比较的值
nuxt.config.ts
export default defineNuxtConfig({
llms: {
sections: [
{
title: 'Documentation',
description: 'Technical documentation and guides',
contentCollection: 'docs',
contentFilters: [
// Only include markdown files
{ field: 'extension', operator: '=', value: 'md' },
// Only include published content
{ field: 'draft', operator: '<>', value: true },
// Filter by directory
{ field: 'path', operator: 'LIKE', value: '/guide%' },
]
},
],
},
})
示例过滤器:
contentFilters: [
// Only include markdown files
{ field: 'extension', operator: '=', value: 'md' },
// Only include published content
{ field: 'draft', operator: '<>', value: true },
// Filter by directory
{ field: 'path', operator: 'LIKE', value: '/guide%' },
]
查看 nuxt-llms 文档 以获取有关如何使用 LLMs 模块的更多信息。