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.0.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.0-py3-none-any.whl (14.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: incept_python_sdk-0.1.0.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.0.tar.gz
Algorithm Hash digest
SHA256 a38bc6c0cd2ac3a6ff74158e4e75808da181172bd21e596b034f0261d714bf05
MD5 6adf2bfbc3ba1ffe6a9cd25809aa1a16
BLAKE2b-256 2aca28262fa7ce184ab50d029f6ea55a70779c54e1499aaa32e327bc5870cfd9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for incept_python_sdk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6e9356da41e55b7357ed6caaaba269fa055a65d826206929528552737be7f27e
MD5 758b62a1195bdff955ede0fe3a5a1bc2
BLAKE2b-256 89eeaaeaf588bf3c8dd8d015b825e5765a3fe4eca19aa825cd70690b952b716d

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