{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "!pip install llama-cpp-python huggingface_hub --extra-index-url https://abetlen.github.io/llama-cpp-python/whl/cu124\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from huggingface_hub import HfApi\n", "from llama_cpp import Llama\n", "import os\n", "\n", "ИДЕНТИФИКАТОР_РЕПО = \"darkps/darkit-v2.5\"\n", "АПИ = HfApi()\n", "\n", "ФАЙЛЫ = АПИ.list_repo_files(ИДЕНТИФИКАТОР_РЕПО)\n", "ФАЙЛЫ_GGUF = [файл for файл in ФАЙЛЫ if файл.endswith(\".gguf\")]\n", "\n", "for индекс, файл in enumerate(ФАЙЛЫ_GGUF):\n", " print(f\"[{индекс}] {файл}\")\n", "\n", "ВЫБОР = int(input(\"Выберите номер модели: \"))\n", "ИМЯ_ФАЙЛА = ФАЙЛЫ_GGUF[ВЫБОР]\n", "\n", "МОДЕЛЬ = Llama.from_pretrained(\n", " repo_id=ИДЕНТИФИКАТОР_РЕПО,\n", " filename=ИМЯ_ФАЙЛА,\n", " n_ctx=2048,\n", " n_batch=128,\n", " n_ubatch=128,\n", " n_threads=os.cpu_count() or 4,\n", " n_threads_batch=os.cpu_count() or 4,\n", " n_gpu_layers=-1,\n", " verbose=False,\n", " no_perf=True,\n", ")\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "МОДЕЛЬ.set_cache(None)\n", "\n", "ЗАПРОС = \"Привет, как у тебя дела?\"\n", "\n", "ПОТОК = МОДЕЛЬ(\n", " f\"<|im_start|>user\\n{ЗАПРОС}<|im_end|>\\n<|im_start|>assistant\\n\",\n", " max_tokens=128,\n", " temperature=0.7,\n", " top_p=0.8,\n", " top_k=20,\n", " stream=True,\n", " stop=[\n", " \"<|im_end|>\",\n", " \"<|im_start|>\",\n", " \"\\n\\nUser:\",\n", " \"\\n\\nAssistant:\"\n", " ],\n", " echo=False\n", ")\n", "\n", "for ЧАСТЬ in ПОТОК:\n", " ТЕКСТ = ЧАСТЬ[\"choices\"][0][\"text\"]\n", "\n", " if ТЕКСТ:\n", " print(ТЕКСТ, end=\"\", flush=True)\n", "\n", "print()\n" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" } }, "nbformat": 4, "nbformat_minor": 0 }