wikiqa 0.1.3
A powerful Wikipedia Question Answering system using LLMs
Requires Python: >=3.8

# 🎯 WikiQA

A powerful Wikipedia Question Answering system that leverages Large Language Models (LLMs) to provide accurate and context-aware answers from Wikipedia content.

## ✨ Features

- 🤖 Multiple LLM Provider Support (OpenAI, Anthropic, Together)
- 📚 Wikipedia Integration
- ❓ Question Answering
- 🔍 Entity Extraction
- 📝 Smart Summarization
- ✅ Fact Verification
- 🔗 Related Articles Discovery
- 📊 Confidence Scores
- 🚀 Task-Aware Processing

## 🚀 Installation

```bash
pip install wikiqa
```

## 🎮 Quick Start

```python
from wikiqa import WikiQA

# Initialize with your preferred LLM provider
qa = WikiQA(
    llm_provider="openai",  # or "anthropic" or "together"
    api_key="your-api-key",
    model="gpt-4"  # or any other model supported by your provider
)

# Ask a question about a Wikipedia article
answer, confidence, url, revision = qa.ask(
    question="What is the capital of France?",
    article="France"
)
print(f"Answer: {answer}")
print(f"Confidence: {confidence}")
print(f"Source: {url}")

# Extract specific information
birth_date = qa.extract_entity(
    text="Albert Einstein was born on March 14, 1879 in Germany.",
    entity_type="DATE"
)
print(f"Birth Date: {birth_date}")

# Get a smart summary
summary, url, revision = qa.summarize(
    article="Artificial Intelligence",
    length="paragraph",
    focus="history"
)
print(f"Summary: {summary}")

# Verify a fact
is_true, confidence, url, revision = qa.verify_fact(
    statement="Albert Einstein won the Nobel Prize in Physics in 1921",
    article="Albert Einstein"
)
print(f"Is True: {is_true}")
print(f"Confidence: {confidence}")

# Find related articles
related = qa.get_related_articles(
    article="Machine Learning",
    max_results=5
)
for article in related:
    print(f"Title: {article['title']}")
    print(f"Relevance: {article['relevance_score']}")
    print(f"Relationship: {article['relationship']}")
```

## 🤝 Supported LLM Providers

- 🎨 OpenAI (GPT models)
- 🧠 Anthropic (Claude models)
- 🌟 Together (various open-source models)

## 📋 Requirements

- 🐍 Python 3.8 or higher
- 🌐 Internet connection for Wikipedia access
- 🔑 API key for your chosen LLM provider

## 📄 License

MIT License

## 🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

## ⭐ Star History

[![Star History Chart](https://api.star-history.com/svg?repos=yourusername/wikiqa&type=Date)](https://star-history.com/#yourusername/wikiqa&Date)

## 📊 Stats

![GitHub stars](https://img.shields.io/github/stars/yourusername/wikiqa?style=social)
![GitHub forks](https://img.shields.io/github/forks/yourusername/wikiqa?style=social)
![GitHub issues](https://img.shields.io/github/issues/yourusername/wikiqa)
![GitHub license](https://img.shields.io/github/license/yourusername/wikiqa)
![Python Version](https://img.shields.io/badge/python-3.8%2B-blue)

## Advanced Usage

### Smart Summarization

The system automatically handles long articles using task-aware summarization:

```python
# QA-focused summarization
answer, confidence, url, revision = qa.ask(
    question="What are the main causes of climate change?",
    article="Climate Change"  # Long article, automatically summarized for QA
)

# Entity-focused summarization
entity = qa.extract_entity(
    text=long_text,  # Long text, automatically summarized for entity extraction
    entity_type="PERSON"
)
```

### Fact Verification with Multiple Sources

```python
# Verify against a specific article
is_true, confidence, url, revision = qa.verify_fact(
    statement="The Great Wall of China is visible from space",
    article="Great Wall of China"
)

# Verify against multiple Wikipedia articles
is_true, confidence, url, revision = qa.verify_fact(
    statement="The first computer was invented in the 1940s"
)
```

### Finding Related Articles with Context

```python
related = qa.get_related_articles(
    article="Quantum Computing",
    max_results=5
)

for article in related:
    print(f"Title: {article['title']}")
    print(f"URL: {article['url']}")
    print(f"Relevance Score: {article['relevance_score']}")
    print(f"Relationship: {article['relationship']}")
    print("---")
```

## Configuration

```python
qa = WikiQA(
    llm_provider="openai",  # or "anthropic" or "together"
    api_key="your-api-key",
    model="gpt-4",  # or any other model supported by your provider
    temperature=0.7,  # control randomness in responses
    max_tokens=1000,  # maximum length of responses
    cache_results=True  # cache results for better performance
)
```

## Error Handling

The package provides specific exceptions for different error cases:

```python
from wikiqa import WikiQAError, PageNotFoundError, EntityNotFoundError, QuestionAnswerError

try:
    answer, confidence, url, revision = qa.ask(
        question="What is the capital of France?",
        article="France"
    )
except PageNotFoundError as e:
    print(f"Article not found: {e}")
except QuestionAnswerError as e:
    print(f"Could not answer question: {e}")
except WikiQAError as e:
    print(f"General error: {e}")
```

## Citation

If you use this package in your research, please cite:

```bibtex
@software{wikiqa2024,
  author = {Pawan Kumar Rajpoot},
  title = {WikiQA: A Wikipedia Question Answering System},
  year = {2024},
  url = {https://github.com/pawan2411/WikiQA}
}
```