Metadata-Version: 2.1
Name: codeqai
Version: 0.0.5
Summary: 
Author: fynnfluegge
Author-email: fynnfluegge@gmx.de
Requires-Python: >=3.9,<4.0
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Requires-Dist: gitpython (>=3.1.36,<4.0.0)
Requires-Dist: inquirer (>=3.1.3,<4.0.0)
Requires-Dist: langchain (>=0.0.310,<0.0.313)
Requires-Dist: openai (>=0.28.0,<0.29.0)
Requires-Dist: pytest (>=7.4.0,<8.0.0)
Requires-Dist: python-dotenv (>=1.0.0,<2.0.0)
Requires-Dist: pyyaml (>=6.0.1,<7.0.0)
Requires-Dist: rich (>=13.5.3,<14.0.0)
Requires-Dist: tiktoken (>=0.4.0,<0.5.0)
Requires-Dist: tree-sitter (>=0.20.2,<0.21.0)
Requires-Dist: tree-sitter-languages (>=1.7.0,<2.0.0)
Requires-Dist: yaspin (>=3.0.0,<4.0.0)
Description-Content-Type: text/markdown

<div align="center">

# codeqai

[![Build](https://github.com/fynnfluegge/codeqai/actions/workflows/build.yaml/badge.svg)](https://github.com/fynnfluegge/codeqai/actions/workflows/build.yaml)
[![Publish](https://github.com/fynnfluegge/codeqai/actions/workflows/publish.yaml/badge.svg)](https://github.com/fynnfluegge/codeqai/actions/workflows/publish.yaml)
[![License](https://img.shields.io/badge/License-Apache%202.0-green.svg)](https://opensource.org/licenses/Apache-2.0)

</div>

<div align="center">

Search your codebase semantically or chat with it from cli. 100% local support without any dataleaks.  
Built with [langchain](https://github.com/langchain-ai/langchain), [treesitter](https://github.com/tree-sitter/tree-sitter), [sentence-transformers](https://github.com/UKPLab/sentence-transformers), [instructor-embedding](https://github.com/xlang-ai/instructor-embedding), [faiss](https://github.com/facebookresearch/faiss), [lama.cpp](https://github.com/ggerganov/llama.cpp), [Ollama](https://github.com/jmorganca/ollama).

![codeqai_demo](https://github.com/fynnfluegge/codeqai/assets/16321871/3882a30f-7d20-4208-9aea-7da62dbdeef9)

</div>

## ✨ Features

- 🔎 &nbsp;Semantic code search
- 💬 &nbsp;GPT-like chat with your codebase
- 💻 &nbsp;100% local embeddings and llms
  - sentence-transformers, instructor-embeddings, llama.cpp, Ollama
- 🌐 &nbsp;OpenAI and Azure OpenAI support
- 🌳 &nbsp;Treesitter integration

> [!NOTE]  
> There will be better results if the code is well documented. You might consider [doc-comments-ai](https://github.com/fynnfluegge/doc-comments.ai) for code documentation generation.

## 🚀 Usage

Start semantic search:

```
codeqai search
```

Start chat dialog:

```
codeqai chat
```

At first usage, the repository will be indexed with the configured embeddings model which micht take some minutes.

## 📋 Requirements

- Python >= 3.9

## 📦 Installation

```
pipx install codeqai
```

> [!NOTE]  
> Some packages are not installed by default. At first usage it is asked to install faiss-cpu or faiss-gpu. Faiss-gpu is recommended if the hardware supports CUDA 7.5+.
> If local embeddings and llms are used it will be further asked to install sentence-transformers, instructor or llama.cpp.

## ⚙️ Configuration

At first usage or by running

```
codeqai configure
```

the configuration process is initiated, where the embeddings and llms can be chosen.

> [!IMPORTANT]  
> If you want to change the embeddings model in the configuration later, make sure to delete the old files from `~/.cache/codeqai`.
> Afterwards the vector store files are created again with the recent configured embeddings model. This is neccessary since the similarity search does not work if the models differ.

## 🌐 Remote models

If remote models are used, the following environment variables are required.
If the required environment variables are already set, they will be used, otherwise you will be prompted to enter them which are then stored in `~/.config/codeqai/.env`.

### OpenAI

```bash
export OPENAI_API_KEY = "your OpenAI api key"
```

### Azure OpenAI

```bash
export OPENAI_API_TYPE = "azure"
export OPENAI_API_BASE = "https://<your-endpoint>.openai.azure.com/"
export OPENAI_API_KEY = "your Azure OpenAI api key"
export OPENAI_API_VERSION = "2023-05-15"
```

> [!NOTE]  
> To change the environment variables later, update the `~/.config/codeqai/.env` manually.

## 💡 How it works

The entire git repo is parsed with treesitter to extract all methods with documentations and saved to a local FAISS vector database with either sentence-transformers, instructor-embeddings or OpenAI's text-embedding-ada-002.
The vector database is saved to a file on your system and will be loaded later again after further usage.  
Afterwards it is possible to do semantic search on the codebase based on the embeddings model.  
To chat with the codebase locally llama.cpp or Ollama is used by specifying the desired model.
Using llama.cpp the specified model needs to be available on the system in advance.
Using Ollama the Ollama container with the desired model needs to be running locally in advance on port 11434.
Also OpenAI or Azure-OpenAI can be used for remote chat models.

## 📚 Supported Languages

- [x] Python
- [x] Typescript
- [x] Javascript
- [x] Java
- [x] Rust
- [x] Kotlin
- [x] Go
- [x] C++
- [x] C
- [x] C#

## FAQ

### Where do I get models for llama.cpp?

Install the `huggingface-cli` and download your desired model from the model hub.
For example

```
huggingface-cli download TheBloke/CodeLlama-13B-Python-GGUF codellama-13b-python.Q5_K_M.gguf
```

will download the `codellama-13b-python.Q5_K_M` model. After the download has finished the absolute path of the model `.gguf` file is printed to the console.

> [!IMPORTANT]  
> `llama.cpp` compatible models must be in the `.gguf` format.

