Files
task_6a1865008a94f887e50d47…/README.md
T
2026-06-02 14:56:25 +00:00

84 lines
2.0 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Text Extractor CLI
## Overview
This project provides a commandline tool that extracts structured data from freeform text using **LangChain** and **Pydantic**. It supports two schemas:
1. **PersonInfo** name, age, profession, skills.
2. **MeetingNotes** title, date, participants, agenda.
The tool automatically detects which schema to use based on the input text.
## Installation
```bash
# Create a virtual environment
python -m venv .venv
source .venv/bin/activate # On Windows use .venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
```
## Environment variables
The tool uses OpenAIs API. Create a `.env` file in the project root with the following variables:
```
OPENAI_API_KEY=your_api_key_here
OPENAI_MODEL=gpt-3.5-turbo # optional, defaults to gpt-3.5-turbo
OPENAI_BASE_URL= # optional, for local LLMs (e.g. http://localhost:11434/v1)
```
If you are using a local model (Ollama/LM Studio) provide the `OPENAI_BASE_URL` and set `OPENAI_API_KEY` to any nonempty string (e.g. `ollama`).
## Usage
```bash
# Pass text as a commandline argument
python agent.py "Anna, 28 years old, Python developer. Skills: FastAPI, Docker."
# Or pipe text via stdin
cat <<EOF | python agent.py
Meeting: Sprint Planning
Date: 2024-06-01
Participants: Alice, Bob, Charlie
Agenda: Review backlog, assign tasks, estimate effort
EOF
```
### Output
The tool prints two sections:
1. **JSON** a prettyprinted JSON representation of the Pydantic model.
2. **Summary** a humanreadable summary of the key fields.
Example output for a person:
```json
{
"name": "Anna",
"age": 28,
"profession": "Python developer",
"skills": [
"FastAPI",
"Docker"
]
}
Summary:
Anna, 28 years old, works as Python developer.
Skills: FastAPI, Docker.
```
## Extending
To add a new schema:
1. Define a new `Pydantic` model.
2. Create a prompt and parser similar to the existing ones.
3. Update the `detect_schema` logic or add a new classifier.
## License
MIT