mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-06-28 02:53:30 +00:00
Update LocalInference to use public repos
This commit is contained in:
parent
4fcda00872
commit
b3b0349931
19 changed files with 22 additions and 1093 deletions
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
[submodule "llama_stack/providers/impls/ios/inference/executorch"]
|
||||||
|
path = llama_stack/providers/impls/ios/inference/executorch
|
||||||
|
url = https://github.com/pytorch/executorch
|
|
@ -1,548 +0,0 @@
|
||||||
// !$*UTF8*$!
|
|
||||||
{
|
|
||||||
archiveVersion = 1;
|
|
||||||
classes = {
|
|
||||||
};
|
|
||||||
objectVersion = 60;
|
|
||||||
objects = {
|
|
||||||
|
|
||||||
/* Begin PBXBuildFile section */
|
|
||||||
5C03561F2CA3AB9600E3BB46 /* LlamaStackClient in Frameworks */ = {isa = PBXBuildFile; productRef = 5C03561E2CA3AB9600E3BB46 /* LlamaStackClient */; };
|
|
||||||
5C5B6E212CA3D89F00AF6130 /* LlamaStackClient in Frameworks */ = {isa = PBXBuildFile; productRef = 5C5B6E202CA3D89F00AF6130 /* LlamaStackClient */; };
|
|
||||||
5CCBC60C2CA1F04A00E958D0 /* LocalInference.h in Headers */ = {isa = PBXBuildFile; fileRef = 5CCBC60B2CA1F04A00E958D0 /* LocalInference.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
|
||||||
5CCBC6752CA1F45800E958D0 /* executorch_debug in Frameworks */ = {isa = PBXBuildFile; productRef = 5CCBC6742CA1F45800E958D0 /* executorch_debug */; };
|
|
||||||
5CCBC6862CA1F64A00E958D0 /* LLaMARunner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5CCBC6802CA1F63F00E958D0 /* LLaMARunner.framework */; platformFilter = ios; };
|
|
||||||
5CCBC6872CA1F64A00E958D0 /* LLaMARunner.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 5CCBC6802CA1F63F00E958D0 /* LLaMARunner.framework */; platformFilter = ios; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
|
|
||||||
5CCBC68D2CA1F7A100E958D0 /* PromptTemplate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5CCBC6892CA1F7A000E958D0 /* PromptTemplate.swift */; };
|
|
||||||
5CCBC68E2CA1F7A100E958D0 /* LocalInference.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5CCBC68A2CA1F7A000E958D0 /* LocalInference.swift */; };
|
|
||||||
5CCBC68F2CA1F7A100E958D0 /* Parsing.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5CCBC68B2CA1F7A000E958D0 /* Parsing.swift */; };
|
|
||||||
5CCBC6902CA1F7A100E958D0 /* SystemPrompts.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5CCBC68C2CA1F7A100E958D0 /* SystemPrompts.swift */; };
|
|
||||||
5CCBC6932CA1F7D000E958D0 /* Stencil in Frameworks */ = {isa = PBXBuildFile; productRef = 5CCBC6922CA1F7D000E958D0 /* Stencil */; };
|
|
||||||
/* End PBXBuildFile section */
|
|
||||||
|
|
||||||
/* Begin PBXContainerItemProxy section */
|
|
||||||
5CCBC67D2CA1F63F00E958D0 /* PBXContainerItemProxy */ = {
|
|
||||||
isa = PBXContainerItemProxy;
|
|
||||||
containerPortal = 5CCBC6762CA1F63F00E958D0 /* LLaMA.xcodeproj */;
|
|
||||||
proxyType = 2;
|
|
||||||
remoteGlobalIDString = 036CAF9D2BB1444500D6C2D5;
|
|
||||||
remoteInfo = LLaMA;
|
|
||||||
};
|
|
||||||
5CCBC67F2CA1F63F00E958D0 /* PBXContainerItemProxy */ = {
|
|
||||||
isa = PBXContainerItemProxy;
|
|
||||||
containerPortal = 5CCBC6762CA1F63F00E958D0 /* LLaMA.xcodeproj */;
|
|
||||||
proxyType = 2;
|
|
||||||
remoteGlobalIDString = 03729ED52BB1F8DE00152F2E;
|
|
||||||
remoteInfo = LLaMARunner;
|
|
||||||
};
|
|
||||||
5CCBC69E2CA2036B00E958D0 /* PBXContainerItemProxy */ = {
|
|
||||||
isa = PBXContainerItemProxy;
|
|
||||||
containerPortal = 5CCBC6762CA1F63F00E958D0 /* LLaMA.xcodeproj */;
|
|
||||||
proxyType = 2;
|
|
||||||
remoteGlobalIDString = 5CCBC6982CA2036A00E958D0;
|
|
||||||
remoteInfo = LLaMAPerfBenchmark;
|
|
||||||
};
|
|
||||||
5CCBC6A02CA2036B00E958D0 /* PBXContainerItemProxy */ = {
|
|
||||||
isa = PBXContainerItemProxy;
|
|
||||||
containerPortal = 5CCBC6762CA1F63F00E958D0 /* LLaMA.xcodeproj */;
|
|
||||||
proxyType = 2;
|
|
||||||
remoteGlobalIDString = 5CCBC6992CA2036A00E958D0;
|
|
||||||
remoteInfo = LLaMAPerfBenchmarkTests;
|
|
||||||
};
|
|
||||||
/* End PBXContainerItemProxy section */
|
|
||||||
|
|
||||||
/* Begin PBXCopyFilesBuildPhase section */
|
|
||||||
5CCBC6882CA1F64A00E958D0 /* Embed Frameworks */ = {
|
|
||||||
isa = PBXCopyFilesBuildPhase;
|
|
||||||
buildActionMask = 2147483647;
|
|
||||||
dstPath = "";
|
|
||||||
dstSubfolderSpec = 10;
|
|
||||||
files = (
|
|
||||||
5CCBC6872CA1F64A00E958D0 /* LLaMARunner.framework in Embed Frameworks */,
|
|
||||||
);
|
|
||||||
name = "Embed Frameworks";
|
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
|
||||||
};
|
|
||||||
/* End PBXCopyFilesBuildPhase section */
|
|
||||||
|
|
||||||
/* Begin PBXFileReference section */
|
|
||||||
5CCBC6082CA1F04A00E958D0 /* LocalInference.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = LocalInference.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
|
||||||
5CCBC60B2CA1F04A00E958D0 /* LocalInference.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LocalInference.h; sourceTree = "<group>"; };
|
|
||||||
5CCBC6762CA1F63F00E958D0 /* LLaMA.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = LLaMA.xcodeproj; path = "executorch/examples/demo-apps/apple_ios/LLaMA/LLaMA.xcodeproj"; sourceTree = "<group>"; };
|
|
||||||
5CCBC6892CA1F7A000E958D0 /* PromptTemplate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PromptTemplate.swift; sourceTree = "<group>"; };
|
|
||||||
5CCBC68A2CA1F7A000E958D0 /* LocalInference.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LocalInference.swift; sourceTree = "<group>"; };
|
|
||||||
5CCBC68B2CA1F7A000E958D0 /* Parsing.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Parsing.swift; sourceTree = "<group>"; };
|
|
||||||
5CCBC68C2CA1F7A100E958D0 /* SystemPrompts.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SystemPrompts.swift; sourceTree = "<group>"; };
|
|
||||||
/* End PBXFileReference section */
|
|
||||||
|
|
||||||
/* Begin PBXFrameworksBuildPhase section */
|
|
||||||
5CCBC6052CA1F04A00E958D0 /* Frameworks */ = {
|
|
||||||
isa = PBXFrameworksBuildPhase;
|
|
||||||
buildActionMask = 2147483647;
|
|
||||||
files = (
|
|
||||||
5C03561F2CA3AB9600E3BB46 /* LlamaStackClient in Frameworks */,
|
|
||||||
5C5B6E212CA3D89F00AF6130 /* LlamaStackClient in Frameworks */,
|
|
||||||
5CCBC6932CA1F7D000E958D0 /* Stencil in Frameworks */,
|
|
||||||
5CCBC6862CA1F64A00E958D0 /* LLaMARunner.framework in Frameworks */,
|
|
||||||
5CCBC6752CA1F45800E958D0 /* executorch_debug in Frameworks */,
|
|
||||||
);
|
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
|
||||||
};
|
|
||||||
/* End PBXFrameworksBuildPhase section */
|
|
||||||
|
|
||||||
/* Begin PBXGroup section */
|
|
||||||
5CCBC5FE2CA1F04A00E958D0 = {
|
|
||||||
isa = PBXGroup;
|
|
||||||
children = (
|
|
||||||
5CCBC6762CA1F63F00E958D0 /* LLaMA.xcodeproj */,
|
|
||||||
5CCBC60A2CA1F04A00E958D0 /* LocalInference */,
|
|
||||||
5CCBC6092CA1F04A00E958D0 /* Products */,
|
|
||||||
5CCBC6852CA1F64A00E958D0 /* Frameworks */,
|
|
||||||
);
|
|
||||||
sourceTree = "<group>";
|
|
||||||
};
|
|
||||||
5CCBC6092CA1F04A00E958D0 /* Products */ = {
|
|
||||||
isa = PBXGroup;
|
|
||||||
children = (
|
|
||||||
5CCBC6082CA1F04A00E958D0 /* LocalInference.framework */,
|
|
||||||
);
|
|
||||||
name = Products;
|
|
||||||
sourceTree = "<group>";
|
|
||||||
};
|
|
||||||
5CCBC60A2CA1F04A00E958D0 /* LocalInference */ = {
|
|
||||||
isa = PBXGroup;
|
|
||||||
children = (
|
|
||||||
5CCBC68A2CA1F7A000E958D0 /* LocalInference.swift */,
|
|
||||||
5CCBC68B2CA1F7A000E958D0 /* Parsing.swift */,
|
|
||||||
5CCBC6892CA1F7A000E958D0 /* PromptTemplate.swift */,
|
|
||||||
5CCBC68C2CA1F7A100E958D0 /* SystemPrompts.swift */,
|
|
||||||
5CCBC60B2CA1F04A00E958D0 /* LocalInference.h */,
|
|
||||||
);
|
|
||||||
path = LocalInference;
|
|
||||||
sourceTree = "<group>";
|
|
||||||
};
|
|
||||||
5CCBC6772CA1F63F00E958D0 /* Products */ = {
|
|
||||||
isa = PBXGroup;
|
|
||||||
children = (
|
|
||||||
5CCBC67E2CA1F63F00E958D0 /* LLaMA.app */,
|
|
||||||
5CCBC6802CA1F63F00E958D0 /* LLaMARunner.framework */,
|
|
||||||
5CCBC69F2CA2036B00E958D0 /* LLaMAPerfBenchmark.app */,
|
|
||||||
5CCBC6A12CA2036B00E958D0 /* LLaMAPerfBenchmarkTests.xctest */,
|
|
||||||
);
|
|
||||||
name = Products;
|
|
||||||
sourceTree = "<group>";
|
|
||||||
};
|
|
||||||
5CCBC6852CA1F64A00E958D0 /* Frameworks */ = {
|
|
||||||
isa = PBXGroup;
|
|
||||||
children = (
|
|
||||||
);
|
|
||||||
name = Frameworks;
|
|
||||||
sourceTree = "<group>";
|
|
||||||
};
|
|
||||||
/* End PBXGroup section */
|
|
||||||
|
|
||||||
/* Begin PBXHeadersBuildPhase section */
|
|
||||||
5CCBC6032CA1F04A00E958D0 /* Headers */ = {
|
|
||||||
isa = PBXHeadersBuildPhase;
|
|
||||||
buildActionMask = 2147483647;
|
|
||||||
files = (
|
|
||||||
5CCBC60C2CA1F04A00E958D0 /* LocalInference.h in Headers */,
|
|
||||||
);
|
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
|
||||||
};
|
|
||||||
/* End PBXHeadersBuildPhase section */
|
|
||||||
|
|
||||||
/* Begin PBXNativeTarget section */
|
|
||||||
5CCBC6072CA1F04A00E958D0 /* LocalInference */ = {
|
|
||||||
isa = PBXNativeTarget;
|
|
||||||
buildConfigurationList = 5CCBC60F2CA1F04A00E958D0 /* Build configuration list for PBXNativeTarget "LocalInference" */;
|
|
||||||
buildPhases = (
|
|
||||||
5CCBC6032CA1F04A00E958D0 /* Headers */,
|
|
||||||
5CCBC6042CA1F04A00E958D0 /* Sources */,
|
|
||||||
5CCBC6052CA1F04A00E958D0 /* Frameworks */,
|
|
||||||
5CCBC6062CA1F04A00E958D0 /* Resources */,
|
|
||||||
5CCBC6882CA1F64A00E958D0 /* Embed Frameworks */,
|
|
||||||
);
|
|
||||||
buildRules = (
|
|
||||||
);
|
|
||||||
dependencies = (
|
|
||||||
);
|
|
||||||
name = LocalInference;
|
|
||||||
packageProductDependencies = (
|
|
||||||
5CCBC6742CA1F45800E958D0 /* executorch_debug */,
|
|
||||||
5CCBC6922CA1F7D000E958D0 /* Stencil */,
|
|
||||||
5C03561E2CA3AB9600E3BB46 /* LlamaStackClient */,
|
|
||||||
5C5B6E202CA3D89F00AF6130 /* LlamaStackClient */,
|
|
||||||
);
|
|
||||||
productName = LocalInferenceProvider;
|
|
||||||
productReference = 5CCBC6082CA1F04A00E958D0 /* LocalInference.framework */;
|
|
||||||
productType = "com.apple.product-type.framework";
|
|
||||||
};
|
|
||||||
/* End PBXNativeTarget section */
|
|
||||||
|
|
||||||
/* Begin PBXProject section */
|
|
||||||
5CCBC5FF2CA1F04A00E958D0 /* Project object */ = {
|
|
||||||
isa = PBXProject;
|
|
||||||
attributes = {
|
|
||||||
BuildIndependentTargetsInParallel = 1;
|
|
||||||
LastUpgradeCheck = 1540;
|
|
||||||
TargetAttributes = {
|
|
||||||
5CCBC6072CA1F04A00E958D0 = {
|
|
||||||
CreatedOnToolsVersion = 15.4;
|
|
||||||
LastSwiftMigration = 1540;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
buildConfigurationList = 5CCBC6022CA1F04A00E958D0 /* Build configuration list for PBXProject "LocalInference" */;
|
|
||||||
compatibilityVersion = "Xcode 14.0";
|
|
||||||
developmentRegion = en;
|
|
||||||
hasScannedForEncodings = 0;
|
|
||||||
knownRegions = (
|
|
||||||
en,
|
|
||||||
Base,
|
|
||||||
);
|
|
||||||
mainGroup = 5CCBC5FE2CA1F04A00E958D0;
|
|
||||||
packageReferences = (
|
|
||||||
5CCBC6732CA1F45800E958D0 /* XCRemoteSwiftPackageReference "executorch" */,
|
|
||||||
5CCBC6912CA1F7D000E958D0 /* XCRemoteSwiftPackageReference "Stencil" */,
|
|
||||||
5C5B6E1F2CA3D89F00AF6130 /* XCLocalSwiftPackageReference "internal-llama-stack-client-swift" */,
|
|
||||||
);
|
|
||||||
productRefGroup = 5CCBC6092CA1F04A00E958D0 /* Products */;
|
|
||||||
projectDirPath = "";
|
|
||||||
projectReferences = (
|
|
||||||
{
|
|
||||||
ProductGroup = 5CCBC6772CA1F63F00E958D0 /* Products */;
|
|
||||||
ProjectRef = 5CCBC6762CA1F63F00E958D0 /* LLaMA.xcodeproj */;
|
|
||||||
},
|
|
||||||
);
|
|
||||||
projectRoot = "";
|
|
||||||
targets = (
|
|
||||||
5CCBC6072CA1F04A00E958D0 /* LocalInference */,
|
|
||||||
);
|
|
||||||
};
|
|
||||||
/* End PBXProject section */
|
|
||||||
|
|
||||||
/* Begin PBXReferenceProxy section */
|
|
||||||
5CCBC67E2CA1F63F00E958D0 /* LLaMA.app */ = {
|
|
||||||
isa = PBXReferenceProxy;
|
|
||||||
fileType = wrapper.application;
|
|
||||||
path = LLaMA.app;
|
|
||||||
remoteRef = 5CCBC67D2CA1F63F00E958D0 /* PBXContainerItemProxy */;
|
|
||||||
sourceTree = BUILT_PRODUCTS_DIR;
|
|
||||||
};
|
|
||||||
5CCBC6802CA1F63F00E958D0 /* LLaMARunner.framework */ = {
|
|
||||||
isa = PBXReferenceProxy;
|
|
||||||
fileType = wrapper.framework;
|
|
||||||
path = LLaMARunner.framework;
|
|
||||||
remoteRef = 5CCBC67F2CA1F63F00E958D0 /* PBXContainerItemProxy */;
|
|
||||||
sourceTree = BUILT_PRODUCTS_DIR;
|
|
||||||
};
|
|
||||||
5CCBC69F2CA2036B00E958D0 /* LLaMAPerfBenchmark.app */ = {
|
|
||||||
isa = PBXReferenceProxy;
|
|
||||||
fileType = wrapper.application;
|
|
||||||
path = LLaMAPerfBenchmark.app;
|
|
||||||
remoteRef = 5CCBC69E2CA2036B00E958D0 /* PBXContainerItemProxy */;
|
|
||||||
sourceTree = BUILT_PRODUCTS_DIR;
|
|
||||||
};
|
|
||||||
5CCBC6A12CA2036B00E958D0 /* LLaMAPerfBenchmarkTests.xctest */ = {
|
|
||||||
isa = PBXReferenceProxy;
|
|
||||||
fileType = wrapper.cfbundle;
|
|
||||||
path = LLaMAPerfBenchmarkTests.xctest;
|
|
||||||
remoteRef = 5CCBC6A02CA2036B00E958D0 /* PBXContainerItemProxy */;
|
|
||||||
sourceTree = BUILT_PRODUCTS_DIR;
|
|
||||||
};
|
|
||||||
/* End PBXReferenceProxy section */
|
|
||||||
|
|
||||||
/* Begin PBXResourcesBuildPhase section */
|
|
||||||
5CCBC6062CA1F04A00E958D0 /* Resources */ = {
|
|
||||||
isa = PBXResourcesBuildPhase;
|
|
||||||
buildActionMask = 2147483647;
|
|
||||||
files = (
|
|
||||||
);
|
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
|
||||||
};
|
|
||||||
/* End PBXResourcesBuildPhase section */
|
|
||||||
|
|
||||||
/* Begin PBXSourcesBuildPhase section */
|
|
||||||
5CCBC6042CA1F04A00E958D0 /* Sources */ = {
|
|
||||||
isa = PBXSourcesBuildPhase;
|
|
||||||
buildActionMask = 2147483647;
|
|
||||||
files = (
|
|
||||||
5CCBC6902CA1F7A100E958D0 /* SystemPrompts.swift in Sources */,
|
|
||||||
5CCBC68D2CA1F7A100E958D0 /* PromptTemplate.swift in Sources */,
|
|
||||||
5CCBC68F2CA1F7A100E958D0 /* Parsing.swift in Sources */,
|
|
||||||
5CCBC68E2CA1F7A100E958D0 /* LocalInference.swift in Sources */,
|
|
||||||
);
|
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
|
||||||
};
|
|
||||||
/* End PBXSourcesBuildPhase section */
|
|
||||||
|
|
||||||
/* Begin XCBuildConfiguration section */
|
|
||||||
5CCBC60D2CA1F04A00E958D0 /* Debug */ = {
|
|
||||||
isa = XCBuildConfiguration;
|
|
||||||
buildSettings = {
|
|
||||||
ALWAYS_SEARCH_USER_PATHS = NO;
|
|
||||||
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
|
|
||||||
CLANG_ANALYZER_NONNULL = YES;
|
|
||||||
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
|
|
||||||
CLANG_CXX_LANGUAGE_STANDARD = "gnu++20";
|
|
||||||
CLANG_ENABLE_MODULES = YES;
|
|
||||||
CLANG_ENABLE_OBJC_ARC = YES;
|
|
||||||
CLANG_ENABLE_OBJC_WEAK = YES;
|
|
||||||
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
|
|
||||||
CLANG_WARN_BOOL_CONVERSION = YES;
|
|
||||||
CLANG_WARN_COMMA = YES;
|
|
||||||
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
|
||||||
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
|
|
||||||
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
|
||||||
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
|
|
||||||
CLANG_WARN_EMPTY_BODY = YES;
|
|
||||||
CLANG_WARN_ENUM_CONVERSION = YES;
|
|
||||||
CLANG_WARN_INFINITE_RECURSION = YES;
|
|
||||||
CLANG_WARN_INT_CONVERSION = YES;
|
|
||||||
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
|
|
||||||
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
|
|
||||||
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
|
|
||||||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
|
||||||
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
|
|
||||||
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
|
|
||||||
CLANG_WARN_STRICT_PROTOTYPES = YES;
|
|
||||||
CLANG_WARN_SUSPICIOUS_MOVE = YES;
|
|
||||||
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
|
|
||||||
CLANG_WARN_UNREACHABLE_CODE = YES;
|
|
||||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
|
||||||
COPY_PHASE_STRIP = NO;
|
|
||||||
CURRENT_PROJECT_VERSION = 1;
|
|
||||||
DEBUG_INFORMATION_FORMAT = dwarf;
|
|
||||||
ENABLE_STRICT_OBJC_MSGSEND = YES;
|
|
||||||
ENABLE_TESTABILITY = YES;
|
|
||||||
ENABLE_USER_SCRIPT_SANDBOXING = YES;
|
|
||||||
GCC_C_LANGUAGE_STANDARD = gnu17;
|
|
||||||
GCC_DYNAMIC_NO_PIC = NO;
|
|
||||||
GCC_NO_COMMON_BLOCKS = YES;
|
|
||||||
GCC_OPTIMIZATION_LEVEL = 0;
|
|
||||||
GCC_PREPROCESSOR_DEFINITIONS = (
|
|
||||||
"DEBUG=1",
|
|
||||||
"$(inherited)",
|
|
||||||
);
|
|
||||||
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
|
|
||||||
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
|
|
||||||
GCC_WARN_UNDECLARED_SELECTOR = YES;
|
|
||||||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
|
||||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
|
||||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
|
||||||
IPHONEOS_DEPLOYMENT_TARGET = 17.5;
|
|
||||||
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
|
|
||||||
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
|
|
||||||
MTL_FAST_MATH = YES;
|
|
||||||
ONLY_ACTIVE_ARCH = YES;
|
|
||||||
SDKROOT = iphoneos;
|
|
||||||
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG $(inherited)";
|
|
||||||
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
|
||||||
VERSIONING_SYSTEM = "apple-generic";
|
|
||||||
VERSION_INFO_PREFIX = "";
|
|
||||||
};
|
|
||||||
name = Debug;
|
|
||||||
};
|
|
||||||
5CCBC60E2CA1F04A00E958D0 /* Release */ = {
|
|
||||||
isa = XCBuildConfiguration;
|
|
||||||
buildSettings = {
|
|
||||||
ALWAYS_SEARCH_USER_PATHS = NO;
|
|
||||||
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
|
|
||||||
CLANG_ANALYZER_NONNULL = YES;
|
|
||||||
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
|
|
||||||
CLANG_CXX_LANGUAGE_STANDARD = "gnu++20";
|
|
||||||
CLANG_ENABLE_MODULES = YES;
|
|
||||||
CLANG_ENABLE_OBJC_ARC = YES;
|
|
||||||
CLANG_ENABLE_OBJC_WEAK = YES;
|
|
||||||
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
|
|
||||||
CLANG_WARN_BOOL_CONVERSION = YES;
|
|
||||||
CLANG_WARN_COMMA = YES;
|
|
||||||
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
|
||||||
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
|
|
||||||
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
|
||||||
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
|
|
||||||
CLANG_WARN_EMPTY_BODY = YES;
|
|
||||||
CLANG_WARN_ENUM_CONVERSION = YES;
|
|
||||||
CLANG_WARN_INFINITE_RECURSION = YES;
|
|
||||||
CLANG_WARN_INT_CONVERSION = YES;
|
|
||||||
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
|
|
||||||
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
|
|
||||||
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
|
|
||||||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
|
||||||
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
|
|
||||||
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
|
|
||||||
CLANG_WARN_STRICT_PROTOTYPES = YES;
|
|
||||||
CLANG_WARN_SUSPICIOUS_MOVE = YES;
|
|
||||||
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
|
|
||||||
CLANG_WARN_UNREACHABLE_CODE = YES;
|
|
||||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
|
||||||
COPY_PHASE_STRIP = NO;
|
|
||||||
CURRENT_PROJECT_VERSION = 1;
|
|
||||||
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
|
|
||||||
ENABLE_NS_ASSERTIONS = NO;
|
|
||||||
ENABLE_STRICT_OBJC_MSGSEND = YES;
|
|
||||||
ENABLE_USER_SCRIPT_SANDBOXING = YES;
|
|
||||||
GCC_C_LANGUAGE_STANDARD = gnu17;
|
|
||||||
GCC_NO_COMMON_BLOCKS = YES;
|
|
||||||
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
|
|
||||||
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
|
|
||||||
GCC_WARN_UNDECLARED_SELECTOR = YES;
|
|
||||||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
|
||||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
|
||||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
|
||||||
IPHONEOS_DEPLOYMENT_TARGET = 17.5;
|
|
||||||
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
|
|
||||||
MTL_ENABLE_DEBUG_INFO = NO;
|
|
||||||
MTL_FAST_MATH = YES;
|
|
||||||
SDKROOT = iphoneos;
|
|
||||||
SWIFT_COMPILATION_MODE = wholemodule;
|
|
||||||
VALIDATE_PRODUCT = YES;
|
|
||||||
VERSIONING_SYSTEM = "apple-generic";
|
|
||||||
VERSION_INFO_PREFIX = "";
|
|
||||||
};
|
|
||||||
name = Release;
|
|
||||||
};
|
|
||||||
5CCBC6102CA1F04A00E958D0 /* Debug */ = {
|
|
||||||
isa = XCBuildConfiguration;
|
|
||||||
buildSettings = {
|
|
||||||
BUILD_LIBRARY_FOR_DISTRIBUTION = YES;
|
|
||||||
CLANG_ENABLE_MODULES = YES;
|
|
||||||
CODE_SIGN_STYLE = Automatic;
|
|
||||||
CURRENT_PROJECT_VERSION = 1;
|
|
||||||
DEFINES_MODULE = YES;
|
|
||||||
DYLIB_COMPATIBILITY_VERSION = 1;
|
|
||||||
DYLIB_CURRENT_VERSION = 1;
|
|
||||||
DYLIB_INSTALL_NAME_BASE = "@rpath";
|
|
||||||
ENABLE_MODULE_VERIFIER = YES;
|
|
||||||
GENERATE_INFOPLIST_FILE = YES;
|
|
||||||
HEADER_SEARCH_PATHS = "";
|
|
||||||
INFOPLIST_KEY_NSHumanReadableCopyright = "";
|
|
||||||
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
|
|
||||||
LD_RUNPATH_SEARCH_PATHS = (
|
|
||||||
"$(inherited)",
|
|
||||||
"@executable_path/Frameworks",
|
|
||||||
"@loader_path/Frameworks",
|
|
||||||
);
|
|
||||||
MARKETING_VERSION = 1.0;
|
|
||||||
MODULE_VERIFIER_SUPPORTED_LANGUAGES = "objective-c objective-c++";
|
|
||||||
MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu17 gnu++20";
|
|
||||||
OTHER_LDFLAGS = "";
|
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = meta.llamatsack.LocalInferenceProvider;
|
|
||||||
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
|
|
||||||
SKIP_INSTALL = YES;
|
|
||||||
SWIFT_EMIT_LOC_STRINGS = YES;
|
|
||||||
SWIFT_INSTALL_OBJC_HEADER = NO;
|
|
||||||
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
|
||||||
SWIFT_VERSION = 5.0;
|
|
||||||
TARGETED_DEVICE_FAMILY = "1,2";
|
|
||||||
};
|
|
||||||
name = Debug;
|
|
||||||
};
|
|
||||||
5CCBC6112CA1F04A00E958D0 /* Release */ = {
|
|
||||||
isa = XCBuildConfiguration;
|
|
||||||
buildSettings = {
|
|
||||||
BUILD_LIBRARY_FOR_DISTRIBUTION = YES;
|
|
||||||
CLANG_ENABLE_MODULES = YES;
|
|
||||||
CODE_SIGN_STYLE = Automatic;
|
|
||||||
CURRENT_PROJECT_VERSION = 1;
|
|
||||||
DEFINES_MODULE = YES;
|
|
||||||
DYLIB_COMPATIBILITY_VERSION = 1;
|
|
||||||
DYLIB_CURRENT_VERSION = 1;
|
|
||||||
DYLIB_INSTALL_NAME_BASE = "@rpath";
|
|
||||||
ENABLE_MODULE_VERIFIER = YES;
|
|
||||||
GENERATE_INFOPLIST_FILE = YES;
|
|
||||||
HEADER_SEARCH_PATHS = "";
|
|
||||||
INFOPLIST_KEY_NSHumanReadableCopyright = "";
|
|
||||||
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
|
|
||||||
LD_RUNPATH_SEARCH_PATHS = (
|
|
||||||
"$(inherited)",
|
|
||||||
"@executable_path/Frameworks",
|
|
||||||
"@loader_path/Frameworks",
|
|
||||||
);
|
|
||||||
MARKETING_VERSION = 1.0;
|
|
||||||
MODULE_VERIFIER_SUPPORTED_LANGUAGES = "objective-c objective-c++";
|
|
||||||
MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu17 gnu++20";
|
|
||||||
OTHER_LDFLAGS = "";
|
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = meta.llamatsack.LocalInferenceProvider;
|
|
||||||
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
|
|
||||||
SKIP_INSTALL = YES;
|
|
||||||
SWIFT_EMIT_LOC_STRINGS = YES;
|
|
||||||
SWIFT_INSTALL_OBJC_HEADER = NO;
|
|
||||||
SWIFT_VERSION = 5.0;
|
|
||||||
TARGETED_DEVICE_FAMILY = "1,2";
|
|
||||||
};
|
|
||||||
name = Release;
|
|
||||||
};
|
|
||||||
/* End XCBuildConfiguration section */
|
|
||||||
|
|
||||||
/* Begin XCConfigurationList section */
|
|
||||||
5CCBC6022CA1F04A00E958D0 /* Build configuration list for PBXProject "LocalInference" */ = {
|
|
||||||
isa = XCConfigurationList;
|
|
||||||
buildConfigurations = (
|
|
||||||
5CCBC60D2CA1F04A00E958D0 /* Debug */,
|
|
||||||
5CCBC60E2CA1F04A00E958D0 /* Release */,
|
|
||||||
);
|
|
||||||
defaultConfigurationIsVisible = 0;
|
|
||||||
defaultConfigurationName = Release;
|
|
||||||
};
|
|
||||||
5CCBC60F2CA1F04A00E958D0 /* Build configuration list for PBXNativeTarget "LocalInference" */ = {
|
|
||||||
isa = XCConfigurationList;
|
|
||||||
buildConfigurations = (
|
|
||||||
5CCBC6102CA1F04A00E958D0 /* Debug */,
|
|
||||||
5CCBC6112CA1F04A00E958D0 /* Release */,
|
|
||||||
);
|
|
||||||
defaultConfigurationIsVisible = 0;
|
|
||||||
defaultConfigurationName = Release;
|
|
||||||
};
|
|
||||||
/* End XCConfigurationList section */
|
|
||||||
|
|
||||||
/* Begin XCLocalSwiftPackageReference section */
|
|
||||||
5C5B6E1F2CA3D89F00AF6130 /* XCLocalSwiftPackageReference "internal-llama-stack-client-swift" */ = {
|
|
||||||
isa = XCLocalSwiftPackageReference;
|
|
||||||
relativePath = "internal-llama-stack-client-swift";
|
|
||||||
};
|
|
||||||
/* End XCLocalSwiftPackageReference section */
|
|
||||||
|
|
||||||
/* Begin XCRemoteSwiftPackageReference section */
|
|
||||||
5CCBC6732CA1F45800E958D0 /* XCRemoteSwiftPackageReference "executorch" */ = {
|
|
||||||
isa = XCRemoteSwiftPackageReference;
|
|
||||||
repositoryURL = "https://github.com/pytorch/executorch";
|
|
||||||
requirement = {
|
|
||||||
branch = latest;
|
|
||||||
kind = branch;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
5CCBC6912CA1F7D000E958D0 /* XCRemoteSwiftPackageReference "Stencil" */ = {
|
|
||||||
isa = XCRemoteSwiftPackageReference;
|
|
||||||
repositoryURL = "https://github.com/stencilproject/Stencil";
|
|
||||||
requirement = {
|
|
||||||
kind = upToNextMajorVersion;
|
|
||||||
minimumVersion = 0.15.1;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
/* End XCRemoteSwiftPackageReference section */
|
|
||||||
|
|
||||||
/* Begin XCSwiftPackageProductDependency section */
|
|
||||||
5C03561E2CA3AB9600E3BB46 /* LlamaStackClient */ = {
|
|
||||||
isa = XCSwiftPackageProductDependency;
|
|
||||||
productName = LlamaStackClient;
|
|
||||||
};
|
|
||||||
5C5B6E202CA3D89F00AF6130 /* LlamaStackClient */ = {
|
|
||||||
isa = XCSwiftPackageProductDependency;
|
|
||||||
productName = LlamaStackClient;
|
|
||||||
};
|
|
||||||
5CCBC6742CA1F45800E958D0 /* executorch_debug */ = {
|
|
||||||
isa = XCSwiftPackageProductDependency;
|
|
||||||
package = 5CCBC6732CA1F45800E958D0 /* XCRemoteSwiftPackageReference "executorch" */;
|
|
||||||
productName = executorch_debug;
|
|
||||||
};
|
|
||||||
5CCBC6922CA1F7D000E958D0 /* Stencil */ = {
|
|
||||||
isa = XCSwiftPackageProductDependency;
|
|
||||||
package = 5CCBC6912CA1F7D000E958D0 /* XCRemoteSwiftPackageReference "Stencil" */;
|
|
||||||
productName = Stencil;
|
|
||||||
};
|
|
||||||
/* End XCSwiftPackageProductDependency section */
|
|
||||||
};
|
|
||||||
rootObject = 5CCBC5FF2CA1F04A00E958D0 /* Project object */;
|
|
||||||
}
|
|
|
@ -1,7 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<Workspace
|
|
||||||
version = "1.0">
|
|
||||||
<FileRef
|
|
||||||
location = "self:">
|
|
||||||
</FileRef>
|
|
||||||
</Workspace>
|
|
|
@ -1,8 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
||||||
<plist version="1.0">
|
|
||||||
<dict>
|
|
||||||
<key>IDEDidComputeMac32BitWarning</key>
|
|
||||||
<true/>
|
|
||||||
</dict>
|
|
||||||
</plist>
|
|
|
@ -1,16 +0,0 @@
|
||||||
//
|
|
||||||
// LocalInference.h
|
|
||||||
// LocalInference
|
|
||||||
//
|
|
||||||
// Created by Dalton Flanagan on 9/23/24.
|
|
||||||
//
|
|
||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
|
||||||
|
|
||||||
//! Project version number for LocalInference.
|
|
||||||
FOUNDATION_EXPORT double LocalInferenceVersionNumber;
|
|
||||||
|
|
||||||
//! Project version string for LocalInference.
|
|
||||||
FOUNDATION_EXPORT const unsigned char LocalInferenceVersionString[];
|
|
||||||
|
|
||||||
// In this header, you should import all the public headers of your framework using statements like #import <LocalInference/PublicHeader.h>
|
|
|
@ -1,167 +0,0 @@
|
||||||
import Foundation
|
|
||||||
|
|
||||||
import LLaMARunner
|
|
||||||
import LlamaStackClient
|
|
||||||
|
|
||||||
class RunnerHolder: ObservableObject {
|
|
||||||
var runner: Runner?
|
|
||||||
}
|
|
||||||
|
|
||||||
public class LocalInference: Inference {
|
|
||||||
private var runnerHolder = RunnerHolder()
|
|
||||||
private let runnerQueue: DispatchQueue
|
|
||||||
|
|
||||||
public init (queue: DispatchQueue) {
|
|
||||||
runnerQueue = queue
|
|
||||||
}
|
|
||||||
|
|
||||||
public func loadModel(modelPath: String, tokenizerPath: String, completion: @escaping (Result<Void, Error>) -> Void) {
|
|
||||||
runnerHolder.runner = runnerHolder.runner ?? Runner(
|
|
||||||
modelPath: modelPath,
|
|
||||||
tokenizerPath: tokenizerPath
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
runnerQueue.async {
|
|
||||||
let runner = self.runnerHolder.runner
|
|
||||||
do {
|
|
||||||
try runner!.load()
|
|
||||||
completion(.success(()))
|
|
||||||
} catch let loadError {
|
|
||||||
print("error: " + loadError.localizedDescription)
|
|
||||||
completion(.failure(loadError))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public func chatCompletion(request: Components.Schemas.ChatCompletionRequest) -> AsyncStream<Components.Schemas.ChatCompletionResponseStreamChunk> {
|
|
||||||
return AsyncStream { continuation in
|
|
||||||
runnerQueue.async {
|
|
||||||
do {
|
|
||||||
var tokens: [String] = []
|
|
||||||
|
|
||||||
let prompt = try encodeDialogPrompt(messages: prepareMessages(request: request))
|
|
||||||
var stopReason: Components.Schemas.StopReason? = nil
|
|
||||||
var buffer = ""
|
|
||||||
var ipython = false
|
|
||||||
var echoDropped = false
|
|
||||||
|
|
||||||
try self.runnerHolder.runner?.generate(prompt, sequenceLength: 4096) { token in
|
|
||||||
buffer += token
|
|
||||||
|
|
||||||
// HACK: Workaround until LlamaRunner exposes echo param
|
|
||||||
if (!echoDropped) {
|
|
||||||
if (buffer.hasPrefix(prompt)) {
|
|
||||||
buffer = String(buffer.dropFirst(prompt.count))
|
|
||||||
echoDropped = true
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
tokens.append(token)
|
|
||||||
|
|
||||||
if !ipython && (buffer.starts(with: "<|python_tag|>") || buffer.starts(with: "[") ) {
|
|
||||||
ipython = true
|
|
||||||
continuation.yield(
|
|
||||||
Components.Schemas.ChatCompletionResponseStreamChunk(
|
|
||||||
event: Components.Schemas.ChatCompletionResponseEvent(
|
|
||||||
delta: .ToolCallDelta(Components.Schemas.ToolCallDelta(
|
|
||||||
content: .case1(""),
|
|
||||||
parse_status: Components.Schemas.ToolCallParseStatus.started
|
|
||||||
)
|
|
||||||
),
|
|
||||||
event_type: .progress
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
if (buffer.starts(with: "<|python_tag|>")) {
|
|
||||||
buffer = String(buffer.dropFirst("<|python_tag|>".count))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Non-streaming lobprobs
|
|
||||||
|
|
||||||
var text = ""
|
|
||||||
if token == "<|eot_id|>" {
|
|
||||||
stopReason = Components.Schemas.StopReason.end_of_turn
|
|
||||||
} else if token == "<|eom_id|>" {
|
|
||||||
stopReason = Components.Schemas.StopReason.end_of_message
|
|
||||||
} else {
|
|
||||||
text = token
|
|
||||||
}
|
|
||||||
|
|
||||||
var delta: Components.Schemas.ChatCompletionResponseEvent.deltaPayload
|
|
||||||
if ipython {
|
|
||||||
delta = .ToolCallDelta(Components.Schemas.ToolCallDelta(
|
|
||||||
content: .case1(text),
|
|
||||||
parse_status: .in_progress
|
|
||||||
))
|
|
||||||
} else {
|
|
||||||
delta = .case1(text)
|
|
||||||
}
|
|
||||||
|
|
||||||
if stopReason == nil {
|
|
||||||
continuation.yield(
|
|
||||||
Components.Schemas.ChatCompletionResponseStreamChunk(
|
|
||||||
event: Components.Schemas.ChatCompletionResponseEvent(
|
|
||||||
delta: delta,
|
|
||||||
event_type: .progress
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if stopReason == nil {
|
|
||||||
stopReason = Components.Schemas.StopReason.out_of_tokens
|
|
||||||
}
|
|
||||||
|
|
||||||
let message = decodeAssistantMessage(tokens: tokens.joined(), stopReason: stopReason!)
|
|
||||||
// TODO: non-streaming support
|
|
||||||
|
|
||||||
let didParseToolCalls = message.tool_calls.count > 0
|
|
||||||
if ipython && !didParseToolCalls {
|
|
||||||
continuation.yield(
|
|
||||||
Components.Schemas.ChatCompletionResponseStreamChunk(
|
|
||||||
event: Components.Schemas.ChatCompletionResponseEvent(
|
|
||||||
delta: .ToolCallDelta(Components.Schemas.ToolCallDelta(content: .case1(""), parse_status: .failure)),
|
|
||||||
event_type: .progress
|
|
||||||
)
|
|
||||||
// TODO: stopReason
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
for toolCall in message.tool_calls {
|
|
||||||
continuation.yield(
|
|
||||||
Components.Schemas.ChatCompletionResponseStreamChunk(
|
|
||||||
event: Components.Schemas.ChatCompletionResponseEvent(
|
|
||||||
delta: .ToolCallDelta(Components.Schemas.ToolCallDelta(
|
|
||||||
content: .ToolCall(toolCall),
|
|
||||||
parse_status: .success
|
|
||||||
)),
|
|
||||||
event_type: .progress
|
|
||||||
)
|
|
||||||
// TODO: stopReason
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
continuation.yield(
|
|
||||||
Components.Schemas.ChatCompletionResponseStreamChunk(
|
|
||||||
event: Components.Schemas.ChatCompletionResponseEvent(
|
|
||||||
delta: .case1(""),
|
|
||||||
event_type: .complete
|
|
||||||
)
|
|
||||||
// TODO: stopReason
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
catch (let error) {
|
|
||||||
print("Inference error: " + error.localizedDescription)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,235 +0,0 @@
|
||||||
import Foundation
|
|
||||||
|
|
||||||
import LlamaStackClient
|
|
||||||
|
|
||||||
func encodeHeader(role: String) -> String {
|
|
||||||
return "<|start_header_id|>\(role)<|end_header_id|>\n\n"
|
|
||||||
}
|
|
||||||
|
|
||||||
func encodeDialogPrompt(messages: [Components.Schemas.ChatCompletionRequest.messagesPayloadPayload]) -> String {
|
|
||||||
var prompt = ""
|
|
||||||
|
|
||||||
prompt.append("<|begin_of_text|>")
|
|
||||||
for message in messages {
|
|
||||||
let msg = encodeMessage(message: message)
|
|
||||||
prompt += msg
|
|
||||||
}
|
|
||||||
|
|
||||||
prompt.append(encodeHeader(role: "assistant"))
|
|
||||||
|
|
||||||
return prompt
|
|
||||||
}
|
|
||||||
|
|
||||||
func getRole(message: Components.Schemas.ChatCompletionRequest.messagesPayloadPayload) -> String {
|
|
||||||
switch (message) {
|
|
||||||
case .UserMessage(let m):
|
|
||||||
return m.role.rawValue
|
|
||||||
case .SystemMessage(let m):
|
|
||||||
return m.role.rawValue
|
|
||||||
case .ToolResponseMessage(let m):
|
|
||||||
return m.role.rawValue
|
|
||||||
case .CompletionMessage(let m):
|
|
||||||
return m.role.rawValue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func encodeMessage(message: Components.Schemas.ChatCompletionRequest.messagesPayloadPayload) -> String {
|
|
||||||
var prompt = encodeHeader(role: getRole(message: message))
|
|
||||||
|
|
||||||
switch (message) {
|
|
||||||
case .CompletionMessage(let m):
|
|
||||||
if (m.tool_calls.count > 0) {
|
|
||||||
prompt += "<|python_tag|>"
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
func _processContent(_ content: Any) -> String {
|
|
||||||
func _process(_ c: Any) {
|
|
||||||
if let str = c as? String {
|
|
||||||
prompt += str
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if let str = content as? String {
|
|
||||||
_process(str)
|
|
||||||
} else if let list = content as? [Any] {
|
|
||||||
for c in list {
|
|
||||||
_process(c)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (message) {
|
|
||||||
case .UserMessage(let m):
|
|
||||||
prompt += _processContent(m.content)
|
|
||||||
case .SystemMessage(let m):
|
|
||||||
prompt += _processContent(m.content)
|
|
||||||
case .ToolResponseMessage(let m):
|
|
||||||
prompt += _processContent(m.content)
|
|
||||||
case .CompletionMessage(let m):
|
|
||||||
prompt += _processContent(m.content)
|
|
||||||
}
|
|
||||||
|
|
||||||
var eom = false
|
|
||||||
|
|
||||||
switch (message) {
|
|
||||||
case .UserMessage(let m):
|
|
||||||
switch (m.content) {
|
|
||||||
case .case1(let c):
|
|
||||||
prompt += _processContent(c)
|
|
||||||
case .case2(let c):
|
|
||||||
prompt += _processContent(c)
|
|
||||||
}
|
|
||||||
case .CompletionMessage(let m):
|
|
||||||
// TODO: Support encoding past tool call history
|
|
||||||
// for t in m.tool_calls {
|
|
||||||
// _processContent(t.)
|
|
||||||
//}
|
|
||||||
eom = m.stop_reason == Components.Schemas.StopReason.end_of_message
|
|
||||||
case .SystemMessage(_):
|
|
||||||
break
|
|
||||||
case .ToolResponseMessage(_):
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
if (eom) {
|
|
||||||
prompt += "<|eom_id|>"
|
|
||||||
} else {
|
|
||||||
prompt += "<|eot_id|>"
|
|
||||||
}
|
|
||||||
|
|
||||||
return prompt
|
|
||||||
}
|
|
||||||
|
|
||||||
func prepareMessages(request: Components.Schemas.ChatCompletionRequest) throws -> [Components.Schemas.ChatCompletionRequest.messagesPayloadPayload] {
|
|
||||||
var existingMessages = request.messages
|
|
||||||
var existingSystemMessage: Components.Schemas.ChatCompletionRequest.messagesPayloadPayload?
|
|
||||||
// TODO: Existing system message
|
|
||||||
|
|
||||||
var messages: [Components.Schemas.ChatCompletionRequest.messagesPayloadPayload] = []
|
|
||||||
|
|
||||||
let defaultGen = SystemDefaultGenerator()
|
|
||||||
let defaultTemplate = defaultGen.gen()
|
|
||||||
|
|
||||||
var sysContent = ""
|
|
||||||
|
|
||||||
// TODO: Built-in tools
|
|
||||||
|
|
||||||
sysContent += try defaultTemplate.render()
|
|
||||||
|
|
||||||
messages.append(.SystemMessage(Components.Schemas.SystemMessage(
|
|
||||||
content: .case1(sysContent),
|
|
||||||
role: .system))
|
|
||||||
)
|
|
||||||
|
|
||||||
if request.tools?.isEmpty == false {
|
|
||||||
// TODO: Separate built-ins and custom tools (right now everything treated as custom)
|
|
||||||
let toolGen = FunctionTagCustomToolGenerator()
|
|
||||||
let toolTemplate = try toolGen.gen(customTools: request.tools!)
|
|
||||||
let tools = try toolTemplate.render()
|
|
||||||
messages.append(.UserMessage(Components.Schemas.UserMessage(
|
|
||||||
content: .case1(tools),
|
|
||||||
role: .user)
|
|
||||||
))
|
|
||||||
}
|
|
||||||
|
|
||||||
messages.append(contentsOf: existingMessages)
|
|
||||||
|
|
||||||
return messages
|
|
||||||
}
|
|
||||||
|
|
||||||
struct FunctionCall {
|
|
||||||
let name: String
|
|
||||||
let params: [String: Any]
|
|
||||||
}
|
|
||||||
|
|
||||||
public func maybeExtractCustomToolCalls(input: String) -> [Components.Schemas.ToolCall] {
|
|
||||||
guard input.hasPrefix("[") && input.hasSuffix("]") else {
|
|
||||||
return []
|
|
||||||
}
|
|
||||||
|
|
||||||
do {
|
|
||||||
let trimmed = input.trimmingCharacters(in: CharacterSet(charactersIn: "[]"))
|
|
||||||
let calls = trimmed.components(separatedBy: "),").map { $0.hasSuffix(")") ? $0 : $0 + ")" }
|
|
||||||
|
|
||||||
var result: [Components.Schemas.ToolCall] = []
|
|
||||||
|
|
||||||
for call in calls {
|
|
||||||
guard let nameEndIndex = call.firstIndex(of: "("),
|
|
||||||
let paramsStartIndex = call.firstIndex(of: "{"),
|
|
||||||
let paramsEndIndex = call.lastIndex(of: "}") else {
|
|
||||||
return []
|
|
||||||
}
|
|
||||||
|
|
||||||
let name = String(call[..<nameEndIndex]).trimmingCharacters(in: .whitespacesAndNewlines)
|
|
||||||
let paramsString = String(call[paramsStartIndex...paramsEndIndex])
|
|
||||||
|
|
||||||
guard let data = paramsString.data(using: .utf8),
|
|
||||||
let params = try? JSONSerialization.jsonObject(with: data, options: []) as? [String: Any] else {
|
|
||||||
return []
|
|
||||||
}
|
|
||||||
|
|
||||||
var props: [String : Components.Schemas.ToolCall.argumentsPayload.additionalPropertiesPayload] = [:]
|
|
||||||
for (param_name, param) in params {
|
|
||||||
switch (param) {
|
|
||||||
case let value as String:
|
|
||||||
props[param_name] = .case1(value)
|
|
||||||
case let value as Int:
|
|
||||||
props[param_name] = .case2(value)
|
|
||||||
case let value as Double:
|
|
||||||
props[param_name] = .case3(value)
|
|
||||||
case let value as Bool:
|
|
||||||
props[param_name] = .case4(value)
|
|
||||||
default:
|
|
||||||
return []
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
result.append(
|
|
||||||
Components.Schemas.ToolCall(
|
|
||||||
arguments: .init(additionalProperties: props),
|
|
||||||
call_id: UUID().uuidString,
|
|
||||||
tool_name: .case2(name) // custom_tool
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
return result.isEmpty ? [] : result
|
|
||||||
} catch {
|
|
||||||
return []
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func decodeAssistantMessage(tokens: String, stopReason: Components.Schemas.StopReason) -> Components.Schemas.CompletionMessage {
|
|
||||||
var content = tokens
|
|
||||||
|
|
||||||
let roles = ["user", "system", "assistant"]
|
|
||||||
for role in roles {
|
|
||||||
let headerStr = encodeHeader(role: role)
|
|
||||||
if content.hasPrefix(headerStr) {
|
|
||||||
content = String(content.dropFirst(encodeHeader(role: role).count))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if content.hasPrefix("<|python_tag|>") {
|
|
||||||
content = String(content.dropFirst("<|python_tag|>".count))
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if content.hasSuffix("<|eot_id|>") {
|
|
||||||
content = String(content.dropLast("<|eot_id|>".count))
|
|
||||||
} else {
|
|
||||||
content = String(content.dropLast("<|eom_id|>".count))
|
|
||||||
}
|
|
||||||
|
|
||||||
return Components.Schemas.CompletionMessage(
|
|
||||||
content: .case1(content),
|
|
||||||
role: .assistant,
|
|
||||||
stop_reason: stopReason,
|
|
||||||
tool_calls: maybeExtractCustomToolCalls(input: content)
|
|
||||||
)
|
|
||||||
}
|
|
|
@ -1,12 +0,0 @@
|
||||||
import Foundation
|
|
||||||
import Stencil
|
|
||||||
|
|
||||||
public struct PromptTemplate {
|
|
||||||
let template: String
|
|
||||||
let data: [String: Any]
|
|
||||||
|
|
||||||
public func render() throws -> String {
|
|
||||||
let template = Template(templateString: self.template)
|
|
||||||
return try template.render(self.data)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,91 +0,0 @@
|
||||||
import Foundation
|
|
||||||
|
|
||||||
import LlamaStackClient
|
|
||||||
|
|
||||||
func convertToNativeSwiftType(_ value: Any) -> Any {
|
|
||||||
switch value {
|
|
||||||
case let number as NSNumber:
|
|
||||||
if CFGetTypeID(number) == CFBooleanGetTypeID() {
|
|
||||||
return number.boolValue
|
|
||||||
}
|
|
||||||
if floor(number.doubleValue) == number.doubleValue {
|
|
||||||
return number.intValue
|
|
||||||
}
|
|
||||||
return number.doubleValue
|
|
||||||
case let string as String:
|
|
||||||
return string
|
|
||||||
case let array as [Any]:
|
|
||||||
return array.map(convertToNativeSwiftType)
|
|
||||||
case let dict as [String: Any]:
|
|
||||||
return dict.mapValues(convertToNativeSwiftType)
|
|
||||||
case is NSNull:
|
|
||||||
return NSNull()
|
|
||||||
default:
|
|
||||||
return value
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class SystemDefaultGenerator {
|
|
||||||
public init() {}
|
|
||||||
|
|
||||||
public func gen() -> PromptTemplate {
|
|
||||||
let templateStr = """
|
|
||||||
Cutting Knowledge Date: December 2023
|
|
||||||
Today Date: {{ today }}
|
|
||||||
"""
|
|
||||||
|
|
||||||
let dateFormatter = DateFormatter()
|
|
||||||
dateFormatter.dateFormat = "dd MMMM yyyy"
|
|
||||||
|
|
||||||
return PromptTemplate(
|
|
||||||
template: templateStr,
|
|
||||||
data: ["today": dateFormatter.string(from: Date())]
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public class FunctionTagCustomToolGenerator {
|
|
||||||
public init() {}
|
|
||||||
|
|
||||||
public func gen(customTools: [Components.Schemas.ToolDefinition]) throws -> PromptTemplate {
|
|
||||||
// TODO: required params
|
|
||||||
// TODO: {{#unless @last}},{{/unless}}
|
|
||||||
|
|
||||||
let templateStr = """
|
|
||||||
You are an expert in composing functions. You are given a question and a set of possible functions.
|
|
||||||
Based on the question, you will need to make one or more function/tool calls to achieve the purpose.
|
|
||||||
If none of the function can be used, point it out. If the given question lacks the parameters required by the function,
|
|
||||||
also point it out. You should only return the function call in tools call sections.
|
|
||||||
|
|
||||||
If you decide to invoke any of the function(s), you MUST put it in the format of [func_name1(params_name1=params_value1, params_name2=params_value2...), func_name2(params)]
|
|
||||||
You SHOULD NOT include any other text in the response.
|
|
||||||
|
|
||||||
Here is a list of functions in JSON format that you can invoke.
|
|
||||||
|
|
||||||
[
|
|
||||||
{% for t in custom_tools %}
|
|
||||||
{
|
|
||||||
"name": "{{t.tool_name}}",
|
|
||||||
"description": "{{t.description}}",
|
|
||||||
"parameters": {
|
|
||||||
"type": "dict",
|
|
||||||
"properties": { {{t.parameters}} }
|
|
||||||
}
|
|
||||||
|
|
||||||
{{/let}}
|
|
||||||
{% endfor -%}
|
|
||||||
]
|
|
||||||
"""
|
|
||||||
|
|
||||||
let encoder = JSONEncoder()
|
|
||||||
return PromptTemplate(
|
|
||||||
template: templateStr,
|
|
||||||
data: ["custom_tools": try customTools.map {
|
|
||||||
let data = try encoder.encode($0)
|
|
||||||
let obj = try JSONSerialization.jsonObject(with: data)
|
|
||||||
return convertToNativeSwiftType(obj)
|
|
||||||
}]
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -3,11 +3,12 @@
|
||||||
archiveVersion = 1;
|
archiveVersion = 1;
|
||||||
classes = {
|
classes = {
|
||||||
};
|
};
|
||||||
objectVersion = 60;
|
objectVersion = 56;
|
||||||
objects = {
|
objects = {
|
||||||
|
|
||||||
/* Begin PBXBuildFile section */
|
/* Begin PBXBuildFile section */
|
||||||
5CADC71A2CA471CC007662D2 /* LlamaStackClient in Frameworks */ = {isa = PBXBuildFile; productRef = 5CADC7192CA471CC007662D2 /* LlamaStackClient */; };
|
5CADC71A2CA471CC007662D2 /* LlamaStackClient in Frameworks */ = {isa = PBXBuildFile; productRef = 5CADC7192CA471CC007662D2 /* LlamaStackClient */; };
|
||||||
|
5CAF3DD82CA485740029CD2B /* LlamaStackClient in Frameworks */ = {isa = PBXBuildFile; productRef = 5CAF3DD72CA485740029CD2B /* LlamaStackClient */; };
|
||||||
5CCBC60C2CA1F04A00E958D0 /* LocalInference.h in Headers */ = {isa = PBXBuildFile; fileRef = 5CCBC60B2CA1F04A00E958D0 /* LocalInference.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
5CCBC60C2CA1F04A00E958D0 /* LocalInference.h in Headers */ = {isa = PBXBuildFile; fileRef = 5CCBC60B2CA1F04A00E958D0 /* LocalInference.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||||
5CCBC6752CA1F45800E958D0 /* executorch_debug in Frameworks */ = {isa = PBXBuildFile; productRef = 5CCBC6742CA1F45800E958D0 /* executorch_debug */; };
|
5CCBC6752CA1F45800E958D0 /* executorch_debug in Frameworks */ = {isa = PBXBuildFile; productRef = 5CCBC6742CA1F45800E958D0 /* executorch_debug */; };
|
||||||
5CCBC6862CA1F64A00E958D0 /* LLaMARunner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5CCBC6802CA1F63F00E958D0 /* LLaMARunner.framework */; platformFilter = ios; };
|
5CCBC6862CA1F64A00E958D0 /* LLaMARunner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5CCBC6802CA1F63F00E958D0 /* LLaMARunner.framework */; platformFilter = ios; };
|
||||||
|
@ -80,6 +81,7 @@
|
||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
5CADC71A2CA471CC007662D2 /* LlamaStackClient in Frameworks */,
|
5CADC71A2CA471CC007662D2 /* LlamaStackClient in Frameworks */,
|
||||||
|
5CAF3DD82CA485740029CD2B /* LlamaStackClient in Frameworks */,
|
||||||
5CCBC6932CA1F7D000E958D0 /* Stencil in Frameworks */,
|
5CCBC6932CA1F7D000E958D0 /* Stencil in Frameworks */,
|
||||||
5CCBC6862CA1F64A00E958D0 /* LLaMARunner.framework in Frameworks */,
|
5CCBC6862CA1F64A00E958D0 /* LLaMARunner.framework in Frameworks */,
|
||||||
5CCBC6752CA1F45800E958D0 /* executorch_debug in Frameworks */,
|
5CCBC6752CA1F45800E958D0 /* executorch_debug in Frameworks */,
|
||||||
|
@ -170,6 +172,7 @@
|
||||||
5CCBC6742CA1F45800E958D0 /* executorch_debug */,
|
5CCBC6742CA1F45800E958D0 /* executorch_debug */,
|
||||||
5CCBC6922CA1F7D000E958D0 /* Stencil */,
|
5CCBC6922CA1F7D000E958D0 /* Stencil */,
|
||||||
5CADC7192CA471CC007662D2 /* LlamaStackClient */,
|
5CADC7192CA471CC007662D2 /* LlamaStackClient */,
|
||||||
|
5CAF3DD72CA485740029CD2B /* LlamaStackClient */,
|
||||||
);
|
);
|
||||||
productName = LocalInferenceProvider;
|
productName = LocalInferenceProvider;
|
||||||
productReference = 5CCBC6082CA1F04A00E958D0 /* LocalInferenceImpl.framework */;
|
productReference = 5CCBC6082CA1F04A00E958D0 /* LocalInferenceImpl.framework */;
|
||||||
|
@ -202,7 +205,7 @@
|
||||||
packageReferences = (
|
packageReferences = (
|
||||||
5CCBC6732CA1F45800E958D0 /* XCRemoteSwiftPackageReference "executorch" */,
|
5CCBC6732CA1F45800E958D0 /* XCRemoteSwiftPackageReference "executorch" */,
|
||||||
5CCBC6912CA1F7D000E958D0 /* XCRemoteSwiftPackageReference "Stencil" */,
|
5CCBC6912CA1F7D000E958D0 /* XCRemoteSwiftPackageReference "Stencil" */,
|
||||||
5CADC7182CA471CC007662D2 /* XCLocalSwiftPackageReference "internal-llama-stack-client-swift" */,
|
5CAF3DD62CA485740029CD2B /* XCRemoteSwiftPackageReference "llama-stack-client-swift" */,
|
||||||
);
|
);
|
||||||
productRefGroup = 5CCBC6092CA1F04A00E958D0 /* Products */;
|
productRefGroup = 5CCBC6092CA1F04A00E958D0 /* Products */;
|
||||||
projectDirPath = "";
|
projectDirPath = "";
|
||||||
|
@ -494,14 +497,15 @@
|
||||||
};
|
};
|
||||||
/* End XCConfigurationList section */
|
/* End XCConfigurationList section */
|
||||||
|
|
||||||
/* Begin XCLocalSwiftPackageReference section */
|
|
||||||
5CADC7182CA471CC007662D2 /* XCLocalSwiftPackageReference "internal-llama-stack-client-swift" */ = {
|
|
||||||
isa = XCLocalSwiftPackageReference;
|
|
||||||
relativePath = "internal-llama-stack-client-swift";
|
|
||||||
};
|
|
||||||
/* End XCLocalSwiftPackageReference section */
|
|
||||||
|
|
||||||
/* Begin XCRemoteSwiftPackageReference section */
|
/* Begin XCRemoteSwiftPackageReference section */
|
||||||
|
5CAF3DD62CA485740029CD2B /* XCRemoteSwiftPackageReference "llama-stack-client-swift" */ = {
|
||||||
|
isa = XCRemoteSwiftPackageReference;
|
||||||
|
repositoryURL = "https://github.com/meta-llama/llama-stack-client-swift";
|
||||||
|
requirement = {
|
||||||
|
branch = main;
|
||||||
|
kind = branch;
|
||||||
|
};
|
||||||
|
};
|
||||||
5CCBC6732CA1F45800E958D0 /* XCRemoteSwiftPackageReference "executorch" */ = {
|
5CCBC6732CA1F45800E958D0 /* XCRemoteSwiftPackageReference "executorch" */ = {
|
||||||
isa = XCRemoteSwiftPackageReference;
|
isa = XCRemoteSwiftPackageReference;
|
||||||
repositoryURL = "https://github.com/pytorch/executorch";
|
repositoryURL = "https://github.com/pytorch/executorch";
|
||||||
|
@ -525,6 +529,11 @@
|
||||||
isa = XCSwiftPackageProductDependency;
|
isa = XCSwiftPackageProductDependency;
|
||||||
productName = LlamaStackClient;
|
productName = LlamaStackClient;
|
||||||
};
|
};
|
||||||
|
5CAF3DD72CA485740029CD2B /* LlamaStackClient */ = {
|
||||||
|
isa = XCSwiftPackageProductDependency;
|
||||||
|
package = 5CAF3DD62CA485740029CD2B /* XCRemoteSwiftPackageReference "llama-stack-client-swift" */;
|
||||||
|
productName = LlamaStackClient;
|
||||||
|
};
|
||||||
5CCBC6742CA1F45800E958D0 /* executorch_debug */ = {
|
5CCBC6742CA1F45800E958D0 /* executorch_debug */ = {
|
||||||
isa = XCSwiftPackageProductDependency;
|
isa = XCSwiftPackageProductDependency;
|
||||||
package = 5CCBC6732CA1F45800E958D0 /* XCRemoteSwiftPackageReference "executorch" */;
|
package = 5CCBC6732CA1F45800E958D0 /* XCRemoteSwiftPackageReference "executorch" */;
|
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit 9b6d4b4a7b9b8f811bb6b269b0c2ce254e3a0c1b
|
Loading…
Add table
Add a link
Reference in a new issue