Skip to main content
Import: from gaia.chat.sdk import ChatSDK, ChatConfig, SimpleChat, ChatSession, quick_chat
See also: User Guide · API Specification

Core Classes

ChatConfig

Configure your chat session:
@dataclass
class ChatConfig:
    model: str = "Qwen3-Coder-30B-A3B-Instruct-GGUF"  # Default validated model
    max_tokens: int = 512
    temperature: Optional[float] = None
    system_prompt: Optional[str] = None
    max_history_length: int = 4
    show_stats: bool = False
    logging_level: str = "INFO"
    use_claude: bool = False       # Use Claude API
    use_chatgpt: bool = False      # Use ChatGPT/OpenAI API
    use_local_llm: bool = True     # Use local LLM
    claude_model: str = "claude-sonnet-4-20250514"
    base_url: Optional[str] = None # Lemonade server URL
    assistant_name: str = "gaia"

ChatResponse

Responses include text, history, and optional statistics:
@dataclass
class ChatResponse:
    text: str
    history: Optional[List[str]] = None
    stats: Optional[Dict[str, Any]] = None
    is_complete: bool = True  # False for streaming chunks

SimpleChat

Lightweight wrapper for basic chat without complex configuration. Perfect for getting started quickly.
from gaia.chat.sdk import SimpleChat

chat = SimpleChat()
response = chat.ask("What is Python?")
print(response)

# Follow-up with conversation memory
response = chat.ask("Give me an example")
print(response)

Quick Chat (One-Off)

from gaia.chat.sdk import quick_chat

# Single query — returns str directly
response = quick_chat("What is machine learning?")
print(response)

# With options
response = quick_chat(
    "Explain quantum computing",
    model="Qwen3-Coder-30B-A3B-Instruct-GGUF",
    system_prompt="You are a physics teacher."
)
print(response)

Chat with Memory

from gaia.chat.sdk import ChatSDK, ChatConfig

config = ChatConfig(
    model="Qwen3-0.6B-GGUF",
    max_tokens=512,
    max_history_length=4,
    system_prompt="You are a helpful coding assistant.",
    assistant_name="CodeBot"
)

chat = ChatSDK(config)

# Multi-turn conversation
response1 = chat.send("What is Python?")
print(response1.text)

response2 = chat.send("Show me an example")
print(response2.text)  # LLM remembers context

# Check history
history = chat.get_history()
print(f"Conversation turns: {len(history)}")

chat.clear_history()

Streaming

from gaia.chat.sdk import ChatSDK

chat = ChatSDK()

print("AI: ", end="", flush=True)
for chunk in chat.send_stream("Tell me a story"):
    if not chunk.is_complete:
        print(chunk.text, end="", flush=True)
print()

Custom Assistant

from gaia.chat.sdk import ChatConfig, ChatSDK

config = ChatConfig(
    assistant_name="Gaia",
    system_prompt="You are Gaia, a helpful AI assistant."
)
chat = ChatSDK(config)

response = chat.send("What's your name?")
print(f"Gaia: {response.text}")

Session Management

Manage multiple conversation contexts:
from gaia.chat.sdk import ChatSession

sessions = ChatSession()

# Create different contexts with custom names
work_chat = sessions.create_session(
    "work",
    system_prompt="You are a professional assistant.",
    assistant_name="WorkBot"
)

personal_chat = sessions.create_session(
    "personal",
    system_prompt="You are a friendly companion.",
    assistant_name="Buddy"
)

# Separate conversation histories
work_response = work_chat.send("Draft a team email")
personal_response = personal_chat.send("What's for dinner?")

Conversation History

from gaia.chat.sdk import ChatSDK

chat = ChatSDK()

chat.send("Hello")
chat.send("How are you?")

# Get formatted history
for entry in chat.get_formatted_history():
    print(f"{entry['role']}: {entry['message']}")

chat.clear_history()
print(f"Conversation pairs: {chat.conversation_pairs}")

Chat with RAG

from gaia.chat.sdk import ChatSDK

chat = ChatSDK()

# Enable RAG and index documents
chat.enable_rag(documents=["manual.pdf", "guide.pdf"])

# Chat with document context
response = chat.send("What does the manual say about installation?")
print(response.text)

# Add more documents
chat.add_document("troubleshooting.pdf")

# Disable RAG when done
chat.disable_rag()

Advanced RAG Configuration

from gaia.chat.sdk import ChatSDK

chat = ChatSDK()

chat.enable_rag(
    documents=["doc1.pdf", "doc2.pdf"],
    chunk_size=600,      # Larger chunks for more context
    max_chunks=4,        # More chunks per query
    chunk_overlap=100    # Overlap for context preservation
)

if chat.rag:
    status = chat.rag.get_status()
    print(f"Indexed {status['indexed_files']} files")
    print(f"Total chunks: {status['total_chunks']}")

Custom Messages

from gaia.chat.sdk import ChatSDK

chat = ChatSDK()

messages = [
    {"role": "system", "content": "You are a math tutor."},
    {"role": "user", "content": "Explain calculus"},
    {"role": "assistant", "content": "Calculus is..."},
    {"role": "user", "content": "Give me an example"}
]

response = chat.send_messages(
    messages=messages,
    system_prompt="Be concise and clear"
)
print(response.text)

API Reference

ChatSDK Methods

Messaging

  • send(message: str) -> ChatResponse
  • send_stream(message: str)
  • send_messages(messages, system_prompt) -> ChatResponse

History

  • get_history() -> List[str]
  • clear_history()
  • get_formatted_history() -> List[Dict]
  • conversation_pairs (property)

RAG (Document Q&A)

  • enable_rag(documents=None, **kwargs)
  • disable_rag()
  • add_document(path: str) -> bool

Configuration

  • update_config(**kwargs)
  • get_stats() -> Dict
  • display_stats(stats=None)
  • start_interactive_session()

SimpleChat Methods

  • ask(question: str) -> str — Ask question, get response
  • ask_stream(question: str) — Ask question, stream response
  • clear_memory() — Clear conversation memory
  • get_conversation() -> List[Dict] — Get conversation history

ChatSession Methods

  • create_session(session_id, config=None, **kwargs) -> ChatSDK — Create new session
  • get_session(session_id) -> ChatSDK — Get existing session
  • delete_session(session_id) -> bool — Delete session
  • list_sessions() -> List[str] — List all sessions
  • clear_all_sessions() — Delete all sessions

Utility Functions

  • quick_chat(message, system_prompt=None, model=None, assistant_name=None) -> str
  • quick_chat_with_memory(messages, system_prompt=None, model=None, assistant_name=None) -> List[str]

Best Practices

Choose the Right Interface

SimpleChat for basic needs, ChatSDK for full features, ChatSession for multi-context apps

Memory Management

Configure max_history_length based on memory constraints

Performance

Enable show_stats=True during development

Resource Cleanup

Clear sessions when done to free memory