A single Python file that connects via the OpenAI Chat Completions API, giving you something akin to OpenAI High Compute at home. Any models are compatible. Using dynamic programming methods, computational capacity is increased by tens or even hundreds of times for both reasoning and non-reasoning models, significantly improving answer quality and the ability to solve extremely complex tasks for LLMs.
This is a simple Gradio-based web application providing an interface for interacting with a locally hosted Large Language Model (LLM). The key feature is the ability to select a "Computation Level," which determines the strategy for processing user queries—ranging from direct responses to multi-level task decomposition for obtaining more structured and comprehensive answers to complex queries.
Test.mp4
The application connects to your specified LLM API endpoint, compatible with the OpenAI Chat Completions API format.
- Local LLM Integration: Works with your own LLM server (e.g., llama.cpp, Ollama, LM Studio, vLLM with an OpenAI-compatible endpoint).
- Compute Levels:
- Low: Direct query to the LLM for a quick response. This is a standard chat mode. Generates N tokens — for example, solving a task may only consume 700 tokens.
- Medium: Single-level task decomposition into subtasks, solving them, and synthesizing the final answer. Suitable for moderately complex queries. The number of generated tokens is approximately 10-15x higher compared to Low Compute (average value, depends on the task): if solving a task in Low Compute took 700 tokens, Medium level would require around 7,000 tokens.
- High: Two-level task decomposition (stages → steps), solving individual steps, synthesizing stage results, and generating the final answer. Designed for highly complex and multi-component tasks. The number of generated tokens is approximately 100-150x higher compared to Low Compute: if solving a task in Low Compute took 700 tokens, High level would require around 70,000 tokens.
- Flexible Compute Adjustment: You can freely adjust the Compute Level for each query individually. For example, initiate the first query in High Compute, then switch to Low mode, and later use Medium Compute to solve a specific problem mid-chat.
The core idea is that for complex tasks, a simple direct query to the LLM may not yield optimal results. Decomposition allows breaking down a complex problem into smaller, manageable parts, solving them individually, and then combining the results.
-
Low:
User Query
→LLM (single call)
→Response
- The fastest mode, suitable for simple questions or when a quick response is needed. Essentially, this is the standard chat mode.
-
Medium:
User Query
→LLM (decomposition request)
→List of subtasks
- For each subtask:
Subtask + Context
→LLM (subtask solution)
→Subtask result
All subtask results + Original query
→LLM (final synthesis)
→Final answer
- Uses multiple LLM calls. Decomposition and synthesis requests use a lower
temperature
for greater predictability.
-
High:
User Query
→LLM (Level 1 decomposition)
→List of stages (L1)
- For each L1 stage:
L1 Stage + Context
→LLM (Level 2 decomposition)
→List of steps (L2)
- If L2 decomposition is not needed:
L1 Stage + Context
→LLM (direct L1 stage solution)
→L1 Stage result
- If L2 decomposition succeeds:
- For each L2 step:
L2 Step + L1 Context
→LLM (L2 step solution)
→L2 Step result
All L2 Step results + L1 Context
→LLM (L1 stage synthesis)
→L1 Stage result
- For each L2 step:
All L1 Stage results + Original query
→LLM (final synthesis)
→Final answer
- The most resource-intensive mode, using multiple LLM calls. Designed for highly complex tasks requiring multi-stage planning and solving. Uses a lower
temperature
for all decomposition and synthesis steps. If L1 decomposition fails, it automatically switches toMedium
mode. WARNING! This can increase the number of generated tokens by hundreds of times! If you're using a paid API, consider this carefully!
- Python 3.11
- pip (Python package manager)
- A working LLM server: You need an accessible HTTP server with an LLM that provides an API compatible with OpenAI Chat Completions API.
- Examples of such servers:
- Ollama (with the
--api
flag or via a separate proxy for OpenAI compatibility) - LM Studio (provides an OpenAI-compatible endpoint)
- vLLM (with an OpenAI-compatible server)
- OpenRouter.
- Ollama (with the
- Important: The server must accept POST requests at the path specified in
LLM_API_ENDPOINT
(default:/v1/chat/completions
) and process JSON data in OpenAI format (fields:model
,messages
,temperature
,top_p
,top_k
). The response must also follow the OpenAI format (expected field:choices[0].message.content
).
- Examples of such servers:
-
Clone the repository:
git clone https://github.com/AlexBefest/highCompute.py.git cd highCompute.py
-
Create and activate a virtual environment (recommended):
- On Linux/macOS:
python3 -m venv venv source venv/bin/activate
- On Windows:
python -m venv venv .\venv\Scripts\activate
- On Linux/macOS:
-
Install dependencies:
Install Python dependencies:pip install -r requirements.txt
-
Create a
.env
file in the project root folder. -
Add
LLM_API_ENDPOINT
,LLM_MODEL
, andLLM_API_KEY
to.env
, specifying the full URL of your local LLM API endpoint compatible with OpenAI Chat Completions API, your LLM model name, and API key.Example
.env
file content:LLM_API_ENDPOINT=http://192.168.2.33:8000/v1/chat/completions LLM_API_KEY="token-abc123" LLM_MODEL="AlexBefest/Gemma3-27B"
- Ensure your LLM server is actually listening at this address and path.
- Ensure your local LLM server is running and accessible at the URL specified in
.env
(or the default address). - Run the Python script:
python highCompute.py
- Open the web interface: The console will display a Gradio message with the local URL, typically
http://127.0.0.1:7860
. Open this URL in your web browser.
- Select Computation Level: Low, Medium, or High, depending on query complexity.
- (Optional) Adjust parameters: Modify the
Temperature
,Top-P
, andTop-K
sliders if you want to change the LLM's response style.Temperature
: Controls randomness. Lower values (closer to 0) make responses more deterministic and focused. Higher values (closer to 2.0) make responses more creative and diverse but may lead to "hallucinations."Top-P
: Nucleus sampling. The model only considers tokens whose cumulative probability is ≥top_p
. A value of1.0
disables this parameter.Top-K
: Only the topk
most probable tokens are considered. A value of0
disables this parameter.
- Enter your query: Type your message in the "Your message" text field at the bottom.
- Submit the query: Press Enter or click the "Submit" button.
- View the response: The LLM's answer will appear in the chat window.
- Continue the conversation: Enter follow-up messages. Chat history is preserved and passed to the LLM for context.
- Clear chat: Click the "Clear Chat" button to reset history and start a new conversation.
- LLM API Compatibility: Ensure your LLM endpoint strictly follows the OpenAI Chat Completions API format for requests and responses. Incompatibility will cause errors.
- Performance:
Medium
and especiallyHigh
modes perform multiple sequential LLM calls, significantly increasing response time compared toLow
mode. - Decomposition Quality: The success of
Medium
andHigh
modes heavily depends on the LLM's ability to understand and execute decomposition and synthesis instructions. Quality may vary based on the LLM model and task complexity. Sometimes, the LLM may fail to decompose the task or return a response not in a numbered list format. - Method Efficiency: Note that this method may be inefficient with smaller models.
- Network Errors: If you see "Network error," check if your LLM server is running and accessible at the
.env
-specified address. Verify network and firewall settings. - JSON Errors: If you see "Error: Failed to decode JSON response" or "Invalid format," this means the LLM server returned a response that is not valid JSON or does not match the expected OpenAI structure. Check your LLM server logs.
Всего один python-файл, подключение через OpenAI Chat Completions API, и вы получаете что-то вроде OpenAI High Compute at home. Совместимы любые модели. Используя метод динамического программирования, увеличение количества вычислений в десятки и сотни раз для reasoning и no-reasoning моделей, что значительно повышает качество ответов и способность решать чрезвычайно сложные для LLM задачи.
Это простое веб-приложение на базе Gradio, предоставляющее интерфейс для взаимодействия с локально запущенной Большой Языковой Моделью (LLM). Ключевой особенностью является возможность выбора "Уровня Вычислений" (Computation Level), который определяет стратегию обработки запроса пользователя: от прямого ответа до многоуровневой декомпозиции задачи для получения более структурированных и полных ответов на сложные запросы.
Приложение подключается к указанному вами API-эндпоинту LLM, совместимому с форматом OpenAI Chat Completions API.
- Подключение к локальной LLM: Работает с вашим собственным LLM-сервером (например, llama.cpp, Ollama, LM Studio, vLLM с OpenAI-совместимым эндпоинтом).
- Уровни Вычислений:
- Low (Низкий): Прямой запрос к LLM для быстрого ответа. Это совершенно обычный режим чата. Генерируется N-токенов: допустим, на решение задачи ушло всего 7000 токенов.
- Medium (Средний): Одноуровневая декомпозиция задачи на подзадачи, их решение и последующий синтез ответа. Подходит для умеренно сложных запросов. Количество генерируемых токенов примерно в 10-15 раз больше по отношению к Low Compute (среднее значение, всё зависит от задачи): если бы на low compute решение задачи заняло 700 токенов, то на Medium уровне примерно 7000 токенов.
- High (Высокий): Двухуровневая декомпозиция задачи (этапы -> шаги), решение шагов, синтез результатов этапов и финальный синтез общего ответа. Предназначен для наиболее сложных и многокомпонентных задач. Количество генерируемых токенов примерно в 100-150 раз больше по отношению к уровню Low: если бы на low compute решение задачи заняло 700 токенов, то на High уровне это заняло бы 70000 токенов.
- Свободная регулировка Compute: Вы можете свободно регулировать Compute Level для каждого вашего запроса отдельно. Например, первый запрос инициировать на High Compute, затем поработать в режиме Low, и в середине чата решить сделать Medium Compute для решения определённой проблемы.
Основная идея заключается в том, что для сложных задач простой прямой запрос к LLM может не дать оптимального результата. Декомпозиция позволяет разбить сложную проблему на более мелкие, управляемые части, решить их по отдельности, а затем объединить результаты.
-
Low (Низкий):
Пользовательский запрос
->LLM (один вызов)
->Ответ
- Самый быстрый режим, подходит для простых вопросов или когда требуется максимально быстрая реакция. Фактически, это стандартный режим чата.
-
Medium (Средний):
Пользовательский запрос
->LLM (запрос на декомпозицию)
->Список подзадач
- Для каждой подзадачи:
Подзадача + Контекст
->LLM (решение подзадачи)
->Результат подзадачи
Все результаты подзадач + Исходный запрос
->LLM (синтез финального ответа)
->Финальный ответ
- Использует несколько вызовов LLM. Запросы на декомпозицию и синтез используют пониженную
temperature
для большей предсказуемости.
-
High (Высокий):
Пользовательский запрос
->LLM (декомпозиция Уровня 1)
->Список этапов (L1)
- Для каждого этапа L1:
Этап L1 + Контекст
->LLM (декомпозиция Уровня 2)
->Список шагов (L2)
- Если декомпозиция L2 не требуется:
Этап L1 + Контекст
->LLM (прямое решение этапа L1)
->Результат этапа L1
- Если декомпозиция L2 удалась:
- Для каждого шага L2:
Шаг L2 + Контекст L1
->LLM (решение шага L2)
->Результат шага L2
Все результаты шагов L2 + Контекст L1
->LLM (синтез результата этапа L1)
->Результат этапа L1
- Для каждого шага L2:
Все результаты этапов L1 + Исходный запрос
->LLM (финальный синтез)
->Финальный ответ
- Самый ресурсоемкий режим, использующий множество вызовов LLM. Предназначен для очень сложных задач, требующих многоэтапного планирования и решения. Использует пониженную
temperature
для всех шагов декомпозиции и синтеза. Если декомпозиция L1 не удается, автоматически переключается на режимMedium
. ВНИМАНИЕ! Может увеличить количество генерируемых токенов в сотни раз! Если вы используете платный API, вам стоит это учитывать!
- Python 3.11+
- pip (менеджер пакетов Python)
- Работающий LLM сервер: Вам необходим доступный по HTTP сервер с LLM, который предоставляет API, совместимое с OpenAI Chat Completions API.
- Примеры таких серверов:
- Ollama (с флагом
--api
или через отдельный прокси для OpenAI совместимости) - LM Studio (предоставляет OpenAI-совместимый эндпоинт)
- vLLM (с OpenAI-совместимым сервером)
- OpenRouter.
- Ollama (с флагом
- Важно: Сервер должен принимать POST-запросы на путь, указанный в
LLM_API_ENDPOINT
(по умолчанию/v1/chat/completions
), и обрабатывать JSON-данные в формате OpenAI (поляmodel
,messages
,temperature
,top_p
,top_k
). Ответ также должен соответствовать формату OpenAI (ожидается полеchoices[0].message.content
).
- Примеры таких серверов:
-
Клонируйте репозиторий:
git clone https://github.com/AlexBefest/highCompute.py.git cd highCompute.py
-
Создайте и активируйте виртуальное окружение (рекомендуется):
- На Linux/macOS:
python3 -m venv venv source venv/bin/activate
- На Windows:
python -m venv venv .\venv\Scripts\activate
- На Linux/macOS:
-
Установите зависимости: Выполните установку python-зависимостей:
pip install -r requirements.txt
-
Создайте файл
.env
в корневой папке проекта. -
Добавьте в
.env
переменнуюLLM_API_ENDPOINT
,LLM_MODEL
иLLM_API_KEY
, указав полный URL вашего локального LLM API эндпоинта, который совместим с OpenAI Chat Completions API. А также имя вашей LLM-модели и API-ключ.Пример содержимого файла
.env
:LLM_API_ENDPOINT=http://192.168.2.33:8000/v1/chat/completions LLM_API_KEY="token-abc123" LLM_MODEL ="AlexBefest/Gemma3-27B"
- Убедитесь, что ваш LLM сервер действительно слушает этот адрес и путь.
- Убедитесь, что ваш локальный LLM сервер запущен и доступен по URL, указанному в файле
.env
(или по адресу по умолчанию). - Запустите Python скрипт:
python highCompute.py
- Откройте веб-интерфейс: В консоли вы увидите сообщение от Gradio с локальным URL, обычно
http://127.0.0.1:7860
. Откройте этот URL в вашем веб-браузере.
- Выберите Уровень Вычислений (Computation Level): Low, Medium или High, в зависимости от сложности вашего запроса.
- (Опционально) Настройте параметры: Отрегулируйте ползунки
Temperature
,Top-P
,Top-K
, если хотите изменить стиль генерации ответа LLM.Temperature
: Контролирует случайность. Низкие значения (ближе к 0) делают ответы более детерминированными и сфокусированными. Высокие значения (ближе к 2.0) делают ответы более креативными и разнообразными, но могут привести к "галлюцинациям".Top-P
: Нуклеусное сэмплирование. Модель рассматривает только токены, чья суммарная вероятность больше или равнаtop_p
. Значение1.0
отключает этот параметр.Top-K
: Рассматриваются толькоk
наиболее вероятных токенов. Значение0
отключает этот параметр.
- Введите ваш запрос: Напишите сообщение в текстовое поле "Your message" внизу.
- Отправьте запрос: Нажмите Enter или кнопку "Submit".
- Просмотрите ответ: Ответ LLM появится в окне чата.
- Продолжайте диалог: Вводите следующие сообщения. История чата будет сохраняться и передаваться LLM для контекста.
- Очистить чат: Нажмите кнопку "Clear Chat", чтобы сбросить историю и начать новый диалог.
- Совместимость LLM API: Убедитесь, что ваш LLM эндпоинт строго следует формату OpenAI Chat Completions API для запросов и ответов. Несовместимость формата приведет к ошибкам.
- Производительность: Режимы
Medium
и особенноHigh
выполняют несколько последовательных вызовов LLM, что значительно увеличивает время ожидания ответа по сравнению с режимомLow
. - Качество декомпозиции: Успех режимов
Medium
иHigh
сильно зависит от способности LLM понимать и выполнять инструкции по декомпозиции и синтезу. Качество может варьироваться в зависимости от используемой модели LLM и сложности исходной задачи. Иногда LLM может не суметь разбить задачу или вернуть ответ не в виде нумерованного списка. - Эффективность метода: Нужно понимать, что данный метод может быть неэффективен с небольшими моделями
- Сетевые ошибки: Если вы видите "Network error", проверьте, запущен ли ваш LLM сервер и доступен ли он по указанному в
.env
адресу. Проверьте настройки сети и файрвола. - Ошибки JSON: Если вы видите "Error: Failed to decode JSON response" или "Invalid format", это означает, что LLM сервер вернул ответ, который не является валидным JSON или не соответствует ожидаемой структуре OpenAI. Проверьте логи вашего LLM сервера.