Module: Askcii

Defined in:
lib/askcii.rb,
lib/askcii/cli.rb,
lib/askcii/version.rb,
lib/askcii/application.rb,
lib/askcii/models/chat.rb,
lib/askcii/chat_session.rb,
lib/askcii/models/config.rb,
lib/askcii/models/message.rb,
lib/askcii/configuration_manager.rb

Defined Under Namespace

Classes: Application, CLI, Chat, ChatSession, Config, ConfigurationManager, Error, Message

Constant Summary collapse

VERSION =
'0.3.0'

Class Method Summary collapse

Class Method Details

.configure_llm(selected_config = nil) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/askcii.rb', line 55

def self.configure_llm(selected_config = nil)
  RubyLLM.configure do |config|
    config.log_file = '/dev/null'

    if selected_config
      provider = selected_config['provider'] || 'openai'
      api_key = selected_config['api_key']

      # Set the appropriate API key based on provider
      case provider.downcase
      when 'openai'
        config.openai_api_key = api_key || 'blank'
        config.openai_api_base = selected_config['api_endpoint'] || 'https://api.openai.com/v1'
      when 'anthropic'
        config.anthropic_api_key = api_key || 'blank'
      when 'gemini'
        config.gemini_api_key = api_key || 'blank'
      when 'deepseek'
        config.deepseek_api_key = api_key || 'blank'
      when 'openrouter'
        config.openrouter_api_key = api_key || 'blank'
      when 'ollama'
        # Ollama doesn't need an API key
        config.openai_api_base = selected_config['api_endpoint'] || 'http://localhost:11434/v1'
      end
    else
      # Legacy configuration fallback
      config.openai_api_key = begin
        Askcii::Config.api_key || ENV['ASKCII_API_KEY'] || 'blank'
      rescue StandardError
        ENV['ASKCII_API_KEY'] || 'blank'
      end

      config.openai_api_base = begin
        Askcii::Config.api_endpoint || ENV['ASKCII_API_ENDPOINT'] || 'http://localhost:11434/v1'
      rescue StandardError
        ENV['ASKCII_API_ENDPOINT'] || 'http://localhost:11434/v1'
      end
    end
  end
end

.databaseObject



11
12
13
# File 'lib/askcii.rb', line 11

def self.database
  @@database ||= Sequel.amalgalite(db_path)
end

.db_pathObject

Get the path to the database file



16
17
18
19
20
# File 'lib/askcii.rb', line 16

def self.db_path
  db_dir = File.join(ENV['HOME'], '.local', 'share', 'askcii')
  FileUtils.mkdir_p(db_dir) unless Dir.exist?(db_dir)
  File.join(db_dir, 'askcii.db')
end

.require_applicationObject



103
104
105
# File 'lib/askcii.rb', line 103

def self.require_application
  require_relative './askcii/application'
end

.require_modelsObject



97
98
99
100
101
# File 'lib/askcii.rb', line 97

def self.require_models
  require_relative './askcii/models/chat'
  require_relative './askcii/models/message'
  require_relative './askcii/models/config'
end

.setup_databaseObject

Initialize the database



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/askcii.rb', line 23

def self.setup_database
  unless database.table_exists?(:chats)
    database.create_table :chats do
      primary_key :id
      String :model_id, null: true
      String :context, null: true
      Datetime :created_at, null: false, default: Sequel::CURRENT_TIMESTAMP
    end
  end

  unless database.table_exists?(:messages)
    database.create_table :messages do
      primary_key :id
      foreign_key :chat_id, :chats, null: false
      String :role, null: true
      Text :content, null: true
      String :model_id, null: true
      Integer :input_tokens, null: true
      Integer :output_tokens, null: true
      Datetime :created_at, null: false, default: Sequel::CURRENT_TIMESTAMP
    end
  end

  return if database.table_exists?(:configs)

  database.create_table :configs do
    primary_key :id
    String :key, null: false, unique: true
    Text :value, null: true
  end
end