Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

This repository demonstrates structured data extraction using various language models and frameworks. It includes examples of generating JSON outputs for name and age extraction from text prompts. The project leverages models like Qwen and frameworks such as LangChain, vLLM, and Outlines for Transformers models.

NotificationsYou must be signed in to change notification settings

vishvaRam/Structured-Output-Examples-for-LLMs

Repository files navigation

A comprehensive collection of examples demonstrating structured data extraction and JSON output generation using various language models and frameworks. This repository showcases different approaches to ensure LLMs return well-formatted, schema-compliant responses.

🚀 Features

  • Multiple Framework Support: Examples for LangChain, vLLM, Outlines, Ollama,OpenAI and more
  • Pydantic Integration: Type-safe structured outputs with validation
  • Batch Processing: Efficient handling of multiple prompts
  • Vision Model Support: Structured outputs from multimodal models
  • Flexible Backends: Support for local models, API services, and GGUF formats

📁 File Structure

API-Based Solutions

FileDescriptionFramework
Groq_Langchain.pyGroq API integration with LangChainLangChain + Groq
Gemini_langchain.pyGoogle Gemini API with guided decodingLangChain + Gemini
OpenAI_langchain.pyOpenAI API with guided decodingLangChain + OpenAI
OpenAI_API.pyUse OpenAI API Lib for guided decodingOpenAI Lib + Gemini + Groq + Local + etc

Local Model Solutions

FileDescriptionFramework
vLLM.pyLocal vLLM server with JSON schema validationvLLM
vLLM_openai_client.pyvLLM server via OpenAI-compatible clientvLLM + OpenAI Client

Ollama Integration

FileDescriptionUse Case
ollama.pyDirect Ollama chat API usageSimple structured outputs
OllamaLLM.pySingle prompt processingIndividual requests
OllamaLLM_MultiModel.pyMultiModel with structured outputsIndividual requests with Image
OllamaLLM_Batch_Processing.pyBatch processing with Pydantic validationHigh-throughput scenarios
chatOllama.pyChat-based interfaceConversational structured outputs

Outlines Library

FileDescriptionModel Type
Outlines_for_transformers.pyTransformer models with JSON generationHuggingFace Transformers
Outlines_for_GGUF.pyGGUF models via llama_cpp backendQuantized models
Outlines_for_transformers_vision.pyVision-language modelsMultimodal inputs
Outlines_for_transformers_vision_batch.pyBatch vision processingHigh-volume multimodal

🔧 Quick Start

Basic Name and Age Extraction

frompydanticimportBaseModelfromtypingimportOptionalclassPersonInfo(BaseModel):name:strage:Optional[int]=None# Use any of the provided scripts with this schema

⚠️ Important Notes

  • Vision Models:Outlines_for_transformers_vision.py requires PyTorch 2.4 specifically
  • GGUF Models: Ensure llama_cpp is properly installed for GGUF examples
  • API Keys: Set appropriate environment variables for Groq and Gemini examples

🎯 Use Cases

  • Data Extraction: Extract structured information from unstructured text
  • API Responses: Ensure consistent JSON responses from LLMs
  • Batch Processing: Process large datasets with structured outputs
  • Multimodal Analysis: Extract structured data from images and text
  • Validation: Type-safe outputs with automatic validation

🤝 Contributing

Contributions are welcome! Feel free to:

  • Add examples for new frameworks
  • Improve existing implementations
  • Add error handling and edge cases
  • Enhance documentation

📄 License

This project is open source. Please check individual dependencies for their licensing terms.

🔗 Related Resources

About

This repository demonstrates structured data extraction using various language models and frameworks. It includes examples of generating JSON outputs for name and age extraction from text prompts. The project leverages models like Qwen and frameworks such as LangChain, vLLM, and Outlines for Transformers models.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp