Module: OllamaChat::LocationHandling

Included in:
Chat
Defined in:
lib/ollama_chat/location_handling.rb

Overview

A module that provides location handling functionality for OllamaChat.

The LocationHandling module encapsulates methods for managing location information, including generating location data and creating location descriptions for use in chat sessions. It integrates with the application’s configuration to provide contextual location information to language models.

Examples:

Generating location information

chat.location_data # => { location_name: "New York", location_decimal_degrees: "40.7128, -74.0060", units: "metric" }
chat.location_description # => "Current location: New York (40.7128, -74.0060) at 2023-10-15T10:30:00Z in metric units"

Instance Method Summary collapse

Instance Method Details

#location_dataHash

Generates a hash containing current location data.

This method collects and returns structured location information including the location name, decimal degrees coordinates, and units.

Returns:

  • (Hash)

    a hash containing location data with keys:

    • location_name: The name of the location

    • location_decimal_degrees: Comma-separated decimal degrees coordinates

    • units: The unit system (metric, imperial, etc.)



41
42
43
44
45
46
47
# File 'lib/ollama_chat/location_handling.rb', line 41

def location_data
  {
    location_name:            config.location.name,
    location_decimal_degrees: config.location.decimal_degrees * ', ',
    units:                    config.location.units,
  }
end

#location_descriptionString

Generates a location description string formatted with the current location data.

This method creates a formatted string containing location information including name, coordinates, local and units, using the configured location prompt template.

Returns:

  • (String)

    a formatted location description string



20
21
22
# File 'lib/ollama_chat/location_handling.rb', line 20

def location_description
  config.prompts.location % location_data
end

#location_description?String?

The location_description? method returns the location description string if the location setting is enabled; otherwise it returns nil.

Returns:

  • (String, nil)


28
29
30
# File 'lib/ollama_chat/location_handling.rb', line 28

def location_description?
  location_description if location.on?
end