Starting a Chat Session#
Once you have deployed your model, you can start a chat session to interact with it. A chat session allows you to:
Add or modify constraints using natural language
Query the current state of the model
Solve the model with different input data
Creating a Chat Session#
To start a chat session, you need:
Your input data (instance of
InputData)The model ID from deployment
from decision_ai import DecisionAI
# Initialize client
client = DecisionAI()
# Create chat session
chat_session = client.create_chat_session(
your_input_data,
your_model_id
)
Interactive Chat#
Use the async context manager for real-time interaction:
async with chat_session.connect() as chat:
async for message in chat.stream_messages("Add a constraint that limits total production to 1000"):
print(message)
Note
The stream_messages method returns MessageContainer objects. When printing or displaying these messages,
you need to convert them to string first using str(message).
Direct Model Access#
Solve the model directly:
# Solve with current constraints
solution = chat_session.solve()
# Convert solution to string
solution_str = chat_session.solution_to_str(your_input_data, solution)
For more advanced usage and state management, see Working with Chat Sessions.
For a complete working example, see Chat Session Example.