Skip to content

Latest commit

 

History

43 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

LLM

Chat with Large Language Models (LLMs a.k.a. AI) using Textadept. Requires curl to be installed. This module can interact with OpenAI-compatible LLM servers, whether they are local (like mlx_lm) or remote. It can also interact with Ollama. Local LLM servers need to be running with one or more local models available.

Install this module by copying it into your ~/.textadept/modules/ directory or Textadept's modules/ directory, and then putting the following in your ~/.textadept/init.lua:

local llm = require('llm')
-- Remote, OpenAI-compatible server config.
llm.config.url = 'https://dev.example.com' -- if not OpenAI
llm.config.api_key = 'API_KEY'
-- Local mlx_lm server config.
llm.config.url = 'http://localhost:8080/v1'
-- Local Ollama config.
llm.config = llm.configs.ollama

Start a chat session from the "Tools > LLM (AI) > Chat..." menu.

Pressing Enter will prompt the model. Pressing Shift+Enter adds a new line without prompting the model. Typing @ will prompt you for an open file to inline as context to the model prompt.

If you have custom model options you want to use, like temperature and top_p, each server config has a models table with fields you can set. For example:

llm.config.model['mlx-community/Qwen3.5-9B-4bit'] = {
	stream = true, temperature = 0.7, top_p = 0.8, top_k = 20, max_tokens = 32768
}

The default model options enable streaming.

Note: if you are also using the scratch module, require this module after scratch, so that chats can be considered scratch buffers too.

llm.INDIC_LLM_END

The indicator number for where the LLM response ends.

llm.MARK_PROMPT

The marker number for prompt lines.

llm.MARK_PROMPT_COLOR

The color of prompt markers.

events.MODEL_RESPONSE

Emitted after a model is finished responding.

This could be used to provide a notification after a long wait time. Arguments:

  • message: The model's entire response.

events.MODEL_RESPONSE_STREAM

Emitted after a model emits a streamed response.

Arguments:

  • text: Partial model message.
  • done: Whether or not this is the last part of the stream.

llm.chat([model[, system_prompt[, current_buffer]]])

Opens a new chat session with a model.

Parameters:

  • model: String model name to chat with. If nil, the user is prompted for one.
  • system_prompt: String system prompt to use for model. If both this and model are nil, the user has the option to specify a system prompt for the model.
  • current_buffer: Whether or not to chat in the current buffer. The default value is false.

llm.config

The config table in configs to use.

Note: you may still have to configure things like the URL and API key. The default value is llm.configs.openai.

Fields:

  • url: String URL and port the server is running on.
  • models_endpoint: String REST endpoint that returns list of available models.
  • model_name_key: String key whose value is the model name for each model in the REST response for models_endpoint.
  • chat_endpoint: String REST endpoint for chatting with a model.
  • chat_message: Function that accepts a REST response table fromchat_endpoint and returns its message object (not a string).
  • done: Function that accepts a REST streaming response table from chat_endpoint and returns whether or not that endpoint is done streaming.
  • curl_headers: Optional map of HTTP headers to send with curl requests to the server.
  • api_key: Optional string API authorization key for the server. server does not support this option.
  • model: Map of model names to maps of model-specific options like 'stream', 'think', 'temperature', 'top_p', etc.

Usage:

llm.config = llm.configs.ollama

llm.configs

Configurations for various LLM servers.

Fields:

  • openai:
  • ollama:

See also: llm.config

llm.prompt(input)

Prompts the current chat model with input.

A model's response will be printed when it is received.

Parameters:

  • input: String input to prompt with. Any '@filename' references are replaced with their file's contents.

llm.prompts

Map of system prompt names (e.g. personas) to their prompt text. Users will typically select from this list prior to starting a chat session.

Usage:

llm.prompts.coding = 'You are a helpful coding assistant'

llm.show_system_prompt

Whether or not to show the system prompt when starting up a chat.

The default value is false.

llm.undo()

Undo the most recent chat message you submitted.

You will be able to edit and resend it.

About

Chat with local Ollama models using Textadept.

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Contributors

Languages