如何用l1m API从文本和图片中提取结构化JSON数据?
AI Summary (BLUF)
l1m is a lightweight API that simplifies structured data extraction from unstructured text and images using LLMs, eliminating the need for prompt engineering through a schema-first approach with JSON Schema.
原文翻译: l1m 是一个轻量级 API,通过 JSON Schema 优先的方法,简化了使用 LLM 从非结构化文本和图像中提取结构化数据的过程,无需进行提示工程。
引言
在当今由大型语言模型驱动的世界中,从非结构化文本或图像中提取结构化数据已成为一项常见但复杂的任务。开发者通常需要投入大量精力进行提示工程、管理对话历史,并处理不同模型提供商的 API 差异。l1m一个用于从非结构化文本和图像中提取结构化 JSON 数据的轻量级 API 工具。 应运而生,旨在通过一个简单、统一的 API 彻底改变这一流程,让开发者能够专注于数据本身,而非繁琐的集成工作。
In today's LLM-driven world, extracting structured data from unstructured text or images has become a common yet complex task. Developers often need to invest significant effort in prompt engineering, managing chat history, and handling API differences across various model providers. l1m一个用于从非结构化文本和图像中提取结构化 JSON 数据的轻量级 API 工具。 emerges to revolutionize this process with a simple, unified API, allowing developers to focus on the data itself rather than cumbersome integration work.
为什么选择 l1m一个用于从非结构化文本和图像中提取结构化 JSON 数据的轻量级 API 工具。?
l1m一个用于从非结构化文本和图像中提取结构化 JSON 数据的轻量级 API 工具。 是利用 LLM 从非结构化文本或图像中获取结构化数据的最简单方式。无需提示工程,无需管理聊天历史,只需一个简单的 API 即可从文本或图像中提取结构化的 JSON 数据。
l1m一个用于从非结构化文本和图像中提取结构化 JSON 数据的轻量级 API 工具。 is the easiest way to get structured data from unstructured text or images using LLMs. No prompt engineering, no chat history, just a simple API to extract structured JSON from text or images.
核心特性
l1m一个用于从非结构化文本和图像中提取结构化 JSON 数据的轻量级 API 工具。 的设计围绕几个核心原则展开,旨在为开发者提供强大、灵活且易于使用的工具。
l1m一个用于从非结构化文本和图像中提取结构化 JSON 数据的轻量级 API 工具。 is designed around several core principles aimed at providing developers with a powerful, flexible, and easy-to-use tool.
| 特性 | 描述 | 关键优势 |
|---|---|---|
| 模式优先方法 | 使用 JSON Schema一种用于描述 JSON 数据结构的标准格式,在 l1m 中用于定义期望的输出数据模型。 定义所需的数据结构,API 将精确返回您需要的内容。 | 确保输出格式的严格一致性,消除解析歧义。 |
| 零提示工程 | 无需设计复杂提示或链式调用。通过 JSON Schema一种用于描述 JSON 数据结构的标准格式,在 l1m 中用于定义期望的输出数据模型。 的描述字段提供上下文。 | 降低使用门槛,提升开发效率。 |
| 提供商灵活性 | 支持自带提供商,兼容任何 OpenAI 兼容接口或 Anthropic 提供商及模型。 | 避免供应商锁定,可与现有基础设施无缝集成。 |
| 内置缓存 | 提供 x-cache-ttl 请求头,可将 l1m一个用于从非结构化文本和图像中提取结构化 JSON 数据的轻量级 API 工具。.io 用作 LLM 请求的缓存层。 |
减少重复调用成本,提升响应速度。 |
| 开源与托管 | 项目完全开源,无供应商锁定。也可使用提供免费层和高可用性的托管版本。 | 兼顾灵活性与便利性。 |
| 无数据保留 | 除非使用 x-cache-ttl 头,否则不会存储您的数据。 |
保障数据隐私与安全。 |
快速开始
图像提取示例
以下示例演示了如何从一张包含菜单的图片中提取结构化数据。
The following example demonstrates how to extract structured data from an image containing a menu.
curl -X POST https://api.l1m.io/structured \
-H "Content-Type: application/json" \
-H "X-Provider-Url: demo" \
-H "X-Provider-Key: demo" \
-H "X-Provider-Model: demo" \
-d '{
"input": "'$(curl -s https://public.l1m.io/menu.jpg | base64)'",
"schema": {
"type": "object",
"properties": {
"items": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": { "type": "string" },
"price": { "type": "number" }
}
}
}
}
}
}'
将此示例复制到终端中运行。演示端点会返回预渲染的 LLM 响应,以便快速测试。
↑ Copy and run this example in your terminal. The demo endpoints return pre-rendered LLM responses for quick testing.
文本提取示例
此示例展示了如何从一段历史文本中提取特定信息。
This example shows how to extract specific information from a piece of historical text.
curl -X POST https://api.l1m.io/structured \
-H "Content-Type: application/json" \
-H "X-Provider-Url: demo" \
-H "X-Provider-Key: demo" \
-H "X-Provider-Model: demo" \
-d '{
"input": "A particularly severe crisis in 1907 led Congress to enact the Federal Reserve Act in 1913",
"schema": {
"type": "object",
"properties": {
"year": {
"type": "number",
"description": "The year the Federal Reserve Act was enacted"
}
}
}
}'
将此示例复制到终端中运行。演示端点会返回预渲染的 LLM 响应,以便快速测试。
↑ Copy and run this example in your terminal. The demo endpoints return pre-rendered LLM responses for quick testing.
实用技巧与方案
使用 TTL 缓存模型响应
通过设置 X-Cache-TTL 请求头,您可以缓存 LLM 的响应,从而在指定时间内对相同请求返回缓存结果,显著降低成本和延迟。
By setting the
X-Cache-TTLrequest header, you can cache LLM responses, returning cached results for identical requests within a specified time frame, significantly reducing cost and latency.
#!/bin/bash
# 启用缓存后多次运行相同请求
# 缓存键由输入、模式、提供商密钥和模型生成
# Cache key = hash(input + schema + x-provider-key + x-provider-model)
for i in {1..5}; do
curl -X POST https://api.l1m.io/structured \
-H "Content-Type: application/json" \
-H "X-Provider-Url: $PROVIDER_URL" \
-H "X-Provider-Key: $PROVIDER_KEY" \
-H "X-Provider-Model: $PROVIDER_MODEL" \
-H "X-Cache-TTL: 300" \
-d '{
"input": "The weather in San Francisco is sunny and 72°F",
"schema": {
"type": "object",
"properties": {
"temperature": { "type": "number" },
"conditions": { "type": "string" }
}
}
}'
echo "\n--- Request $i completed ---\n"
done
# 只有第一次会调用 LLM,后续请求将在 X-Cache-TTL 指定的时间内(本例为300秒)从缓存中获取响应。
# Only 1 LLM call will be made, subsequent calls will be served from cache for the duration specified in X-Cache-TTL (300 seconds in this example).
实现工具调用/路由功能
虽然 l1m一个用于从非结构化文本和图像中提取结构化 JSON 数据的轻量级 API 工具。 不直接支持其他模型提供商那样的“工具调用”功能,但您可以通过巧妙使用 JSON Schema一种用于描述 JSON 数据结构的标准格式,在 l1m 中用于定义期望的输出数据模型。 中的 enum 属性来实现类似的路由逻辑。
While l1m一个用于从非结构化文本和图像中提取结构化 JSON 数据的轻量级 API 工具。 does not support "tool calling" in the same sense as other model providers, you can achieve similar routing logic by cleverly using the
enumproperty in JSON Schema一种用于描述 JSON 数据结构的标准格式,在 l1m 中用于定义期望的输出数据模型。.
其核心思路是进行两次调用:第一次调用根据用户输入确定应使用的工具(通过 enum 定义的选择器),第二次调用则根据选定的工具提取相应的参数。
The core idea involves two calls: the first determines which tool to use based on user input (via an
enum-defined selector), and the second extracts the corresponding parameters based on the selected tool.
与本地模型(如 Ollama)集成
l1m一个用于从非结构化文本和图像中提取结构化 JSON 数据的轻量级 API 工具。 支持与本地运行的 LLM 服务(例如使用 Ollama)集成,为注重隐私或需要离线运行的场景提供了理想解决方案。
l1m一个用于从非结构化文本和图像中提取结构化 JSON 数据的轻量级 API 工具。 supports integration with locally run LLM services (e.g., using Ollama), providing an ideal solution for privacy-conscious or offline operation scenarios.
您只需将 X-Provider-Url 指向本地服务的端点(或通过 ngrok 等工具暴露的端点),并使用相应的模型名称即可。
You simply need to point
X-Provider-Urlto your local service endpoint (or one exposed via a tool like ngrok) and use the corresponding model name.
API 文档详解
请求头
下表概述了 l1m一个用于从非结构化文本和图像中提取结构化 JSON 数据的轻量级 API 工具。 API 支持的关键请求头。
The following table outlines the key request headers supported by the l1m一个用于从非结构化文本和图像中提取结构化 JSON 数据的轻量级 API 工具。 API.
| 请求头 | 是否必需 | 描述 |
|---|---|---|
x-provider-model |
可选 | 指定要使用的 LLM 模型。 |
x-provider-url |
可选 | LLM 提供商的 URL 端点。 |
x-provider-key |
可选 | LLM 提供商的 API 密钥。 |
x-cache-ttl |
可选 | 缓存生存时间(秒)。 缓存键 = hash(输入 + 模式 + x-provider-key + x-provider-model)。 缓存命中时,响应会包含 x-cache: HIT 头。 |
请求体
请求体是一个 JSON 对象,包含以下字段:
The request body is a JSON object containing the following fields:
| 字段 | 类型 | 描述 |
|---|---|---|
input |
字符串 | 需要处理的文本或 Base64 编码的图像数据。 |
schema |
对象 | 描述期望输出对象的类 JSON Schema一种用于描述 JSON 数据结构的标准格式,在 l1m 中用于定义期望的输出数据模型。 对象。 注意:支持 JSON Schema一种用于描述 JSON 数据结构的标准格式,在 l1m 中用于定义期望的输出数据模型。 的一个子集。顶层类型必须为 object。支持嵌套的 array 和 enum。不支持 min/maxLength、one/any/allOf 等高级约束。 |
instruction |
字符串(可选) | 发送给模型的额外指令文本。 |
响应与错误处理
l1m一个用于从非结构化文本和图像中提取结构化 JSON 数据的轻量级 API 工具。 API 遵循清晰的响应约定:
The l1m一个用于从非结构化文本和图像中提取结构化 JSON 数据的轻量级 API 工具。 API follows clear response conventions:
- 成功响应:HTTP 状态码为 200,响应体是一个包含
data属性的 JSON 对象,其内容严格符合提供的schema。Successful Response: HTTP status code 200. The response body is a JSON object containing a
dataproperty, the content of which strictly matches the providedschema. - 模式验证失败:如果 LLM 的输出无法匹配提供的模式,将返回 422 状态码及错误信息。
Schema Validation Failure: If the LLM output cannot match the provided schema, a 422 status code and error message will be returned.
- 提供商错误:来自底层模型提供商的错误(如认证失败、额度不足)将连同其原始状态码一并返回。
Provider Error: Errors from the underlying model provider (such as authentication failure, insufficient quota) will be returned along with their original status code.
支持的数据类型
对于图像输入,Base64 编码数据必须为以下格式之一:
For image inputs, Base64-encoded data must be in one of the following formats:
image/jpegimage/png
官方 SDK 支持
为了便于集成,l1m一个用于从非结构化文本和图像中提取结构化 JSON 数据的轻量级 API 工具。 为多种流行编程语言提供了官方 SDK。
To facilitate integration, l1m一个用于从非结构化文本和图像中提取结构化 JSON 数据的轻量级 API 工具。 provides official SDKs for several popular programming languages.
| 语言 | 仓库链接 | 说明 |
|---|---|---|
| Node.js | Node.js SDK | 适用于 JavaScript/TypeScript 生态系统。 |
| Python | Python SDK | 适用于数据科学、后端服务等场景。 |
| Go | Go SDK | 适用于高性能、并发要求高的服务。 |
托管 API 定价
l1m一个用于从非结构化文本和图像中提取结构化 JSON 数据的轻量级 API 工具。 提供透明且友好的定价策略。
l1m一个用于从非结构化文本和图像中提取结构化 JSON 数据的轻量级 API 工具。 offers transparent and friendly pricing.
| 套餐 | 请求次数 | 价格 | 备注 |
|---|---|---|---|
| 免费层 | 首 500 次请求 | 免费 | 体验核心功能。 |
| 标准版 | 每 10,000 次请求 | $5 | 公开测试期间免费。 |
总结与展望
l1m一个用于从非结构化文本和图像中提取结构化 JSON 数据的轻量级 API 工具。 通过其独特的“模式优先”和“零提示工程”理念,为 LLM 的结构化数据提取提供了一个极其简洁而强大的抽象层。它降低了开发者的认知负担和集成成本,同时通过开源和灵活的提供商支持避免了技术锁定。无论是处理文档、图像还是构建复杂的 AI 工作流,l1m一个用于从非结构化文本和图像中提取结构化 JSON 数据的轻量级 API 工具。 都值得作为您的首选工具进行尝试。
With its unique "schema-first" and "zero prompt engineering" philosophy, l1m一个用于从非结构化文本和图像中提取结构化 JSON 数据的轻量级 API 工具。 provides an exceptionally simple yet powerful abstraction layer for structured data extraction using LLMs. It reduces the cognitive load and integration costs for developers while avoiding vendor lock-in through open-source availability and flexible provider support. Whether you're processing documents, images, or building complex AI workflows, l1m一个用于从非结构化文本和图像中提取结构化 JSON 数据的轻量级 API 工具。 is worth trying as your tool of choice.
加入等待列表:对即将正式发布的托管生产版本感兴趣?您可以加入我们的等待列表以获取早期访问权限。
Join the Waitlist: Interested in the upcoming production release of our hosted version? You can join our waitlist for early access.
常见问题(FAQ)
l1m一个用于从非结构化文本和图像中提取结构化 JSON 数据的轻量级 API 工具。 是什么?它如何简化数据提取?
l1m一个用于从非结构化文本和图像中提取结构化 JSON 数据的轻量级 API 工具。 是一个轻量级 API,通过 JSON Schema一种用于描述 JSON 数据结构的标准格式,在 l1m 中用于定义期望的输出数据模型。 优先的方法,直接从非结构化文本或图像中提取结构化 JSON 数据,无需进行复杂的提示工程,简化了开发流程。
使用 l1m一个用于从非结构化文本和图像中提取结构化 JSON 数据的轻量级 API 工具。 需要自己设计提示词吗?
不需要。l1m一个用于从非结构化文本和图像中提取结构化 JSON 数据的轻量级 API 工具。 采用零提示工程设计,开发者只需通过 JSON Schema一种用于描述 JSON 数据结构的标准格式,在 l1m 中用于定义期望的输出数据模型。 定义所需的数据结构并提供上下文描述,API 即可精确返回对应格式的数据,降低了使用门槛。
l1m一个用于从非结构化文本和图像中提取结构化 JSON 数据的轻量级 API 工具。 支持哪些模型提供商?数据安全如何保障?
l1m一个用于从非结构化文本和图像中提取结构化 JSON 数据的轻量级 API 工具。 支持自带提供商,兼容任何 OpenAI 兼容接口或 Anthropic 提供商,避免供应商锁定。除非使用缓存功能,否则不会存储用户数据,保障了隐私与安全。
版权与免责声明:本文仅用于信息分享与交流,不构成任何形式的法律、投资、医疗或其他专业建议,也不构成对任何结果的承诺或保证。
文中提及的商标、品牌、Logo、产品名称及相关图片/素材,其权利归各自合法权利人所有。本站内容可能基于公开资料整理,亦可能使用 AI 辅助生成或润色;我们尽力确保准确与合规,但不保证完整性、时效性与适用性,请读者自行甄别并以官方信息为准。
若本文内容或素材涉嫌侵权、隐私不当或存在错误,请相关权利人/当事人联系本站,我们将及时核实并采取删除、修正或下架等处理措施。 也请勿在评论或联系信息中提交身份证号、手机号、住址等个人敏感信息。