README.md

# Aleph Ollama Translator

A simple Erlang module to translate source code files or strings to a target language using Ollama LLMs.

[![Hex.pm](https://img.shields.io/hexpm/v/aleph_ollama.svg)](https://hex.pm/packages/aleph_ollama)
[![Hex Docs](https://img.shields.io/badge/hex-docs-blue.svg)](https://hexdocs.pm/aleph_ollama)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
[![Erlang/OTP](https://img.shields.io/badge/Erlang-OTP%2024+-red.svg)](https://www.erlang.org/)
[![AI Powered](https://img.shields.io/badge/AI-Powered-green.svg)](https://ollama.ai/)

## Features

- Translate source code from files or strings
- Supports various programming languages
- Configurable via environment variables
- Simple and easy-to-use API

## Usage

### Translate a File

```erlang
aleph_ollama\:translate_code("path/to/your/file.rs", "Python").
```

### Translate a String

```erlang
aleph_ollama\:translate_code_from_string("fn main() { println!(\"Hello\"); }", "JavaScript").
```

## Configuration

You can configure the module using the following environment variables:

- `OLLAMA_MODEL`: Model name (default: "qwen2.5-coder")
- `OLLAMA_URL`: API endpoint (default: "http://localhost:11434/api/generate")
- `OLLAMA_PROMPT`: Prompt template (optional)

## Example

```erlang
{ok, TranslatedCode} = aleph_ollama\:translate_code("example.rs", "Python"),
io\:format("~s~n", [TranslatedCode]).
```

## Functions

| Function | Description |
|----------|-------------|
| `translate_code/2` | Translates source code from a file to the target language. |
| `translate_code_from_string/2` | Translates code from a string to the target language. |
| `translate_code_from_string_stream/2` | Streams translation output from Ollama. |
| `parse_response/1` | Cleans and parses the response from Ollama to extract only the translated code. |
| `default_config/0` | Returns the default configuration map. |
| `get_env_config/0` | Returns the configuration map from environment variables, falling back to defaults. |
| `default_prompt_template/0` | Returns the default prompt template for code translation. |

## License

This project is licensed under the Apache License 2.0. See the [LICENSE](LICENSE) file for details.