Skip to main content

ask

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

Import

from openstackai 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

ParameterTypeDefaultDescription
questionstrrequiredThe question to ask
contextstrNoneAdditional context to include
modelstrNoneOverride default model
temperaturefloat0.7Response creativity (0-1)

Return Value

Returns a string containing the AI's response.

Examples

Simple Questions

from openstackai 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 = """
openstackai is a Python SDK for building AI agents.
It supports multiple providers and enterprise features.
"""

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

Async Usage

import asyncio
from openstackai import ask

async def main():
answer = await ask.async_("What is openstackai?")
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

  • [[research]] - Deep topic research
  • [[summarize]] - Text summarization
  • [[chat]] - Interactive conversation