GithubHelp home page GithubHelp logo

llm-intellij's Introduction

LLM powered development for IntelliJ

llm-intellij is a plugin for all things LLM. It uses llm-ls as a backend.

Note

When using the Inference API, you will probably encounter some limitations. Subscribe to the PRO plan to avoid getting rate limited in the free tier.

https://huggingface.co/pricing#pro

Features

Code completion

This plugin supports "ghost-text" code completion, à la Copilot.

Choose your model

Requests for code generation are made via an HTTP request.

You can use the Hugging Face Inference API or your own HTTP endpoint, provided it adheres to the API specified here or here.

Always fit within the context window

The prompt sent to the model will always be sized to fit within the context window, with the number of tokens determined using tokenizers.

Configuration

Endpoint

With Inference API

  1. Create and get your API token from here https://huggingface.co/settings/tokens.

  2. Define how the plugin will read your token. For this you have multiple options, in order of precedence:

    1. Set API token = <your token> in plugin settings
    2. (not supported yet) You can define your HF_HOME environment variable and create a file containing your token at $HF_HOME/token
    3. (not supported yet) Install the huggingface-cli and run huggingface-cli login - this will prompt you to enter your token and set it at the right path
  3. Choose your model on the Hugging Face Hub, and set Model = <model identifier> in plugin settings

With your own HTTP endpoint

All of the above still applies, but note:

  • When an API token is provided, it will be passed as a header: Authorization: Bearer <api_token>.

  • Instead of setting a Hugging Face model identifier in model, set the URL for your HTTP endpoint

Models

llm-intellij is assumed to be compatible with any model that generates code.

Here are some configs for popular models in JSON format that you can put in your Settings (Cmd+, > LLM Settings)

{
   "tokensToClear": [
      "<|endoftext|>"
   ],
   "fim": {
      "enabled": true,
      "prefix": "<fim_prefix>",
      "middle": "<fim_middle>",
      "suffix": "<fim_suffix>"
   },
   "model": "bigcode/starcoder",
   "context_window": 8192,
   "tokenizer": {
     "repository": "bigcode/starcoder"
   }
}

Note

These are the default config values

{
   "tokensToClear": [
      "<EOT>"
   ],
   "fim": {
      "enabled": true,
      "prefix": "<PRE> ",
      "middle": " <MID>",
      "suffix": " <SUF>"
   },
   "model": "codellama/CodeLlama-13b-hf",
   "context_window": 4096,
   "tokenizer": {
      "repository": "codellama/CodeLlama-13b-hf"
   }
}

Note

Spaces are important here

By default, llm-ls is installed by llm-intellij the first time it is loaded. The binary is downloaded from the release page and stored in:

"$HOME/.cache/llm_intellij/bin"

When developing locally or if you built your own binary because your platform is not supported, you can set the llm-ls > Binary path setting to the path of the binary.

llm-ls > Version is used only when llm-intellij downloads llm-ls from the release page.

You can also set the log level for llm-ls with llm-ls > Log level, which can take any of the usual info, warn, error, etc as a value. The log file is located in:

"$HOME/.cache/llm_ls/llm-ls.log"

Tokenizer

llm-ls uses tokenizers to make sure the prompt fits the context_window.

To configure it, you have a few options:

  • No tokenization, llm-ls will count the number of characters instead:
  • from a local file on your disk:
  • from a Hugging Face repository, llm-ls will attempt to download tokenizer.json at the root of the repository:
  • from an HTTP endpoint, llm-ls will attempt to download a file via an HTTP GET request:

llm-intellij's People

Contributors

mcpatate avatar

Stargazers

Hoik avatar Jioh L. Jung avatar  avatar  avatar zjw57 avatar  avatar  avatar Bertil Chapuis avatar Kenny Freitas avatar Nikita Samoylov avatar Sylvain Garden avatar  avatar David avatar Tonic avatar  avatar zhanghaiqiang avatar Abhinav Atul avatar huihai avatar Jonas Kesselmeier avatar Laurent Kempé avatar Daniel Adari avatar  avatar Dmitriy Zhavoronkov avatar Timothy Spann avatar Giáo Hồ avatar Sarfraz Ahmed avatar Gary Blankenship avatar  avatar  avatar  avatar  avatar Ryuukae  avatar Andy Xue avatar Joel Handwell avatar Ashok Kallarakuzhi avatar Cedric Kring avatar yixinzhang avatar  avatar Yec avatar  avatar Suresh avatar kafka0102 avatar  avatar  avatar Arthur ROUÉ avatar nathfavour avatar  avatar Roc avatar BruceMa avatar JustasM avatar Manuel Eiweck avatar  avatar Antoine Boegli avatar Mike Shi avatar Gennaro Landolfi avatar Jonathan Sowards avatar  avatar David Abutbul avatar  avatar Ilan Aliouchouche avatar  avatar  avatar  avatar  avatar

Watchers

Julien Chaumond avatar Andrew Denyes avatar Funtowicz Morgan avatar  avatar Thomas Wolf avatar  avatar Guillaume Salou avatar Arun Sathiya avatar  avatar

llm-intellij's Issues

PHPStorm - Error

Hi!
If i try to install this plugin into my PHPStorm, i get this error:

Plugin 'LLM' (version 0.0.2) was explicitly marked as incompatible with the current version of the IDE

any chance to get this running? or is there any other plugin available to connect my local huggingface/text-generation-inference ?

thx!

Download of llm-ls does not work

Hi,

At first thank you very much about this great plugin. It is great to have the possibility to test LLMs out of the IDE. This is great stuff.

Unfortunately I have also an issue. At first I had some troubles to get a request out of the IDE until I recognised, that the llm-ls was missing. I am not sure, if the IDE proxy settings are respected for the download.

I managed it to download and install it by hand (Ubuntu 22.04).

Now when I enter the API access token with my own endpoint. The field is empty when I reopen the settings window. A header dump on the server does not show the bearer token either:

HTTP_HOST=XXX
SSL_TLS_SNI=XXX
CONTEXT_DOCUMENT_ROOT=/var/www/cgi-bin/
HTTPS=on
HTTP_USER_AGENT=llm-ls/0.4.0; rust/unknown; ide/JetBrains
SERVER_ADMIN=XXX
CONTEXT_PREFIX=/cgi-bin/
SERVER_PORT=443
SERVER_NAME=XXX
QUERY_STRING=
SCRIPT_FILENAME=/var/www/cgi-bin/postTest.sh
PWD=/var/www/cgi-bin
HTTP_ACCEPT=/
CONTENT_TYPE=application/json
REQUEST_METHOD=POST
SERVER_SIGNATURE=
SCRIPT_NAME=/cgi-bin/postTest.sh
REMOTE_PORT=54435
UNIQUE_ID=ZUyNoRkEkSDekapOW0nrsQAAAMw
DOCUMENT_ROOT=/var/www/html
SHLVL=1
SERVER_PROTOCOL=HTTP/1.1
REQUEST_URI=/cgi-bin/postTest.sh
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
SERVER_ADDR=XXX
GATEWAY_INTERFACE=CGI/1.1
REQUEST_SCHEME=https
REMOTE_ADDR=XXX
CONTENT_LENGTH=259
SERVER_SOFTWARE=XXX
_=/usr/bin/env

Do you have any idea how this could happen, or do you need some further informations?

Arch Linux: llm-ls binary is not downloaded by default

Hi there, very happy about and eager to use this plugin.

A minor issue:
On my system (Arch-Linux, Intel® Core™ i7 Processor) the llm-ls binary is not downloaded automatically at first start as claimed in the Readme.

In the settings menu it seems to expect llm-ls-amd64-unknown-linux-gnu-0.4.0 which does not exist on the release page.

Manually downloading and using the x86_64-unknown-linux version from https://github.com/huggingface/llm-ls/releases works.

Plugin does not work: llm-ls process creation fails

System: Arch Linux
Processor: Intel® Core™ i7-1270P
Intellij Version: IntelliJ IDEA 2023.2.4 (Ultimate Edition)

I am trying to use the plugin with a self-hosted instance. I was able to make the neovim-plugin work on my computer, but the one for intellij does not do anything (using the same llm-ls binary).

Intellij logs the following error right after startup which might be related:

2023-10-27 16:00:51,173 [ 133942]   WARN - #c.i.e.p.BaseOSProcessHandler - Process hasn't generated any output for a long time.
If it's a long-running mostly idle daemon process, consider overriding OSProcessHandler#readerOptions with 'BaseOutputReader.Options.forMostlySilentProcess()' to reduce CPU usage.
Command line: /home/tng/.cache/llm_intellij/bin/llm-ls-amd64-unknown-linux-gnu-0.4.0 --stdio
java.lang.Throwable: Process creation:
	at com.intellij.execution.process.BaseOSProcessHandler.<init>(BaseOSProcessHandler.java:35)
	at com.intellij.execution.process.OSProcessHandler.<init>(OSProcessHandler.java:44)
	at com.intellij.platform.lsp.api.LspServerDescriptor.startServerProcess(LspServerDescriptor.kt:95)
	at com.intellij.platform.lsp.impl.connector.Lsp4jServerConnectorStdio.<init>(Lsp4jServerConnectorStdio.java:19)
	at com.intellij.platform.lsp.impl.LspServerImpl.q(LspServerImpl.java:377)
	at com.intellij.openapi.application.impl.ApplicationImpl$2.run(ApplicationImpl.java:272)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
	at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:702)
	at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:699)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
	at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1.run(Executors.java:699)
	at java.base/java.lang.Thread.run(Thread.java:833)

Potential Memory Leak in LlmLsCompletionProvider.kt Affecting Plugin Performance

Title: Potential Memory Leak in LlmLsCompletionProvider.kt Affecting Plugin Performance

Description:

I've encountered what appears to be a memory leak within the Hugging Face plugin, potentially related to the use of coroutines in LlmLsCompletionProvider.kt. This issue has led to significant performance degradation over time.

Details:

  • Initial Observation: I noticed memory leak messages in the plugin logs. Although these messages have not reappeared recently, I will update this issue with more details if they occur again.

  • Suspected Cause: The issue may be stemming from how coroutines are handled in LlmLsCompletionProvider.kt. I suspect inefficient memory management or coroutine handling could be leading to gradual resource consumption.

Other Observations:

  1. Testing Environment: The issue was observed on a Mac M1 Max with 32GB RAM.

  2. User Experience Under Light Load: After continuous, yet light usage of the plugin, my entire system experienced a significant slowdown. This necessitated the execution of $ pkill java to alleviate the issue. Post this action, the system's performance reverted to normal.

  3. Gradle Daemon Instances: Over time, there's been an increase in the number of running GradleDaemon processes. This might indicate a resource management issue where these processes are not being properly shut down.

Impact:

This issue has substantial implications for performance, particularly for users operating in environments with similar or lower specifications. It has the potential to significantly hinder the efficiency and usability of the plugin.

Request:

I would greatly appreciate an investigation into this matter. Optimizing coroutine usage in LlmLsCompletionProvider.kt and ensuring efficient resource management could potentially resolve these issues.

Thank you for your attention to this matter. I am available for further information or assistance in troubleshooting this issue.

Gunzip mv chmod Throws errors in Windows

I'm trying to debug why the plugin isn't working on my machine and came across this:

Maybe a OS check or command change would solve some things.

2024-01-07 00:56:50,187 [   3575]   WARN - #c.i.p.l.i.LspServerImpl - LlmLsLspServerDescriptor@proj(RUNNING;0): Failed to start server
java.io.IOException: Cannot run program "mv": CreateProcess error=2, O sistema não pode encontrar o arquivo especificado
	at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1143)
	at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1073)
	at java.base/java.lang.Runtime.exec(Runtime.java:594)
	at java.base/java.lang.Runtime.exec(Runtime.java:418)
	at java.base/java.lang.Runtime.exec(Runtime.java:315)
	at co.huggingface.llmintellij.lsp.LlmLsLspServerDescriptorKt.runCommand(LlmLsLspServerDescriptor.kt:98)

when I remove gunzip from my path:

2024-01-07 01:24:02,917 [   4024]   WARN - #c.i.p.l.i.LspServerImpl - LlmLsLspServerDescriptor@proj(RUNNING;0): Failed to start server
java.io.IOException: Cannot run program "gunzip": CreateProcess error=2, O sistema não pode encontrar o arquivo especificado
	at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1143)
	at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1073)
	at java.base/java.lang.Runtime.exec(Runtime.java:594)
	at java.base/java.lang.Runtime.exec(Runtime.java:418)
	at java.base/java.lang.Runtime.exec(Runtime.java:315)
	at co.huggingface.llmintellij.lsp.LlmLsLspServerDescriptorKt.runCommand(LlmLsLspServerDescriptor.kt:98)
	at co.huggingface.llmintellij.lsp.LlmLsLspServerDescriptorKt.downloadAndUnzip(LlmLsLspServerDescriptor.kt:91)
	at co.huggingface.llmintellij.lsp.LlmLsLspServerDescriptorKt.downloadLlmLs(LlmLsLspServerDescriptor.kt:117)
	at co.huggingface.llmintellij.lsp.LlmLsLspServerDescriptor.createCommandLine(LlmLsLspServerDescriptor.kt:20)
	at com.intellij.platform.lsp.api.LspServerDescriptor.startServerProcess(LspServerDescriptor.kt:93)
	at com.intellij.platform.lsp.impl.connector.Lsp4jServerConnectorStdio.<init>(Lsp4jServerConnectorStdio.java:19)
	at com.intellij.platform.lsp.impl.LspServerImpl.d(LspServerImpl.java:377)
	at com.intellij.openapi.application.impl.ApplicationImpl$2.run(ApplicationImpl.java:272)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
	at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:702)
	at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:699)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
	at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1.run(Executors.java:699)
	at java.base/java.lang.Thread.run(Thread.java:840)

Workaround selfhost Windows

Hi I finally got it working and I'm going to share my step by step to make this work.

My system:

RTX 3060 12GB
CUDA 12.1
Windows 10
PHPSTORM 2023.2.4

Step 1 - Install TGI

Follow the step by step here: https://huggingface.co/docs/text-generation-inference/quicktour and make/test your docker

I'm using this rn: docker run --gpus all --shm-size 1g -p 8080:80 -v C:/data:/data ghcr.io/huggingface/text-generation-inference:1.3 --model-id TheBloke/CodeLlama-7B-GPTQ --quantize gptq
Test it using:
curl http://127.0.0.1:8080/generate -X POST -d "{\"inputs\":\"What is Deep Learning?\",\"parameters\":{\"max_new_tokens\":20}}" -H "Content-Type: application/json"

Step 2 - Install the plugin

Install and configure, don't forget to update the model to the docker url:
image
Also set the log level to info.

If something is missing/not working you can edit the config later here :
%appData%/JetBrains/ MY IDE /options/LlmSettingsPlugin.xml

Step 3 - PATH Hell

Right now the plugin ignore the llm-ls path setting on startup, so it always try to re-install from github, and to do so it is using some commands that not all windows machines have

val downloadCommand = "curl -L -o $path.gz $url"
val unzipCommand = "gunzip $path.gz"
val renameCommand = "mv $path $fullPath"
val chmodCommand = "chmod +x $fullPath"
val cleanZipCommand = "rm $path.gz"

So configure a new folder into your system path (mine C:/mybins/ )
Download/grab a random .exe ( please, don't use doom ), I grabbed the gzip windows bin here: https://gnuwin32.sourceforge.net/packages/gzip.htm .
And duplicate for these commands: chmod,gunzip,mv,rm Like this:
image

Step 4 - Restart the IDE and logs

Restart your IDE and open the logs:
%LOCALAPPDATA%/JetBrains/ MY IDE /log/idea.log
Look for something like this:

2024-01-07 01:46:07,650 [   4200]   WARN - #c.i.p.l.i.LspServerImpl - LlmLsLspServerDescriptor@aaa(RUNNING;0): Failed to start server
com.intellij.execution.process.ProcessNotCreatedException: Cannot run program "C:\Users\p\.cache\llm_intellij\bin\llm-ls-amd64-pc-windows-msvc-0.4.0": CreateProcess error=2, O sistema não pode encontrar o arquivo especificado
	at com.intellij.execution.configurations.GeneralCommandLine.createProcess(GeneralCommandLine.java:356)
	at com.intellij.execution.process.OSProcessHandler.startProcess(OSProcessHandler.java:84)
	at com.intellij.execution.process.OSProcessHandler.<init>(OSProcessHandler.java:44)
	at com.intellij.platform.lsp.api.LspServerDescriptor.startServerProcess(LspServerDescriptor.kt:95)
	at com.intellij.platform.lsp.impl.connector.Lsp4jServerConnectorStdio.<init>(Lsp4jServerConnectorStdio.java:19)

Get the file name (in this case llm-ls-amd64-pc-windows-msvc-0.4.0 ), rename the current llm-ls bin (the .exe file in the .zip) to match this file ( v0.4.0 Here ).
Close the IDE, and put the new file in %HOME%/.cache/llm_intellij/bin/ (or whatever path the log indicates )

Step 5 - Open the IDE and test

Open a file, type something and wait ~3 seconds. It should trigger a request to the docker api.
You can check too in the llm-ls log %HOME%/.cache/llm_ls/llm-ls.log.
It should look like this in the log:
image

And like this in the IDE:

image

Important notes

Right now there isn't so much info about the plugin, and this guide is a workaround for testing the plugin.
I didn't find a hotkey to ask to generate, or to make an manual input if you find it please tell me.

Good luck

Connect to local Model

Hi,

Will I be able to connect to my local Model?
Did you release the plugin to the marketplace? I can't find it.

Thanks,
Stasik

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.