Metadata-Version: 2.4
Name: LLMTextualAnswer
Version: 0.1.1
Summary: Find textual answers via an LLM.
Author: Anton Antonov
License: MIT License
        
        Copyright (c) 2026 Anton Antonov
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Keywords: llm,question-answer,text-mining
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: langchain-core>=0.1.0
Dynamic: license-file

# LLMTextualAnswer

Python package for finding textual answers via LLMs. This is a Python port of the Wolfram Language `LLMTextualAnswer` function, focused on building prompts, wiring LangChain models, and parsing structured outputs.

-----

## Install

```bash
pip install LLMTextualAnswer
```

-----

## Usage

### Question answering

```python
from LLMTextualAnswer import LLMTextualAnswer
from langchain_openai import ChatOpenAI

llm = ChatOpenAI(model="gpt-4o-mini")

text = (
    "Born and raised in the Austrian Empire, Tesla studied engineering and physics "
    "in the 1870s without receiving a degree."
)

questions = ["Where born?"]

result = LLMTextualAnswer(
    text,
    questions,
    llm=llm,
    form=dict,
)

print(result)
```


### Classification

Here is a list of workflow construction specifications:

```python
queries = [
    'Make a classifier with the method RandomForest over the data dfTitanic; show precision and accuracy; plot True Positive Rate vs Positive Predictive Value.',
    'Make a recommender over the data frame dfOrders. Give the top 5 recommendations for the profile year:2022, type:Clothing, and status:Unpaid',
    'Create an LSA object over the text collection aAbstracts; extract 40 topics; show statistical thesaurus for "notebook", "equation", "changes", and "prediction"',
    'Compute quantile regression for dfTS with interpolation order 3 and knots 12 for the probabilities 0.2, 0.4, and 0.9.'
]
```

Here are possible workflows names:

```python
workflows = ['Classification', 'Latent Semantic Analysis', 'Quantile Regression', 'Recommendations']
```

For each workflow spec give the corresponding (most likely) workflow name:

```python
for q in queries:
    print("Spec  : " + q)
    print("Class : " + llm_classify(q, workflows, llm = llm, form=dict) + "\n")
```

```
# Spec  : Make a classifier with the method RandomForest over the data dfTitanic; show precision and accuracy; plot True Positive Rate vs Positive Predictive Value.
# Class : Classification
# 
# Spec  : Make a recommender over the data frame dfOrders. Give the top 5 recommendations for the profile year:2022, type:Clothing, and status:Unpaid
# Class : Recommendations
# 
# Spec  : Create an LSA object over the text collection aAbstracts; extract 40 topics; show statistical thesaurus for "notebook", "equation", "changes", and "prediction"
# Class : Latent Semantic Analysis
# 
# Spec  : Compute quantile regression for dfTS with interpolation order 3 and knots 12 for the probabilities 0.2, 0.4, and 0.9.
# Class : Quantile Regression
# 

```

-----

## Notes

- For more detailed examples see the notebook ["Basic-usage.ipynb](https://github.com/antononcube/Python-LLMTextualAnswer/blob/main/docs/Basic-usage.ipynb).
- `llm_textual_answer` and `llm_classify` accept ["LangChain"](https://docs.langchain.com/oss/python/langchain/overview) chat/text models that support `.invoke`.
- Use `prompt_style="chat"` or `prompt_style="text"` if auto-detection is not desired.
- When you want only the prompt template, pass `form="StringTemplate"`.
