Luxury Property Listings - AI-Powered Chat Interface

Engage with our advanced AI chat system, utilizing the latest in .NET MVC and SignalR technology for real-time communication.

Interactive Chat with AI - Luxury Property Listings

Experience an interactive chat interface with Luxury Property Listings powered by AI. Discover how PromptSpark enhances communication with advanced SignalR integration and seamless user interactions.

Features of PromptSpark

  • Core Sparks: Define standard AI behaviors for consistent performance.
  • Spark Variants: Explore and test different prompt implementations.
  • Spark Inputs: Evaluate and refine responses with various input configurations.
  • Performance Tracking: Monitor accuracy, relevance, and efficiency of prompts.

ChatCompletions Functionality

The ChatCompletions feature enables interactive conversations with specific PromptSpark Variants. Users can tailor AI responses by selecting the appropriate variant, which influences the behavior and tone of the interaction.

Why Choose PromptSpark?

PromptSpark provides a streamlined approach to managing and optimizing AI prompts, making it an essential tool for developers and businesses seeking to enhance their AI-driven applications. By leveraging Core Sparks, Variants, and Inputs, users can refine their interactions with large language models, ensuring more accurate and contextually appropriate responses.

What is Microsoft SignalR?

Microsoft SignalR is an open-source library that simplifies the process of adding real-time web functionality to applications. Real-time web functionality is the ability of a server to push content updates to clients instantly, as they happen. SignalR supports WebSockets, server-sent events, and long polling, enabling seamless client-server communication.

  • Real-Time Communication: SignalR allows bi-directional communication between server and client.
  • Transport Protocols: Automatically selects the best transport available, falling back through WebSockets, server-sent events, and long polling.
  • Hub API: Provides a simple API to call methods on clients from the server and vice versa.
  • Security: Integrates with ASP.NET Core authentication and authorization, securing communication channels.

Pros and Cons of Using SignalR

Pros

  • Real-Time Capability: Enables instant updates without client polling.
  • Scalability: Can be scaled easily with Azure SignalR Service.
  • Flexibility: Supports various transport protocols, providing robust fallback mechanisms.
  • Easy Integration: Integrates well with ASP.NET Core, simplifying real-time features in web applications.

Cons

  • Resource Intensive: High frequency of real-time updates can be resource-intensive for servers.
  • Complex Scaling: Self-hosted SignalR scaling requires careful planning and infrastructure.
  • Browser Compatibility: Not all transport protocols are supported across all browsers.
  • Latency: Potential latency issues when using fallback transports like long polling.

Scaling SignalR with Azure SignalR Service

Azure SignalR Service is a fully managed Azure service that simplifies the process of adding real-time web functionality to applications using SignalR. It offloads the responsibility of scaling SignalR connections, managing performance, and maintaining the service infrastructure.

  • Automatic Scaling: Azure SignalR Service automatically scales to handle a large number of connections, making it suitable for large-scale applications.
  • Performance Optimization: Offloads connection handling from your server, improving overall application performance.
  • Security and Compliance: Built-in support for security and compliance, integrating seamlessly with other Azure services.
  • Easy Integration: Minimal configuration needed; simply switch the connection from your local SignalR setup to Azure SignalR Service.

To use Azure SignalR Service, you just need to configure your ASP.NET Core application to connect to Azure SignalR Service instead of self-hosting SignalR.

Example Configuration for self-hosting:

    
// ========================
// SignalR Configuration
// ========================
// Add CORS configuration if needed for SignalR
builder.Services.AddCors(options =>
{
    options.AddPolicy("AllowAllOrigins", builder =>
    {
        builder.AllowAnyHeader()
               .AllowAnyMethod()
               .SetIsOriginAllowed(_ => true)  // Allows all origins
               .AllowCredentials();            // Necessary for SignalR
    });
});

// SignalR Configuration
builder.Services.AddSignalR().AddJsonProtocol(options =>
{
    // Configuring JSON serializer options if needed
    options.PayloadSerializerOptions.PropertyNamingPolicy = null;
});

// ========================
// Endpoint Configuration
// ========================
app.MapHub("/chatHub");
app.MapHub("/crawlHub");




Real-Time Chat with SignalR

SignalR enables real-time communication between the browser and server, facilitating interactive conversations with OpenAI through ChatCompletions. Below is a basic setup for SignalR and its integration with OpenAI API calls:

            
// ChatHub.cs
public class ChatHub : Hub
{
    public async Task SendMessage(string user, string message)
    {
        await Clients.All.SendAsync("ReceiveMessage", user, message);
    }
}

// Startup.cs
public void ConfigureServices(IServiceCollection services)
{
    services.AddSignalR();
}

public void Configure(IApplicationBuilder app)
{
    app.UseRouting();
    app.UseEndpoints(endpoints => { endpoints.MapHub<ChatHub>("/chatHub"); });
}

Client-Side Integration

On the client side, JavaScript connects to the SignalR hub and listens for messages from the server:

            
// Client-side JavaScript
const connection = new signalR.HubConnectionBuilder().withUrl("/chatHub").build();
connection.start().catch(err => console.error(err.toString()));
connection.on("ReceiveMessage", function (user, message) {
    const msg = `${user}: ${message}`;
    document.getElementById("messagesList").appendChild(document.createElement("li")).textContent = msg;
});