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
pip install LLMTextualAnswer
Usage
Question answering
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:
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:
workflows = ['Classification', 'Latent Semantic Analysis', 'Quantile Regression', 'Recommendations']
For each workflow spec give the corresponding (most likely) workflow name:
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.
llm_textual_answerandllm_classifyaccept "LangChain" chat/text models that support.invoke.- Use
prompt_style="chat"orprompt_style="text"if auto-detection is not desired. - When you want only the prompt template, pass
form="StringTemplate".
Release files for LLMTextualAnswer 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| llmtextualanswer-0.1.1.tar.gz | 8.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| llmtextualanswer-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 16.3 kB
Release files / llmtextualanswer-0.1.1.tar.gz
| Download URL | llmtextualanswer-0.1.1.tar.gz |
|---|---|
| Size | 8.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c7e8b916ac566bbc39cc8fc9096752a258dfb9a0da147cf161918a7b700f4efe
|
|
BLAKE2b-256 checksum How to use checksums |
8d47d4974b01508aec7cd2c0ca5f20f78cb1df840aa84b6c7f884e9be94e2d1d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.2
|
Release files / llmtextualanswer-0.1.1-py3-none-any.whl
| Download URL | llmtextualanswer-0.1.1-py3-none-any.whl |
|---|---|
| Size | 7.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a60f46b22d03d30594e68c9598629970d7673f9d943ca38ef7da18e45bd14a79
|
|
BLAKE2b-256 checksum How to use checksums |
b9daa3c7a1616485805dc5f10d993b8ef91dedbedfed425f9f03290bfb240849
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.2
|