Skip to content
gitpavleenbali edited this page Feb 17, 2026 · 2 revisions

ask

The ask function is the simplest way to get answers from an AI model.

Import

from pyai import ask

Basic Usage

# Simple question
answer = ask("What is the capital of France?")
print(answer)  # "Paris"

# With context
answer = ask("Summarize this", context="Long text here...")

# Async version
answer = await ask.async_("What is Python?")

Parameters

Parameter Type Default Description
question str required The question to ask
context str None Additional context to include
model str None Override default model
temperature float 0.7 Response creativity (0-1)

Return Value

Returns a string containing the AI's response.

Examples

Simple Questions

from pyai import ask

# Factual questions
answer = ask("What is machine learning?")

# With specific model
answer = ask("Explain quantum computing", model="gpt-4")

# With custom temperature
answer = ask("Write a creative story", temperature=0.9)

With Context

document = """
PYAI is a Python SDK for building AI agents.
It supports multiple providers and enterprise features.
"""

answer = ask("What does PYAI support?", context=document)
# "PYAI supports multiple providers and enterprise features."

Async Usage

import asyncio
from pyai import ask

async def main():
    answer = await ask.async_("What is PYAI?")
    print(answer)

asyncio.run(main())

Configuration

Configure default behavior using environment variables:

OPENAI_API_KEY=your-key
# or
AZURE_OPENAI_ENDPOINT=https://your-resource.openai.azure.com/
AZURE_OPENAI_DEPLOYMENT=gpt-4o-mini

See Also

🧠 PYAI Wiki

Home


πŸš€ Getting Started


πŸ’‘ Core Concepts


🎯 One-Liner APIs


πŸ€– Agent Framework


πŸ”— Multi-Agent


πŸ› οΈ Tools & Skills


🏒 Enterprise


πŸŽ™οΈ Voice


πŸ–ΌοΈ Multimodal


πŸ“Š Vector DB


🌐 OpenAPI


πŸ”Œ Plugins


🀝 A2A Protocol


πŸ”’ Security


πŸ“š Reference


Intelligence, Embedded.

Clone this wiki locally