llms.txt 在不同领域的应用
本页面为不同领域的网站提供了如何利用 llms.txt
文件来让大型语言模型(LLM)更好地与其交互的指南和建议。
请记住,在构建您的 llms.txt
文件时,应“使用简洁、清晰的语言。在链接到资源时,附上简短、信息丰富的描述。避免使用含糊不清的术语或未经解释的行话。”此外,判断您的 llms.txt
是否能与 LLM 良好协作的最佳方法是直接用它们进行测试!这里有一个使用 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
= models[1] # Sonnet 3.5
model = Chat(model, sp="""You are a helpful and concise assistant.""")
chat
= 'your_url/llms.txt'
url = requests.get(url).text
text = create_ctx(text)
llm_ctx + '\n\nThe above is necessary context for the conversation.')
chat(llm_ctx
while True:
= input('Your question about the site: ')
msg = chat(msg)
res print('From Claude:', contents(res))
上述脚本使用了相对较新的 uv
Python 脚本语法。如果您安装了 uv
,只需通过 uv run test_llms_txt.py
命令运行该脚本,它就会在一个隔离的 Python 环境中处理并安装必要的库依赖。否则,您可以手动安装所需依赖,然后像运行普通 Python 脚本一样使用 python test_llms_txt.py
来运行它。
餐厅
以下是一家餐厅可以为大型语言模型(LLM)构建的 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 Menu](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 |