LLM Integration¶
The Virtualitics SDK integrates with Large Language Models through IRIS, enabling AI-powered features in your apps.
Overview¶
LLM integration provides:
- Chat Interface: Interactive conversations with LLMs
- Agent System: Custom AI agents for specific tasks
- Context Awareness: Apps can provide context to LLM queries
- Customization: Pre/post-process LLM requests and responses
Key Components¶
Basic Usage¶
Adding Chat to Your App¶
from virtualitics_sdk import App, Step, Page, Section, Card
from virtualitics_sdk.llm import Chat
class ChatStep(Step):
def run(self, flow_metadata):
# Create chat interface
chat = Chat(
id="assistant",
title="AI Assistant",
system_prompt="You are a helpful data analysis assistant."
)
return Page(
title="Chat",
sections=[
Section(
title="AI Assistant",
cards=[Card(title="Chat", content=[chat])]
)
]
)
Providing Context to LLM¶
from virtualitics_sdk import App
# Define context callbacks
async def on_llm_request(request_data, link, flow_metadata):
"""Pre-process data before sending to LLM."""
# Add app-specific context
dataset = link.dataset
context = {
"dataset_summary": {
"rows": len(dataset.data),
"columns": list(dataset.data.columns),
"stats": dataset.data.describe().to_dict()
}
}
request_data["context"] = context
return request_data
async def on_llm_response(response_data, link, flow_metadata):
"""Post-process LLM response."""
# Log response
print(f"LLM responded: {response_data}")
return response_data
# Create app with LLM callbacks
app = App(
name="AI-Powered Analysis",
description="App with LLM integration",
on_llm_request=on_llm_request,
on_llm_response=on_llm_response
)
Default Prompts¶
Provide suggested prompts for users:
app = App(
name="Sales Analysis",
description="Analyze sales data with AI",
default_prompts=[
"What are the top selling products?",
"Show me sales trends over time",
"Identify any anomalies in the data",
"Suggest ways to improve sales"
]
)
See Also¶
- Chat - Chat interface details
- Agent - Custom AI agents
- Concepts: LLM Integration