不同领域中的llms.txt

本页面提供了一些指南和建议,帮助不同领域如何利用 llms.txt 让LLMs更好地与他们的网站接口,如果他们选择这样做的话。

请记住,在构建您的 llms.txt 时,您应该“使用简洁、清晰的语言。当链接到资源时,包含简短、信息丰富的描述。避免模糊的术语或未解释的行话。”此外,确定您的 llms.txt 是否与 LLMs 良好配合的最佳方法是与它们进行测试!以下是测试 Anthropic 的 Claude 与您的 llms.txt 的一种简便方法:

# /// script
# requires-python = ">=3.8"
# dependencies = [
#     "claudette",
#     "llms-txt",
#     "requests",
# ]
# ///
from claudette import *
from llms_txt import create_ctx

import requests

model = models[1] # Sonnet 3.5
chat = Chat(model, sp="""You are a helpful and concise assistant.""")

url = 'your_url/llms.txt'
text = requests.get(url).text
llm_ctx = create_ctx(text)
chat(llm_ctx + '\n\nThe above is necessary context for the conversation.')

while True:
    msg = input('Your question about the site: ')
    res = chat(msg)
    print('From Claude:', contents(res))

上面的脚本利用了相对较新的 uv 语法用于 python 脚本。如果你安装了 uv,你可以简单地使用 uv run test_llms_txt.py 运行上面的脚本,它将在一个独立的 python 环境中处理安装必要的库依赖。否则,你可以手动安装需求,并像任何普通的 python 脚本一样运行它,使用 python test_llms_txt.py.

餐馆

这是一个餐厅可以为LLMs构建的示例 llms.txt

# Nate the Great's Grill

> Nate the Great's Grill is a popular destination off of Sesame Street that has been serving the community for over 20 years. We offer the best BBQ for a great price.

Here are our weekly hours:

- Monday - Friday: 9am - 9pm
- Saturday: 11am - 9pm
- Sunday: Closed

## Menus

- [Lunch Menu](https://host/lunch.html.md): Our lunch menu served from 11am to 4pm every day.
- [Dinner Menu](https://host/dinner.html.md): Our dinner menu served from 4pm to 9pm every day.

## Optional

- [Dessert Mneu](https://host/dessert.md): A subset of the Starlette docs

这里有一个来自 Franklin’s BBQ 的例子午餐菜单:

## By The Pound

| Item              | Price         |
| --------------    | -----------   |
| Brisket           | 34            |
| Pork Spare Ribs   | 30            |
| Pulled Pork       | 28            |

## Drinks

| Item              | Price         |
| --------------    | -----------   |
| Iced Tea          | 3             |
| Mexican Coke      | 3             |

## Sides

| Item              | Price         |
| --------------    | -----------   |
| Potato Salad      | 4             |
| Slaw              | 4             |