Pretend there is a black box. You can ask it any question, and it will return a response in a particular form. However, you are only allowed to ask types of questions.
A question type is a clearly defined query that accepts one or more objects as input. Each class (object specification) must be defined with typed fields before you can use it.
Every question type takes objects as input. Every response is also a structured object. You define both.
Here is an example. The oracle answers questions about stocks. First, define your questions:
Then define your input classes and response classes:
from pydantic import BaseModel from typing import Optional from enum import Enum # The objects (inputs) class Stock(BaseModel): symbol: str market: str class StockPurchase(BaseModel): stock: Stock quantity: float price: float # The response (output) class Status(Enum): SELL = "SELL" HOLD = "HOLD" BUY = "BUY" class Response(BaseModel): status: Optional[Status] by: Optional[float] # percentage/amount reason: str
Design your law oracle.
You do not need to write the specifications in Python. I got AI to do that for me from natural language.
Here is how the objects relate to each other and to the oracle:
Imagina que exista una caja negra. Puedes preguntarle cualquier cosa y te devolverá una respuesta en una forma particular. Sin embargo, el oráculo solo puede entender tipos de preguntas.
Un tipo de pregunta es una consulta claramente definida que acepta uno o más objetos como entrada. Cada objeto debe definirse en una clase con variables tipados.
Cada tipo de pregunta recibe objetos como entrada. Cada respuesta también es un objeto estructurado. Tú defines ambos.
Aquí hay un ejemplo. El oráculo responde preguntas sobre acciones bursátiles. Primero, define tus preguntas:
Luego define tus clases de entrada y de respuesta:
from pydantic import BaseModel from typing import Optional from enum import Enum # Los objetos (entradas) class Accion(BaseModel): simbolo: str mercado: str class CompraDeAccion(BaseModel): accion: Accion cantidad: float precio: float # La respuesta (salida) class Estado(Enum): VENDER = "VENDER" MANTENER = "MANTENER" COMPRAR = "COMPRAR" class Respuesta(BaseModel): estado: Optional[Estado] por: Optional[float] # porcentaje/cantidad razon: str
Diseña tu oráculo de leyes.
No necesitas escribir las especificaciones en Python. Yo usé IA para hacerlo desde lenguaje natural.
Así es como los objetos se relacionan entre ellos y con el oráculo: