Managing Multiple Tutoring Sessions with DeepSeek in Go

Managing Multiple Tutoring Sessions with DeepSeek in Go

Welcome to the next step in building your personal tutor with DeepSeek! In previous lessons, you learned how to send queries to DeepSeek's language model, customize model parameters, maintain session history, and personalize your AI tutor using system prompts — all in Go. Now, you'll learn how to manage multiple tutoring sessions at once. This is essential for applications that serve several students simultaneously, such as an online tutoring platform. By the end of this lesson, you'll be able to create and manage multiple tutoring sessions using Go, setting the foundation for scalable educational applications.

Creating Unique Tutoring Sessions

In a tutoring application, each educational interaction should be treated as a separate session. To achieve this in Go, we use a map to store all active sessions, where each session is identified by a unique session ID. We generate these unique IDs using the github.com/google/uuid package. Each session's history is stored as a slice of Message structs.

Here's how you can set up session management in Go:

package main

import (
    "fmt"
    "github.com/google/uuid"
)

// Message struct represents a single message in the conversation
type Message struct {
    Role    string
    Content string
}

// Define a map to store all active tutoring sessions
// The key is a string representing the unique session ID
// The value is a slice of Message structs representing the conversation history
var tutoringSessions map[string][]Message

func init() {
    // Initialize the map to store tutoring sessions
    tutoringSessions = make(map[string][]Message)
}

// Common system prompt for all sessions
var systemPrompt = Message{
    Role:    "system",
    Content: "You are a knowledgeable and patient tutor, ready to assist with various academic subjects.",
}

// CreateSession creates a new tutoring session with a unique identifier
func CreateSession() string {
    sessionID := uuid.New().String() // Generate unique session ID
    // Initialize session history with the system prompt
    tutoringSessions[sessionID] = []Message{systemPrompt}
    return sessionID
}

In this setup, we define a map called tutoringSessions that stores all active tutoring sessions. Each key in the map is a unique session ID (a string), and each value is a slice of Message structs that represents the conversation history for that session. We initialize this map in the init() function, which runs automatically when the package is loaded.

When a new session is created using the CreateSession() function, we generate a unique ID using the UUID package, initialize the session's history with the system prompt, and store it in the map. This ensures that each student gets their own separate conversation context with the AI tutor.

Sign up

Join the 1M+ learners on CodeSignal

Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal