Nuxt LLMs
Nuxt LLMsは、あなたのNuxtアプリケーションのためにllms.txtマークダウンドキュメントを自動的に生成します。様々なソース(CMS、Nuxt Contentなど)からデータを収集し、テキストベースの形式で構造化されたドキュメントを生成するためのランタイムフックを提供します。
機能
/llms.txtを自動的に生成&プリレンダリングします- 有効にすると
/llms-full.txtを生成&プリレンダリングします nuxt.config.tsから直接カスタマイズ可能なセクション- ランタイムフックシステムを介してNuxtモジュールとアプリケーションを統合します
クイックセットアップ
- モジュールのインストール
npm i nuxt-llms
nuxt.config.tsにnuxt-llmsを登録します
export default defineNuxtConfig({
modules: ['nuxt-llms']
})
- アプリケーションの詳細を設定します
export default defineNuxtConfig({
modules: ['nuxt-llms'],
llms: {
domain: 'https://example.com',
title: 'My Application',
description: 'My Application Description',
sections: [
{
title: 'Section 1',
description: 'Section 1 Description',
links: [
{
title: 'Link 1',
description: 'Link 1 Description',
href: '/link-1',
},
{
title: 'Link 2',
description: 'Link 2 Description',
href: '/link-2',
},
],
},
],
},
})
以上です!/llms.txtにアクセスすると、生成されたドキュメントを見ることができます✨
オプション
domain(必須): アプリケーションのドメインtitle: アプリケーションのタイトル。ドキュメントの最上部に表示されます。description: アプリケーションの説明。ドキュメントの最上部、タイトルの直後に表示されます。sections: ドキュメントのセクション。セクションは、タイトル、1つ以上の説明の段落、そして場合によってはリンクのリストで構成されます。各セクションは以下のプロパティを持つオブジェクトです。title(必須): セクションのタイトルdescription: セクションの説明links: セクションのリンクtitle(必須): リンクのタイトルdescription: リンクの説明href(必須): リンクのhref
notes: ドキュメントの注釈。注釈は常にドキュメントの最後に表示される特別なセクションです。注釈は、アプリケーションまたはドキュメント自体に関する情報を追加するのに役立ちます。full:llms-full.txtの設定。このオプションを設定すると、llms-full.txtルートが有効になります。title: llms-fullドキュメントのタイトルdescription: llms-fullドキュメントの説明
ドキュメント形式
このモジュールは2つの異なるドキュメント形式を生成します
llms.txt
/llms.txtルートは、llms.txt仕様に従った簡潔で構造化されたドキュメントを生成します。この形式は、人間の可読性とAIによる消費の両方に最適化されています。含まれるもの:
- アプリケーションのタイトルと説明
- タイトルと説明を持つ整理されたセクション
- タイトル、説明、URLを持つリンク
- オプションの注釈セクション
llms-full.txt
/llms-full.txtルートは、より詳細な自由形式のドキュメント形式を提供します。これは、アプリケーションのクローラーのトラフィックを削減し、ユーザーとLLMに詳細なドキュメントを提供するために役立ちます。
デフォルトでは、モジュールはllms-full.txtルートを生成しません。nuxt.config.tsでfull.titleとfull.descriptionを設定することで有効にする必要があります。
export default defineNuxtConfig({
llms: {
domain: 'https://example.com',
title: 'My Application',
full: {
title: 'Full Documentation',
description: 'Full documentation of the application',
},
},
})
フックを使用したドキュメントの拡張
このモジュールは、両方のドキュメント形式を動的に拡張できるフックシステムを提供します。主なフックは2つあります。
利用可能なフック
llms:generate(event, options)
このフックは、/llms.txtへのすべてのリクエストに対して呼び出されます。このフックを使用して、構造化されたドキュメントを変更し、セクション、リンク、メタデータを追加できます。
パラメーター
event: H3Event - 現在のリクエストイベントoptions: ModuleOptions - セクション、リンクなどを追加するために変更できるモジュールオプション
llms:generate:llms-full(event, options, contents)
このフックは、/llms-full.txtへのすべてのリクエストに対して呼び出されます。任意の形式でカスタムコンテンツセクションを追加できます。
パラメーター
event: H3Event - 現在のリクエストイベントoptions: ModuleOptions - セクション、リンクなどを追加するために変更できるモジュールオプションcontents: string - 追加または変更できるコンテンツセクションの配列
アプリケーションでのフックの使用
server/pluginsディレクトリにサーバープラグインを作成します
// server/plugins/llms.ts
export default defineNitroPlugin((nitroApp) => {
// Method 1: Using the hooks directly
nitroApp.hooks.hook('llms:generate', (event, options) => {
// Add a new section to llms.txt
options.sections.push({
title: 'API Documentation',
description: 'REST API endpoints and usage',
links: [
{
title: 'Authentication',
description: 'API authentication methods',
href: `${options.domain}/api/auth`
}
]
})
})
// Method 2: Using the helper function
nitroApp.hooks.hook('llms:generate:full', (event, options, contents) => {
// Add detailed documentation to llms-full.txt
contents.push(`## API Authentication
### Bearer Token
To authenticate API requests, include a Bearer token in the Authorization header:
\`\`\`
Authorization: Bearer <your-token>
\`\`\`
### API Keys
For server-to-server communication, use API keys:
\`\`\`
X-API-Key: <your-api-key>
\`\`\`
`)
})
})
Nuxtモジュールでのフックの使用
LLMドキュメントを拡張する必要があるNuxtモジュールを開発している場合
- モジュールにサーバープラグインを作成します
// module/runtime/server/plugins/my-module-llms.ts
export default defineNitroPlugin((nitroApp) => {
nitroApp.hooks.hook('llms:generate', (event, options) => {
options.sections.push({
title: 'My Module',
description: 'Documentation for my module features',
links: [/* ... */]
})
})
})
- モジュールのセットアップでプラグインを登録します
import { defineNuxtModule, addServerPlugin } from '@nuxt/kit'
import { fileURLToPath } from 'url'
export default defineNuxtModule({
setup(options, nuxt) {
const runtimeDir = fileURLToPath(new URL('./runtime', import.meta.url))
addServerPlugin(resolve(runtimeDir, 'server/plugins/my-module-llms'))
}
})
統合
Nuxt Content
Nuxt Content ^3.2.0には、LLMドキュメントの組み込みサポートが含まれています。nuxt-llmsを@nuxt/contentと組み合わせて使用すると、Webサイトのコンテンツとドキュメントを効率的に記述し、追加の労力なしにLLMフレンドリーなドキュメントを生成できます。Contentモジュールはnuxt-llmsフックを使用し、すべてのコンテンツをllms.txtおよびllms-full.txtドキュメントに自動的に追加します。
両方のモジュールをインストールし、contentディレクトリにコンテンツファイルを作成するだけです。
export default defineNuxtConfig({
modules: ['nuxt-llms', '@nuxt/content'],
llms: {
domain: 'https://example.com',
title: 'My Application',
description: 'My Application Description',
},
})
コンテンツファイルの作成方法については、Nuxt Contentドキュメントを確認してください。
nuxt-llmsと@nuxt/contentでLLMコンテンツをカスタマイズする方法の詳細については、Nuxt Content llmsドキュメントを確認してください。
💻 開発
- リポジトリをクローン
pnpm installを使用して依存関係をインストールするpnpm dev:prepareを使用して準備しますpnpm prepackを使用してビルドしますpnpm devを使用してプレイグラウンドを試しますpnpm testを使用してテストします
ライセンス
Copyright (c) NuxtLabs