Skip to content
This repository has been archived by the owner on Oct 30, 2024. It is now read-only.

Commit

Permalink
openai settings
Browse files Browse the repository at this point in the history
  • Loading branch information
iwilltry42 committed Apr 30, 2024
1 parent 5f8de63 commit 9fdafa3
Show file tree
Hide file tree
Showing 4 changed files with 160 additions and 3 deletions.
68 changes: 68 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Test & Release

on:
- push
- workflow_dispatch

env:
GO_VERSION: "1.22.x"

jobs:
test-suite:
timeout-minutes: 30
name: Full Test Suite
runs-on: ubuntu-22.04
steps:
# Setup
- uses: actions/checkout@v3
- name: Setup Go environment
uses: actions/setup-go@v3
with:
go-version: "${{ env.GO_VERSION }}"
# Tests
- name: Run Go Tests
run: make test
# Builds
- name: Test Platform Builds
run: make build-cross


release-github:
name: Build & Release Binaries
# Only run on tags
runs-on: ubuntu-22.04
steps:
# Setup
- uses: actions/checkout@v3
- name: Setup Go environment
uses: actions/setup-go@v3
with:
go-version: "${{ env.GO_VERSION }}"
- name: Setup CI Tools
run: make ci-setup
# Go Build
- name: Build k3d Binary
run: make gen-checksum build-cross
# Create Git Release
- name: Extract Tag from Ref
if: startsWith(github.ref, 'refs/tags/')
id: tag
run: echo VERSION=${GITHUB_REF/refs\/tags\//} >> $GITHUB_OUTPUT
shell: bash
- uses: apexskier/github-semver-parse@v1
if: startsWith(github.ref, 'refs/tags/')
id: semver
with:
version: ${{ steps.tag.outputs.VERSION }}
- name: Create Release
if: startsWith(github.ref, 'refs/tags/')
uses: ncipollo/release-action@v1
with:
allowUpdates: true
artifactErrorsFailBuild: true
artifacts: _dist/*
discussionCategory: releases
generateReleaseNotes: true
prerelease: ${{ steps.semver.outputs.prerelease != '' }}
replacesArtifacts: true
token: ${{ secrets.GITHUB_TOKEN }}
29 changes: 29 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,32 @@ openapi:

tools:
if ! command -v swag &> /dev/null; then go install github.com/swaggo/swag/cmd/swag@latest; fi



# cross-compilation for all targets
build-cross: LDFLAGS += -extldflags "-static"
build-cross:
CGO_ENABLED=0 gox -parallel=3 -output="_dist/$(BINARIES)-{{.OS}}-{{.Arch}}" -osarch='$(TARGETS)' $(GOFLAGS) $(if $(TAGS),-tags '$(TAGS)',) -ldflags '$(LDFLAGS)'
gen-checksum: build-cross
$(eval ARTIFACTS_TO_PUBLISH := $(shell ls _dist/*))
$$(sha256sum $(ARTIFACTS_TO_PUBLISH) > _dist/checksums.txt)

.PHONY: install-tools
install-tools:
ifndef HAS_GOX
($(GO) install $(PKG_GOX))
endif
ifndef HAS_GOLANGCI
(curl -sfL $(PKG_GOLANGCI_LINT_SCRIPT) | sh -s -- -b $(GOENVPATH)/bin v${PKG_GOLANGCI_LINT_VERSION})
endif
ifdef HAS_GOLANGCI
ifeq ($(HAS_GOLANGCI_VERSION),)
ifdef INTERACTIVE
@echo "Warning: Your installed version of golangci-lint (interactive: ${INTERACTIVE}) differs from what we'd like to use. Switch to v${PKG_GOLANGCI_LINT_VERSION}? [Y/n]"
@read line; if [ $$line == "y" ]; then (curl -sfL $(PKG_GOLANGCI_LINT_SCRIPT) | sh -s -- -b $(GOENVPATH)/bin v${PKG_GOLANGCI_LINT_VERSION}); fi
else
@echo "Warning: you're not using the same version of golangci-lint as us (v${PKG_GOLANGCI_LINT_VERSION})"
endif
endif
endif
6 changes: 3 additions & 3 deletions pkg/types/config.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package types

type OpenAIConfig struct {
APIBase string `usage:"OpenAI API base" default:"http://localhost:8080/v1" env:"KNOW_OPENAI_API_BASE"` // clicky-chats
APIKey string `usage:"OpenAI API key (not required if used with clicky-chats)" default:"sk-foo" env:"KNOW_OPENAI_API_KEY"`
EmbeddingModel string `usage:"OpenAI Embedding model" default:"text-embedding-ada-002" env:"KNOW_OPENAI_EMBEDDING_MODEL"`
APIBase string `usage:"OpenAI API base" default:"https://api.openai.com/v1" env:"OPENAI_BASE_URL"` // clicky-chats
APIKey string `usage:"OpenAI API key (not required if used with clicky-chats)" default:"sk-foo" env:"OPENAI_API_KEY"`
EmbeddingModel string `usage:"OpenAI Embedding model" default:"text-embedding-ada-002" env:"OPENAI_EMBEDDING_MODEL"`
}

type DatabaseConfig struct {
Expand Down
60 changes: 60 additions & 0 deletions scripts/install-tools.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/bin/sh

# initArch discovers the architecture for this system.
initArch() {
if [ -z $ARCH ]; then
ARCH=$(uname -m)
case $ARCH in
armv5*) ARCH="armv5";;
armv6*) ARCH="armv6";;
armv7*) ARCH="arm";;
aarch64) ARCH="arm64";;
x86) ARCH="386";;
x86_64) ARCH="amd64";;
i686) ARCH="386";;
i386) ARCH="386";;
esac
fi
}

# initOS discovers the operating system for this system.
initOS() {
if [ -z $OS ]; then
OS=$(uname|tr '[:upper:]' '[:lower:]')

case "$OS" in
# Minimalist GNU for Windows
mingw*) OS='windows';;
esac
fi
}


install_golangci_lint() {
echo "Installing golangci-lint..."
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.49.0
}

install_gox() {
echo "Installing gox for $OS/$ARCH..."
GOX_REPO=iwilltry42/gox
GOX_VERSION=0.1.0
curl -sSfL https://github.com/${GOX_REPO}/releases/download/v${GOX_VERSION}/gox_${GOX_VERSION}_${OS}_${ARCH}.tar.gz | tar -xz -C /tmp
chmod +x /tmp/gox
mv /tmp/gox /usr/local/bin/gox
}

#
# MAIN
#

initOS
initArch

for pkg in "$@"; do
case "$pkg" in
golangci-lint) install_golangci_lint;;
gox) install_gox;;
*) printf "ERROR: Unknown Package '%s'" $pkg;;
esac
done

0 comments on commit 9fdafa3

Please sign in to comment.