NumpyAISession

class numpyai.NumpyAISession(data: List[ndarray | array], verbose=False, provider_name='google', model_name=None)

Bases: object

Session to handle chatting with multiple arrays.

Parameters:
  • data – List[numpy.ndarray] The data of the array class.

  • verbose – boolean Shows all code executions if True, else only shows the final execution.

  • provider_name (str) – LLM provider name (“google”, “openai”, or “claude”).

  • model_name (Optional[str]) – Specific model name to use (defaults per provider).

MAX_TRIES = 3
assert_is_code(llm_response: str) str

Ensure LLM response is valid Python/NumPy code.

chat(query: str) Any

Handles user queries by generating and executing NumPy code with retries.

execute_numpy_code(code: str, code_out=None) Any

Executes generated NumPy code within the session’s context.

generate_numpy_code(query: str, context: Dict) str

Generate valid NumPy code from the query.

validate_output(query: str, output: Any, explainer, error=None) bool

Validates the output of a NumPy operation.