Giter Club home page Giter Club logo

refact-lsp's Introduction

Refact LSP Server

This code converts high level code completion or chat calls into low level LLM prompts and converts results back.

It's written in Rust, compiles into the refact-lsp binary. This binary is bunlded with VS Code JetBrains IDEs VS Classic, Sublime Text, and Qt Creator plugins.

It's a great way to organize code for the plugins, because it can absorb all the common logic, such as cache, debounce, telemetry, scratchpads for different models.

Compiling and Running

Depending on which API key you have handy, or maybe you have Refact self-hosting server:

cargo build && target/debug/refact-lsp --address-url Refact --api-key YYYY --http-port 8001 --lsp-port 8002 --logs-stderr
cargo build && target/debug/refact-lsp --address-url HF --api-key hf_XXXX --http-port 8001 --lsp-port 8002 --logs-stderr
cargo build && target/debug/refact-lsp --address-url http://127.0.0.1:8008/ --http-port 8001 --lsp-port 8002 --logs-stderr

Try --help for more options.

Usage

HTTP example:

curl http://127.0.0.1:8001/v1/code-completion -k \
  -H 'Content-Type: application/json' \
  -d '{
  "inputs": {
    "sources": {"hello.py": "def hello_world():"},
    "cursor": {
      "file": "hello.py",
      "line": 0,
      "character": 18
    },
    "multiline": true
  },
  "stream": false,
  "parameters": {
    "temperature": 0.1,
    "max_new_tokens": 20
  }
}'

Output is [{"code_completion": "\n return \"Hello World!\"\n"}].

LSP example

Telemetry

The flags --basic-telemetry and --snippet-telemetry control what telemetry is sent. To be clear: without these flags, no telemetry is sent. Those flags are typically controlled from IDE plugin settings.

Basic telemetry means counters and error messages without information about you or your code. It is "compressed" into .cache/refact/telemetry/compressed folder, then from time to time it's sent and moved to .cache/refact/telemetry/sent folder.

"Compressed" means similar records are joined together, increasing the counter. "Sent" means the rust binary communicates with a HTTP endpoint specified in caps (see Caps section below) and sends .json file exactly how you see it in .cache/refact/telemetry. The files are human-readable.

When using Refact self-hosted server, telemetry goes to the self-hosted server, not to the cloud.

Caps File

The --address-url parameter controls the behavior of this program by a lot. The address is first used to construct $URL/coding_assistant_caps.json address to fetch the caps file. Furthermore, there are compiled-in caps you can use by magic addresses "Refact" and "HF".

The caps file describes which models are running, default models for completion and chat, where to send the telemetry, how to download a tokenizer, where is the endpoint to access actual language models. To read more, check out compiled-in caps in caps.rs.

Tests

The one to run often is test_edge_cases.py.

You can also run measure_humaneval_fim.py for your favorite model.

Credits

The initial version of this project was written by looking at llm-ls by @McPatate. He's a Rust fan who inspired this project!

refact-lsp's People

Contributors

olegklimov avatar reymondzzzz avatar valaises avatar jegernoutt avatar mitya52 avatar

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.