Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch dev Command to Use llamafile #559

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/platform-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ jobs:
shell: bash
run: |
./build/scripts/sign ./dist/kitops-darwin-arm64.zip
./build/scripts/sign ./dist/kitops-offline-darwin-arm64.zip
./build/scripts/sign ./dist/kitops-darwin-x86_64.zip
./build/scripts/sign ./dist/kitops-offline-darwin-x86_64.zip
- name: Upload macOS artifacts
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
with:
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@
kit
kit.exe
dist/
pkg/lib/harness/generated/downloads/
pkg/lib/harness/ui.tar.gz
pkg/lib/harness/llamafile
pkg/lib/harness/checksums.txt
pkg/lib/harness/llamafile.tar.gz
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
[submodule "pkg/lib/harness/llama.cpp"]
path = pkg/lib/harness/llama.cpp
url = https://github.com/ggerganov/llama.cpp.git
32 changes: 31 additions & 1 deletion .goreleaser.darwin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ project_name: kitops
before:
hooks:
- go mod tidy
- ./build/scripts/generate-arch
- go generate ./...

builds:
- id: "kit-macos"
Expand All @@ -23,6 +23,23 @@ builds:
post:
- cmd: ./build/scripts/sign '{{ .Path }}'
output: true
- id: "kit-macos-offline"
flags:
- --tags=embed_harness
env:
- CGO_ENABLED=0
goos:
- darwin
goarch:
- amd64
- arm64
binary: kit
ldflags:
- -s -w -X kitops/pkg/lib/constants.Version={{.Version}} -X kitops/pkg/lib/constants.GitCommit={{.Commit}} -X kitops/pkg/lib/constants.BuildTime={{.CommitDate}}
hooks:
post:
- cmd: ./build/scripts/sign '{{ .Path }}'
output: true

archives:
# zip archives for Mac OS:
Expand All @@ -41,6 +58,19 @@ archives:
files:
- LICENSE
- README.md
- id: kit-macos-zip-offline-archive
format: zip
builds:
- kit-macos-offline
name_template: >-
{{ .ProjectName }}-offline-
{{- tolower .Os }}-
{{- if eq .Arch "amd64" }}x86_64
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}v{{ .Arm }}{{ end }}
files:
- LICENSE
- README.md
# tar.gz archives for Mac OS:
# - will not be notarized
# - will be installable via homebrew (i.e. "brew install kitops")
Expand Down
25 changes: 25 additions & 0 deletions .goreleaser.linux.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ project_name: kitops
before:
hooks:
- go mod tidy
- go generate ./...

builds:
- id: "kit-linux"
Expand All @@ -15,6 +16,16 @@ builds:
binary: kit
ldflags:
- -s -w -X kitops/pkg/lib/constants.Version={{.Version}} -X kitops/pkg/lib/constants.GitCommit={{.Commit}} -X kitops/pkg/lib/constants.BuildTime={{.CommitDate}}
- id: "kit-linux-embedded"
flags:
- --tags=embed_harness
env:
- CGO_ENABLED=0
goos:
- linux
binary: kit
ldflags:
- -s -w -X kitops/pkg/lib/constants.Version={{.Version}} -X kitops/pkg/lib/constants.GitCommit={{.Commit}} -X kitops/pkg/lib/constants.BuildTime={{.CommitDate}}

archives:
- id: kit-archive
Expand All @@ -31,6 +42,20 @@ archives:
files:
- LICENSE
- README.md
- id: kit-archive-offline
format: tar.gz
builds:
- kit-linux-embedded
name_template: >-
{{ .ProjectName }}-offline-
{{- tolower .Os }}-
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}v{{ .Arm }}{{ end }}
files:
- LICENSE
- README.md

git:
ignore_tags:
Expand Down
25 changes: 25 additions & 0 deletions .goreleaser.windows.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ project_name: kitops
before:
hooks:
- go mod tidy
- go generate ./...

builds:
- id: "kit-wins"
Expand All @@ -15,6 +16,16 @@ builds:
binary: kit
ldflags:
- -s -w -X kitops/pkg/lib/constants.Version={{.Version}} -X kitops/pkg/lib/constants.GitCommit={{.Commit}} -X kitops/pkg/lib/constants.BuildTime={{.CommitDate}}
- id: "kit-wins-embedded"
flags:
- --tags=embed_harness
env:
- CGO_ENABLED=0
goos:
- windows
binary: kit
ldflags:
- -s -w -X kitops/pkg/lib/constants.Version={{.Version}} -X kitops/pkg/lib/constants.GitCommit={{.Commit}} -X kitops/pkg/lib/constants.BuildTime={{.CommitDate}}

archives:
- id: kit-archive
Expand All @@ -31,6 +42,20 @@ archives:
files:
- LICENSE
- README.md
- id: kit-archive-offline
format: zip
builds:
- kit-wins-embedded
name_template: >-
{{ .ProjectName }}-offline-
{{- tolower .Os }}-
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}v{{ .Arm }}{{ end }}
files:
- LICENSE
- README.md

snapshot:
name_template: "{{ .Version }}"
7 changes: 0 additions & 7 deletions pkg/cmd/dev/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package dev
import (
"net"
"os"
"runtime"
"strconv"

"kitops/pkg/lib/harness"
Expand Down Expand Up @@ -82,12 +81,6 @@ func DevLogsCommand() *cobra.Command {

func runStartCommand(opts *DevStartOptions) func(cmd *cobra.Command, args []string) {
return func(cmd *cobra.Command, args []string) {
if runtime.GOOS == "windows" || runtime.GOOS == "linux" {
output.Infoln("Development server is not yet supported in this platform")
output.Infof("We are working to bring it to %s soon", runtime.GOOS)
return
}

if err := opts.complete(cmd.Context(), args); err != nil {
output.Errorf("failed to complete options: %s", err)
return
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/dev/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func runDev(ctx context.Context, options *DevStartOptions) error {
if util.IsModelKitReference(kitfile.Model.Path) {
resolvedKitfile, err := kfutils.ResolveKitfile(ctx, options.configHome, kitfile.Model.Path, kitfile.Model.Path)
if err != nil {
return fmt.Errorf("Failed to resolve referenced modelkit %s: %w", kitfile.Model.Path, err)
return fmt.Errorf("failed to resolve referenced modelkit %s: %w", kitfile.Model.Path, err)
}
kitfile.Model.Path = resolvedKitfile.Model.Path
kitfile.Model.Parts = append(kitfile.Model.Parts, resolvedKitfile.Model.Parts...)
Expand Down
99 changes: 55 additions & 44 deletions pkg/lib/harness/generated/gen_common.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,50 +1,14 @@
# common logic across linux and darwin
#!/bin/sh

UI_DIR=../../../../frontend/dev-mode

init_vars() {
case "${GOARCH}" in
"amd64")
ARCH="x86_64"
;;
"arm64")
ARCH="arm64"
;;
*)
ARCH=$(uname -m | sed -e "s/aarch64/arm64/g")
esac

LLAMACPP_DIR=../llama.cpp
CMAKE_DEFS=""
CMAKE_TARGETS="--target server"
if echo "${CGO_CFLAGS}" | grep -- '-g' >/dev/null; then
CMAKE_DEFS="-DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_VERBOSE_MAKEFILE=on -DLLAMA_GPROF=on -DLLAMA_SERVER_VERBOSE=on ${CMAKE_DEFS}"
else
CMAKE_DEFS="-DCMAKE_BUILD_TYPE=Release -DLLAMA_SERVER_VERBOSE=off ${CMAKE_DEFS}"
fi
if [ -z "${CMAKE_CUDA_ARCHITECTURES}" ] ; then
CMAKE_CUDA_ARCHITECTURES="50;52;61;70;75;80"
fi
}

build() {
cmake -S ${LLAMACPP_DIR} -B ${BUILD_DIR} ${CMAKE_DEFS}
cmake --build ${BUILD_DIR} ${CMAKE_TARGETS} -j8
# ls ${BUILD_DIR}
}

git_module_setup() {
# Make sure the tree is clean
if [ -d "${LLAMACPP_DIR}/build/darwin/${GOARCH}/build" ]; then
echo "Cleaning up old submodule"
rm -rf ${LLAMACPP_DIR}
fi
git submodule init
git submodule update --force ${LLAMACPP_DIR}
}
LLAMAFILE_VER=$(go run ./llamafile_ver_helper.go)

build_ui() {
pushd ${UI_DIR}
UI_HOME=$1

echo "Building harness UI from ${UI_HOME}"

pushd ${UI_HOME}
pnpm install
pnpm run build
popd
Expand All @@ -53,4 +17,51 @@ build_ui() {
compress() {
echo "Compressing $1 to $2"
tar -czf $2 -C $1 .
}
}

generate_sha() {
FILE=$1
CHECKSUM_FILE=$2

echo "Generating SHA256 checksum for ${FILE}"
sha256sum ${FILE} | awk '{print $1 " " FILENAME}' FILENAME="${FILE}" >> ${CHECKSUM_FILE}
echo "Checksum for ${FILE} saved to ${CHECKSUM_FILE}"
}


# Function to download a binary asset from a GitHub release
download_github_release_binary() {
OWNER=$1
REPO=$2
RELEASE_TAG=$3
ASSET_NAME=$4
OUTPUT_DIR=$5

echo "Downloading asset '${ASSET_NAME}' from release '${RELEASE_TAG}' of repository '${OWNER}/${REPO}'"

DOWNLOAD_URL="https://github.com/${OWNER}/${REPO}/releases/download/${RELEASE_TAG}/llamafile-${RELEASE_TAG}"

mkdir -p ${OUTPUT_DIR}

curl -L -o ${OUTPUT_DIR}/llamafile ${DOWNLOAD_URL}

echo "Asset '${ASSET_NAME}' downloaded successfully to: ${OUTPUT_DIR}/${ASSET_NAME}"

echo "${RELEASE_TAG}" > ${OUTPUT_DIR}/llamafile.version

COMPRESSED_FILE="llamafile.tar.gz"
compress ${OUTPUT_DIR} ../${COMPRESSED_FILE}

echo "Compressed asset saved to: ${COMPRESSED_FILE}"
}
Comment on lines +33 to +56
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The usage of $ASSET_NAME is not clear here -- it looks like it's actually hard-coded to llamafile in commands. Maybe the argument can just be dropped?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea was we could use it to download other binaries or checksums. We did not need that at the moment but kept it just in case.


build_ui ${UI_DIR}
compress ${UI_DIR}/dist ../ui.tar.gz
download_github_release_binary "Mozilla-Ocho" "llamafile" "${LLAMAFILE_VER}" "llamafile-${LLAMAFILE_VER}" "./downloads"

CHECKSUM_FILE="../checksums.txt"
> ${CHECKSUM_FILE} # Clear the checksum file if it exists
generate_sha "../ui.tar.gz" ${CHECKSUM_FILE}
generate_sha "../llamafile.tar.gz" ${CHECKSUM_FILE}

echo "All checksums have been saved to ${CHECKSUM_FILE}"
59 changes: 0 additions & 59 deletions pkg/lib/harness/generated/gen_darwin.sh

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
// SPDX-License-Identifier: Apache-2.0
package generated

//go:generate sh ./gen_darwin.sh
//go:generate sh ./gen_common.sh
Loading