Skip to main content

Python SDK for Incept Question Generation API

Project description

Incept Python SDK

A Python client library for the Incept Question Generation API.

Installation

pip install incept-python-sdk

Quick Start

from incept import InceptClient

# Initialize the client
client = InceptClient(api_key="your-api-key-here")

# Generate questions
response = client.generate_questions(
    grade=5,
    instructions="Generate questions about fractions",
    count=3,
    difficulty="medium"
)

print(f"Generated {len(response.data)} questions")
for question in response.data:
    print(f"Q: {question.question}")
    print(f"A: {question.answer}")

Configuration

Initialize Client

from incept import InceptClient

# Basic configuration
client = InceptClient(api_key="your-api-key")

# Custom endpoint and timeout
client = InceptClient(
    api_key="your-api-key",
    base_url="https://your-custom-endpoint.com",
    timeout=60  # seconds
)

API Methods

Generate Questions

Generate educational questions with comprehensive options:

response = client.generate_questions(
    grade=7,
    instructions="Create algebra problems",
    count=5,
    question_type="mcq",
    language="english",
    difficulty="medium",
    subject="mathematics",
    model="openai",
    translate=False,
    evaluate=True,
    skill={
        "id": "algebra_basics",
        "title": "Linear Equations",
        "unit_name": "Algebra",
        "lesson_title": "Solving Equations"
    },
    topic="Linear Equations",
    student_level="average"
)

# Access generated questions
for question in response.data:
    print(f"Question: {question.question}")
    print(f"Answer: {question.answer}")
    print(f"Difficulty: {question.difficulty}")
    if question.options:
        print(f"Options: {question.options}")
    if question.detailed_explanation:
        for step in question.detailed_explanation.steps:
            print(f"Step: {step.title} - {step.content}")

# Check evaluation results (if evaluate=True)
if response.evaluation:
    print(f"Overall Score: {response.evaluation.overall_score}")
    print(f"Recommendations: {response.evaluation.recommendations}")

Completions

Get text completions:

response = client.completions(
    messages=[
        {"role": "system", "content": "You are a helpful math tutor"},
        {"role": "user", "content": "Explain the Pythagorean theorem"}
    ],
    provider="openai",
    max_tokens=1000,
    language="english"
)

print(response.response)

Wolfram Alpha Integration

Solve math problems using Wolfram Alpha:

response = client.wolfram_solve(
    question_text="What is the derivative of x^2 + 3x + 2?",
    subject="calculus",
    app_id="your-wolfram-app-id"
)

print(f"Solution: {response.solution}")
if response.steps:
    for step in response.steps:
        print(f"Step: {step}")

Health Check

Check API status:

health = client.health_check()
print(f"Status: {health['status']}")

API Documentation

Get API documentation:

docs = client.get_api_documentation()
print(docs)

Request Parameters

GenerateQuestionsRequest

Parameter Type Default Description
grade int required Grade level (0-12)
instructions str required Instructions for question generation
count int 5 Number of questions (1-100)
question_type str "mcq" Question type (currently only "mcq")
language str "english" Content language
difficulty str "mixed" Difficulty level: "easy", "medium", "hard", "expert", "mixed"
subject str None Subject override
model str "openai" AI model: "openai", "falcon"
translate bool False Enable translation
evaluate bool False Enable quality evaluation
skill dict None Skill context information
topic str None Topic specification
subtopic str None Subtopic specification
unit str None Unit specification
student_level str None Student level: "struggling", "average", "advanced"
previous_mistakes list None Previous student mistakes

Response Models

GeneratedQuestion

{
    "type": "mcq",
    "question": "What is 2 + 2?",
    "answer": "A",
    "difficulty": "easy",
    "explanation": "Addition of two numbers...",
    "options": ["4", "3", "5", "6"],
    "detailed_explanation": {
        "steps": [...],
        "personalized_academic_insights": [...]
    },
    "voiceover_script": {...},
    "image_url": "https://...",
    "di_formats_used": [...]
}

EvaluationInfo

{
    "overall_score": 0.85,
    "scores": {
        "clarity": 0.9,
        "difficulty": 0.8,
        "relevance": 0.9
    },
    "recommendations": [
        "Consider adding more visual aids",
        "Simplify the language for grade level"
    ],
    "report": "Overall excellent question quality..."
}

Error Handling

The SDK provides specific exception types for different error scenarios:

from incept import InceptClient
from incept.exceptions import (
    AuthenticationError,
    ValidationError,
    RateLimitError,
    ServerError,
    NetworkError,
    InceptAPIError
)

client = InceptClient(api_key="your-api-key")

try:
    response = client.generate_questions(
        grade=5,
        instructions="Generate questions about fractions",
        count=3
    )
except AuthenticationError:
    print("Invalid API key")
except ValidationError as e:
    print(f"Validation error: {e}")
except RateLimitError:
    print("Rate limit exceeded, please wait")
except ServerError as e:
    print(f"Server error: {e}")
except NetworkError as e:
    print(f"Network error: {e}")
except InceptAPIError as e:
    print(f"API error: {e}")

Development

Install from source

git clone https://github.com/incept/incept-python-sdk
cd incept-python-sdk
pip install -e .

Install development dependencies

pip install -e ".[dev]"

Run tests

pytest

Format code

black incept/

Lint code

flake8 incept/

License

MIT License

Support

For support, please contact support@inceptapi.com or visit our documentation at https://docs.inceptapi.com.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

incept_python_sdk-0.1.1.tar.gz (18.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

incept_python_sdk-0.1.1-py3-none-any.whl (14.3 kB view details)

Uploaded Python 3

File details

Details for the file incept_python_sdk-0.1.1.tar.gz.

File metadata

  • Download URL: incept_python_sdk-0.1.1.tar.gz
  • Upload date:
  • Size: 18.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for incept_python_sdk-0.1.1.tar.gz
Algorithm Hash digest
SHA256 931a0508e3aa50c7addf14277b1ec7132ba40177519906fe02339b27c6e28db7
MD5 cd1d73e1032f8bef1c34a92b7fd18c9f
BLAKE2b-256 bf9ac6bba263956a7689bf10033e0592a857dac2035e9d5f7b73864c126d2b39

See more details on using hashes here.

File details

Details for the file incept_python_sdk-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for incept_python_sdk-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5b732d8e28b05452631e888fdc3da2ef446538df32eea9a81da0c749ea2ccc7f
MD5 afbbabd41f53fc01a222aecb86517841
BLAKE2b-256 5bad5e4f0c49d9c4dac8d7f465c9f2017d43286e164803961bd7f93cfa365b7e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page