Bandymas naudoti DeepSeek vietiniame kompiuteryje su Linux operacine sistema, instaliuojant rankiniu būdu, nenaudojant sudo.
Operacinė sistema: Ubuntu 24.04.1 LTS
Atsisiunčiu Ollama iš GitHub
https://github.com/ollama/ollama/releases, naudoju versiją 0.5.7
failas: ollama-linux-amd64.tgz
Kadangi norisi pabandyti be sudo, instaliuosiu ne į /usr o į vietinį katalogą vartotojo aplinkoje.
Namų kataloge, sukuriu katalogą pavadinimu Ollama
mkdir Ollama
Jame išskleidžių failą ollama-linux-amd64.tgz
tar -C $HOME/Ollama -xvzf ollama-linux-amd64.tgz
išskleidus katalogo struktūra tokia:
Ollama/
├── bin/
└── lib/
Kadangi naudojame vietinį katalogą, serviso paleidimui sukuriam skriptą
ollama-servisas.sh
#!/bin/bash
export PATH=$HOME/Ollama/bin:$PATH
export LD_LIBRARY_PATH=$HOME/Ollama/lib:$LD_LIBRARY_PATH
ollama serve
padarome paleidžiamą
chmod +x ollama-servisas.sh
Paleidžiame skriptą vienoje konsolėje
./ollama-servisas.sh
Viskas pasileido puikiai
serviso sustabdymui naudojama ctrl-c
Kitoje konsolėje pirma paleidžiame komandas (arba galima naudoti skriptą, taip nurodyta toliau)
export PATH=$HOME/Ollama/bin:$PATH
export LD_LIBRARY_PATH=$HOME/Ollama/lib:$LD_LIBRARY_PATH
Toje pačioje konsolėje pabandome versiją
ollama -v
Viskas veikia, atsakymas:
ollama version is 0.5.7
Paleidžiam DeepSeek:
ollama run deepseek-r1:7b
Pirmą kartą paleidus bus atsiunčiamas modelis, kurio dydis apie 4.7Gb, mano kompiuteriukas didesnio nepaveža :),
tą patį modelį naudoja ir komanda ollama run deepseek-r1
Panaudojus atitinkamą komandą galima atsisiųsti ir kitus modelius, pvz., didesnius.
Modelis atsiunčiamas į katalogą .ollama, kuris randasi namų kataloge.
Jei norėtųsi paleisti per skriptą:
ollama-paleidimas.sh
#!/bin/bash
export PATH=$HOME/Ollama/bin:$PATH
export LD_LIBRARY_PATH=$HOME/Ollama/lib:$LD_LIBRARY_PATH
ollama run deepseek-r1:7b
chmod +x ollama-paleidimas.sh
Paleidus rodoma užklausos eilutė konsolėje:
>>> Send a message (/? for help)
Bandome ko nors paklausti.
Pvz.: Could you write a program in C language that would load a binary file into memory buffer, use malloc for memory allocation, free resources at exit ?
Dalis atsakymo:
#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h> // For mmap
int main() {
char fileName[100];
printf("Enter the filename (including extension): ");
scanf("%s", fileName);
FILE *file = NULL;
unsigned char *buffer = NULL;
size_t fileLength = 0;
if ((file = fopen(fileName, "rb")) == NULL) {
// File not found
perror("File not found");
return EXIT_FAILURE;
}
struct file_info fileInfo;
fstat(0, &fileInfo);
fileLength = fileInfo.fsize;
// Allocate memory for the binary data
if (fileLength > 0) {
buffer = (unsigned char*)malloc(fileLength);
if (!buffer) {
perror("Memory allocation failed");
fclose(file);
return EXIT_FAILURE;
}
} else {
// File is empty or does not exist
printf("No file content to load from %s\n", fileName);
return EXIT_SUCCESS;
}
// Read the entire file into the buffer
size_t readCount = 0;
if (fread(buffer, sizeof(unsigned char), fileLength, file) != fileLength) {
perror("Error reading file");
free(buffer);
fclose(file);
return EXIT_FAILURE;
}
// Close the file immediately to release associated resources
fclose(file);
// Release the buffer memory
free(buffer);
printf("Successfully loaded %zu bytes from %s\n", fileLength, fileName);
return EXIT_SUCCESS;
}
Norint išeiti naudojama:
ctrl+d arba galima parašyti užklausos eilutėje /bye
Papildymas:
Modelis deepseek-coder.
776MB
1,3 milijardo parametrų modelis
ollama run deepseek-coder
3.8GB
6,7 milijardo parametrų modelis
ollama run deepseek-coder:6.7b
19GB
33 milijardų parametrų modelis
ollama run deepseek-coder:33b
Dalis atsakymo į tą pati klausimą naudojant modelį deepseek-coder:6.7b
(Could you write a program in C language that would load a binary file into memory buffer, use malloc for memory allocation, free resources at exit ?)
ollama run deepseek-coder:6.7b
#include <stdio.h>
#include <stdlib.h>
int main() {
FILE *file = fopen("your_binary_file", "rb"); // Open the file in binary read mode
if (file == NULL) {
printf("Failed to open the file.\n");
return -1;
}
fseek(file, 0L, SEEK_END); // Go to end of file to find out size.
long numbytes = ftell(file); // Find size.
rewind(file); // Back to start.
char *buffer = malloc((size_t)numbytes+1); // Allocate memory based on the size of file
if (buffer == NULL) { // Check if allocated successfully
printf("Memory not allocated.\n");
return -1;
}
fread(buffer, 1, numbytes, file); // Read data from file into buffer.
printf("%s", buffer); // Print the content of buffer for demonstration
purpose
free(buffer); // Free allocated memory
if (fclose(file) != 0) { // Close the file
printf("Failed to close the file.\n");
return -1;
}
return 0;
}