diff --git a/.dockerignore b/.dockerignore index de70e0d16772..ca65e5c7b99b 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,2 +1,7 @@ +.idea +ci +clients +.github +python **/target **/node_modules diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 1e7482119d18..58ee2b6b4a3b 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -50,7 +50,10 @@ jobs: # Workaround: https://github.com/docker/build-push-action/issues/461 - name: Setup Docker buildx - uses: docker/setup-buildx-action@v2.0.0 + uses: docker/setup-buildx-action@v3.0.0 + with: + # Needed to support OCI annotations + version: v0.12.0 # Login against a Docker registry except on PR # https://github.com/docker/login-action @@ -78,7 +81,7 @@ jobs: - name: Docker meta id: meta - uses: docker/metadata-action@v4 + uses: docker/metadata-action@v5.0.0 with: # list of Docker images to use as base name for tags images: | @@ -91,17 +94,50 @@ jobs: type=schedule,pattern={{date 'YYYYMMDD'}} type=semver,pattern={{version}} + - name: Docker meta for ROCm + id: meta-rocm + uses: docker/metadata-action@v5.0.0 + with: + # list of Docker images to use as base name for tags + images: | + ghcr.io/${{ env.IMAGE_NAME }}/rocm + ${{ env.IMAGE_NAME }}-rocm + # generate Docker tags based on the following events/attributes + variant: rocm + tags: | + type=raw,value={{branch}}-{{sha}},enable=${{ startsWith(github.ref, 'refs/heads') }} + type=schedule,pattern=nightly + type=schedule,pattern={{date 'YYYYMMDD'}} + type=semver,pattern={{version}} + # Build and push Docker image with Buildx (don't push on PR) # https://github.com/docker/build-push-action - name: Build and push Docker image id: build-and-push - uses: docker/build-push-action@v3.1.1 + uses: docker/build-push-action@v5.1.0 with: - file: Dockerfile + file: cuda.Dockerfile push: true context: . tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} + annotations: ${{ steps.meta.outputs.labels }} + cache-from: ${{ steps.cache.outputs.cache-from }} + cache-to: ${{ steps.cache.outputs.cache-to }} + build-args: RUST_TOOLCHAIN=${{ env.RUST_TOOLCHAIN }} + + # Build and push Docker image with Buildx (don't push on PR) + # https://github.com/docker/build-push-action + - name: Build and push Docker image for ROCm + id: build-and-push-rocm + uses: docker/build-push-action@v5.1.0 + with: + file: rocm.Dockerfile + push: true + context: . + tags: ${{ steps.meta-rocm.outputs.tags }} + labels: ${{ steps.meta-rocm.outputs.labels }} + annotations: ${{ steps.meta-rocm.outputs.labels }} cache-from: ${{ steps.cache.outputs.cache-from }} cache-to: ${{ steps.cache.outputs.cache-to }} build-args: RUST_TOOLCHAIN=${{ env.RUST_TOOLCHAIN }} @@ -112,4 +148,3 @@ jobs: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} repository: tabbyml/tabby - diff --git a/clients/tabby-agent/src/AgentConfig.ts b/clients/tabby-agent/src/AgentConfig.ts index 356bc2e53982..bbbf3bf3490f 100644 --- a/clients/tabby-agent/src/AgentConfig.ts +++ b/clients/tabby-agent/src/AgentConfig.ts @@ -5,7 +5,7 @@ import fs from "fs-extra"; import toml from "toml"; import chokidar from "chokidar"; import deepEqual from "deep-equal"; -import { getProperty, deleteProperty } from "dot-prop"; +import { deleteProperty, getProperty } from "dot-prop"; import { isBrowser } from "./env"; import { rootLogger } from "./logger"; diff --git a/clients/tabby-agent/src/Auth.ts b/clients/tabby-agent/src/Auth.ts index 610ac347473b..25688bd9ca60 100644 --- a/clients/tabby-agent/src/Auth.ts +++ b/clients/tabby-agent/src/Auth.ts @@ -3,7 +3,7 @@ import decodeJwt from "jwt-decode"; import createClient from "openapi-fetch"; import type { paths as CloudApi } from "./types/cloudApi"; import type { AbortSignalOption } from "./Agent"; -import { HttpError, abortSignalFromAnyOf } from "./utils"; +import { abortSignalFromAnyOf, HttpError } from "./utils"; import { dataStore, DataStore } from "./dataStore"; import { rootLogger } from "./logger"; diff --git a/clients/tabby-agent/src/CompletionCache.ts b/clients/tabby-agent/src/CompletionCache.ts index 709e7be6e11e..a2fd3a92abc1 100644 --- a/clients/tabby-agent/src/CompletionCache.ts +++ b/clients/tabby-agent/src/CompletionCache.ts @@ -1,7 +1,7 @@ import { LRUCache } from "lru-cache"; import { CompletionContext, CompletionResponse } from "./CompletionContext"; import { rootLogger } from "./logger"; -import { splitLines, autoClosingPairOpenings, autoClosingPairClosings, findUnpairedAutoClosingChars } from "./utils"; +import { autoClosingPairClosings, autoClosingPairOpenings, findUnpairedAutoClosingChars, splitLines } from "./utils"; type CompletionCacheKey = CompletionContext; type CompletionCacheValue = CompletionResponse; diff --git a/clients/tabby-agent/src/CompletionContext.ts b/clients/tabby-agent/src/CompletionContext.ts index 0be7a8750764..b9690cef3acf 100644 --- a/clients/tabby-agent/src/CompletionContext.ts +++ b/clients/tabby-agent/src/CompletionContext.ts @@ -1,4 +1,4 @@ -import { splitLines, autoClosingPairClosings } from "./utils"; +import { autoClosingPairClosings, splitLines } from "./utils"; import hashObject from "object-hash"; export type CompletionRequest = { diff --git a/clients/tabby-agent/src/CompletionDebounce.ts b/clients/tabby-agent/src/CompletionDebounce.ts index 23bf368c14ca..77b679b4bfaf 100644 --- a/clients/tabby-agent/src/CompletionDebounce.ts +++ b/clients/tabby-agent/src/CompletionDebounce.ts @@ -1,4 +1,4 @@ -import type { CompletionRequest, AbortSignalOption } from "./Agent"; +import type { AbortSignalOption, CompletionRequest } from "./Agent"; import type { AgentConfig } from "./AgentConfig"; import { splitLines } from "./utils"; diff --git a/clients/tabby-agent/src/StdIO.ts b/clients/tabby-agent/src/StdIO.ts index b79d61a469fb..69252bcaa983 100644 --- a/clients/tabby-agent/src/StdIO.ts +++ b/clients/tabby-agent/src/StdIO.ts @@ -1,5 +1,5 @@ import readline from "readline"; -import { AgentFunction, AgentEvent, Agent, agentEventNames } from "./Agent"; +import { Agent, AgentEvent, agentEventNames, AgentFunction } from "./Agent"; import { rootLogger } from "./logger"; import { isCanceledError } from "./utils"; diff --git a/clients/tabby-agent/src/TabbyAgent.ts b/clients/tabby-agent/src/TabbyAgent.ts index 40001a9876ba..37fa077caf96 100644 --- a/clients/tabby-agent/src/TabbyAgent.ts +++ b/clients/tabby-agent/src/TabbyAgent.ts @@ -2,32 +2,32 @@ import { EventEmitter } from "events"; import { v4 as uuid } from "uuid"; import deepEqual from "deep-equal"; import { deepmerge } from "deepmerge-ts"; -import { getProperty, setProperty, deleteProperty } from "dot-prop"; -import createClient from "openapi-fetch"; +import { deleteProperty, getProperty, setProperty } from "dot-prop"; import type { ParseAs } from "openapi-fetch"; +import createClient from "openapi-fetch"; import type { paths as TabbyApi } from "./types/tabbyApi"; import type { + AbortSignalOption, Agent, - AgentStatus, - AgentIssue, AgentEvent, - ClientProperties, AgentInitOptions, - AbortSignalOption, - ServerHealthState, + AgentIssue, + AgentStatus, + ClientProperties, CompletionRequest, CompletionResponse, LogEventRequest, + ServerHealthState, } from "./Agent"; import type { DataStore } from "./dataStore"; -import { isBlank, abortSignalFromAnyOf, HttpError, isTimeoutError, isCanceledError, errorToString } from "./utils"; +import { abortSignalFromAnyOf, errorToString, HttpError, isBlank, isCanceledError, isTimeoutError } from "./utils"; import { Auth } from "./Auth"; -import { AgentConfig, PartialAgentConfig, defaultAgentConfig, configFile } from "./AgentConfig"; +import { AgentConfig, configFile, defaultAgentConfig, PartialAgentConfig } from "./AgentConfig"; import { CompletionCache } from "./CompletionCache"; import { CompletionDebounce } from "./CompletionDebounce"; import { CompletionContext } from "./CompletionContext"; -import { preCacheProcess, postCacheProcess, calculateReplaceRange } from "./postprocess"; -import { rootLogger, allLoggers } from "./logger"; +import { calculateReplaceRange, postCacheProcess, preCacheProcess } from "./postprocess"; +import { allLoggers, rootLogger } from "./logger"; import { AnonymousUsageLogger } from "./AnonymousUsageLogger"; import { CompletionProviderStats, CompletionProviderStatsEntry } from "./CompletionProviderStats"; diff --git a/clients/tabby-agent/src/postprocess/base.ts b/clients/tabby-agent/src/postprocess/base.ts index 39f57f95e905..6e4dc78b1f67 100644 --- a/clients/tabby-agent/src/postprocess/base.ts +++ b/clients/tabby-agent/src/postprocess/base.ts @@ -1,4 +1,4 @@ -import { CompletionResponse, CompletionContext } from "../CompletionContext"; +import { CompletionContext, CompletionResponse } from "../CompletionContext"; import { rootLogger } from "../logger"; export type PostprocessFilter = (item: string, context: CompletionContext) => string | null | Promise; diff --git a/clients/tabby-agent/src/postprocess/calculateReplaceRangeByBracketStack.ts b/clients/tabby-agent/src/postprocess/calculateReplaceRangeByBracketStack.ts index 175424ad7394..a2468e0b992c 100644 --- a/clients/tabby-agent/src/postprocess/calculateReplaceRangeByBracketStack.ts +++ b/clients/tabby-agent/src/postprocess/calculateReplaceRangeByBracketStack.ts @@ -1,5 +1,5 @@ import { CompletionContext, CompletionResponse } from "../CompletionContext"; -import { isBlank, findUnpairedAutoClosingChars } from "../utils"; +import { findUnpairedAutoClosingChars, isBlank } from "../utils"; import { logger } from "./base"; export function calculateReplaceRangeByBracketStack( diff --git a/clients/tabby-agent/src/postprocess/dropDuplicated.ts b/clients/tabby-agent/src/postprocess/dropDuplicated.ts index dbc8149a3b34..61cce32b739a 100644 --- a/clients/tabby-agent/src/postprocess/dropDuplicated.ts +++ b/clients/tabby-agent/src/postprocess/dropDuplicated.ts @@ -1,6 +1,6 @@ import { CompletionContext } from "../CompletionContext"; -import { PostprocessFilter, logger } from "./base"; -import { splitLines, isBlank, calcDistance } from "../utils"; +import { logger, PostprocessFilter } from "./base"; +import { calcDistance, isBlank, splitLines } from "../utils"; export function dropDuplicated(): PostprocessFilter { return (input: string, context: CompletionContext) => { diff --git a/clients/tabby-agent/src/postprocess/formatIndentation.ts b/clients/tabby-agent/src/postprocess/formatIndentation.ts index 14e49926cc3f..379c80f834dc 100644 --- a/clients/tabby-agent/src/postprocess/formatIndentation.ts +++ b/clients/tabby-agent/src/postprocess/formatIndentation.ts @@ -1,5 +1,5 @@ import { CompletionContext } from "../CompletionContext"; -import { PostprocessFilter, logger } from "./base"; +import { logger, PostprocessFilter } from "./base"; import { isBlank, splitLines } from "../utils"; function detectIndentation(lines: string[]): string | null { diff --git a/clients/tabby-agent/src/postprocess/limitScopeByIndentation.ts b/clients/tabby-agent/src/postprocess/limitScopeByIndentation.ts index cee01a937dd8..9c49a82d0a30 100644 --- a/clients/tabby-agent/src/postprocess/limitScopeByIndentation.ts +++ b/clients/tabby-agent/src/postprocess/limitScopeByIndentation.ts @@ -1,6 +1,6 @@ import { CompletionContext } from "../CompletionContext"; import { AgentConfig } from "../AgentConfig"; -import { PostprocessFilter, logger } from "./base"; +import { logger, PostprocessFilter } from "./base"; import { isBlank, splitLines } from "../utils"; function calcIndentLevel(line: string): number { diff --git a/clients/tabby-agent/src/postprocess/limitScopeBySyntax.ts b/clients/tabby-agent/src/postprocess/limitScopeBySyntax.ts index 178f899affad..6534b8cda80f 100644 --- a/clients/tabby-agent/src/postprocess/limitScopeBySyntax.ts +++ b/clients/tabby-agent/src/postprocess/limitScopeBySyntax.ts @@ -2,7 +2,7 @@ import type TreeSitterParser from "web-tree-sitter"; import { getParser, languagesConfigs } from "../syntax/parser"; import { typeList } from "../syntax/typeList"; import { CompletionContext } from "../CompletionContext"; -import { PostprocessFilter, logger } from "./base"; +import { logger, PostprocessFilter } from "./base"; export const supportedLanguages = Object.keys(languagesConfigs); diff --git a/clients/tabby-agent/src/postprocess/removeLineEndsWithRepetition.ts b/clients/tabby-agent/src/postprocess/removeLineEndsWithRepetition.ts index 5fb15e99649a..7603a7a408ba 100644 --- a/clients/tabby-agent/src/postprocess/removeLineEndsWithRepetition.ts +++ b/clients/tabby-agent/src/postprocess/removeLineEndsWithRepetition.ts @@ -1,5 +1,5 @@ -import { PostprocessFilter, logger } from "./base"; -import { splitLines, isBlank } from "../utils"; +import { logger, PostprocessFilter } from "./base"; +import { isBlank, splitLines } from "../utils"; const repetitionTests = [ /(.{3,}?)\1{5,}$/g, // match a 3+ characters pattern repeating 5+ times diff --git a/clients/tabby-agent/src/postprocess/removeRepetitiveBlocks.ts b/clients/tabby-agent/src/postprocess/removeRepetitiveBlocks.ts index 4da2a47a099a..7d135b62f03c 100644 --- a/clients/tabby-agent/src/postprocess/removeRepetitiveBlocks.ts +++ b/clients/tabby-agent/src/postprocess/removeRepetitiveBlocks.ts @@ -1,6 +1,6 @@ import { CompletionContext } from "../CompletionContext"; -import { PostprocessFilter, logger } from "./base"; -import { isBlank, calcDistance } from "../utils"; +import { logger, PostprocessFilter } from "./base"; +import { calcDistance, isBlank } from "../utils"; function blockSplitter(_: string) { // Have not implemented this for each language for now diff --git a/clients/tabby-agent/src/postprocess/removeRepetitiveLines.ts b/clients/tabby-agent/src/postprocess/removeRepetitiveLines.ts index 812e65f5eb49..92a44bb76d52 100644 --- a/clients/tabby-agent/src/postprocess/removeRepetitiveLines.ts +++ b/clients/tabby-agent/src/postprocess/removeRepetitiveLines.ts @@ -1,5 +1,5 @@ -import { PostprocessFilter, logger } from "./base"; -import { splitLines, isBlank, calcDistance } from "../utils"; +import { logger, PostprocessFilter } from "./base"; +import { calcDistance, isBlank, splitLines } from "../utils"; export function removeRepetitiveLines(): PostprocessFilter { return (input: string) => { diff --git a/clients/tabby-agent/src/utils.ts b/clients/tabby-agent/src/utils.ts index 97f02712ad25..6d559048c42a 100644 --- a/clients/tabby-agent/src/utils.ts +++ b/clients/tabby-agent/src/utils.ts @@ -65,6 +65,7 @@ export function findUnpairedAutoClosingChars(input: string): string { // Such as distance is 9 between `const fooFooFoo = 1;` and `const barBarBar = 1;`, but maybe 1 is enough. // May be better to count distance based on words instead of characters. import * as levenshtein from "fast-levenshtein"; + export function calcDistance(a: string, b: string) { return levenshtein.get(a, b); } diff --git a/clients/vscode/src/TabbyCompletionProvider.ts b/clients/vscode/src/TabbyCompletionProvider.ts index b572cf73af20..88c74b11c701 100644 --- a/clients/vscode/src/TabbyCompletionProvider.ts +++ b/clients/vscode/src/TabbyCompletionProvider.ts @@ -1,15 +1,15 @@ import { CancellationToken, + env, InlineCompletionContext, InlineCompletionItem, InlineCompletionItemProvider, InlineCompletionTriggerKind, + NotebookDocument, + NotebookRange, Position, Range, TextDocument, - NotebookDocument, - NotebookRange, - env, window, workspace, } from "vscode"; diff --git a/clients/vscode/src/agent.ts b/clients/vscode/src/agent.ts index 69437f85d117..1a3a28fa2ae4 100644 --- a/clients/vscode/src/agent.ts +++ b/clients/vscode/src/agent.ts @@ -1,5 +1,5 @@ -import { ExtensionContext, workspace, env, version } from "vscode"; -import { TabbyAgent, AgentInitOptions, PartialAgentConfig, ClientProperties, DataStore } from "tabby-agent"; +import { env, ExtensionContext, version, workspace } from "vscode"; +import { AgentInitOptions, ClientProperties, DataStore, PartialAgentConfig, TabbyAgent } from "tabby-agent"; function buildInitOptions(context: ExtensionContext): AgentInitOptions { const configuration = workspace.getConfiguration("tabby"); diff --git a/clients/vscode/src/commands.ts b/clients/vscode/src/commands.ts index 66e3049351e1..9ec893038995 100644 --- a/clients/vscode/src/commands.ts +++ b/clients/vscode/src/commands.ts @@ -1,14 +1,14 @@ import { + commands, ConfigurationTarget, + env, + ExtensionContext, InputBoxValidationSeverity, ProgressLocation, - Uri, ThemeIcon, - ExtensionContext, - workspace, + Uri, window, - env, - commands, + workspace, } from "vscode"; import os from "os"; import { strict as assert } from "assert"; diff --git a/clients/vscode/src/notifications.ts b/clients/vscode/src/notifications.ts index fc98b73a3786..5f49f665a4e3 100644 --- a/clients/vscode/src/notifications.ts +++ b/clients/vscode/src/notifications.ts @@ -1,8 +1,8 @@ -import { commands, window, workspace, ConfigurationTarget } from "vscode"; +import { commands, ConfigurationTarget, window, workspace } from "vscode"; import type { + ConnectionFailedIssue, HighCompletionTimeoutRateIssue, SlowCompletionResponseTimeIssue, - ConnectionFailedIssue, } from "tabby-agent"; import { agent } from "./agent"; diff --git a/crates/aim-downloader/src/error.rs b/crates/aim-downloader/src/error.rs index 03150c9805c6..3d588306fc97 100644 --- a/crates/aim-downloader/src/error.rs +++ b/crates/aim-downloader/src/error.rs @@ -1,4 +1,5 @@ extern crate custom_error; + use custom_error::custom_error; custom_error! { diff --git a/crates/juniper-axum/src/lib.rs b/crates/juniper-axum/src/lib.rs index 092f46f873d0..452f6236c3ac 100644 --- a/crates/juniper-axum/src/lib.rs +++ b/crates/juniper-axum/src/lib.rs @@ -1,6 +1,3 @@ -pub mod extract; -pub mod response; - use std::future; use axum::{ @@ -12,6 +9,9 @@ use juniper_graphql_ws::Schema; use self::{extract::JuniperRequest, response::JuniperResponse}; +pub mod extract; +pub mod response; + pub trait FromAuth { fn build(state: S, bearer: Option) -> Self; } diff --git a/crates/llama-cpp-bindings/Cargo.toml b/crates/llama-cpp-bindings/Cargo.toml index a054d36f73a7..7b7156df6250 100644 --- a/crates/llama-cpp-bindings/Cargo.toml +++ b/crates/llama-cpp-bindings/Cargo.toml @@ -6,6 +6,7 @@ edition = "2021" [features] cuda = [] rocm = [] +oneapi = [] [build-dependencies] cxx-build = "1.0" diff --git a/crates/llama-cpp-bindings/build.rs b/crates/llama-cpp-bindings/build.rs index b4e09f6c8506..e9a15889f1c7 100644 --- a/crates/llama-cpp-bindings/build.rs +++ b/crates/llama-cpp-bindings/build.rs @@ -4,6 +4,19 @@ use cmake::Config; fn main() { const LLAMA_CMAKE_PATH: &str = "llama.cpp/CMakeLists.txt"; + let intel_compile_flags: Vec<&str> = vec![ + "-fsycl", + "-fsycl-targets=spir64_gen", + "-fiopenmp", + "-fopenmp-targets=spir64_gen", + "-m64", + "-DMKL_ILP64", + "-qopt-report=3", + "-O3", + "-Xs", + "-device skl", + //"-device *", + ]; assert!( Path::new(LLAMA_CMAKE_PATH).exists(), @@ -68,6 +81,41 @@ fn main() { println!("cargo:rustc-link-lib=rocblas"); println!("cargo:rustc-link-lib=hipblas"); } + if cfg!(feature = "oneapi") { + let mkl_root = env::var("MKLROOT") + .expect("MKLROOT needs to be defined to compile for oneAPI (use setvars.sh to set)"); + let compiler_root = env::var("CMPLR_ROOT") + .expect("CMPLR_ROOT needs to be defined to compile for oneAPI (use setvars.sh to set)"); + config.define("LLAMA_BLAS", "ON"); + config.define("LLAMA_BLAS_VENDOR", "Intel10_64lp"); + config.define("C_FLAGS", intel_compile_flags.join(" ")); + config.define("CXX_FLAGS", intel_compile_flags.join(" ")); + config.define("CMAKE_C_COMPILER", format!("{}/bin/icx", compiler_root)); + config.define("CMAKE_CXX_COMPILER", format!("{}/bin/icpx", compiler_root)); + println!("cargo:rustc-link-arg=-fiopenmp"); + println!("cargo:rustc-link-arg=-fopenmp-targets=spir64_gen"); + println!("cargo:rustc-link-arg=-fsycl"); + println!("cargo:rustc-link-arg=-Wl,--no-as-needed"); + println!("cargo:rustc-link-search=native={}/lib", compiler_root); + println!("cargo:rustc-link-search=native={}/lib", mkl_root); + println!("cargo:rustc-link-lib=svml"); + println!("cargo:rustc-link-lib=mkl_sycl_blas"); + println!("cargo:rustc-link-lib=mkl_sycl_lapack"); + println!("cargo:rustc-link-lib=mkl_sycl_dft"); + println!("cargo:rustc-link-lib=mkl_sycl_sparse"); + println!("cargo:rustc-link-lib=mkl_sycl_vm"); + println!("cargo:rustc-link-lib=mkl_sycl_rng"); + println!("cargo:rustc-link-lib=mkl_sycl_stats"); + println!("cargo:rustc-link-lib=mkl_sycl_data_fitting"); + println!("cargo:rustc-link-lib=mkl_intel_ilp64"); + println!("cargo:rustc-link-lib=mkl_intel_thread"); + println!("cargo:rustc-link-lib=mkl_core"); + println!("cargo:rustc-link-lib=iomp5"); + println!("cargo:rustc-link-lib=sycl"); + println!("cargo:rustc-link-lib=pthread"); + println!("cargo:rustc-link-lib=m"); + println!("cargo:rustc-link-lib=dl"); + } let dst = config.build(); println!("cargo:rustc-link-search=native={}/build", dst.display()); diff --git a/crates/llama-cpp-bindings/src/lib.rs b/crates/llama-cpp-bindings/src/lib.rs index 0dbdaf9cbea2..12ec2d219022 100644 --- a/crates/llama-cpp-bindings/src/lib.rs +++ b/crates/llama-cpp-bindings/src/lib.rs @@ -1,6 +1,3 @@ -mod llama; -mod utils; - use async_stream::stream; use async_trait::async_trait; use derive_builder::Builder; @@ -11,6 +8,9 @@ use tabby_inference::{ decoding::StopConditionFactory, helpers, TextGeneration, TextGenerationOptions, }; +mod llama; +mod utils; + #[cxx::bridge(namespace = "llama")] mod ffi { struct StepOutput { diff --git a/crates/tabby-inference/src/lib.rs b/crates/tabby-inference/src/lib.rs index e4052d0cf919..07888311c958 100644 --- a/crates/tabby-inference/src/lib.rs +++ b/crates/tabby-inference/src/lib.rs @@ -1,10 +1,10 @@ -pub mod decoding; - use async_trait::async_trait; use derive_builder::Builder; use futures::stream::BoxStream; use tabby_common::languages::Language; +pub mod decoding; + #[derive(Builder, Debug)] pub struct TextGenerationOptions { #[builder(default = "1024")] diff --git a/crates/tabby/Cargo.toml b/crates/tabby/Cargo.toml index d74b8ad0894d..63b7582811d9 100644 --- a/crates/tabby/Cargo.toml +++ b/crates/tabby/Cargo.toml @@ -8,6 +8,7 @@ default = ["ee"] ee = ["dep:tabby-webserver"] cuda = ["llama-cpp-bindings/cuda"] rocm = ["llama-cpp-bindings/rocm"] +oneapi = ["llama-cpp-bindings/oneapi"] experimental-http = ["dep:http-api-bindings"] [dependencies] diff --git a/crates/tabby/build.rs b/crates/tabby/build.rs index dc138d230671..4c876d1429f3 100644 --- a/crates/tabby/build.rs +++ b/crates/tabby/build.rs @@ -1,8 +1,38 @@ +use std::env; use std::error::Error; use vergen::EmitBuilder; fn main() -> Result<(), Box> { + if cfg!(feature = "oneapi") { + let mkl_root = env::var("MKLROOT") + .expect("MKLROOT needs to be defined to compile for oneAPI (use setvars.sh to set)"); + let compiler_root = env::var("CMPLR_ROOT") + .expect("CMPLR_ROOT needs to be defined to compile for oneAPI (use setvars.sh to set)"); + println!("cargo:rustc-link-arg=-fiopenmp"); + println!("cargo:rustc-link-arg=-fopenmp-targets=spir64_gen"); + println!("cargo:rustc-link-arg=-fsycl"); + println!("cargo:rustc-link-arg=-Wl,--no-as-needed"); + println!("cargo:rustc-link-search=native={}/lib", compiler_root); + println!("cargo:rustc-link-search=native={}/lib", mkl_root); + println!("cargo:rustc-link-lib=svml"); + println!("cargo:rustc-link-lib=mkl_sycl_blas"); + println!("cargo:rustc-link-lib=mkl_sycl_lapack"); + println!("cargo:rustc-link-lib=mkl_sycl_dft"); + println!("cargo:rustc-link-lib=mkl_sycl_sparse"); + println!("cargo:rustc-link-lib=mkl_sycl_vm"); + println!("cargo:rustc-link-lib=mkl_sycl_rng"); + println!("cargo:rustc-link-lib=mkl_sycl_stats"); + println!("cargo:rustc-link-lib=mkl_sycl_data_fitting"); + println!("cargo:rustc-link-lib=mkl_intel_ilp64"); + println!("cargo:rustc-link-lib=mkl_intel_thread"); + println!("cargo:rustc-link-lib=mkl_core"); + println!("cargo:rustc-link-lib=iomp5"); + println!("cargo:rustc-link-lib=sycl"); + println!("cargo:rustc-link-lib=pthread"); + println!("cargo:rustc-link-lib=m"); + println!("cargo:rustc-link-lib=dl"); + } // touch EmitBuilder::builder() .all_build() diff --git a/crates/tabby/src/main.rs b/crates/tabby/src/main.rs index e13f13849ade..b626abed97ac 100644 --- a/crates/tabby/src/main.rs +++ b/crates/tabby/src/main.rs @@ -73,6 +73,10 @@ pub enum Device { #[strum(serialize = "rocm")] Rocm, + #[cfg(feature = "oneapi")] + #[strum(serialize = "oneapi")] + OneApi, + #[cfg(all(target_os = "macos", target_arch = "aarch64"))] #[strum(serialize = "metal")] Metal, @@ -98,10 +102,16 @@ impl Device { *self == Device::Rocm } + #[cfg(feature = "oneapi")] + pub fn ggml_use_gpu(&self) -> bool { + *self == Device::OneApi + } + #[cfg(not(any( all(target_os = "macos", target_arch = "aarch64"), feature = "cuda", feature = "rocm", + feature = "oneapi" )))] pub fn ggml_use_gpu(&self) -> bool { false diff --git a/crates/tabby/src/routes/chat.rs b/crates/tabby/src/routes/chat.rs index cab8a58c881f..28b51054b8a8 100644 --- a/crates/tabby/src/routes/chat.rs +++ b/crates/tabby/src/routes/chat.rs @@ -1,16 +1,3 @@ -use std::sync::Arc; - -use async_stream::stream; -use axum::{ - extract::State, - response::{IntoResponse, Response}, - Json, -}; -use axum_streams::StreamBodyAs; -use tracing::instrument; - -use crate::services::chat::{ChatCompletionRequest, ChatService}; - #[utoipa::path( post, path = "/v1beta/chat/completions", diff --git a/crates/tabby/src/routes/completions.rs b/crates/tabby/src/routes/completions.rs index 72a192218cbd..d157e1687116 100644 --- a/crates/tabby/src/routes/completions.rs +++ b/crates/tabby/src/routes/completions.rs @@ -1,11 +1,3 @@ -use std::sync::Arc; - -use axum::{extract::State, Json}; -use hyper::StatusCode; -use tracing::{instrument, warn}; - -use crate::services::completion::{CompletionRequest, CompletionResponse, CompletionService}; - #[utoipa::path( post, path = "/v1/completions", diff --git a/crates/tabby/src/routes/events.rs b/crates/tabby/src/routes/events.rs index f8b7c744a50b..4df1f5d11ede 100644 --- a/crates/tabby/src/routes/events.rs +++ b/crates/tabby/src/routes/events.rs @@ -1,12 +1,3 @@ -use std::{collections::HashMap, sync::Arc}; - -use axum::{ - extract::{Query, State}, - Json, -}; -use hyper::StatusCode; -use tabby_common::api::event::{Event, EventLogger, LogEventRequest, SelectKind}; - #[utoipa::path( post, path = "/v1/events", diff --git a/crates/tabby/src/routes/health.rs b/crates/tabby/src/routes/health.rs index 055763726bd4..71c801dbc006 100644 --- a/crates/tabby/src/routes/health.rs +++ b/crates/tabby/src/routes/health.rs @@ -1,9 +1,3 @@ -use std::sync::Arc; - -use axum::{extract::State, Json}; - -use crate::services::health; - #[utoipa::path( get, path = "/v1/health", diff --git a/crates/tabby/src/routes/search.rs b/crates/tabby/src/routes/search.rs index a7ff29aa06db..7f65a04e44aa 100644 --- a/crates/tabby/src/routes/search.rs +++ b/crates/tabby/src/routes/search.rs @@ -1,14 +1,4 @@ -use std::sync::Arc; - -use anyhow::Result; -use axum::{ - extract::{Query, State}, - Json, -}; -use hyper::StatusCode; use serde::Deserialize; -use tabby_common::api::code::{CodeSearch, CodeSearchError, SearchResponse}; -use tracing::{instrument, warn}; use utoipa::IntoParams; #[derive(Deserialize, IntoParams)] diff --git a/crates/tabby/src/services/chat.rs b/crates/tabby/src/services/chat.rs index e81096dc6057..115cd1a69e9c 100644 --- a/crates/tabby/src/services/chat.rs +++ b/crates/tabby/src/services/chat.rs @@ -1,5 +1,3 @@ -mod chat_prompt; - use std::sync::Arc; use async_stream::stream; @@ -13,6 +11,8 @@ use utoipa::ToSchema; use super::model; use crate::{fatal, Device}; +mod chat_prompt; + #[derive(Serialize, Deserialize, ToSchema, Clone, Debug)] #[schema(example=json!({ "messages": [ diff --git a/crates/tabby/src/services/completion.rs b/crates/tabby/src/services/completion.rs index ecdc2df8b1d0..b0d36c537e73 100644 --- a/crates/tabby/src/services/completion.rs +++ b/crates/tabby/src/services/completion.rs @@ -1,5 +1,3 @@ -mod completion_prompt; - use std::sync::Arc; use serde::{Deserialize, Serialize}; @@ -19,6 +17,8 @@ use utoipa::ToSchema; use super::model; use crate::Device; +mod completion_prompt; + #[derive(Error, Debug)] pub enum CompletionError { #[error("empty prompt from completion request")] diff --git a/Dockerfile b/cuda.Dockerfile similarity index 99% rename from Dockerfile rename to cuda.Dockerfile index f939d143ec2f..947368d4a68d 100644 --- a/Dockerfile +++ b/cuda.Dockerfile @@ -29,12 +29,13 @@ RUN curl https://sh.rustup.rs -sSf | bash -s -- --default-toolchain ${RUST_TOOLC ENV PATH="/root/.cargo/bin:${PATH}" WORKDIR /root/workspace -COPY . . RUN mkdir -p /opt/tabby/bin RUN mkdir -p /opt/tabby/lib RUN mkdir -p target +COPY . . + RUN --mount=type=cache,target=/usr/local/cargo/registry \ --mount=type=cache,target=/root/workspace/target \ cargo build --features cuda --release --package tabby && \ diff --git a/ee/tabby-ui/app/(dashboard)/page.tsx b/ee/tabby-ui/app/(dashboard)/page.tsx index b939aebda965..7fa7b7bd91e8 100644 --- a/ee/tabby-ui/app/(dashboard)/page.tsx +++ b/ee/tabby-ui/app/(dashboard)/page.tsx @@ -6,12 +6,7 @@ import { graphql } from '@/lib/gql/generates' import { useHealth } from '@/lib/hooks/use-health' import { useAuthenticatedGraphQLQuery, useGraphQLForm } from '@/lib/tabby/gql' import { Button } from '@/components/ui/button' -import { - CardContent, - CardFooter, - CardHeader, - CardTitle -} from '@/components/ui/card' +import { CardContent, CardFooter, CardHeader, CardTitle } from '@/components/ui/card' import { IconRotate } from '@/components/ui/icons' import { Input } from '@/components/ui/input' import { Label } from '@/components/ui/label' diff --git a/ee/tabby-ui/app/(dashboard)/team/components/create-invitation-form.tsx b/ee/tabby-ui/app/(dashboard)/team/components/create-invitation-form.tsx index 00f27c9ee01f..c884d511aff9 100644 --- a/ee/tabby-ui/app/(dashboard)/team/components/create-invitation-form.tsx +++ b/ee/tabby-ui/app/(dashboard)/team/components/create-invitation-form.tsx @@ -8,13 +8,7 @@ import * as z from 'zod' import { graphql } from '@/lib/gql/generates' import { useGraphQLForm } from '@/lib/tabby/gql' import { Button } from '@/components/ui/button' -import { - Form, - FormControl, - FormField, - FormItem, - FormMessage -} from '@/components/ui/form' +import { Form, FormControl, FormField, FormItem, FormMessage } from '@/components/ui/form' import { Input } from '@/components/ui/input' const createInvitation = graphql(/* GraphQL */ ` diff --git a/ee/tabby-ui/app/(dashboard)/team/components/invitation-table.tsx b/ee/tabby-ui/app/(dashboard)/team/components/invitation-table.tsx index 994ee0db0bfd..a58481be1ff9 100644 --- a/ee/tabby-ui/app/(dashboard)/team/components/invitation-table.tsx +++ b/ee/tabby-ui/app/(dashboard)/team/components/invitation-table.tsx @@ -7,14 +7,7 @@ import { graphql } from '@/lib/gql/generates' import { useAuthenticatedGraphQLQuery, useGraphQLForm } from '@/lib/tabby/gql' import { Button } from '@/components/ui/button' import { IconTrash } from '@/components/ui/icons' -import { - Table, - TableBody, - TableCell, - TableHead, - TableHeader, - TableRow -} from '@/components/ui/table' +import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table' import { CopyButton } from '@/components/copy-button' import CreateInvitationForm from './create-invitation-form' diff --git a/ee/tabby-ui/app/(dashboard)/team/components/user-table.tsx b/ee/tabby-ui/app/(dashboard)/team/components/user-table.tsx index c4fb9868099e..e1f16bf3ed07 100644 --- a/ee/tabby-ui/app/(dashboard)/team/components/user-table.tsx +++ b/ee/tabby-ui/app/(dashboard)/team/components/user-table.tsx @@ -6,14 +6,7 @@ import moment from 'moment' import { graphql } from '@/lib/gql/generates' import { useAuthenticatedGraphQLQuery } from '@/lib/tabby/gql' import { Badge } from '@/components/ui/badge' -import { - Table, - TableBody, - TableCell, - TableHead, - TableHeader, - TableRow -} from '@/components/ui/table' +import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table' const listUsers = graphql(/* GraphQL */ ` query ListUsers { diff --git a/ee/tabby-ui/app/auth/signin/components/user-signin-form.tsx b/ee/tabby-ui/app/auth/signin/components/user-signin-form.tsx index 001f5b868c6e..69b06c8b663c 100644 --- a/ee/tabby-ui/app/auth/signin/components/user-signin-form.tsx +++ b/ee/tabby-ui/app/auth/signin/components/user-signin-form.tsx @@ -11,14 +11,7 @@ import { useSignIn } from '@/lib/tabby/auth' import { useGraphQLForm } from '@/lib/tabby/gql' import { cn } from '@/lib/utils' import { Button } from '@/components/ui/button' -import { - Form, - FormControl, - FormField, - FormItem, - FormLabel, - FormMessage -} from '@/components/ui/form' +import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from '@/components/ui/form' import { IconSpinner } from '@/components/ui/icons' import { Input } from '@/components/ui/input' diff --git a/ee/tabby-ui/app/auth/signup/components/user-register-form.tsx b/ee/tabby-ui/app/auth/signup/components/user-register-form.tsx index fffcc18001b7..8e2c3dbd13af 100644 --- a/ee/tabby-ui/app/auth/signup/components/user-register-form.tsx +++ b/ee/tabby-ui/app/auth/signup/components/user-register-form.tsx @@ -11,14 +11,7 @@ import { useSignIn } from '@/lib/tabby/auth' import { useGraphQLForm } from '@/lib/tabby/gql' import { cn } from '@/lib/utils' import { Button } from '@/components/ui/button' -import { - Form, - FormControl, - FormField, - FormItem, - FormLabel, - FormMessage -} from '@/components/ui/form' +import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from '@/components/ui/form' import { IconSpinner } from '@/components/ui/icons' import { Input } from '@/components/ui/input' diff --git a/ee/tabby-ui/app/playground/components/chat-sessions.tsx b/ee/tabby-ui/app/playground/components/chat-sessions.tsx index 821a17722c7a..9b31f95b04ce 100644 --- a/ee/tabby-ui/app/playground/components/chat-sessions.tsx +++ b/ee/tabby-ui/app/playground/components/chat-sessions.tsx @@ -3,21 +3,13 @@ import React from 'react' import { useStore } from '@/lib/hooks/use-store' -import { - clearChats, - deleteChat, - setActiveChatId -} from '@/lib/stores/chat-actions' +import { clearChats, deleteChat, setActiveChatId } from '@/lib/stores/chat-actions' import { useChatStore } from '@/lib/stores/chat-store' import { cn, nanoid } from '@/lib/utils' import { Button } from '@/components/ui/button' import { IconPlus, IconTrash } from '@/components/ui/icons' import { Separator } from '@/components/ui/separator' -import { - Tooltip, - TooltipContent, - TooltipTrigger -} from '@/components/ui/tooltip' +import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip' import { ListSkeleton } from '@/components/skeleton' import { ClearChatsButton } from './clear-chats-button' diff --git a/ee/tabby-ui/app/playground/components/edit-chat-title-dialog.tsx b/ee/tabby-ui/app/playground/components/edit-chat-title-dialog.tsx index f6cb7b8ce1c3..ec018ceefe58 100644 --- a/ee/tabby-ui/app/playground/components/edit-chat-title-dialog.tsx +++ b/ee/tabby-ui/app/playground/components/edit-chat-title-dialog.tsx @@ -4,20 +4,10 @@ import React from 'react' import { updateChat } from '@/lib/stores/chat-actions' import { Button } from '@/components/ui/button' -import { - Dialog, - DialogContent, - DialogDescription, - DialogHeader, - DialogTitle -} from '@/components/ui/dialog' +import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from '@/components/ui/dialog' import { IconArrowElbow, IconEdit } from '@/components/ui/icons' import { Input } from '@/components/ui/input' -import { - Tooltip, - TooltipContent, - TooltipTrigger -} from '@/components/ui/tooltip' +import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip' interface EditChatTitleDialogProps { initialValue: string | undefined diff --git a/ee/tabby-ui/codegen.ts b/ee/tabby-ui/codegen.ts index a8a91ef1b079..076b12ff2dce 100644 --- a/ee/tabby-ui/codegen.ts +++ b/ee/tabby-ui/codegen.ts @@ -1,4 +1,3 @@ - import type { CodegenConfig } from '@graphql-codegen/cli'; const config: CodegenConfig = { diff --git a/ee/tabby-ui/components/chat.tsx b/ee/tabby-ui/components/chat.tsx index 87454c8f4fdb..2e2c93263ef7 100644 --- a/ee/tabby-ui/components/chat.tsx +++ b/ee/tabby-ui/components/chat.tsx @@ -1,8 +1,8 @@ 'use client' import React from 'react' -import { useChat } from 'ai/react' import type { Message } from 'ai/react' +import { useChat } from 'ai/react' import { find, findIndex } from 'lodash-es' import { toast } from 'react-hot-toast' diff --git a/ee/tabby-ui/components/prompt-form.tsx b/ee/tabby-ui/components/prompt-form.tsx index 879ce10065ca..36d9e5e9cb16 100644 --- a/ee/tabby-ui/components/prompt-form.tsx +++ b/ee/tabby-ui/components/prompt-form.tsx @@ -9,24 +9,10 @@ import fetcher from '@/lib/tabby/fetcher' import type { ISearchHit, SearchReponse } from '@/lib/types' import { cn } from '@/lib/utils' import { Button, buttonVariants } from '@/components/ui/button' -import { - Combobox, - ComboboxAnchor, - ComboboxContent, - ComboboxOption, - ComboboxTextarea -} from '@/components/ui/combobox' -import { - IconArrowElbow, - IconEdit, - IconSymbolFunction -} from '@/components/ui/icons' +import { Combobox, ComboboxAnchor, ComboboxContent, ComboboxOption, ComboboxTextarea } from '@/components/ui/combobox' +import { IconArrowElbow, IconEdit, IconSymbolFunction } from '@/components/ui/icons' import { Popover, PopoverAnchor, PopoverContent } from '@/components/ui/popover' -import { - Tooltip, - TooltipContent, - TooltipTrigger -} from '@/components/ui/tooltip' +import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip' export interface PromptProps extends Pick { diff --git a/ee/tabby-ui/components/ui/combobox.tsx b/ee/tabby-ui/components/ui/combobox.tsx index ca499f5127a1..630308af958e 100644 --- a/ee/tabby-ui/components/ui/combobox.tsx +++ b/ee/tabby-ui/components/ui/combobox.tsx @@ -1,21 +1,11 @@ import * as React from 'react' +import type { UseComboboxReturnValue, UseComboboxState, UseComboboxStateChangeOptions } from 'downshift' import { useCombobox } from 'downshift' -import type { - UseComboboxReturnValue, - UseComboboxState, - UseComboboxStateChangeOptions -} from 'downshift' import { isNil, omitBy } from 'lodash-es' import Textarea from 'react-textarea-autosize' import { cn } from '@/lib/utils' -import { - Popover, - PopoverAnchor, - PopoverClose, - PopoverContent, - PopoverPortal -} from '@/components/ui/popover' +import { Popover, PopoverAnchor, PopoverClose, PopoverContent, PopoverPortal } from '@/components/ui/popover' interface ComboboxContextValue extends UseComboboxReturnValue { open: boolean diff --git a/ee/tabby-ui/components/ui/form.tsx b/ee/tabby-ui/components/ui/form.tsx index 1fd11f45f922..12a78f0ec27a 100644 --- a/ee/tabby-ui/components/ui/form.tsx +++ b/ee/tabby-ui/components/ui/form.tsx @@ -1,14 +1,7 @@ import * as React from 'react' import * as LabelPrimitive from '@radix-ui/react-label' import { Slot } from '@radix-ui/react-slot' -import { - Controller, - ControllerProps, - FieldPath, - FieldValues, - FormProvider, - useFormContext -} from 'react-hook-form' +import { Controller, ControllerProps, FieldPath, FieldValues, FormProvider, useFormContext } from 'react-hook-form' import { cn } from '@/lib/utils' import { Label } from '@/components/ui/label' diff --git a/ee/tabby-ui/lib/hooks/use-patch-fetch.ts b/ee/tabby-ui/lib/hooks/use-patch-fetch.ts index 61ba2ed5f0e8..3dd8494cf4f9 100644 --- a/ee/tabby-ui/lib/hooks/use-patch-fetch.ts +++ b/ee/tabby-ui/lib/hooks/use-patch-fetch.ts @@ -1,9 +1,9 @@ import { useEffect } from 'react' import { + type AIStreamCallbacksAndOptions, createCallbacksTransformer, createStreamDataTransformer, - StreamingTextResponse, - type AIStreamCallbacksAndOptions + StreamingTextResponse } from 'ai' import { useSession } from '../tabby/auth' diff --git a/ee/tabby-ui/lib/hooks/use-workers.ts b/ee/tabby-ui/lib/hooks/use-workers.ts index 982b16b603d1..e19822fd960f 100644 --- a/ee/tabby-ui/lib/hooks/use-workers.ts +++ b/ee/tabby-ui/lib/hooks/use-workers.ts @@ -5,7 +5,7 @@ import { graphql } from '@/lib/gql/generates' import { Worker, WorkerKind } from '@/lib/gql/generates/graphql' import { useAuthenticatedGraphQLQuery } from '@/lib/tabby/gql' -import { useHealth, type HealthInfo } from './use-health' +import { type HealthInfo, useHealth } from './use-health' const modelNameMap: Record = { [WorkerKind.Chat]: 'chat_model', diff --git a/ee/tabby-webserver/src/lib.rs b/ee/tabby-webserver/src/lib.rs index ec2fedcf95dc..974036cbf1c6 100644 --- a/ee/tabby-webserver/src/lib.rs +++ b/ee/tabby-webserver/src/lib.rs @@ -1,23 +1,6 @@ -pub mod api; - -mod schema; -use api::Hub; -pub use schema::create_schema; -use tabby_common::api::{ - code::{CodeSearch, SearchResponse}, - event::RawEventLogger, -}; -use tokio::sync::Mutex; -use tracing::{error, warn}; -use websocket::WebSocketTransport; - -mod repositories; -mod service; -mod ui; -mod websocket; - use std::{net::SocketAddr, sync::Arc}; +use api::Hub; use axum::{ extract::{ws::WebSocket, ConnectInfo, State, WebSocketUpgrade}, http::Request, @@ -27,12 +10,21 @@ use axum::{ }; use hyper::Body; use juniper_axum::{graphiql, graphql, playground}; -use schema::{ - worker::{RegisterWorkerError, Worker, WorkerKind}, - Schema, ServiceLocator, -}; +pub use schema::create_schema; +use schema::{Schema, ServiceLocator}; use service::create_service_locator; +use tabby_common::api::{code::CodeSearch, event::RawEventLogger}; use tarpc::server::{BaseChannel, Channel}; +use tokio::sync::Mutex; +use websocket::WebSocketTransport; + +pub mod api; + +mod repositories; +mod schema; +mod service; +mod ui; +mod websocket; pub async fn attach_webserver( api: Router, diff --git a/ee/tabby-webserver/src/repositories/mod.rs b/ee/tabby-webserver/src/repositories/mod.rs index b9d3ca2c9e41..7f85c3a27db9 100644 --- a/ee/tabby-webserver/src/repositories/mod.rs +++ b/ee/tabby-webserver/src/repositories/mod.rs @@ -1,5 +1,3 @@ -mod resolve; - use anyhow::Result; use axum::{extract::Path, http::StatusCode, response::Response, routing, Json, Router}; use tabby_common::path::repositories_dir; @@ -10,6 +8,8 @@ use crate::{ repositories::resolve::{resolve_dir, resolve_file, resolve_meta, Meta, ResolveParams}, }; +mod resolve; + pub fn routes() -> Router { Router::new() .route("/:name/resolve/", routing::get(repositories::resolve)) diff --git a/ee/tabby-webserver/src/schema/auth.rs b/ee/tabby-webserver/src/schema/auth.rs index 7a48e7f5f10d..7f67c406b843 100644 --- a/ee/tabby-webserver/src/schema/auth.rs +++ b/ee/tabby-webserver/src/schema/auth.rs @@ -13,7 +13,6 @@ use uuid::Uuid; use validator::ValidationErrors; use super::{from_validation_errors, User}; - lazy_static! { static ref JWT_TOKEN_SECRET: String = jwt_token_secret(); @@ -283,6 +282,7 @@ pub trait AuthenticationService: Send + Sync { #[cfg(test)] mod tests { use super::*; + #[test] fn test_generate_jwt() { let claims = JWTPayload::new("test".to_string(), false); diff --git a/ee/tabby-webserver/src/schema/mod.rs b/ee/tabby-webserver/src/schema/mod.rs index f7f3a298952f..48635db9a052 100644 --- a/ee/tabby-webserver/src/schema/mod.rs +++ b/ee/tabby-webserver/src/schema/mod.rs @@ -1,6 +1,3 @@ -pub mod auth; -pub mod worker; - use std::sync::Arc; use auth::AuthenticationService; @@ -13,17 +10,10 @@ use juniper_axum::FromAuth; use tabby_common::api::{code::CodeSearch, event::RawEventLogger}; use validator::ValidationErrors; -use self::{ - auth::{validate_jwt, Invitation, RegisterError, TokenAuthError}, - worker::WorkerService, -}; -use crate::schema::{ - auth::{ - RefreshTokenError, RefreshTokenResponse, RegisterResponse, TokenAuthResponse, - VerifyTokenResponse, - }, - worker::Worker, -}; +use self::{auth::validate_jwt, worker::WorkerService}; + +pub mod auth; +pub mod worker; pub trait ServiceLocator: Send + Sync { fn auth(&self) -> &dyn AuthenticationService; diff --git a/ee/tabby-webserver/src/service/db/mod.rs b/ee/tabby-webserver/src/service/db/mod.rs index dd912212166e..bcad708ab37c 100644 --- a/ee/tabby-webserver/src/service/db/mod.rs +++ b/ee/tabby-webserver/src/service/db/mod.rs @@ -1,18 +1,17 @@ -mod invitations; -mod refresh_tokens; -mod users; - use std::{path::PathBuf, sync::Arc}; use anyhow::Result; use lazy_static::lazy_static; use rusqlite::params; -use rusqlite_migration::{AsyncMigrations, M}; use tabby_common::path::tabby_root; use tokio_rusqlite::Connection; use crate::service::cron::run_offline_job; +mod invitations; +mod refresh_tokens; +mod users; + lazy_static! { static ref MIGRATIONS: AsyncMigrations = AsyncMigrations::new(vec![ M::up( @@ -164,7 +163,6 @@ impl DbConn { #[cfg(test)] mod tests { - use super::*; use crate::schema::auth::AuthenticationService; diff --git a/ee/tabby-webserver/src/service/db/refresh_tokens.rs b/ee/tabby-webserver/src/service/db/refresh_tokens.rs index 63dd45288de3..e833f9a6c941 100644 --- a/ee/tabby-webserver/src/service/db/refresh_tokens.rs +++ b/ee/tabby-webserver/src/service/db/refresh_tokens.rs @@ -109,7 +109,6 @@ impl DbConn { #[cfg(test)] mod tests { - use std::ops::Add; use super::*; diff --git a/ee/tabby-webserver/src/service/mod.rs b/ee/tabby-webserver/src/service/mod.rs index ae2d8ef3f699..7a64a592158c 100644 --- a/ee/tabby-webserver/src/service/mod.rs +++ b/ee/tabby-webserver/src/service/mod.rs @@ -1,9 +1,3 @@ -mod auth; -mod cron; -mod db; -mod proxy; -mod worker; - use std::{net::SocketAddr, sync::Arc}; use anyhow::Result; @@ -24,6 +18,12 @@ use crate::schema::{ ServiceLocator, }; +mod auth; +mod cron; +mod db; +mod proxy; +mod worker; + struct ServerContext { client: Client, completion: worker::WorkerGroup, diff --git a/ee/tabby-webserver/src/service/worker.rs b/ee/tabby-webserver/src/service/worker.rs index 370112989a64..2fb8a577f383 100644 --- a/ee/tabby-webserver/src/service/worker.rs +++ b/ee/tabby-webserver/src/service/worker.rs @@ -59,7 +59,6 @@ fn random_index(size: usize) -> usize { #[cfg(test)] mod tests { - use super::*; use crate::schema::worker::WorkerKind; diff --git a/oneapi.Dockerfile b/oneapi.Dockerfile new file mode 100644 index 000000000000..263be55489d8 --- /dev/null +++ b/oneapi.Dockerfile @@ -0,0 +1,70 @@ +ARG UBUNTU_VERSION=22.04 +# This needs to generally match the container host's environment. +ARG ONEAPI_VERSION=2024.0.0 +# Target the CUDA build image +ARG BASE_ONEAPI_DEV_CONTAINER="intel/oneapi-basekit:${ONEAPI_VERSION}-devel-ubuntu${UBUNTU_VERSION}" +# Target the CUDA runtime image +ARG BASE_ONEAPI_RUN_CONTAINER="intel/oneapi-runtime:${ONEAPI_VERSION}-devel-ubuntu${UBUNTU_VERSION}" + +FROM ${BASE_ONEAPI_DEV_CONTAINER} as build + +# Rust toolchain version +ARG RUST_TOOLCHAIN=stable + +ENV DEBIAN_FRONTEND=noninteractive +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + curl \ + pkg-config \ + libssl-dev \ + protobuf-compiler \ + git \ + cmake \ + intel-opencl-icd \ + && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +# setup rust. +RUN curl https://sh.rustup.rs -sSf | bash -s -- --default-toolchain ${RUST_TOOLCHAIN} -y +ENV PATH="/root/.cargo/bin:${PATH}" + +RUN update-alternatives --install "/usr/bin/cc" "cc" "${CMPLR_ROOT}/bin/icx" 100 +RUN update-alternatives --install "/usr/bin/c++" "c++" "${CMPLR_ROOT}/bin/icpx" 100 +RUN update-alternatives --install "/usr/bin/ld" "ld" "${CMPLR_ROOT}/bin/compiler/ld.lld" 100 +ENV RUSTFLAGS="-C link-args=-fPIC -C link-args=-fsycl -C link-args=-L${CMPLR_ROOT}/lib -C link-args=-lsycl -C link-args=-lintlc" +ENV OPENSSL_NO_VENDOR=1 + +WORKDIR /root/workspace + +RUN mkdir -p /opt/tabby/bin +RUN mkdir -p /opt/tabby/lib +RUN mkdir -p target + +COPY . . + +#RUN --mount=type=cache,target=/usr/local/cargo/registry \ +# --mount=type=cache,target=/root/workspace/target \ +# cargo build --features oneapi --release --package tabby && \ +# cp target/release/tabby /opt/tabby/bin/ +RUN cargo build --features oneapi --release --package tabby && \ + cp target/release/tabby /opt/tabby/bin/ + +FROM ${BASE_ONEAPI_RUN_CONTAINER} as runtime + +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + git \ + && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +# Disable safe directory in docker +# Context: https://github.com/git/git/commit/8959555cee7ec045958f9b6dd62e541affb7e7d9 +RUN git config --system --add safe.directory "*" + +COPY --from=build /opt/tabby /opt/tabby + +ENV TABBY_ROOT=/data + +ENTRYPOINT ["/opt/tabby/bin/tabby"] diff --git a/python/tabby-loadtest/loadtest.js b/python/tabby-loadtest/loadtest.js index d1c95dcaee6f..f042f6d02448 100644 --- a/python/tabby-loadtest/loadtest.js +++ b/python/tabby-loadtest/loadtest.js @@ -1,6 +1,5 @@ import http from "k6/http"; -import { check, sleep } from "k6"; -import { textSummary } from "https://jslib.k6.io/k6-utils/1.4.0/index.js"; +import {check, sleep} from "k6"; const PARALLELISM = parseInt(__ENV.PARALLELISM); diff --git a/rocm.Dockerfile b/rocm.Dockerfile new file mode 100644 index 000000000000..87ccd51acf11 --- /dev/null +++ b/rocm.Dockerfile @@ -0,0 +1,61 @@ +ARG UBUNTU_VERSION=22.04 +# This needs to generally match the container host's environment. +ARG ROCM_VERSION=5.7 +# Target the CUDA build image +ARG BASE_ROCM_DEV_CONTAINER="rocm/dev-ubuntu-${UBUNTU_VERSION}:${ROCM_VERSION}-complete" +# Target the CUDA runtime image +ARG BASE_ROCM_RUN_CONTAINER="rocm/dev-ubuntu-${UBUNTU_VERSION}:${ROCM_VERSION}-complete" + +FROM ${BASE_ROCM_DEV_CONTAINER} as build + +# Rust toolchain version +ARG RUST_TOOLCHAIN=stable + +ENV DEBIAN_FRONTEND=noninteractive +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + curl \ + pkg-config \ + libssl-dev \ + protobuf-compiler \ + git \ + cmake \ + && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +# setup rust. +RUN curl https://sh.rustup.rs -sSf | bash -s -- --default-toolchain ${RUST_TOOLCHAIN} -y +ENV PATH="/root/.cargo/bin:${PATH}" + +WORKDIR /root/workspace + +RUN mkdir -p /opt/tabby/bin +RUN mkdir -p /opt/tabby/lib +RUN mkdir -p target + +COPY . . + +RUN --mount=type=cache,target=/usr/local/cargo/registry \ + --mount=type=cache,target=/root/workspace/target \ + cargo build --features rocm --release --package tabby && \ + cp target/release/tabby /opt/tabby/bin/ + +FROM ${BASE_ROCM_RUN_CONTAINER} as runtime + +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + git \ + && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +# Disable safe directory in docker +# Context: https://github.com/git/git/commit/8959555cee7ec045958f9b6dd62e541affb7e7d9 +RUN git config --system --add safe.directory "*" + +COPY --from=build /opt/tabby /opt/tabby + +ENV TABBY_ROOT=/data + +ENTRYPOINT ["/opt/tabby/bin/tabby"] diff --git a/website/docs/installation/docker-compose.mdx b/website/docs/installation/docker-compose.mdx index 8dab5c47b985..dd3193ccd3a7 100644 --- a/website/docs/installation/docker-compose.mdx +++ b/website/docs/installation/docker-compose.mdx @@ -5,6 +5,7 @@ sidebar_position: 1 # Docker Compose This guide explains how to launch Tabby using docker-compose. + import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; diff --git a/website/docs/installation/docker.mdx b/website/docs/installation/docker.mdx index 7f26f87c0c13..857c16644b3f 100644 --- a/website/docs/installation/docker.mdx +++ b/website/docs/installation/docker.mdx @@ -6,6 +6,7 @@ sidebar_position: 0 This guide explains how to launch Tabby using docker. + import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem';