-
Notifications
You must be signed in to change notification settings - Fork 4
/
Ollm_Bridge_v0.6.ps1
129 lines (104 loc) · 4.71 KB
/
Ollm_Bridge_v0.6.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# Ollm Bridge v 0.6
# Ollm Bridge aims to create a structure of directories and symlinks to make Ollama models more easily accessible to LMStudio users.
# Define the directory variables
$manifest_dir = "$env:USERPROFILE\.ollama\models\manifests\registry.ollama.ai"
$blob_dir = "$env:USERPROFILE\.ollama\models\blobs"
$publicModels_dir = "$env:USERPROFILE\publicmodels"
# Print the base directories to confirm the variables
Write-Host ""
Write-Host "Confirming Directories:"
Write-Host ""
Write-Host "Manifest Directory: $manifest_dir"
Write-Host "Blob Directory: $blob_dir"
Write-Host "Public Models Directory: $publicModels_dir"
# Check if the $publicmodels\lmstudio directory already exists, and delete it if so
if (Test-Path $publicModels_dir\lmstudio) {
Write-Host ""
Remove-Item -Path $publicModels_dir\lmstudio -Recurse -Force
Write-Host "Ollm Bridge Directory Reset."
}
if (Test-Path $publicModels_dir) {
Write-Host ""
Write-Host "Public Models Directory Confirmed."
} else {
New-Item -Type Directory -Path $publicModels_dir
Write-Host ""
Write-Host "Public Models Directory Created."
}
# Explore the manifest directory and record the manifest file locations
Write-Host ""
Write-Host "Exploring Manifest Directory:"
Write-Host ""
$files = Get-ChildItem -Path $manifest_dir -Recurse -Force | Where-Object {$_.PSIsContainer -eq $false}
$manifestLocations = @()
foreach ($file in $files) {
$path = "$($file.DirectoryName)\$($file.Name)"
$manifestLocations += $path
}
Write-Host ""
Write-Host "File Locations:"
Write-Host ""
$manifestLocations | ForEach-Object { Write-Host $_ }
# Parse through json files to get model info
foreach ($manifest in $manifestLocations) {
$json = Get-Content -Path $manifest
$obj = ConvertFrom-Json -InputObject $json
# Check if the digest is a child of "config"
if ($obj.config.digest) {
# Replace "sha256:" with "sha256-" in the config digest
$modelConfig = "$blob_dir\$('sha256-' + $($obj.config.digest.Replace('sha256:', '')))"
}
foreach ($layer in $obj.layers) {
# If mediaType ends in "model", build $modelfile
if ($layer.mediaType -like "*model") {
# Replace "sha256:" with "sha256-" in the model digest
$modelFile = "$blob_dir\$('sha256-' + $($layer.digest.Replace('sha256:', '')))"
}
# If mediaType ends in "template", build $modelTemplate
if ($layer.mediaType -like "*template") {
# Replace "sha256:" with "sha256-" in the template digest
$modelTemplate = "$blob_dir\$('sha256-' + $($layer.digest.Replace('sha256:', '')))"
}
# If mediaType ends in "params", build $modelParams
if ($layer.mediaType -like "*params") {
# Replace "sha256:" with "sha256-" in the parameter digest
$modelParams = "$blob_dir\$('sha256-' + $($layer.digest.Replace('sha256:', '')))"
}
}
# Extract variables from $modelConfig
$modelConfigObj = ConvertFrom-Json (Get-Content -Path $modelConfig)
$modelQuant = $modelConfigObj.'file_type'
$modelExt = $modelConfigObj.'model_format'
$modelTrainedOn = $modelConfigObj.'model_type'
# Get the parent directory of $manifest
$parentDir = Split-Path -Path $manifest -Parent
# Set the $modelName variable to the name of the directory
$modelName = (Get-Item -Path $parentDir).Name
Write-Host ""
Write-Host "Model Name is" $modelName
Write-Host "Quant is" $modelQuant
Write-Host "Extension is" $modelExt
Write-Host "Number of Parameters Trained on is" $modelTrainedOn
Write-Host ""
# Check if the directory exists and create it if necessary
if (-not (Test-Path -Path $publicModels_dir\lmstudio)) {
Write-Host ""
Write-Host "Creating lmstudio directory..."
New-Item -Type Directory -Path $publicModels_dir\lmstudio
}
# Check if the subdirectory exists and create it if necessary
if (-not (Test-Path -Path $publicModels_dir\lmstudio\$modelName)) {
Write-Host ""
Write-Host "Creating $modelName directory..."
New-Item -Type Directory -Path $publicModels_dir\lmstudio\$modelName
}
# Create the symbolic link
Write-Host ""
Write-Host "Creating symbolic link for $modelFile..."
New-Item -ItemType SymbolicLink -Path "$publicModels_dir\lmstudio\$modelName\$($modelName)-$($modelTrainedOn)-$($modelQuant).$($modelExt)" -Value $modelFile
}
Write-Host ""
Write-Host ""
Write-Host "*********************"
Write-Host "Ollm Bridge complete."
Write-Host "Set the Models Directory in LMStudio to"$publicModels_dir"\lmstudio"