Class: OllamaChat::Chat
- Inherits:
-
Object
- Object
- OllamaChat::Chat
- Includes:
- Clipboard, Dialog, DocumentCache, History, Information, MessageFormat, ModelHandling, Parsing, ServerSocket, SourceFetching, Switches, WebSearching, Term::ANSIColor, Tins::GO
- Defined in:
- lib/ollama_chat/chat.rb
Class Attribute Summary collapse
-
.config ⇒ Object
Returns the value of attribute config.
Instance Attribute Summary collapse
-
#documents ⇒ Object
readonly
Returns the value of attribute documents.
-
#messages ⇒ Object
readonly
Returns the value of attribute messages.
-
#ollama ⇒ Object
readonly
Returns the value of attribute ollama.
Attributes included from ServerSocket
Attributes included from Dialog
Attributes included from Switches
#embedding, #embedding_enabled, #embedding_paused, #location, #markdown, #stream, #think, #voice
Instance Method Summary collapse
- #config ⇒ Object
- #config=(config) ⇒ Object
-
#initialize(argv: ARGV.dup) ⇒ Chat
constructor
A new instance of Chat.
- #links ⇒ Object
- #start ⇒ Object
Methods included from ServerSocket
#init_server_socket, runtime_dir, send_to_server_socket, server_socket_path
Methods included from History
#chat_history_filename, #clear_history, #init_chat_history, #save_history
Methods included from MessageFormat
#message_type, #talk_annotate, #think_annotate
Methods included from Clipboard
#copy_to_clipboard, #paste_from_input
Methods included from Information
#collection_stats, #display_chat_help, #info, #server_version, #usage, #version
Methods included from Dialog
#ask?, #change_system_prompt, #change_voice, #choose_collection, #choose_document_policy, #choose_model, #message_list
Methods included from WebSearching
Methods included from SourceFetching
#add_image, #embed, #embed_source, #fetch_source, #http_options, #import, #import_source, #summarize, #summarize_source
Methods included from Parsing
#parse_atom, #parse_content, #parse_csv, #parse_rss, #parse_source, #pdf_read, #ps_read, #reverse_markdown
Methods included from ModelHandling
#model_present?, #pull_model_from_remote, #pull_model_unless_present
Methods included from Switches
Methods included from DocumentCache
#configure_cache, #document_cache_class
Constructor Details
#initialize(argv: ARGV.dup) ⇒ Chat
Returns a new instance of Chat.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/ollama_chat/chat.rb', line 35 def initialize(argv: ARGV.dup) @opts = go 'f:u:m:s:c:C:D:MESVh', argv @opts[?h] and exit usage @opts[?V] and exit version @ollama_chat_config = OllamaChat::OllamaChatConfig.new(@opts[?f]) self.config = @ollama_chat_config.config setup_switches(config) base_url = @opts[?u] || config.url @ollama = Ollama::Client.new( base_url: base_url, debug: config.debug, user_agent: ) if server_version.version < '0.9.0'.version raise ArgumentError, 'require ollama API version 0.9.0 or higher' end @document_policy = config.document_policy @model = choose_model(@opts[?m], config.model.name) @model_options = Ollama::Options[config.model.] model_system = pull_model_unless_present(@model, @model_options) .set(config..enabled && !@opts[?E]) @messages = OllamaChat::MessageList.new(self) if @opts[?c] .load_conversation(@opts[?c]) else default = config.system_prompts.default? || model_system if @opts[?s] =~ /\A\?/ change_system_prompt(default, system: @opts[?s]) else system = OllamaChat::Utils::FileArgument.get_file_argument(@opts[?s], default:) system.present? and .set_system_prompt(system) end end @documents = setup_documents @cache = setup_cache @current_voice = config.voice.default @images = [] init_chat_history @opts[?S] and init_server_socket rescue ComplexConfig::AttributeMissing, ComplexConfig::ConfigurationSyntaxError => e fix_config(e) end |
Class Attribute Details
.config ⇒ Object
Returns the value of attribute config.
89 90 91 |
# File 'lib/ollama_chat/chat.rb', line 89 def config @config end |
Instance Attribute Details
#documents ⇒ Object (readonly)
Returns the value of attribute documents.
80 81 82 |
# File 'lib/ollama_chat/chat.rb', line 80 def documents @documents end |
#messages ⇒ Object (readonly)
Returns the value of attribute messages.
82 83 84 |
# File 'lib/ollama_chat/chat.rb', line 82 def @messages end |
#ollama ⇒ Object (readonly)
Returns the value of attribute ollama.
78 79 80 |
# File 'lib/ollama_chat/chat.rb', line 78 def ollama @ollama end |
Instance Method Details
#config ⇒ Object
96 97 98 |
# File 'lib/ollama_chat/chat.rb', line 96 def config self.class.config end |
#config=(config) ⇒ Object
92 93 94 |
# File 'lib/ollama_chat/chat.rb', line 92 def config=(config) self.class.config = config end |
#links ⇒ Object
84 85 86 |
# File 'lib/ollama_chat/chat.rb', line 84 def links @links ||= Set.new end |
#start ⇒ Object
100 101 102 103 104 105 106 107 108 |
# File 'lib/ollama_chat/chat.rb', line 100 def start info if .size > 1 .list_conversation(2) end STDOUT.puts "\nType /help to display the chat help." interact_with_user end |