Elffuss BraidHub

kikocis/llama-stack public

Update LocalInference to use public repos
Changeset6c6abf1d1b75cd63d2fef651e58be8c3c73f01c191b32ffd574397c270654fe9
AuthorDalton Flanagan <6599399+dltn@users.noreply.github.com> · 2024-09-25 11:05 -07:00
CommitterDalton Flanagan <6599399+dltn@users.noreply.github.com> · 2024-09-25 11:05 -07:00
Parentsf63e4415fa7b

Browse the files at this changeset

28 files changed

added .gitmodules +3 −0
@@ -0,0 +1,3 @@
1+[submodule "llama_stack/providers/impls/ios/inference/executorch"]
2+ path = llama_stack/providers/impls/ios/inference/executorch
3+ url = https://github.com/pytorch/executorch
deleted llama_stack/providers/impls/ios/inference/LocalInference/LocalInference.xcodeproj/project.pbxproj +0 −548
@@ -1,548 +0,0 @@
1-// !$*UTF8*$!
2-{
3- archiveVersion = 1;
4- classes = {
5- };
6- objectVersion = 60;
7- objects = {
8-
9-/* Begin PBXBuildFile section */
10- 5C03561F2CA3AB9600E3BB46 /* LlamaStackClient in Frameworks */ = {isa = PBXBuildFile; productRef = 5C03561E2CA3AB9600E3BB46 /* LlamaStackClient */; };
11- 5C5B6E212CA3D89F00AF6130 /* LlamaStackClient in Frameworks */ = {isa = PBXBuildFile; productRef = 5C5B6E202CA3D89F00AF6130 /* LlamaStackClient */; };
12- 5CCBC60C2CA1F04A00E958D0 /* LocalInference.h in Headers */ = {isa = PBXBuildFile; fileRef = 5CCBC60B2CA1F04A00E958D0 /* LocalInference.h */; settings = {ATTRIBUTES = (Public, ); }; };
13- 5CCBC6752CA1F45800E958D0 /* executorch_debug in Frameworks */ = {isa = PBXBuildFile; productRef = 5CCBC6742CA1F45800E958D0 /* executorch_debug */; };
14- 5CCBC6862CA1F64A00E958D0 /* LLaMARunner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5CCBC6802CA1F63F00E958D0 /* LLaMARunner.framework */; platformFilter = ios; };
15- 5CCBC6872CA1F64A00E958D0 /* LLaMARunner.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 5CCBC6802CA1F63F00E958D0 /* LLaMARunner.framework */; platformFilter = ios; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
16- 5CCBC68D2CA1F7A100E958D0 /* PromptTemplate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5CCBC6892CA1F7A000E958D0 /* PromptTemplate.swift */; };
17- 5CCBC68E2CA1F7A100E958D0 /* LocalInference.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5CCBC68A2CA1F7A000E958D0 /* LocalInference.swift */; };
18- 5CCBC68F2CA1F7A100E958D0 /* Parsing.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5CCBC68B2CA1F7A000E958D0 /* Parsing.swift */; };
19- 5CCBC6902CA1F7A100E958D0 /* SystemPrompts.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5CCBC68C2CA1F7A100E958D0 /* SystemPrompts.swift */; };
20- 5CCBC6932CA1F7D000E958D0 /* Stencil in Frameworks */ = {isa = PBXBuildFile; productRef = 5CCBC6922CA1F7D000E958D0 /* Stencil */; };
21-/* End PBXBuildFile section */
22-
23-/* Begin PBXContainerItemProxy section */
24- 5CCBC67D2CA1F63F00E958D0 /* PBXContainerItemProxy */ = {
25- isa = PBXContainerItemProxy;
26- containerPortal = 5CCBC6762CA1F63F00E958D0 /* LLaMA.xcodeproj */;
27- proxyType = 2;
28- remoteGlobalIDString = 036CAF9D2BB1444500D6C2D5;
29- remoteInfo = LLaMA;
30- };
31- 5CCBC67F2CA1F63F00E958D0 /* PBXContainerItemProxy */ = {
32- isa = PBXContainerItemProxy;
33- containerPortal = 5CCBC6762CA1F63F00E958D0 /* LLaMA.xcodeproj */;
34- proxyType = 2;
35- remoteGlobalIDString = 03729ED52BB1F8DE00152F2E;
36- remoteInfo = LLaMARunner;
37- };
38- 5CCBC69E2CA2036B00E958D0 /* PBXContainerItemProxy */ = {
39- isa = PBXContainerItemProxy;
40- containerPortal = 5CCBC6762CA1F63F00E958D0 /* LLaMA.xcodeproj */;
41- proxyType = 2;
42- remoteGlobalIDString = 5CCBC6982CA2036A00E958D0;
43- remoteInfo = LLaMAPerfBenchmark;
44- };
45- 5CCBC6A02CA2036B00E958D0 /* PBXContainerItemProxy */ = {
46- isa = PBXContainerItemProxy;
47- containerPortal = 5CCBC6762CA1F63F00E958D0 /* LLaMA.xcodeproj */;
48- proxyType = 2;
49- remoteGlobalIDString = 5CCBC6992CA2036A00E958D0;
50- remoteInfo = LLaMAPerfBenchmarkTests;
51- };
52-/* End PBXContainerItemProxy section */
53-
54-/* Begin PBXCopyFilesBuildPhase section */
55- 5CCBC6882CA1F64A00E958D0 /* Embed Frameworks */ = {
56- isa = PBXCopyFilesBuildPhase;
57- buildActionMask = 2147483647;
58- dstPath = "";
59- dstSubfolderSpec = 10;
60- files = (
61- 5CCBC6872CA1F64A00E958D0 /* LLaMARunner.framework in Embed Frameworks */,
62- );
63- name = "Embed Frameworks";
64- runOnlyForDeploymentPostprocessing = 0;
65- };
66-/* End PBXCopyFilesBuildPhase section */
67-
68-/* Begin PBXFileReference section */
69- 5CCBC6082CA1F04A00E958D0 /* LocalInference.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = LocalInference.framework; sourceTree = BUILT_PRODUCTS_DIR; };
70- 5CCBC60B2CA1F04A00E958D0 /* LocalInference.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LocalInference.h; sourceTree = "<group>"; };
71- 5CCBC6762CA1F63F00E958D0 /* LLaMA.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = LLaMA.xcodeproj; path = "executorch/examples/demo-apps/apple_ios/LLaMA/LLaMA.xcodeproj"; sourceTree = "<group>"; };
72- 5CCBC6892CA1F7A000E958D0 /* PromptTemplate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PromptTemplate.swift; sourceTree = "<group>"; };
73- 5CCBC68A2CA1F7A000E958D0 /* LocalInference.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LocalInference.swift; sourceTree = "<group>"; };
74- 5CCBC68B2CA1F7A000E958D0 /* Parsing.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Parsing.swift; sourceTree = "<group>"; };
75- 5CCBC68C2CA1F7A100E958D0 /* SystemPrompts.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SystemPrompts.swift; sourceTree = "<group>"; };
76-/* End PBXFileReference section */
77-
78-/* Begin PBXFrameworksBuildPhase section */
79- 5CCBC6052CA1F04A00E958D0 /* Frameworks */ = {
80- isa = PBXFrameworksBuildPhase;
81- buildActionMask = 2147483647;
82- files = (
83- 5C03561F2CA3AB9600E3BB46 /* LlamaStackClient in Frameworks */,
84- 5C5B6E212CA3D89F00AF6130 /* LlamaStackClient in Frameworks */,
85- 5CCBC6932CA1F7D000E958D0 /* Stencil in Frameworks */,
86- 5CCBC6862CA1F64A00E958D0 /* LLaMARunner.framework in Frameworks */,
87- 5CCBC6752CA1F45800E958D0 /* executorch_debug in Frameworks */,
88- );
89- runOnlyForDeploymentPostprocessing = 0;
90- };
91-/* End PBXFrameworksBuildPhase section */
92-
93-/* Begin PBXGroup section */
94- 5CCBC5FE2CA1F04A00E958D0 = {
95- isa = PBXGroup;
96- children = (
97- 5CCBC6762CA1F63F00E958D0 /* LLaMA.xcodeproj */,
98- 5CCBC60A2CA1F04A00E958D0 /* LocalInference */,
99- 5CCBC6092CA1F04A00E958D0 /* Products */,
100- 5CCBC6852CA1F64A00E958D0 /* Frameworks */,
101- );
102- sourceTree = "<group>";
103- };
104- 5CCBC6092CA1F04A00E958D0 /* Products */ = {
105- isa = PBXGroup;
106- children = (
107- 5CCBC6082CA1F04A00E958D0 /* LocalInference.framework */,
108- );
109- name = Products;
110- sourceTree = "<group>";
111- };
112- 5CCBC60A2CA1F04A00E958D0 /* LocalInference */ = {
113- isa = PBXGroup;
114- children = (
115- 5CCBC68A2CA1F7A000E958D0 /* LocalInference.swift */,
116- 5CCBC68B2CA1F7A000E958D0 /* Parsing.swift */,
117- 5CCBC6892CA1F7A000E958D0 /* PromptTemplate.swift */,
118- 5CCBC68C2CA1F7A100E958D0 /* SystemPrompts.swift */,
119- 5CCBC60B2CA1F04A00E958D0 /* LocalInference.h */,
120- );
121- path = LocalInference;
122- sourceTree = "<group>";
123- };
124- 5CCBC6772CA1F63F00E958D0 /* Products */ = {
125- isa = PBXGroup;
126- children = (
127- 5CCBC67E2CA1F63F00E958D0 /* LLaMA.app */,
128- 5CCBC6802CA1F63F00E958D0 /* LLaMARunner.framework */,
129- 5CCBC69F2CA2036B00E958D0 /* LLaMAPerfBenchmark.app */,
130- 5CCBC6A12CA2036B00E958D0 /* LLaMAPerfBenchmarkTests.xctest */,
131- );
132- name = Products;
133- sourceTree = "<group>";
134- };
135- 5CCBC6852CA1F64A00E958D0 /* Frameworks */ = {
136- isa = PBXGroup;
137- children = (
138- );
139- name = Frameworks;
140- sourceTree = "<group>";
141- };
142-/* End PBXGroup section */
143-
144-/* Begin PBXHeadersBuildPhase section */
145- 5CCBC6032CA1F04A00E958D0 /* Headers */ = {
146- isa = PBXHeadersBuildPhase;
147- buildActionMask = 2147483647;
148- files = (
149- 5CCBC60C2CA1F04A00E958D0 /* LocalInference.h in Headers */,
150- );
151- runOnlyForDeploymentPostprocessing = 0;
152- };
153-/* End PBXHeadersBuildPhase section */
154-
155-/* Begin PBXNativeTarget section */
156- 5CCBC6072CA1F04A00E958D0 /* LocalInference */ = {
157- isa = PBXNativeTarget;
158- buildConfigurationList = 5CCBC60F2CA1F04A00E958D0 /* Build configuration list for PBXNativeTarget "LocalInference" */;
159- buildPhases = (
160- 5CCBC6032CA1F04A00E958D0 /* Headers */,
161- 5CCBC6042CA1F04A00E958D0 /* Sources */,
162- 5CCBC6052CA1F04A00E958D0 /* Frameworks */,
163- 5CCBC6062CA1F04A00E958D0 /* Resources */,
164- 5CCBC6882CA1F64A00E958D0 /* Embed Frameworks */,
165- );
166- buildRules = (
167- );
168- dependencies = (
169- );
170- name = LocalInference;
171- packageProductDependencies = (
172- 5CCBC6742CA1F45800E958D0 /* executorch_debug */,
173- 5CCBC6922CA1F7D000E958D0 /* Stencil */,
174- 5C03561E2CA3AB9600E3BB46 /* LlamaStackClient */,
175- 5C5B6E202CA3D89F00AF6130 /* LlamaStackClient */,
176- );
177- productName = LocalInferenceProvider;
178- productReference = 5CCBC6082CA1F04A00E958D0 /* LocalInference.framework */;
179- productType = "com.apple.product-type.framework";
180- };
181-/* End PBXNativeTarget section */
182-
183-/* Begin PBXProject section */
184- 5CCBC5FF2CA1F04A00E958D0 /* Project object */ = {
185- isa = PBXProject;
186- attributes = {
187- BuildIndependentTargetsInParallel = 1;
188- LastUpgradeCheck = 1540;
189- TargetAttributes = {
190- 5CCBC6072CA1F04A00E958D0 = {
191- CreatedOnToolsVersion = 15.4;
192- LastSwiftMigration = 1540;
193- };
194- };
195- };
196- buildConfigurationList = 5CCBC6022CA1F04A00E958D0 /* Build configuration list for PBXProject "LocalInference" */;
197- compatibilityVersion = "Xcode 14.0";
198- developmentRegion = en;
199- hasScannedForEncodings = 0;
200- knownRegions = (
201- en,
202- Base,
203- );
204- mainGroup = 5CCBC5FE2CA1F04A00E958D0;
205- packageReferences = (
206- 5CCBC6732CA1F45800E958D0 /* XCRemoteSwiftPackageReference "executorch" */,
207- 5CCBC6912CA1F7D000E958D0 /* XCRemoteSwiftPackageReference "Stencil" */,
208- 5C5B6E1F2CA3D89F00AF6130 /* XCLocalSwiftPackageReference "internal-llama-stack-client-swift" */,
209- );
210- productRefGroup = 5CCBC6092CA1F04A00E958D0 /* Products */;
211- projectDirPath = "";
212- projectReferences = (
213- {
214- ProductGroup = 5CCBC6772CA1F63F00E958D0 /* Products */;
215- ProjectRef = 5CCBC6762CA1F63F00E958D0 /* LLaMA.xcodeproj */;
216- },
217- );
218- projectRoot = "";
219- targets = (
220- 5CCBC6072CA1F04A00E958D0 /* LocalInference */,
221- );
222- };
223-/* End PBXProject section */
224-
225-/* Begin PBXReferenceProxy section */
226- 5CCBC67E2CA1F63F00E958D0 /* LLaMA.app */ = {
227- isa = PBXReferenceProxy;
228- fileType = wrapper.application;
229- path = LLaMA.app;
230- remoteRef = 5CCBC67D2CA1F63F00E958D0 /* PBXContainerItemProxy */;
231- sourceTree = BUILT_PRODUCTS_DIR;
232- };
233- 5CCBC6802CA1F63F00E958D0 /* LLaMARunner.framework */ = {
234- isa = PBXReferenceProxy;
235- fileType = wrapper.framework;
236- path = LLaMARunner.framework;
237- remoteRef = 5CCBC67F2CA1F63F00E958D0 /* PBXContainerItemProxy */;
238- sourceTree = BUILT_PRODUCTS_DIR;
239- };
240- 5CCBC69F2CA2036B00E958D0 /* LLaMAPerfBenchmark.app */ = {
241- isa = PBXReferenceProxy;
242- fileType = wrapper.application;
243- path = LLaMAPerfBenchmark.app;
244- remoteRef = 5CCBC69E2CA2036B00E958D0 /* PBXContainerItemProxy */;
245- sourceTree = BUILT_PRODUCTS_DIR;
246- };
247- 5CCBC6A12CA2036B00E958D0 /* LLaMAPerfBenchmarkTests.xctest */ = {
248- isa = PBXReferenceProxy;
249- fileType = wrapper.cfbundle;
250- path = LLaMAPerfBenchmarkTests.xctest;
251- remoteRef = 5CCBC6A02CA2036B00E958D0 /* PBXContainerItemProxy */;
252- sourceTree = BUILT_PRODUCTS_DIR;
253- };
254-/* End PBXReferenceProxy section */
255-
256-/* Begin PBXResourcesBuildPhase section */
257- 5CCBC6062CA1F04A00E958D0 /* Resources */ = {
258- isa = PBXResourcesBuildPhase;
259- buildActionMask = 2147483647;
260- files = (
261- );
262- runOnlyForDeploymentPostprocessing = 0;
263- };
264-/* End PBXResourcesBuildPhase section */
265-
266-/* Begin PBXSourcesBuildPhase section */
267- 5CCBC6042CA1F04A00E958D0 /* Sources */ = {
268- isa = PBXSourcesBuildPhase;
269- buildActionMask = 2147483647;
270- files = (
271- 5CCBC6902CA1F7A100E958D0 /* SystemPrompts.swift in Sources */,
272- 5CCBC68D2CA1F7A100E958D0 /* PromptTemplate.swift in Sources */,
273- 5CCBC68F2CA1F7A100E958D0 /* Parsing.swift in Sources */,
274- 5CCBC68E2CA1F7A100E958D0 /* LocalInference.swift in Sources */,
275- );
276- runOnlyForDeploymentPostprocessing = 0;
277- };
278-/* End PBXSourcesBuildPhase section */
279-
280-/* Begin XCBuildConfiguration section */
281- 5CCBC60D2CA1F04A00E958D0 /* Debug */ = {
282- isa = XCBuildConfiguration;
283- buildSettings = {
284- ALWAYS_SEARCH_USER_PATHS = NO;
285- ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
286- CLANG_ANALYZER_NONNULL = YES;
287- CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
288- CLANG_CXX_LANGUAGE_STANDARD = "gnu++20";
289- CLANG_ENABLE_MODULES = YES;
290- CLANG_ENABLE_OBJC_ARC = YES;
291- CLANG_ENABLE_OBJC_WEAK = YES;
292- CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
293- CLANG_WARN_BOOL_CONVERSION = YES;
294- CLANG_WARN_COMMA = YES;
295- CLANG_WARN_CONSTANT_CONVERSION = YES;
296- CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
297- CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
298- CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
299- CLANG_WARN_EMPTY_BODY = YES;
300- CLANG_WARN_ENUM_CONVERSION = YES;
301- CLANG_WARN_INFINITE_RECURSION = YES;
302- CLANG_WARN_INT_CONVERSION = YES;
303- CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
304- CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
305- CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
306- CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
307- CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
308- CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
309- CLANG_WARN_STRICT_PROTOTYPES = YES;
310- CLANG_WARN_SUSPICIOUS_MOVE = YES;
311- CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
312- CLANG_WARN_UNREACHABLE_CODE = YES;
313- CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
314- COPY_PHASE_STRIP = NO;
315- CURRENT_PROJECT_VERSION = 1;
316- DEBUG_INFORMATION_FORMAT = dwarf;
317- ENABLE_STRICT_OBJC_MSGSEND = YES;
318- ENABLE_TESTABILITY = YES;
319- ENABLE_USER_SCRIPT_SANDBOXING = YES;
320- GCC_C_LANGUAGE_STANDARD = gnu17;
321- GCC_DYNAMIC_NO_PIC = NO;
322- GCC_NO_COMMON_BLOCKS = YES;
323- GCC_OPTIMIZATION_LEVEL = 0;
324- GCC_PREPROCESSOR_DEFINITIONS = (
325- "DEBUG=1",
326- "$(inherited)",
327- );
328- GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
329- GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
330- GCC_WARN_UNDECLARED_SELECTOR = YES;
331- GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
332- GCC_WARN_UNUSED_FUNCTION = YES;
333- GCC_WARN_UNUSED_VARIABLE = YES;
334- IPHONEOS_DEPLOYMENT_TARGET = 17.5;
335- LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
336- MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
337- MTL_FAST_MATH = YES;
338- ONLY_ACTIVE_ARCH = YES;
339- SDKROOT = iphoneos;
340- SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG $(inherited)";
341- SWIFT_OPTIMIZATION_LEVEL = "-Onone";
342- VERSIONING_SYSTEM = "apple-generic";
343- VERSION_INFO_PREFIX = "";
344- };
345- name = Debug;
346- };
347- 5CCBC60E2CA1F04A00E958D0 /* Release */ = {
348- isa = XCBuildConfiguration;
349- buildSettings = {
350- ALWAYS_SEARCH_USER_PATHS = NO;
351- ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
352- CLANG_ANALYZER_NONNULL = YES;
353- CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
354- CLANG_CXX_LANGUAGE_STANDARD = "gnu++20";
355- CLANG_ENABLE_MODULES = YES;
356- CLANG_ENABLE_OBJC_ARC = YES;
357- CLANG_ENABLE_OBJC_WEAK = YES;
358- CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
359- CLANG_WARN_BOOL_CONVERSION = YES;
360- CLANG_WARN_COMMA = YES;
361- CLANG_WARN_CONSTANT_CONVERSION = YES;
362- CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
363- CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
364- CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
365- CLANG_WARN_EMPTY_BODY = YES;
366- CLANG_WARN_ENUM_CONVERSION = YES;
367- CLANG_WARN_INFINITE_RECURSION = YES;
368- CLANG_WARN_INT_CONVERSION = YES;
369- CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
370- CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
371- CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
372- CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
373- CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
374- CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
375- CLANG_WARN_STRICT_PROTOTYPES = YES;
376- CLANG_WARN_SUSPICIOUS_MOVE = YES;
377- CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
378- CLANG_WARN_UNREACHABLE_CODE = YES;
379- CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
380- COPY_PHASE_STRIP = NO;
381- CURRENT_PROJECT_VERSION = 1;
382- DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
383- ENABLE_NS_ASSERTIONS = NO;
384- ENABLE_STRICT_OBJC_MSGSEND = YES;
385- ENABLE_USER_SCRIPT_SANDBOXING = YES;
386- GCC_C_LANGUAGE_STANDARD = gnu17;
387- GCC_NO_COMMON_BLOCKS = YES;
388- GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
389- GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
390- GCC_WARN_UNDECLARED_SELECTOR = YES;
391- GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
392- GCC_WARN_UNUSED_FUNCTION = YES;
393- GCC_WARN_UNUSED_VARIABLE = YES;
394- IPHONEOS_DEPLOYMENT_TARGET = 17.5;
395- LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
396- MTL_ENABLE_DEBUG_INFO = NO;
397- MTL_FAST_MATH = YES;
398- SDKROOT = iphoneos;
399- SWIFT_COMPILATION_MODE = wholemodule;
400- VALIDATE_PRODUCT = YES;
401- VERSIONING_SYSTEM = "apple-generic";
402- VERSION_INFO_PREFIX = "";
403- };
404- name = Release;
405- };
406- 5CCBC6102CA1F04A00E958D0 /* Debug */ = {
407- isa = XCBuildConfiguration;
408- buildSettings = {
409- BUILD_LIBRARY_FOR_DISTRIBUTION = YES;
410- CLANG_ENABLE_MODULES = YES;
411- CODE_SIGN_STYLE = Automatic;
412- CURRENT_PROJECT_VERSION = 1;
413- DEFINES_MODULE = YES;
414- DYLIB_COMPATIBILITY_VERSION = 1;
415- DYLIB_CURRENT_VERSION = 1;
416- DYLIB_INSTALL_NAME_BASE = "@rpath";
417- ENABLE_MODULE_VERIFIER = YES;
418- GENERATE_INFOPLIST_FILE = YES;
419- HEADER_SEARCH_PATHS = "";
420- INFOPLIST_KEY_NSHumanReadableCopyright = "";
421- INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
422- LD_RUNPATH_SEARCH_PATHS = (
423- "$(inherited)",
424- "@executable_path/Frameworks",
425- "@loader_path/Frameworks",
426- );
427- MARKETING_VERSION = 1.0;
428- MODULE_VERIFIER_SUPPORTED_LANGUAGES = "objective-c objective-c++";
429- MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu17 gnu++20";
430- OTHER_LDFLAGS = "";
431- PRODUCT_BUNDLE_IDENTIFIER = meta.llamatsack.LocalInferenceProvider;
432- PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
433- SKIP_INSTALL = YES;
434- SWIFT_EMIT_LOC_STRINGS = YES;
435- SWIFT_INSTALL_OBJC_HEADER = NO;
436- SWIFT_OPTIMIZATION_LEVEL = "-Onone";
437- SWIFT_VERSION = 5.0;
438- TARGETED_DEVICE_FAMILY = "1,2";
439- };
440- name = Debug;
441- };
442- 5CCBC6112CA1F04A00E958D0 /* Release */ = {
443- isa = XCBuildConfiguration;
444- buildSettings = {
445- BUILD_LIBRARY_FOR_DISTRIBUTION = YES;
446- CLANG_ENABLE_MODULES = YES;
447- CODE_SIGN_STYLE = Automatic;
448- CURRENT_PROJECT_VERSION = 1;
449- DEFINES_MODULE = YES;
450- DYLIB_COMPATIBILITY_VERSION = 1;
451- DYLIB_CURRENT_VERSION = 1;
452- DYLIB_INSTALL_NAME_BASE = "@rpath";
453- ENABLE_MODULE_VERIFIER = YES;
454- GENERATE_INFOPLIST_FILE = YES;
455- HEADER_SEARCH_PATHS = "";
456- INFOPLIST_KEY_NSHumanReadableCopyright = "";
457- INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
458- LD_RUNPATH_SEARCH_PATHS = (
459- "$(inherited)",
460- "@executable_path/Frameworks",
461- "@loader_path/Frameworks",
462- );
463- MARKETING_VERSION = 1.0;
464- MODULE_VERIFIER_SUPPORTED_LANGUAGES = "objective-c objective-c++";
465- MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu17 gnu++20";
466- OTHER_LDFLAGS = "";
467- PRODUCT_BUNDLE_IDENTIFIER = meta.llamatsack.LocalInferenceProvider;
468- PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
469- SKIP_INSTALL = YES;
470- SWIFT_EMIT_LOC_STRINGS = YES;
471- SWIFT_INSTALL_OBJC_HEADER = NO;
472- SWIFT_VERSION = 5.0;
473- TARGETED_DEVICE_FAMILY = "1,2";
474- };
475- name = Release;
476- };
477-/* End XCBuildConfiguration section */
478-
479-/* Begin XCConfigurationList section */
480- 5CCBC6022CA1F04A00E958D0 /* Build configuration list for PBXProject "LocalInference" */ = {
481- isa = XCConfigurationList;
482- buildConfigurations = (
483- 5CCBC60D2CA1F04A00E958D0 /* Debug */,
484- 5CCBC60E2CA1F04A00E958D0 /* Release */,
485- );
486- defaultConfigurationIsVisible = 0;
487- defaultConfigurationName = Release;
488- };
489- 5CCBC60F2CA1F04A00E958D0 /* Build configuration list for PBXNativeTarget "LocalInference" */ = {
490- isa = XCConfigurationList;
491- buildConfigurations = (
492- 5CCBC6102CA1F04A00E958D0 /* Debug */,
493- 5CCBC6112CA1F04A00E958D0 /* Release */,
494- );
495- defaultConfigurationIsVisible = 0;
496- defaultConfigurationName = Release;
497- };
498-/* End XCConfigurationList section */
499-
500-/* Begin XCLocalSwiftPackageReference section */
501- 5C5B6E1F2CA3D89F00AF6130 /* XCLocalSwiftPackageReference "internal-llama-stack-client-swift" */ = {
502- isa = XCLocalSwiftPackageReference;
503- relativePath = "internal-llama-stack-client-swift";
504- };
505-/* End XCLocalSwiftPackageReference section */
506-
507-/* Begin XCRemoteSwiftPackageReference section */
508- 5CCBC6732CA1F45800E958D0 /* XCRemoteSwiftPackageReference "executorch" */ = {
509- isa = XCRemoteSwiftPackageReference;
510- repositoryURL = "https://github.com/pytorch/executorch";
511- requirement = {
512- branch = latest;
513- kind = branch;
514- };
515- };
516- 5CCBC6912CA1F7D000E958D0 /* XCRemoteSwiftPackageReference "Stencil" */ = {
517- isa = XCRemoteSwiftPackageReference;
518- repositoryURL = "https://github.com/stencilproject/Stencil";
519- requirement = {
520- kind = upToNextMajorVersion;
521- minimumVersion = 0.15.1;
522- };
523- };
524-/* End XCRemoteSwiftPackageReference section */
525-
526-/* Begin XCSwiftPackageProductDependency section */
527- 5C03561E2CA3AB9600E3BB46 /* LlamaStackClient */ = {
528- isa = XCSwiftPackageProductDependency;
529- productName = LlamaStackClient;
530- };
531- 5C5B6E202CA3D89F00AF6130 /* LlamaStackClient */ = {
532- isa = XCSwiftPackageProductDependency;
533- productName = LlamaStackClient;
534- };
535- 5CCBC6742CA1F45800E958D0 /* executorch_debug */ = {
536- isa = XCSwiftPackageProductDependency;
537- package = 5CCBC6732CA1F45800E958D0 /* XCRemoteSwiftPackageReference "executorch" */;
538- productName = executorch_debug;
539- };
540- 5CCBC6922CA1F7D000E958D0 /* Stencil */ = {
541- isa = XCSwiftPackageProductDependency;
542- package = 5CCBC6912CA1F7D000E958D0 /* XCRemoteSwiftPackageReference "Stencil" */;
543- productName = Stencil;
544- };
545-/* End XCSwiftPackageProductDependency section */
546- };
547- rootObject = 5CCBC5FF2CA1F04A00E958D0 /* Project object */;
548-}
deleted llama_stack/providers/impls/ios/inference/LocalInference/LocalInference.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 −7
@@ -1,7 +0,0 @@
1-<?xml version="1.0" encoding="UTF-8"?>
2-<Workspace
3- version = "1.0">
4- <FileRef
5- location = "self:">
6- </FileRef>
7-</Workspace>
deleted llama_stack/providers/impls/ios/inference/LocalInference/LocalInference.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 −8
@@ -1,8 +0,0 @@
1-<?xml version="1.0" encoding="UTF-8"?>
2-<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3-<plist version="1.0">
4-<dict>
5- <key>IDEDidComputeMac32BitWarning</key>
6- <true/>
7-</dict>
8-</plist>
deleted llama_stack/providers/impls/ios/inference/LocalInference/LocalInference/LocalInference.h +0 −16
@@ -1,16 +0,0 @@
1-//
2-// LocalInference.h
3-// LocalInference
4-//
5-// Created by Dalton Flanagan on 9/23/24.
6-//
7-
8-#import <Foundation/Foundation.h>
9-
10-//! Project version number for LocalInference.
11-FOUNDATION_EXPORT double LocalInferenceVersionNumber;
12-
13-//! Project version string for LocalInference.
14-FOUNDATION_EXPORT const unsigned char LocalInferenceVersionString[];
15-
16-// In this header, you should import all the public headers of your framework using statements like #import <LocalInference/PublicHeader.h>
deleted llama_stack/providers/impls/ios/inference/LocalInference/LocalInference/LocalInference.swift +0 −167
@@ -1,167 +0,0 @@
1-import Foundation
2-
3-import LLaMARunner
4-import LlamaStackClient
5-
6-class RunnerHolder: ObservableObject {
7- var runner: Runner?
8-}
9-
10-public class LocalInference: Inference {
11- private var runnerHolder = RunnerHolder()
12- private let runnerQueue: DispatchQueue
13-
14- public init (queue: DispatchQueue) {
15- runnerQueue = queue
16- }
17-
18- public func loadModel(modelPath: String, tokenizerPath: String, completion: @escaping (Result<Void, Error>) -> Void) {
19- runnerHolder.runner = runnerHolder.runner ?? Runner(
20- modelPath: modelPath,
21- tokenizerPath: tokenizerPath
22- )
23-
24-
25- runnerQueue.async {
26- let runner = self.runnerHolder.runner
27- do {
28- try runner!.load()
29- completion(.success(()))
30- } catch let loadError {
31- print("error: " + loadError.localizedDescription)
32- completion(.failure(loadError))
33- }
34- }
35- }
36-
37- public func chatCompletion(request: Components.Schemas.ChatCompletionRequest) -> AsyncStream<Components.Schemas.ChatCompletionResponseStreamChunk> {
38- return AsyncStream { continuation in
39- runnerQueue.async {
40- do {
41- var tokens: [String] = []
42-
43- let prompt = try encodeDialogPrompt(messages: prepareMessages(request: request))
44- var stopReason: Components.Schemas.StopReason? = nil
45- var buffer = ""
46- var ipython = false
47- var echoDropped = false
48-
49- try self.runnerHolder.runner?.generate(prompt, sequenceLength: 4096) { token in
50- buffer += token
51-
52- // HACK: Workaround until LlamaRunner exposes echo param
53- if (!echoDropped) {
54- if (buffer.hasPrefix(prompt)) {
55- buffer = String(buffer.dropFirst(prompt.count))
56- echoDropped = true
57- }
58- return
59- }
60-
61- tokens.append(token)
62-
63- if !ipython && (buffer.starts(with: "<|python_tag|>") || buffer.starts(with: "[") ) {
64- ipython = true
65- continuation.yield(
66- Components.Schemas.ChatCompletionResponseStreamChunk(
67- event: Components.Schemas.ChatCompletionResponseEvent(
68- delta: .ToolCallDelta(Components.Schemas.ToolCallDelta(
69- content: .case1(""),
70- parse_status: Components.Schemas.ToolCallParseStatus.started
71- )
72- ),
73- event_type: .progress
74- )
75- )
76- )
77-
78- if (buffer.starts(with: "<|python_tag|>")) {
79- buffer = String(buffer.dropFirst("<|python_tag|>".count))
80- }
81- }
82-
83- // TODO: Non-streaming lobprobs
84-
85- var text = ""
86- if token == "<|eot_id|>" {
87- stopReason = Components.Schemas.StopReason.end_of_turn
88- } else if token == "<|eom_id|>" {
89- stopReason = Components.Schemas.StopReason.end_of_message
90- } else {
91- text = token
92- }
93-
94- var delta: Components.Schemas.ChatCompletionResponseEvent.deltaPayload
95- if ipython {
96- delta = .ToolCallDelta(Components.Schemas.ToolCallDelta(
97- content: .case1(text),
98- parse_status: .in_progress
99- ))
100- } else {
101- delta = .case1(text)
102- }
103-
104- if stopReason == nil {
105- continuation.yield(
106- Components.Schemas.ChatCompletionResponseStreamChunk(
107- event: Components.Schemas.ChatCompletionResponseEvent(
108- delta: delta,
109- event_type: .progress
110- )
111- )
112- )
113- }
114- }
115-
116- if stopReason == nil {
117- stopReason = Components.Schemas.StopReason.out_of_tokens
118- }
119-
120- let message = decodeAssistantMessage(tokens: tokens.joined(), stopReason: stopReason!)
121- // TODO: non-streaming support
122-
123- let didParseToolCalls = message.tool_calls.count > 0
124- if ipython && !didParseToolCalls {
125- continuation.yield(
126- Components.Schemas.ChatCompletionResponseStreamChunk(
127- event: Components.Schemas.ChatCompletionResponseEvent(
128- delta: .ToolCallDelta(Components.Schemas.ToolCallDelta(content: .case1(""), parse_status: .failure)),
129- event_type: .progress
130- )
131- // TODO: stopReason
132- )
133- )
134- }
135-
136- for toolCall in message.tool_calls {
137- continuation.yield(
138- Components.Schemas.ChatCompletionResponseStreamChunk(
139- event: Components.Schemas.ChatCompletionResponseEvent(
140- delta: .ToolCallDelta(Components.Schemas.ToolCallDelta(
141- content: .ToolCall(toolCall),
142- parse_status: .success
143- )),
144- event_type: .progress
145- )
146- // TODO: stopReason
147- )
148- )
149- }
150-
151- continuation.yield(
152- Components.Schemas.ChatCompletionResponseStreamChunk(
153- event: Components.Schemas.ChatCompletionResponseEvent(
154- delta: .case1(""),
155- event_type: .complete
156- )
157- // TODO: stopReason
158- )
159- )
160- }
161- catch (let error) {
162- print("Inference error: " + error.localizedDescription)
163- }
164- }
165- }
166- }
167-}
deleted llama_stack/providers/impls/ios/inference/LocalInference/LocalInference/Parsing.swift +0 −235
@@ -1,235 +0,0 @@
1-import Foundation
2-
3-import LlamaStackClient
4-
5-func encodeHeader(role: String) -> String {
6- return "<|start_header_id|>\(role)<|end_header_id|>\n\n"
7-}
8-
9-func encodeDialogPrompt(messages: [Components.Schemas.ChatCompletionRequest.messagesPayloadPayload]) -> String {
10- var prompt = ""
11-
12- prompt.append("<|begin_of_text|>")
13- for message in messages {
14- let msg = encodeMessage(message: message)
15- prompt += msg
16- }
17-
18- prompt.append(encodeHeader(role: "assistant"))
19-
20- return prompt
21-}
22-
23-func getRole(message: Components.Schemas.ChatCompletionRequest.messagesPayloadPayload) -> String {
24- switch (message) {
25- case .UserMessage(let m):
26- return m.role.rawValue
27- case .SystemMessage(let m):
28- return m.role.rawValue
29- case .ToolResponseMessage(let m):
30- return m.role.rawValue
31- case .CompletionMessage(let m):
32- return m.role.rawValue
33- }
34-}
35-
36-func encodeMessage(message: Components.Schemas.ChatCompletionRequest.messagesPayloadPayload) -> String {
37- var prompt = encodeHeader(role: getRole(message: message))
38-
39- switch (message) {
40- case .CompletionMessage(let m):
41- if (m.tool_calls.count > 0) {
42- prompt += "<|python_tag|>"
43- }
44- default:
45- break
46- }
47-
48- func _processContent(_ content: Any) -> String {
49- func _process(_ c: Any) {
50- if let str = c as? String {
51- prompt += str
52- }
53- }
54-
55- if let str = content as? String {
56- _process(str)
57- } else if let list = content as? [Any] {
58- for c in list {
59- _process(c)
60- }
61- }
62-
63- return ""
64- }
65-
66- switch (message) {
67- case .UserMessage(let m):
68- prompt += _processContent(m.content)
69- case .SystemMessage(let m):
70- prompt += _processContent(m.content)
71- case .ToolResponseMessage(let m):
72- prompt += _processContent(m.content)
73- case .CompletionMessage(let m):
74- prompt += _processContent(m.content)
75- }
76-
77- var eom = false
78-
79- switch (message) {
80- case .UserMessage(let m):
81- switch (m.content) {
82- case .case1(let c):
83- prompt += _processContent(c)
84- case .case2(let c):
85- prompt += _processContent(c)
86- }
87- case .CompletionMessage(let m):
88- // TODO: Support encoding past tool call history
89- // for t in m.tool_calls {
90- // _processContent(t.)
91- //}
92- eom = m.stop_reason == Components.Schemas.StopReason.end_of_message
93- case .SystemMessage(_):
94- break
95- case .ToolResponseMessage(_):
96- break
97- }
98-
99- if (eom) {
100- prompt += "<|eom_id|>"
101- } else {
102- prompt += "<|eot_id|>"
103- }
104-
105- return prompt
106-}
107-
108-func prepareMessages(request: Components.Schemas.ChatCompletionRequest) throws -> [Components.Schemas.ChatCompletionRequest.messagesPayloadPayload] {
109- var existingMessages = request.messages
110- var existingSystemMessage: Components.Schemas.ChatCompletionRequest.messagesPayloadPayload?
111- // TODO: Existing system message
112-
113- var messages: [Components.Schemas.ChatCompletionRequest.messagesPayloadPayload] = []
114-
115- let defaultGen = SystemDefaultGenerator()
116- let defaultTemplate = defaultGen.gen()
117-
118- var sysContent = ""
119-
120- // TODO: Built-in tools
121-
122- sysContent += try defaultTemplate.render()
123-
124- messages.append(.SystemMessage(Components.Schemas.SystemMessage(
125- content: .case1(sysContent),
126- role: .system))
127- )
128-
129- if request.tools?.isEmpty == false {
130- // TODO: Separate built-ins and custom tools (right now everything treated as custom)
131- let toolGen = FunctionTagCustomToolGenerator()
132- let toolTemplate = try toolGen.gen(customTools: request.tools!)
133- let tools = try toolTemplate.render()
134- messages.append(.UserMessage(Components.Schemas.UserMessage(
135- content: .case1(tools),
136- role: .user)
137- ))
138- }
139-
140- messages.append(contentsOf: existingMessages)
141-
142- return messages
143-}
144-
145-struct FunctionCall {
146- let name: String
147- let params: [String: Any]
148-}
149-
150-public func maybeExtractCustomToolCalls(input: String) -> [Components.Schemas.ToolCall] {
151- guard input.hasPrefix("[") && input.hasSuffix("]") else {
152- return []
153- }
154-
155- do {
156- let trimmed = input.trimmingCharacters(in: CharacterSet(charactersIn: "[]"))
157- let calls = trimmed.components(separatedBy: "),").map { $0.hasSuffix(")") ? $0 : $0 + ")" }
158-
159- var result: [Components.Schemas.ToolCall] = []
160-
161- for call in calls {
162- guard let nameEndIndex = call.firstIndex(of: "("),
163- let paramsStartIndex = call.firstIndex(of: "{"),
164- let paramsEndIndex = call.lastIndex(of: "}") else {
165- return []
166- }
167-
168- let name = String(call[..<nameEndIndex]).trimmingCharacters(in: .whitespacesAndNewlines)
169- let paramsString = String(call[paramsStartIndex...paramsEndIndex])
170-
171- guard let data = paramsString.data(using: .utf8),
172- let params = try? JSONSerialization.jsonObject(with: data, options: []) as? [String: Any] else {
173- return []
174- }
175-
176- var props: [String : Components.Schemas.ToolCall.argumentsPayload.additionalPropertiesPayload] = [:]
177- for (param_name, param) in params {
178- switch (param) {
179- case let value as String:
180- props[param_name] = .case1(value)
181- case let value as Int:
182- props[param_name] = .case2(value)
183- case let value as Double:
184- props[param_name] = .case3(value)
185- case let value as Bool:
186- props[param_name] = .case4(value)
187- default:
188- return []
189- }
190- }
191-
192- result.append(
193- Components.Schemas.ToolCall(
194- arguments: .init(additionalProperties: props),
195- call_id: UUID().uuidString,
196- tool_name: .case2(name) // custom_tool
197- )
198- )
199- }
200-
201- return result.isEmpty ? [] : result
202- } catch {
203- return []
204- }
205-}
206-
207-func decodeAssistantMessage(tokens: String, stopReason: Components.Schemas.StopReason) -> Components.Schemas.CompletionMessage {
208- var content = tokens
209-
210- let roles = ["user", "system", "assistant"]
211- for role in roles {
212- let headerStr = encodeHeader(role: role)
213- if content.hasPrefix(headerStr) {
214- content = String(content.dropFirst(encodeHeader(role: role).count))
215- }
216- }
217-
218- if content.hasPrefix("<|python_tag|>") {
219- content = String(content.dropFirst("<|python_tag|>".count))
220- }
221-
222-
223- if content.hasSuffix("<|eot_id|>") {
224- content = String(content.dropLast("<|eot_id|>".count))
225- } else {
226- content = String(content.dropLast("<|eom_id|>".count))
227- }
228-
229- return Components.Schemas.CompletionMessage(
230- content: .case1(content),
231- role: .assistant,
232- stop_reason: stopReason,
233- tool_calls: maybeExtractCustomToolCalls(input: content)
234- )
235-}
deleted llama_stack/providers/impls/ios/inference/LocalInference/LocalInference/PromptTemplate.swift +0 −12
@@ -1,12 +0,0 @@
1-import Foundation
2-import Stencil
3-
4-public struct PromptTemplate {
5- let template: String
6- let data: [String: Any]
7-
8- public func render() throws -> String {
9- let template = Template(templateString: self.template)
10- return try template.render(self.data)
11- }
12-}
deleted llama_stack/providers/impls/ios/inference/LocalInference/LocalInference/SystemPrompts.swift +0 −91
@@ -1,91 +0,0 @@
1-import Foundation
2-
3-import LlamaStackClient
4-
5-func convertToNativeSwiftType(_ value: Any) -> Any {
6- switch value {
7- case let number as NSNumber:
8- if CFGetTypeID(number) == CFBooleanGetTypeID() {
9- return number.boolValue
10- }
11- if floor(number.doubleValue) == number.doubleValue {
12- return number.intValue
13- }
14- return number.doubleValue
15- case let string as String:
16- return string
17- case let array as [Any]:
18- return array.map(convertToNativeSwiftType)
19- case let dict as [String: Any]:
20- return dict.mapValues(convertToNativeSwiftType)
21- case is NSNull:
22- return NSNull()
23- default:
24- return value
25- }
26-}
27-
28-public class SystemDefaultGenerator {
29- public init() {}
30-
31- public func gen() -> PromptTemplate {
32- let templateStr = """
33- Cutting Knowledge Date: December 2023
34- Today Date: {{ today }}
35- """
36-
37- let dateFormatter = DateFormatter()
38- dateFormatter.dateFormat = "dd MMMM yyyy"
39-
40- return PromptTemplate(
41- template: templateStr,
42- data: ["today": dateFormatter.string(from: Date())]
43- )
44- }
45-}
46-
47-
48-public class FunctionTagCustomToolGenerator {
49- public init() {}
50-
51- public func gen(customTools: [Components.Schemas.ToolDefinition]) throws -> PromptTemplate {
52- // TODO: required params
53- // TODO: {{#unless @last}},{{/unless}}
54-
55- let templateStr = """
56- You are an expert in composing functions. You are given a question and a set of possible functions.
57- Based on the question, you will need to make one or more function/tool calls to achieve the purpose.
58- If none of the function can be used, point it out. If the given question lacks the parameters required by the function,
59- also point it out. You should only return the function call in tools call sections.
60-
61- 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)]
62- You SHOULD NOT include any other text in the response.
63-
64- Here is a list of functions in JSON format that you can invoke.
65-
66- [
67- {% for t in custom_tools %}
68- {
69- "name": "{{t.tool_name}}",
70- "description": "{{t.description}}",
71- "parameters": {
72- "type": "dict",
73- "properties": { {{t.parameters}} }
74- }
75-
76- {{/let}}
77- {% endfor -%}
78- ]
79- """
80-
81- let encoder = JSONEncoder()
82- return PromptTemplate(
83- template: templateStr,
84- data: ["custom_tools": try customTools.map {
85- let data = try encoder.encode($0)
86- let obj = try JSONSerialization.jsonObject(with: data)
87- return convertToNativeSwiftType(obj)
88- }]
89- )
90- }
91-}
deleted llama_stack/providers/impls/ios/inference/LocalInference/LocalInferenceImpl.xcodeproj/project.pbxproj +0 −541
@@ -1,541 +0,0 @@
1-// !$*UTF8*$!
2-{
3- archiveVersion = 1;
4- classes = {
5- };
6- objectVersion = 60;
7- objects = {
8-
9-/* Begin PBXBuildFile section */
10- 5CADC71A2CA471CC007662D2 /* LlamaStackClient in Frameworks */ = {isa = PBXBuildFile; productRef = 5CADC7192CA471CC007662D2 /* LlamaStackClient */; };
11- 5CCBC60C2CA1F04A00E958D0 /* LocalInference.h in Headers */ = {isa = PBXBuildFile; fileRef = 5CCBC60B2CA1F04A00E958D0 /* LocalInference.h */; settings = {ATTRIBUTES = (Public, ); }; };
12- 5CCBC6752CA1F45800E958D0 /* executorch_debug in Frameworks */ = {isa = PBXBuildFile; productRef = 5CCBC6742CA1F45800E958D0 /* executorch_debug */; };
13- 5CCBC6862CA1F64A00E958D0 /* LLaMARunner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5CCBC6802CA1F63F00E958D0 /* LLaMARunner.framework */; platformFilter = ios; };
14- 5CCBC6872CA1F64A00E958D0 /* LLaMARunner.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 5CCBC6802CA1F63F00E958D0 /* LLaMARunner.framework */; platformFilter = ios; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
15- 5CCBC68D2CA1F7A100E958D0 /* PromptTemplate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5CCBC6892CA1F7A000E958D0 /* PromptTemplate.swift */; };
16- 5CCBC68E2CA1F7A100E958D0 /* LocalInference.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5CCBC68A2CA1F7A000E958D0 /* LocalInference.swift */; };
17- 5CCBC68F2CA1F7A100E958D0 /* Parsing.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5CCBC68B2CA1F7A000E958D0 /* Parsing.swift */; };
18- 5CCBC6902CA1F7A100E958D0 /* SystemPrompts.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5CCBC68C2CA1F7A100E958D0 /* SystemPrompts.swift */; };
19- 5CCBC6932CA1F7D000E958D0 /* Stencil in Frameworks */ = {isa = PBXBuildFile; productRef = 5CCBC6922CA1F7D000E958D0 /* Stencil */; };
20-/* End PBXBuildFile section */
21-
22-/* Begin PBXContainerItemProxy section */
23- 5CCBC67D2CA1F63F00E958D0 /* PBXContainerItemProxy */ = {
24- isa = PBXContainerItemProxy;
25- containerPortal = 5CCBC6762CA1F63F00E958D0 /* LLaMA.xcodeproj */;
26- proxyType = 2;
27- remoteGlobalIDString = 036CAF9D2BB1444500D6C2D5;
28- remoteInfo = LLaMA;
29- };
30- 5CCBC67F2CA1F63F00E958D0 /* PBXContainerItemProxy */ = {
31- isa = PBXContainerItemProxy;
32- containerPortal = 5CCBC6762CA1F63F00E958D0 /* LLaMA.xcodeproj */;
33- proxyType = 2;
34- remoteGlobalIDString = 03729ED52BB1F8DE00152F2E;
35- remoteInfo = LLaMARunner;
36- };
37- 5CCBC69E2CA2036B00E958D0 /* PBXContainerItemProxy */ = {
38- isa = PBXContainerItemProxy;
39- containerPortal = 5CCBC6762CA1F63F00E958D0 /* LLaMA.xcodeproj */;
40- proxyType = 2;
41- remoteGlobalIDString = 5CCBC6982CA2036A00E958D0;
42- remoteInfo = LLaMAPerfBenchmark;
43- };
44- 5CCBC6A02CA2036B00E958D0 /* PBXContainerItemProxy */ = {
45- isa = PBXContainerItemProxy;
46- containerPortal = 5CCBC6762CA1F63F00E958D0 /* LLaMA.xcodeproj */;
47- proxyType = 2;
48- remoteGlobalIDString = 5CCBC6992CA2036A00E958D0;
49- remoteInfo = LLaMAPerfBenchmarkTests;
50- };
51-/* End PBXContainerItemProxy section */
52-
53-/* Begin PBXCopyFilesBuildPhase section */
54- 5CCBC6882CA1F64A00E958D0 /* Embed Frameworks */ = {
55- isa = PBXCopyFilesBuildPhase;
56- buildActionMask = 2147483647;
57- dstPath = "";
58- dstSubfolderSpec = 10;
59- files = (
60- 5CCBC6872CA1F64A00E958D0 /* LLaMARunner.framework in Embed Frameworks */,
61- );
62- name = "Embed Frameworks";
63- runOnlyForDeploymentPostprocessing = 0;
64- };
65-/* End PBXCopyFilesBuildPhase section */
66-
67-/* Begin PBXFileReference section */
68- 5CCBC6082CA1F04A00E958D0 /* LocalInferenceImpl.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = LocalInferenceImpl.framework; sourceTree = BUILT_PRODUCTS_DIR; };
69- 5CCBC60B2CA1F04A00E958D0 /* LocalInference.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LocalInference.h; sourceTree = "<group>"; };
70- 5CCBC6762CA1F63F00E958D0 /* LLaMA.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = LLaMA.xcodeproj; path = "executorch/examples/demo-apps/apple_ios/LLaMA/LLaMA.xcodeproj"; sourceTree = "<group>"; };
71- 5CCBC6892CA1F7A000E958D0 /* PromptTemplate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PromptTemplate.swift; sourceTree = "<group>"; };
72- 5CCBC68A2CA1F7A000E958D0 /* LocalInference.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LocalInference.swift; sourceTree = "<group>"; };
73- 5CCBC68B2CA1F7A000E958D0 /* Parsing.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Parsing.swift; sourceTree = "<group>"; };
74- 5CCBC68C2CA1F7A100E958D0 /* SystemPrompts.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SystemPrompts.swift; sourceTree = "<group>"; };
75-/* End PBXFileReference section */
76-
77-/* Begin PBXFrameworksBuildPhase section */
78- 5CCBC6052CA1F04A00E958D0 /* Frameworks */ = {
79- isa = PBXFrameworksBuildPhase;
80- buildActionMask = 2147483647;
81- files = (
82- 5CADC71A2CA471CC007662D2 /* LlamaStackClient in Frameworks */,
83- 5CCBC6932CA1F7D000E958D0 /* Stencil in Frameworks */,
84- 5CCBC6862CA1F64A00E958D0 /* LLaMARunner.framework in Frameworks */,
85- 5CCBC6752CA1F45800E958D0 /* executorch_debug in Frameworks */,
86- );
87- runOnlyForDeploymentPostprocessing = 0;
88- };
89-/* End PBXFrameworksBuildPhase section */
90-
91-/* Begin PBXGroup section */
92- 5CCBC5FE2CA1F04A00E958D0 = {
93- isa = PBXGroup;
94- children = (
95- 5CCBC6762CA1F63F00E958D0 /* LLaMA.xcodeproj */,
96- 5CCBC60A2CA1F04A00E958D0 /* LocalInferenceImpl */,
97- 5CCBC6092CA1F04A00E958D0 /* Products */,
98- 5CCBC6852CA1F64A00E958D0 /* Frameworks */,
99- );
100- sourceTree = "<group>";
101- };
102- 5CCBC6092CA1F04A00E958D0 /* Products */ = {
103- isa = PBXGroup;
104- children = (
105- 5CCBC6082CA1F04A00E958D0 /* LocalInferenceImpl.framework */,
106- );
107- name = Products;
108- sourceTree = "<group>";
109- };
110- 5CCBC60A2CA1F04A00E958D0 /* LocalInferenceImpl */ = {
111- isa = PBXGroup;
112- children = (
113- 5CCBC68A2CA1F7A000E958D0 /* LocalInference.swift */,
114- 5CCBC68B2CA1F7A000E958D0 /* Parsing.swift */,
115- 5CCBC6892CA1F7A000E958D0 /* PromptTemplate.swift */,
116- 5CCBC68C2CA1F7A100E958D0 /* SystemPrompts.swift */,
117- 5CCBC60B2CA1F04A00E958D0 /* LocalInference.h */,
118- );
119- path = LocalInferenceImpl;
120- sourceTree = "<group>";
121- };
122- 5CCBC6772CA1F63F00E958D0 /* Products */ = {
123- isa = PBXGroup;
124- children = (
125- 5CCBC67E2CA1F63F00E958D0 /* LLaMA.app */,
126- 5CCBC6802CA1F63F00E958D0 /* LLaMARunner.framework */,
127- 5CCBC69F2CA2036B00E958D0 /* LLaMAPerfBenchmark.app */,
128- 5CCBC6A12CA2036B00E958D0 /* LLaMAPerfBenchmarkTests.xctest */,
129- );
130- name = Products;
131- sourceTree = "<group>";
132- };
133- 5CCBC6852CA1F64A00E958D0 /* Frameworks */ = {
134- isa = PBXGroup;
135- children = (
136- );
137- name = Frameworks;
138- sourceTree = "<group>";
139- };
140-/* End PBXGroup section */
141-
142-/* Begin PBXHeadersBuildPhase section */
143- 5CCBC6032CA1F04A00E958D0 /* Headers */ = {
144- isa = PBXHeadersBuildPhase;
145- buildActionMask = 2147483647;
146- files = (
147- 5CCBC60C2CA1F04A00E958D0 /* LocalInference.h in Headers */,
148- );
149- runOnlyForDeploymentPostprocessing = 0;
150- };
151-/* End PBXHeadersBuildPhase section */
152-
153-/* Begin PBXNativeTarget section */
154- 5CCBC6072CA1F04A00E958D0 /* LocalInferenceImpl */ = {
155- isa = PBXNativeTarget;
156- buildConfigurationList = 5CCBC60F2CA1F04A00E958D0 /* Build configuration list for PBXNativeTarget "LocalInferenceImpl" */;
157- buildPhases = (
158- 5CCBC6032CA1F04A00E958D0 /* Headers */,
159- 5CCBC6042CA1F04A00E958D0 /* Sources */,
160- 5CCBC6052CA1F04A00E958D0 /* Frameworks */,
161- 5CCBC6062CA1F04A00E958D0 /* Resources */,
162- 5CCBC6882CA1F64A00E958D0 /* Embed Frameworks */,
163- );
164- buildRules = (
165- );
166- dependencies = (
167- );
168- name = LocalInferenceImpl;
169- packageProductDependencies = (
170- 5CCBC6742CA1F45800E958D0 /* executorch_debug */,
171- 5CCBC6922CA1F7D000E958D0 /* Stencil */,
172- 5CADC7192CA471CC007662D2 /* LlamaStackClient */,
173- );
174- productName = LocalInferenceProvider;
175- productReference = 5CCBC6082CA1F04A00E958D0 /* LocalInferenceImpl.framework */;
176- productType = "com.apple.product-type.framework";
177- };
178-/* End PBXNativeTarget section */
179-
180-/* Begin PBXProject section */
181- 5CCBC5FF2CA1F04A00E958D0 /* Project object */ = {
182- isa = PBXProject;
183- attributes = {
184- BuildIndependentTargetsInParallel = 1;
185- LastUpgradeCheck = 1540;
186- TargetAttributes = {
187- 5CCBC6072CA1F04A00E958D0 = {
188- CreatedOnToolsVersion = 15.4;
189- LastSwiftMigration = 1540;
190- };
191- };
192- };
193- buildConfigurationList = 5CCBC6022CA1F04A00E958D0 /* Build configuration list for PBXProject "LocalInferenceImpl" */;
194- compatibilityVersion = "Xcode 14.0";
195- developmentRegion = en;
196- hasScannedForEncodings = 0;
197- knownRegions = (
198- en,
199- Base,
200- );
201- mainGroup = 5CCBC5FE2CA1F04A00E958D0;
202- packageReferences = (
203- 5CCBC6732CA1F45800E958D0 /* XCRemoteSwiftPackageReference "executorch" */,
204- 5CCBC6912CA1F7D000E958D0 /* XCRemoteSwiftPackageReference "Stencil" */,
205- 5CADC7182CA471CC007662D2 /* XCLocalSwiftPackageReference "internal-llama-stack-client-swift" */,
206- );
207- productRefGroup = 5CCBC6092CA1F04A00E958D0 /* Products */;
208- projectDirPath = "";
209- projectReferences = (
210- {
211- ProductGroup = 5CCBC6772CA1F63F00E958D0 /* Products */;
212- ProjectRef = 5CCBC6762CA1F63F00E958D0 /* LLaMA.xcodeproj */;
213- },
214- );
215- projectRoot = "";
216- targets = (
217- 5CCBC6072CA1F04A00E958D0 /* LocalInferenceImpl */,
218- );
219- };
220-/* End PBXProject section */
221-
222-/* Begin PBXReferenceProxy section */
223- 5CCBC67E2CA1F63F00E958D0 /* LLaMA.app */ = {
224- isa = PBXReferenceProxy;
225- fileType = wrapper.application;
226- path = LLaMA.app;
227- remoteRef = 5CCBC67D2CA1F63F00E958D0 /* PBXContainerItemProxy */;
228- sourceTree = BUILT_PRODUCTS_DIR;
229- };
230- 5CCBC6802CA1F63F00E958D0 /* LLaMARunner.framework */ = {
231- isa = PBXReferenceProxy;
232- fileType = wrapper.framework;
233- path = LLaMARunner.framework;
234- remoteRef = 5CCBC67F2CA1F63F00E958D0 /* PBXContainerItemProxy */;
235- sourceTree = BUILT_PRODUCTS_DIR;
236- };
237- 5CCBC69F2CA2036B00E958D0 /* LLaMAPerfBenchmark.app */ = {
238- isa = PBXReferenceProxy;
239- fileType = wrapper.application;
240- path = LLaMAPerfBenchmark.app;
241- remoteRef = 5CCBC69E2CA2036B00E958D0 /* PBXContainerItemProxy */;
242- sourceTree = BUILT_PRODUCTS_DIR;
243- };
244- 5CCBC6A12CA2036B00E958D0 /* LLaMAPerfBenchmarkTests.xctest */ = {
245- isa = PBXReferenceProxy;
246- fileType = wrapper.cfbundle;
247- path = LLaMAPerfBenchmarkTests.xctest;
248- remoteRef = 5CCBC6A02CA2036B00E958D0 /* PBXContainerItemProxy */;
249- sourceTree = BUILT_PRODUCTS_DIR;
250- };
251-/* End PBXReferenceProxy section */
252-
253-/* Begin PBXResourcesBuildPhase section */
254- 5CCBC6062CA1F04A00E958D0 /* Resources */ = {
255- isa = PBXResourcesBuildPhase;
256- buildActionMask = 2147483647;
257- files = (
258- );
259- runOnlyForDeploymentPostprocessing = 0;
260- };
261-/* End PBXResourcesBuildPhase section */
262-
263-/* Begin PBXSourcesBuildPhase section */
264- 5CCBC6042CA1F04A00E958D0 /* Sources */ = {
265- isa = PBXSourcesBuildPhase;
266- buildActionMask = 2147483647;
267- files = (
268- 5CCBC6902CA1F7A100E958D0 /* SystemPrompts.swift in Sources */,
269- 5CCBC68D2CA1F7A100E958D0 /* PromptTemplate.swift in Sources */,
270- 5CCBC68F2CA1F7A100E958D0 /* Parsing.swift in Sources */,
271- 5CCBC68E2CA1F7A100E958D0 /* LocalInference.swift in Sources */,
272- );
273- runOnlyForDeploymentPostprocessing = 0;
274- };
275-/* End PBXSourcesBuildPhase section */
276-
277-/* Begin XCBuildConfiguration section */
278- 5CCBC60D2CA1F04A00E958D0 /* Debug */ = {
279- isa = XCBuildConfiguration;
280- buildSettings = {
281- ALWAYS_SEARCH_USER_PATHS = NO;
282- ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
283- CLANG_ANALYZER_NONNULL = YES;
284- CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
285- CLANG_CXX_LANGUAGE_STANDARD = "gnu++20";
286- CLANG_ENABLE_MODULES = YES;
287- CLANG_ENABLE_OBJC_ARC = YES;
288- CLANG_ENABLE_OBJC_WEAK = YES;
289- CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
290- CLANG_WARN_BOOL_CONVERSION = YES;
291- CLANG_WARN_COMMA = YES;
292- CLANG_WARN_CONSTANT_CONVERSION = YES;
293- CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
294- CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
295- CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
296- CLANG_WARN_EMPTY_BODY = YES;
297- CLANG_WARN_ENUM_CONVERSION = YES;
298- CLANG_WARN_INFINITE_RECURSION = YES;
299- CLANG_WARN_INT_CONVERSION = YES;
300- CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
301- CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
302- CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
303- CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
304- CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
305- CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
306- CLANG_WARN_STRICT_PROTOTYPES = YES;
307- CLANG_WARN_SUSPICIOUS_MOVE = YES;
308- CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
309- CLANG_WARN_UNREACHABLE_CODE = YES;
310- CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
311- COPY_PHASE_STRIP = NO;
312- CURRENT_PROJECT_VERSION = 1;
313- DEBUG_INFORMATION_FORMAT = dwarf;
314- ENABLE_STRICT_OBJC_MSGSEND = YES;
315- ENABLE_TESTABILITY = YES;
316- ENABLE_USER_SCRIPT_SANDBOXING = YES;
317- GCC_C_LANGUAGE_STANDARD = gnu17;
318- GCC_DYNAMIC_NO_PIC = NO;
319- GCC_NO_COMMON_BLOCKS = YES;
320- GCC_OPTIMIZATION_LEVEL = 0;
321- GCC_PREPROCESSOR_DEFINITIONS = (
322- "DEBUG=1",
323- "$(inherited)",
324- );
325- GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
326- GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
327- GCC_WARN_UNDECLARED_SELECTOR = YES;
328- GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
329- GCC_WARN_UNUSED_FUNCTION = YES;
330- GCC_WARN_UNUSED_VARIABLE = YES;
331- IPHONEOS_DEPLOYMENT_TARGET = 17.5;
332- LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
333- MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
334- MTL_FAST_MATH = YES;
335- ONLY_ACTIVE_ARCH = YES;
336- SDKROOT = iphoneos;
337- SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG $(inherited)";
338- SWIFT_OPTIMIZATION_LEVEL = "-Onone";
339- VERSIONING_SYSTEM = "apple-generic";
340- VERSION_INFO_PREFIX = "";
341- };
342- name = Debug;
343- };
344- 5CCBC60E2CA1F04A00E958D0 /* Release */ = {
345- isa = XCBuildConfiguration;
346- buildSettings = {
347- ALWAYS_SEARCH_USER_PATHS = NO;
348- ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
349- CLANG_ANALYZER_NONNULL = YES;
350- CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
351- CLANG_CXX_LANGUAGE_STANDARD = "gnu++20";
352- CLANG_ENABLE_MODULES = YES;
353- CLANG_ENABLE_OBJC_ARC = YES;
354- CLANG_ENABLE_OBJC_WEAK = YES;
355- CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
356- CLANG_WARN_BOOL_CONVERSION = YES;
357- CLANG_WARN_COMMA = YES;
358- CLANG_WARN_CONSTANT_CONVERSION = YES;
359- CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
360- CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
361- CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
362- CLANG_WARN_EMPTY_BODY = YES;
363- CLANG_WARN_ENUM_CONVERSION = YES;
364- CLANG_WARN_INFINITE_RECURSION = YES;
365- CLANG_WARN_INT_CONVERSION = YES;
366- CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
367- CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
368- CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
369- CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
370- CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
371- CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
372- CLANG_WARN_STRICT_PROTOTYPES = YES;
373- CLANG_WARN_SUSPICIOUS_MOVE = YES;
374- CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
375- CLANG_WARN_UNREACHABLE_CODE = YES;
376- CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
377- COPY_PHASE_STRIP = NO;
378- CURRENT_PROJECT_VERSION = 1;
379- DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
380- ENABLE_NS_ASSERTIONS = NO;
381- ENABLE_STRICT_OBJC_MSGSEND = YES;
382- ENABLE_USER_SCRIPT_SANDBOXING = YES;
383- GCC_C_LANGUAGE_STANDARD = gnu17;
384- GCC_NO_COMMON_BLOCKS = YES;
385- GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
386- GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
387- GCC_WARN_UNDECLARED_SELECTOR = YES;
388- GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
389- GCC_WARN_UNUSED_FUNCTION = YES;
390- GCC_WARN_UNUSED_VARIABLE = YES;
391- IPHONEOS_DEPLOYMENT_TARGET = 17.5;
392- LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
393- MTL_ENABLE_DEBUG_INFO = NO;
394- MTL_FAST_MATH = YES;
395- SDKROOT = iphoneos;
396- SWIFT_COMPILATION_MODE = wholemodule;
397- VALIDATE_PRODUCT = YES;
398- VERSIONING_SYSTEM = "apple-generic";
399- VERSION_INFO_PREFIX = "";
400- };
401- name = Release;
402- };
403- 5CCBC6102CA1F04A00E958D0 /* Debug */ = {
404- isa = XCBuildConfiguration;
405- buildSettings = {
406- BUILD_LIBRARY_FOR_DISTRIBUTION = YES;
407- CLANG_ENABLE_MODULES = YES;
408- CODE_SIGN_STYLE = Automatic;
409- CURRENT_PROJECT_VERSION = 1;
410- DEFINES_MODULE = YES;
411- DYLIB_COMPATIBILITY_VERSION = 1;
412- DYLIB_CURRENT_VERSION = 1;
413- DYLIB_INSTALL_NAME_BASE = "@rpath";
414- ENABLE_MODULE_VERIFIER = YES;
415- GENERATE_INFOPLIST_FILE = YES;
416- HEADER_SEARCH_PATHS = "";
417- INFOPLIST_KEY_NSHumanReadableCopyright = "";
418- INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
419- LD_RUNPATH_SEARCH_PATHS = (
420- "$(inherited)",
421- "@executable_path/Frameworks",
422- "@loader_path/Frameworks",
423- );
424- MARKETING_VERSION = 1.0;
425- MODULE_VERIFIER_SUPPORTED_LANGUAGES = "objective-c objective-c++";
426- MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu17 gnu++20";
427- OTHER_LDFLAGS = "";
428- PRODUCT_BUNDLE_IDENTIFIER = meta.llamatsack.LocalInferenceProvider;
429- PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
430- SKIP_INSTALL = YES;
431- SWIFT_EMIT_LOC_STRINGS = YES;
432- SWIFT_INSTALL_OBJC_HEADER = NO;
433- SWIFT_OPTIMIZATION_LEVEL = "-Onone";
434- SWIFT_VERSION = 5.0;
435- TARGETED_DEVICE_FAMILY = "1,2";
436- };
437- name = Debug;
438- };
439- 5CCBC6112CA1F04A00E958D0 /* Release */ = {
440- isa = XCBuildConfiguration;
441- buildSettings = {
442- BUILD_LIBRARY_FOR_DISTRIBUTION = YES;
443- CLANG_ENABLE_MODULES = YES;
444- CODE_SIGN_STYLE = Automatic;
445- CURRENT_PROJECT_VERSION = 1;
446- DEFINES_MODULE = YES;
447- DYLIB_COMPATIBILITY_VERSION = 1;
448- DYLIB_CURRENT_VERSION = 1;
449- DYLIB_INSTALL_NAME_BASE = "@rpath";
450- ENABLE_MODULE_VERIFIER = YES;
451- GENERATE_INFOPLIST_FILE = YES;
452- HEADER_SEARCH_PATHS = "";
453- INFOPLIST_KEY_NSHumanReadableCopyright = "";
454- INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
455- LD_RUNPATH_SEARCH_PATHS = (
456- "$(inherited)",
457- "@executable_path/Frameworks",
458- "@loader_path/Frameworks",
459- );
460- MARKETING_VERSION = 1.0;
461- MODULE_VERIFIER_SUPPORTED_LANGUAGES = "objective-c objective-c++";
462- MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu17 gnu++20";
463- OTHER_LDFLAGS = "";
464- PRODUCT_BUNDLE_IDENTIFIER = meta.llamatsack.LocalInferenceProvider;
465- PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
466- SKIP_INSTALL = YES;
467- SWIFT_EMIT_LOC_STRINGS = YES;
468- SWIFT_INSTALL_OBJC_HEADER = NO;
469- SWIFT_VERSION = 5.0;
470- TARGETED_DEVICE_FAMILY = "1,2";
471- };
472- name = Release;
473- };
474-/* End XCBuildConfiguration section */
475-
476-/* Begin XCConfigurationList section */
477- 5CCBC6022CA1F04A00E958D0 /* Build configuration list for PBXProject "LocalInferenceImpl" */ = {
478- isa = XCConfigurationList;
479- buildConfigurations = (
480- 5CCBC60D2CA1F04A00E958D0 /* Debug */,
481- 5CCBC60E2CA1F04A00E958D0 /* Release */,
482- );
483- defaultConfigurationIsVisible = 0;
484- defaultConfigurationName = Release;
485- };
486- 5CCBC60F2CA1F04A00E958D0 /* Build configuration list for PBXNativeTarget "LocalInferenceImpl" */ = {
487- isa = XCConfigurationList;
488- buildConfigurations = (
489- 5CCBC6102CA1F04A00E958D0 /* Debug */,
490- 5CCBC6112CA1F04A00E958D0 /* Release */,
491- );
492- defaultConfigurationIsVisible = 0;
493- defaultConfigurationName = Release;
494- };
495-/* End XCConfigurationList section */
496-
497-/* Begin XCLocalSwiftPackageReference section */
498- 5CADC7182CA471CC007662D2 /* XCLocalSwiftPackageReference "internal-llama-stack-client-swift" */ = {
499- isa = XCLocalSwiftPackageReference;
500- relativePath = "internal-llama-stack-client-swift";
501- };
502-/* End XCLocalSwiftPackageReference section */
503-
504-/* Begin XCRemoteSwiftPackageReference section */
505- 5CCBC6732CA1F45800E958D0 /* XCRemoteSwiftPackageReference "executorch" */ = {
506- isa = XCRemoteSwiftPackageReference;
507- repositoryURL = "https://github.com/pytorch/executorch";
508- requirement = {
509- branch = latest;
510- kind = branch;
511- };
512- };
513- 5CCBC6912CA1F7D000E958D0 /* XCRemoteSwiftPackageReference "Stencil" */ = {
514- isa = XCRemoteSwiftPackageReference;
515- repositoryURL = "https://github.com/stencilproject/Stencil";
516- requirement = {
517- kind = upToNextMajorVersion;
518- minimumVersion = 0.15.1;
519- };
520- };
521-/* End XCRemoteSwiftPackageReference section */
522-
523-/* Begin XCSwiftPackageProductDependency section */
524- 5CADC7192CA471CC007662D2 /* LlamaStackClient */ = {
525- isa = XCSwiftPackageProductDependency;
526- productName = LlamaStackClient;
527- };
528- 5CCBC6742CA1F45800E958D0 /* executorch_debug */ = {
529- isa = XCSwiftPackageProductDependency;
530- package = 5CCBC6732CA1F45800E958D0 /* XCRemoteSwiftPackageReference "executorch" */;
531- productName = executorch_debug;
532- };
533- 5CCBC6922CA1F7D000E958D0 /* Stencil */ = {
534- isa = XCSwiftPackageProductDependency;
535- package = 5CCBC6912CA1F7D000E958D0 /* XCRemoteSwiftPackageReference "Stencil" */;
536- productName = Stencil;
537- };
538-/* End XCSwiftPackageProductDependency section */
539- };
540- rootObject = 5CCBC5FF2CA1F04A00E958D0 /* Project object */;
541-}
deleted llama_stack/providers/impls/ios/inference/LocalInference/LocalInferenceImpl.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 −7
@@ -1,7 +0,0 @@
1-<?xml version="1.0" encoding="UTF-8"?>
2-<Workspace
3- version = "1.0">
4- <FileRef
5- location = "self:">
6- </FileRef>
7-</Workspace>
deleted llama_stack/providers/impls/ios/inference/LocalInference/LocalInferenceImpl.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 −8
@@ -1,8 +0,0 @@
1-<?xml version="1.0" encoding="UTF-8"?>
2-<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3-<plist version="1.0">
4-<dict>
5- <key>IDEDidComputeMac32BitWarning</key>
6- <true/>
7-</dict>
8-</plist>
deleted llama_stack/providers/impls/ios/inference/LocalInference/LocalInferenceImpl/LocalInference.h +0 −16
@@ -1,16 +0,0 @@
1-//
2-// LocalInference.h
3-// LocalInference
4-//
5-// Created by Dalton Flanagan on 9/23/24.
6-//
7-
8-#import <Foundation/Foundation.h>
9-
10-//! Project version number for LocalInference.
11-FOUNDATION_EXPORT double LocalInferenceVersionNumber;
12-
13-//! Project version string for LocalInference.
14-FOUNDATION_EXPORT const unsigned char LocalInferenceVersionString[];
15-
16-// In this header, you should import all the public headers of your framework using statements like #import <LocalInference/PublicHeader.h>
deleted llama_stack/providers/impls/ios/inference/LocalInference/LocalInferenceImpl/LocalInference.swift +0 −167
@@ -1,167 +0,0 @@
1-import Foundation
2-
3-import LLaMARunner
4-import LlamaStackClient
5-
6-class RunnerHolder: ObservableObject {
7- var runner: Runner?
8-}
9-
10-public class LocalInference: Inference {
11- private var runnerHolder = RunnerHolder()
12- private let runnerQueue: DispatchQueue
13-
14- public init (queue: DispatchQueue) {
15- runnerQueue = queue
16- }
17-
18- public func loadModel(modelPath: String, tokenizerPath: String, completion: @escaping (Result<Void, Error>) -> Void) {
19- runnerHolder.runner = runnerHolder.runner ?? Runner(
20- modelPath: modelPath,
21- tokenizerPath: tokenizerPath
22- )
23-
24-
25- runnerQueue.async {
26- let runner = self.runnerHolder.runner
27- do {
28- try runner!.load()
29- completion(.success(()))
30- } catch let loadError {
31- print("error: " + loadError.localizedDescription)
32- completion(.failure(loadError))
33- }
34- }
35- }
36-
37- public func chatCompletion(request: Components.Schemas.ChatCompletionRequest) -> AsyncStream<Components.Schemas.ChatCompletionResponseStreamChunk> {
38- return AsyncStream { continuation in
39- runnerQueue.async {
40- do {
41- var tokens: [String] = []
42-
43- let prompt = try encodeDialogPrompt(messages: prepareMessages(request: request))
44- var stopReason: Components.Schemas.StopReason? = nil
45- var buffer = ""
46- var ipython = false
47- var echoDropped = false
48-
49- try self.runnerHolder.runner?.generate(prompt, sequenceLength: 4096) { token in
50- buffer += token
51-
52- // HACK: Workaround until LlamaRunner exposes echo param
53- if (!echoDropped) {
54- if (buffer.hasPrefix(prompt)) {
55- buffer = String(buffer.dropFirst(prompt.count))
56- echoDropped = true
57- }
58- return
59- }
60-
61- tokens.append(token)
62-
63- if !ipython && (buffer.starts(with: "<|python_tag|>") || buffer.starts(with: "[") ) {
64- ipython = true
65- continuation.yield(
66- Components.Schemas.ChatCompletionResponseStreamChunk(
67- event: Components.Schemas.ChatCompletionResponseEvent(
68- delta: .ToolCallDelta(Components.Schemas.ToolCallDelta(
69- content: .case1(""),
70- parse_status: Components.Schemas.ToolCallParseStatus.started
71- )
72- ),
73- event_type: .progress
74- )
75- )
76- )
77-
78- if (buffer.starts(with: "<|python_tag|>")) {
79- buffer = String(buffer.dropFirst("<|python_tag|>".count))
80- }
81- }
82-
83- // TODO: Non-streaming lobprobs
84-
85- var text = ""
86- if token == "<|eot_id|>" {
87- stopReason = Components.Schemas.StopReason.end_of_turn
88- } else if token == "<|eom_id|>" {
89- stopReason = Components.Schemas.StopReason.end_of_message
90- } else {
91- text = token
92- }
93-
94- var delta: Components.Schemas.ChatCompletionResponseEvent.deltaPayload
95- if ipython {
96- delta = .ToolCallDelta(Components.Schemas.ToolCallDelta(
97- content: .case1(text),
98- parse_status: .in_progress
99- ))
100- } else {
101- delta = .case1(text)
102- }
103-
104- if stopReason == nil {
105- continuation.yield(
106- Components.Schemas.ChatCompletionResponseStreamChunk(
107- event: Components.Schemas.ChatCompletionResponseEvent(
108- delta: delta,
109- event_type: .progress
110- )
111- )
112- )
113- }
114- }
115-
116- if stopReason == nil {
117- stopReason = Components.Schemas.StopReason.out_of_tokens
118- }
119-
120- let message = decodeAssistantMessage(tokens: tokens.joined(), stopReason: stopReason!)
121- // TODO: non-streaming support
122-
123- let didParseToolCalls = message.tool_calls.count > 0
124- if ipython && !didParseToolCalls {
125- continuation.yield(
126- Components.Schemas.ChatCompletionResponseStreamChunk(
127- event: Components.Schemas.ChatCompletionResponseEvent(
128- delta: .ToolCallDelta(Components.Schemas.ToolCallDelta(content: .case1(""), parse_status: .failure)),
129- event_type: .progress
130- )
131- // TODO: stopReason
132- )
133- )
134- }
135-
136- for toolCall in message.tool_calls {
137- continuation.yield(
138- Components.Schemas.ChatCompletionResponseStreamChunk(
139- event: Components.Schemas.ChatCompletionResponseEvent(
140- delta: .ToolCallDelta(Components.Schemas.ToolCallDelta(
141- content: .ToolCall(toolCall),
142- parse_status: .success
143- )),
144- event_type: .progress
145- )
146- // TODO: stopReason
147- )
148- )
149- }
150-
151- continuation.yield(
152- Components.Schemas.ChatCompletionResponseStreamChunk(
153- event: Components.Schemas.ChatCompletionResponseEvent(
154- delta: .case1(""),
155- event_type: .complete
156- )
157- // TODO: stopReason
158- )
159- )
160- }
161- catch (let error) {
162- print("Inference error: " + error.localizedDescription)
163- }
164- }
165- }
166- }
167-}
deleted llama_stack/providers/impls/ios/inference/LocalInference/LocalInferenceImpl/Parsing.swift +0 −235
@@ -1,235 +0,0 @@
1-import Foundation
2-
3-import LlamaStackClient
4-
5-func encodeHeader(role: String) -> String {
6- return "<|start_header_id|>\(role)<|end_header_id|>\n\n"
7-}
8-
9-func encodeDialogPrompt(messages: [Components.Schemas.ChatCompletionRequest.messagesPayloadPayload]) -> String {
10- var prompt = ""
11-
12- prompt.append("<|begin_of_text|>")
13- for message in messages {
14- let msg = encodeMessage(message: message)
15- prompt += msg
16- }
17-
18- prompt.append(encodeHeader(role: "assistant"))
19-
20- return prompt
21-}
22-
23-func getRole(message: Components.Schemas.ChatCompletionRequest.messagesPayloadPayload) -> String {
24- switch (message) {
25- case .UserMessage(let m):
26- return m.role.rawValue
27- case .SystemMessage(let m):
28- return m.role.rawValue
29- case .ToolResponseMessage(let m):
30- return m.role.rawValue
31- case .CompletionMessage(let m):
32- return m.role.rawValue
33- }
34-}
35-
36-func encodeMessage(message: Components.Schemas.ChatCompletionRequest.messagesPayloadPayload) -> String {
37- var prompt = encodeHeader(role: getRole(message: message))
38-
39- switch (message) {
40- case .CompletionMessage(let m):
41- if (m.tool_calls.count > 0) {
42- prompt += "<|python_tag|>"
43- }
44- default:
45- break
46- }
47-
48- func _processContent(_ content: Any) -> String {
49- func _process(_ c: Any) {
50- if let str = c as? String {
51- prompt += str
52- }
53- }
54-
55- if let str = content as? String {
56- _process(str)
57- } else if let list = content as? [Any] {
58- for c in list {
59- _process(c)
60- }
61- }
62-
63- return ""
64- }
65-
66- switch (message) {
67- case .UserMessage(let m):
68- prompt += _processContent(m.content)
69- case .SystemMessage(let m):
70- prompt += _processContent(m.content)
71- case .ToolResponseMessage(let m):
72- prompt += _processContent(m.content)
73- case .CompletionMessage(let m):
74- prompt += _processContent(m.content)
75- }
76-
77- var eom = false
78-
79- switch (message) {
80- case .UserMessage(let m):
81- switch (m.content) {
82- case .case1(let c):
83- prompt += _processContent(c)
84- case .case2(let c):
85- prompt += _processContent(c)
86- }
87- case .CompletionMessage(let m):
88- // TODO: Support encoding past tool call history
89- // for t in m.tool_calls {
90- // _processContent(t.)
91- //}
92- eom = m.stop_reason == Components.Schemas.StopReason.end_of_message
93- case .SystemMessage(_):
94- break
95- case .ToolResponseMessage(_):
96- break
97- }
98-
99- if (eom) {
100- prompt += "<|eom_id|>"
101- } else {
102- prompt += "<|eot_id|>"
103- }
104-
105- return prompt
106-}
107-
108-func prepareMessages(request: Components.Schemas.ChatCompletionRequest) throws -> [Components.Schemas.ChatCompletionRequest.messagesPayloadPayload] {
109- var existingMessages = request.messages
110- var existingSystemMessage: Components.Schemas.ChatCompletionRequest.messagesPayloadPayload?
111- // TODO: Existing system message
112-
113- var messages: [Components.Schemas.ChatCompletionRequest.messagesPayloadPayload] = []
114-
115- let defaultGen = SystemDefaultGenerator()
116- let defaultTemplate = defaultGen.gen()
117-
118- var sysContent = ""
119-
120- // TODO: Built-in tools
121-
122- sysContent += try defaultTemplate.render()
123-
124- messages.append(.SystemMessage(Components.Schemas.SystemMessage(
125- content: .case1(sysContent),
126- role: .system))
127- )
128-
129- if request.tools?.isEmpty == false {
130- // TODO: Separate built-ins and custom tools (right now everything treated as custom)
131- let toolGen = FunctionTagCustomToolGenerator()
132- let toolTemplate = try toolGen.gen(customTools: request.tools!)
133- let tools = try toolTemplate.render()
134- messages.append(.UserMessage(Components.Schemas.UserMessage(
135- content: .case1(tools),
136- role: .user)
137- ))
138- }
139-
140- messages.append(contentsOf: existingMessages)
141-
142- return messages
143-}
144-
145-struct FunctionCall {
146- let name: String
147- let params: [String: Any]
148-}
149-
150-public func maybeExtractCustomToolCalls(input: String) -> [Components.Schemas.ToolCall] {
151- guard input.hasPrefix("[") && input.hasSuffix("]") else {
152- return []
153- }
154-
155- do {
156- let trimmed = input.trimmingCharacters(in: CharacterSet(charactersIn: "[]"))
157- let calls = trimmed.components(separatedBy: "),").map { $0.hasSuffix(")") ? $0 : $0 + ")" }
158-
159- var result: [Components.Schemas.ToolCall] = []
160-
161- for call in calls {
162- guard let nameEndIndex = call.firstIndex(of: "("),
163- let paramsStartIndex = call.firstIndex(of: "{"),
164- let paramsEndIndex = call.lastIndex(of: "}") else {
165- return []
166- }
167-
168- let name = String(call[..<nameEndIndex]).trimmingCharacters(in: .whitespacesAndNewlines)
169- let paramsString = String(call[paramsStartIndex...paramsEndIndex])
170-
171- guard let data = paramsString.data(using: .utf8),
172- let params = try? JSONSerialization.jsonObject(with: data, options: []) as? [String: Any] else {
173- return []
174- }
175-
176- var props: [String : Components.Schemas.ToolCall.argumentsPayload.additionalPropertiesPayload] = [:]
177- for (param_name, param) in params {
178- switch (param) {
179- case let value as String:
180- props[param_name] = .case1(value)
181- case let value as Int:
182- props[param_name] = .case2(value)
183- case let value as Double:
184- props[param_name] = .case3(value)
185- case let value as Bool:
186- props[param_name] = .case4(value)
187- default:
188- return []
189- }
190- }
191-
192- result.append(
193- Components.Schemas.ToolCall(
194- arguments: .init(additionalProperties: props),
195- call_id: UUID().uuidString,
196- tool_name: .case2(name) // custom_tool
197- )
198- )
199- }
200-
201- return result.isEmpty ? [] : result
202- } catch {
203- return []
204- }
205-}
206-
207-func decodeAssistantMessage(tokens: String, stopReason: Components.Schemas.StopReason) -> Components.Schemas.CompletionMessage {
208- var content = tokens
209-
210- let roles = ["user", "system", "assistant"]
211- for role in roles {
212- let headerStr = encodeHeader(role: role)
213- if content.hasPrefix(headerStr) {
214- content = String(content.dropFirst(encodeHeader(role: role).count))
215- }
216- }
217-
218- if content.hasPrefix("<|python_tag|>") {
219- content = String(content.dropFirst("<|python_tag|>".count))
220- }
221-
222-
223- if content.hasSuffix("<|eot_id|>") {
224- content = String(content.dropLast("<|eot_id|>".count))
225- } else {
226- content = String(content.dropLast("<|eom_id|>".count))
227- }
228-
229- return Components.Schemas.CompletionMessage(
230- content: .case1(content),
231- role: .assistant,
232- stop_reason: stopReason,
233- tool_calls: maybeExtractCustomToolCalls(input: content)
234- )
235-}
deleted llama_stack/providers/impls/ios/inference/LocalInference/LocalInferenceImpl/PromptTemplate.swift +0 −12
@@ -1,12 +0,0 @@
1-import Foundation
2-import Stencil
3-
4-public struct PromptTemplate {
5- let template: String
6- let data: [String: Any]
7-
8- public func render() throws -> String {
9- let template = Template(templateString: self.template)
10- return try template.render(self.data)
11- }
12-}
deleted llama_stack/providers/impls/ios/inference/LocalInference/LocalInferenceImpl/SystemPrompts.swift +0 −91
@@ -1,91 +0,0 @@
1-import Foundation
2-
3-import LlamaStackClient
4-
5-func convertToNativeSwiftType(_ value: Any) -> Any {
6- switch value {
7- case let number as NSNumber:
8- if CFGetTypeID(number) == CFBooleanGetTypeID() {
9- return number.boolValue
10- }
11- if floor(number.doubleValue) == number.doubleValue {
12- return number.intValue
13- }
14- return number.doubleValue
15- case let string as String:
16- return string
17- case let array as [Any]:
18- return array.map(convertToNativeSwiftType)
19- case let dict as [String: Any]:
20- return dict.mapValues(convertToNativeSwiftType)
21- case is NSNull:
22- return NSNull()
23- default:
24- return value
25- }
26-}
27-
28-public class SystemDefaultGenerator {
29- public init() {}
30-
31- public func gen() -> PromptTemplate {
32- let templateStr = """
33- Cutting Knowledge Date: December 2023
34- Today Date: {{ today }}
35- """
36-
37- let dateFormatter = DateFormatter()
38- dateFormatter.dateFormat = "dd MMMM yyyy"
39-
40- return PromptTemplate(
41- template: templateStr,
42- data: ["today": dateFormatter.string(from: Date())]
43- )
44- }
45-}
46-
47-
48-public class FunctionTagCustomToolGenerator {
49- public init() {}
50-
51- public func gen(customTools: [Components.Schemas.ToolDefinition]) throws -> PromptTemplate {
52- // TODO: required params
53- // TODO: {{#unless @last}},{{/unless}}
54-
55- let templateStr = """
56- You are an expert in composing functions. You are given a question and a set of possible functions.
57- Based on the question, you will need to make one or more function/tool calls to achieve the purpose.
58- If none of the function can be used, point it out. If the given question lacks the parameters required by the function,
59- also point it out. You should only return the function call in tools call sections.
60-
61- 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)]
62- You SHOULD NOT include any other text in the response.
63-
64- Here is a list of functions in JSON format that you can invoke.
65-
66- [
67- {% for t in custom_tools %}
68- {
69- "name": "{{t.tool_name}}",
70- "description": "{{t.description}}",
71- "parameters": {
72- "type": "dict",
73- "properties": { {{t.parameters}} }
74- }
75-
76- {{/let}}
77- {% endfor -%}
78- ]
79- """
80-
81- let encoder = JSONEncoder()
82- return PromptTemplate(
83- template: templateStr,
84- data: ["custom_tools": try customTools.map {
85- let data = try encoder.encode($0)
86- let obj = try JSONSerialization.jsonObject(with: data)
87- return convertToNativeSwiftType(obj)
88- }]
89- )
90- }
91-}
deleted llama_stack/providers/impls/ios/inference/LocalInference/README.md +0 −109
@@ -1,109 +0,0 @@
1-# LocalInference
2-
3-LocalInference provides a local inference implementation powered by [executorch](https://github.com/pytorch/executorch/).
4-
5-Llama Stack currently supports on-device inference for iOS with Android coming soon. You can run on-device inference on Android today using [executorch](https://github.com/pytorch/executorch/tree/main/examples/demo-apps/android/LlamaDemo), PyTorch’s on-device inference library.
6-
7-## Installation
8-
9-We're working on making LocalInference easier to set up. For now, you'll need to import it via `.xcframework`:
10-
11-1. Clone the executorch submodule in this repo and its dependencies: `git submodule update --init --recursive`
12-1. Install [Cmake](https://cmake.org/) for the executorch build`
13-1. Drag `LocalInference.xcodeproj` into your project
14-1. Add `LocalInference` as a framework in your app target
15-1. Add a package dependency on https://github.com/pytorch/executorch (branch latest)
16-1. Add all the kernels / backends from executorch (but not exectuorch itself!) as frameworks in your app target:
17- - backend_coreml
18- - backend_mps
19- - backend_xnnpack
20- - kernels_custom
21- - kernels_optimized
22- - kernels_portable
23- - kernels_quantized
24-1. In "Build Settings" > "Other Linker Flags" > "Any iOS Simulator SDK", add:
25- ```
26- -force_load
27- $(BUILT_PRODUCTS_DIR)/libkernels_optimized-simulator-release.a
28- -force_load
29- $(BUILT_PRODUCTS_DIR)/libkernels_custom-simulator-release.a
30- -force_load
31- $(BUILT_PRODUCTS_DIR)/libkernels_quantized-simulator-release.a
32- -force_load
33- $(BUILT_PRODUCTS_DIR)/libbackend_xnnpack-simulator-release.a
34- -force_load
35- $(BUILT_PRODUCTS_DIR)/libbackend_coreml-simulator-release.a
36- -force_load
37- $(BUILT_PRODUCTS_DIR)/libbackend_mps-simulator-release.a
38- ```
39-
40-1. In "Build Settings" > "Other Linker Flags" > "Any iOS SDK", add:
41-
42- ```
43- -force_load
44- $(BUILT_PRODUCTS_DIR)/libkernels_optimized-simulator-release.a
45- -force_load
46- $(BUILT_PRODUCTS_DIR)/libkernels_custom-simulator-release.a
47- -force_load
48- $(BUILT_PRODUCTS_DIR)/libkernels_quantized-simulator-release.a
49- -force_load
50- $(BUILT_PRODUCTS_DIR)/libbackend_xnnpack-simulator-release.a
51- -force_load
52- $(BUILT_PRODUCTS_DIR)/libbackend_coreml-simulator-release.a
53- -force_load
54- $(BUILT_PRODUCTS_DIR)/libbackend_mps-simulator-release.a
55- ```
56-
57-## Preparing a model
58-
59-1. Prepare a `.pte` file [following the executorch docs](https://github.com/pytorch/executorch/blob/main/examples/models/llama2/README.md#step-2-prepare-model)
60-2. Bundle the `.pte` and `tokenizer.model` file into your app
61-
62-## Using LocalInference
63-
64-1. Instantiate LocalInference with a DispatchQueue. Optionally, pass it into your agents service:
65-
66-```swift
67- init () {
68- runnerQueue = DispatchQueue(label: "org.meta.llamastack")
69- inferenceService = LocalInferenceService(queue: runnerQueue)
70- agentsService = LocalAgentsService(inference: inferenceService)
71- }
72-```
73-
74-2. Before making any inference calls, load your model from your bundle:
75-
76-```swift
77-let mainBundle = Bundle.main
78-inferenceService.loadModel(
79- modelPath: mainBundle.url(forResource: "llama32_1b_spinquant", withExtension: "pte"),
80- tokenizerPath: mainBundle.url(forResource: "tokenizer", withExtension: "model"),
81- completion: {_ in } // use to handle load failures
82-)
83-```
84-
85-3. Make inference calls (or agents calls) as you normally would with LlamaStack:
86-
87-```
88-for await chunk in try await agentsService.initAndCreateTurn(
89- messages: [
90- .UserMessage(Components.Schemas.UserMessage(
91- content: .case1("Call functions as needed to handle any actions in the following text:\n\n" + text),
92- role: .user))
93- ]
94-) {
95-```
96-
97-## Troubleshooting
98-
99-If you receive errors like "missing package product" or "invalid checksum", try cleaning the build folder and resetting the Swift package cache:
100-
101-(Opt+Click) Product > Clean Build Folder Immediately
102-
103-```
104-rm -rf \
105- ~/Library/org.swift.swiftpm \
106- ~/Library/Caches/org.swift.swiftpm \
107- ~/Library/Caches/com.apple.dt.Xcode \
108- ~/Library/Developer/Xcode/DerivedData
109-```
added llama_stack/providers/impls/ios/inference/LocalInferenceImpl.xcodeproj/project.pbxproj +550 −0
@@ -0,0 +1,550 @@
1+// !$*UTF8*$!
2+{
3+ archiveVersion = 1;
4+ classes = {
5+ };
6+ objectVersion = 56;
7+ objects = {
8+
9+/* Begin PBXBuildFile section */
10+ 5CADC71A2CA471CC007662D2 /* LlamaStackClient in Frameworks */ = {isa = PBXBuildFile; productRef = 5CADC7192CA471CC007662D2 /* LlamaStackClient */; };
11+ 5CAF3DD82CA485740029CD2B /* LlamaStackClient in Frameworks */ = {isa = PBXBuildFile; productRef = 5CAF3DD72CA485740029CD2B /* LlamaStackClient */; };
12+ 5CCBC60C2CA1F04A00E958D0 /* LocalInference.h in Headers */ = {isa = PBXBuildFile; fileRef = 5CCBC60B2CA1F04A00E958D0 /* LocalInference.h */; settings = {ATTRIBUTES = (Public, ); }; };
13+ 5CCBC6752CA1F45800E958D0 /* executorch_debug in Frameworks */ = {isa = PBXBuildFile; productRef = 5CCBC6742CA1F45800E958D0 /* executorch_debug */; };
14+ 5CCBC6862CA1F64A00E958D0 /* LLaMARunner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5CCBC6802CA1F63F00E958D0 /* LLaMARunner.framework */; platformFilter = ios; };
15+ 5CCBC6872CA1F64A00E958D0 /* LLaMARunner.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 5CCBC6802CA1F63F00E958D0 /* LLaMARunner.framework */; platformFilter = ios; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
16+ 5CCBC68D2CA1F7A100E958D0 /* PromptTemplate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5CCBC6892CA1F7A000E958D0 /* PromptTemplate.swift */; };
17+ 5CCBC68E2CA1F7A100E958D0 /* LocalInference.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5CCBC68A2CA1F7A000E958D0 /* LocalInference.swift */; };
18+ 5CCBC68F2CA1F7A100E958D0 /* Parsing.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5CCBC68B2CA1F7A000E958D0 /* Parsing.swift */; };
19+ 5CCBC6902CA1F7A100E958D0 /* SystemPrompts.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5CCBC68C2CA1F7A100E958D0 /* SystemPrompts.swift */; };
20+ 5CCBC6932CA1F7D000E958D0 /* Stencil in Frameworks */ = {isa = PBXBuildFile; productRef = 5CCBC6922CA1F7D000E958D0 /* Stencil */; };
21+/* End PBXBuildFile section */
22+
23+/* Begin PBXContainerItemProxy section */
24+ 5CCBC67D2CA1F63F00E958D0 /* PBXContainerItemProxy */ = {
25+ isa = PBXContainerItemProxy;
26+ containerPortal = 5CCBC6762CA1F63F00E958D0 /* LLaMA.xcodeproj */;
27+ proxyType = 2;
28+ remoteGlobalIDString = 036CAF9D2BB1444500D6C2D5;
29+ remoteInfo = LLaMA;
30+ };
31+ 5CCBC67F2CA1F63F00E958D0 /* PBXContainerItemProxy */ = {
32+ isa = PBXContainerItemProxy;
33+ containerPortal = 5CCBC6762CA1F63F00E958D0 /* LLaMA.xcodeproj */;
34+ proxyType = 2;
35+ remoteGlobalIDString = 03729ED52BB1F8DE00152F2E;
36+ remoteInfo = LLaMARunner;
37+ };
38+ 5CCBC69E2CA2036B00E958D0 /* PBXContainerItemProxy */ = {
39+ isa = PBXContainerItemProxy;
40+ containerPortal = 5CCBC6762CA1F63F00E958D0 /* LLaMA.xcodeproj */;
41+ proxyType = 2;
42+ remoteGlobalIDString = 5CCBC6982CA2036A00E958D0;
43+ remoteInfo = LLaMAPerfBenchmark;
44+ };
45+ 5CCBC6A02CA2036B00E958D0 /* PBXContainerItemProxy */ = {
46+ isa = PBXContainerItemProxy;
47+ containerPortal = 5CCBC6762CA1F63F00E958D0 /* LLaMA.xcodeproj */;
48+ proxyType = 2;
49+ remoteGlobalIDString = 5CCBC6992CA2036A00E958D0;
50+ remoteInfo = LLaMAPerfBenchmarkTests;
51+ };
52+/* End PBXContainerItemProxy section */
53+
54+/* Begin PBXCopyFilesBuildPhase section */
55+ 5CCBC6882CA1F64A00E958D0 /* Embed Frameworks */ = {
56+ isa = PBXCopyFilesBuildPhase;
57+ buildActionMask = 2147483647;
58+ dstPath = "";
59+ dstSubfolderSpec = 10;
60+ files = (
61+ 5CCBC6872CA1F64A00E958D0 /* LLaMARunner.framework in Embed Frameworks */,
62+ );
63+ name = "Embed Frameworks";
64+ runOnlyForDeploymentPostprocessing = 0;
65+ };
66+/* End PBXCopyFilesBuildPhase section */
67+
68+/* Begin PBXFileReference section */
69+ 5CCBC6082CA1F04A00E958D0 /* LocalInferenceImpl.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = LocalInferenceImpl.framework; sourceTree = BUILT_PRODUCTS_DIR; };
70+ 5CCBC60B2CA1F04A00E958D0 /* LocalInference.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LocalInference.h; sourceTree = "<group>"; };
71+ 5CCBC6762CA1F63F00E958D0 /* LLaMA.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = LLaMA.xcodeproj; path = "executorch/examples/demo-apps/apple_ios/LLaMA/LLaMA.xcodeproj"; sourceTree = "<group>"; };
72+ 5CCBC6892CA1F7A000E958D0 /* PromptTemplate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PromptTemplate.swift; sourceTree = "<group>"; };
73+ 5CCBC68A2CA1F7A000E958D0 /* LocalInference.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LocalInference.swift; sourceTree = "<group>"; };
74+ 5CCBC68B2CA1F7A000E958D0 /* Parsing.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Parsing.swift; sourceTree = "<group>"; };
75+ 5CCBC68C2CA1F7A100E958D0 /* SystemPrompts.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SystemPrompts.swift; sourceTree = "<group>"; };
76+/* End PBXFileReference section */
77+
78+/* Begin PBXFrameworksBuildPhase section */
79+ 5CCBC6052CA1F04A00E958D0 /* Frameworks */ = {
80+ isa = PBXFrameworksBuildPhase;
81+ buildActionMask = 2147483647;
82+ files = (
83+ 5CADC71A2CA471CC007662D2 /* LlamaStackClient in Frameworks */,
84+ 5CAF3DD82CA485740029CD2B /* LlamaStackClient in Frameworks */,
85+ 5CCBC6932CA1F7D000E958D0 /* Stencil in Frameworks */,
86+ 5CCBC6862CA1F64A00E958D0 /* LLaMARunner.framework in Frameworks */,
87+ 5CCBC6752CA1F45800E958D0 /* executorch_debug in Frameworks */,
88+ );
89+ runOnlyForDeploymentPostprocessing = 0;
90+ };
91+/* End PBXFrameworksBuildPhase section */
92+
93+/* Begin PBXGroup section */
94+ 5CCBC5FE2CA1F04A00E958D0 = {
95+ isa = PBXGroup;
96+ children = (
97+ 5CCBC6762CA1F63F00E958D0 /* LLaMA.xcodeproj */,
98+ 5CCBC60A2CA1F04A00E958D0 /* LocalInferenceImpl */,
99+ 5CCBC6092CA1F04A00E958D0 /* Products */,
100+ 5CCBC6852CA1F64A00E958D0 /* Frameworks */,
101+ );
102+ sourceTree = "<group>";
103+ };
104+ 5CCBC6092CA1F04A00E958D0 /* Products */ = {
105+ isa = PBXGroup;
106+ children = (
107+ 5CCBC6082CA1F04A00E958D0 /* LocalInferenceImpl.framework */,
108+ );
109+ name = Products;
110+ sourceTree = "<group>";
111+ };
112+ 5CCBC60A2CA1F04A00E958D0 /* LocalInferenceImpl */ = {
113+ isa = PBXGroup;
114+ children = (
115+ 5CCBC68A2CA1F7A000E958D0 /* LocalInference.swift */,
116+ 5CCBC68B2CA1F7A000E958D0 /* Parsing.swift */,
117+ 5CCBC6892CA1F7A000E958D0 /* PromptTemplate.swift */,
118+ 5CCBC68C2CA1F7A100E958D0 /* SystemPrompts.swift */,
119+ 5CCBC60B2CA1F04A00E958D0 /* LocalInference.h */,
120+ );
121+ path = LocalInferenceImpl;
122+ sourceTree = "<group>";
123+ };
124+ 5CCBC6772CA1F63F00E958D0 /* Products */ = {
125+ isa = PBXGroup;
126+ children = (
127+ 5CCBC67E2CA1F63F00E958D0 /* LLaMA.app */,
128+ 5CCBC6802CA1F63F00E958D0 /* LLaMARunner.framework */,
129+ 5CCBC69F2CA2036B00E958D0 /* LLaMAPerfBenchmark.app */,
130+ 5CCBC6A12CA2036B00E958D0 /* LLaMAPerfBenchmarkTests.xctest */,
131+ );
132+ name = Products;
133+ sourceTree = "<group>";
134+ };
135+ 5CCBC6852CA1F64A00E958D0 /* Frameworks */ = {
136+ isa = PBXGroup;
137+ children = (
138+ );
139+ name = Frameworks;
140+ sourceTree = "<group>";
141+ };
142+/* End PBXGroup section */
143+
144+/* Begin PBXHeadersBuildPhase section */
145+ 5CCBC6032CA1F04A00E958D0 /* Headers */ = {
146+ isa = PBXHeadersBuildPhase;
147+ buildActionMask = 2147483647;
148+ files = (
149+ 5CCBC60C2CA1F04A00E958D0 /* LocalInference.h in Headers */,
150+ );
151+ runOnlyForDeploymentPostprocessing = 0;
152+ };
153+/* End PBXHeadersBuildPhase section */
154+
155+/* Begin PBXNativeTarget section */
156+ 5CCBC6072CA1F04A00E958D0 /* LocalInferenceImpl */ = {
157+ isa = PBXNativeTarget;
158+ buildConfigurationList = 5CCBC60F2CA1F04A00E958D0 /* Build configuration list for PBXNativeTarget "LocalInferenceImpl" */;
159+ buildPhases = (
160+ 5CCBC6032CA1F04A00E958D0 /* Headers */,
161+ 5CCBC6042CA1F04A00E958D0 /* Sources */,
162+ 5CCBC6052CA1F04A00E958D0 /* Frameworks */,
163+ 5CCBC6062CA1F04A00E958D0 /* Resources */,
164+ 5CCBC6882CA1F64A00E958D0 /* Embed Frameworks */,
165+ );
166+ buildRules = (
167+ );
168+ dependencies = (
169+ );
170+ name = LocalInferenceImpl;
171+ packageProductDependencies = (
172+ 5CCBC6742CA1F45800E958D0 /* executorch_debug */,
173+ 5CCBC6922CA1F7D000E958D0 /* Stencil */,
174+ 5CADC7192CA471CC007662D2 /* LlamaStackClient */,
175+ 5CAF3DD72CA485740029CD2B /* LlamaStackClient */,
176+ );
177+ productName = LocalInferenceProvider;
178+ productReference = 5CCBC6082CA1F04A00E958D0 /* LocalInferenceImpl.framework */;
179+ productType = "com.apple.product-type.framework";
180+ };
181+/* End PBXNativeTarget section */
182+
183+/* Begin PBXProject section */
184+ 5CCBC5FF2CA1F04A00E958D0 /* Project object */ = {
185+ isa = PBXProject;
186+ attributes = {
187+ BuildIndependentTargetsInParallel = 1;
188+ LastUpgradeCheck = 1540;
189+ TargetAttributes = {
190+ 5CCBC6072CA1F04A00E958D0 = {
191+ CreatedOnToolsVersion = 15.4;
192+ LastSwiftMigration = 1540;
193+ };
194+ };
195+ };
196+ buildConfigurationList = 5CCBC6022CA1F04A00E958D0 /* Build configuration list for PBXProject "LocalInferenceImpl" */;
197+ compatibilityVersion = "Xcode 14.0";
198+ developmentRegion = en;
199+ hasScannedForEncodings = 0;
200+ knownRegions = (
201+ en,
202+ Base,
203+ );
204+ mainGroup = 5CCBC5FE2CA1F04A00E958D0;
205+ packageReferences = (
206+ 5CCBC6732CA1F45800E958D0 /* XCRemoteSwiftPackageReference "executorch" */,
207+ 5CCBC6912CA1F7D000E958D0 /* XCRemoteSwiftPackageReference "Stencil" */,
208+ 5CAF3DD62CA485740029CD2B /* XCRemoteSwiftPackageReference "llama-stack-client-swift" */,
209+ );
210+ productRefGroup = 5CCBC6092CA1F04A00E958D0 /* Products */;
211+ projectDirPath = "";
212+ projectReferences = (
213+ {
214+ ProductGroup = 5CCBC6772CA1F63F00E958D0 /* Products */;
215+ ProjectRef = 5CCBC6762CA1F63F00E958D0 /* LLaMA.xcodeproj */;
216+ },
217+ );
218+ projectRoot = "";
219+ targets = (
220+ 5CCBC6072CA1F04A00E958D0 /* LocalInferenceImpl */,
221+ );
222+ };
223+/* End PBXProject section */
224+
225+/* Begin PBXReferenceProxy section */
226+ 5CCBC67E2CA1F63F00E958D0 /* LLaMA.app */ = {
227+ isa = PBXReferenceProxy;
228+ fileType = wrapper.application;
229+ path = LLaMA.app;
230+ remoteRef = 5CCBC67D2CA1F63F00E958D0 /* PBXContainerItemProxy */;
231+ sourceTree = BUILT_PRODUCTS_DIR;
232+ };
233+ 5CCBC6802CA1F63F00E958D0 /* LLaMARunner.framework */ = {
234+ isa = PBXReferenceProxy;
235+ fileType = wrapper.framework;
236+ path = LLaMARunner.framework;
237+ remoteRef = 5CCBC67F2CA1F63F00E958D0 /* PBXContainerItemProxy */;
238+ sourceTree = BUILT_PRODUCTS_DIR;
239+ };
240+ 5CCBC69F2CA2036B00E958D0 /* LLaMAPerfBenchmark.app */ = {
241+ isa = PBXReferenceProxy;
242+ fileType = wrapper.application;
243+ path = LLaMAPerfBenchmark.app;
244+ remoteRef = 5CCBC69E2CA2036B00E958D0 /* PBXContainerItemProxy */;
245+ sourceTree = BUILT_PRODUCTS_DIR;
246+ };
247+ 5CCBC6A12CA2036B00E958D0 /* LLaMAPerfBenchmarkTests.xctest */ = {
248+ isa = PBXReferenceProxy;
249+ fileType = wrapper.cfbundle;
250+ path = LLaMAPerfBenchmarkTests.xctest;
251+ remoteRef = 5CCBC6A02CA2036B00E958D0 /* PBXContainerItemProxy */;
252+ sourceTree = BUILT_PRODUCTS_DIR;
253+ };
254+/* End PBXReferenceProxy section */
255+
256+/* Begin PBXResourcesBuildPhase section */
257+ 5CCBC6062CA1F04A00E958D0 /* Resources */ = {
258+ isa = PBXResourcesBuildPhase;
259+ buildActionMask = 2147483647;
260+ files = (
261+ );
262+ runOnlyForDeploymentPostprocessing = 0;
263+ };
264+/* End PBXResourcesBuildPhase section */
265+
266+/* Begin PBXSourcesBuildPhase section */
267+ 5CCBC6042CA1F04A00E958D0 /* Sources */ = {
268+ isa = PBXSourcesBuildPhase;
269+ buildActionMask = 2147483647;
270+ files = (
271+ 5CCBC6902CA1F7A100E958D0 /* SystemPrompts.swift in Sources */,
272+ 5CCBC68D2CA1F7A100E958D0 /* PromptTemplate.swift in Sources */,
273+ 5CCBC68F2CA1F7A100E958D0 /* Parsing.swift in Sources */,
274+ 5CCBC68E2CA1F7A100E958D0 /* LocalInference.swift in Sources */,
275+ );
276+ runOnlyForDeploymentPostprocessing = 0;
277+ };
278+/* End PBXSourcesBuildPhase section */
279+
280+/* Begin XCBuildConfiguration section */
281+ 5CCBC60D2CA1F04A00E958D0 /* Debug */ = {
282+ isa = XCBuildConfiguration;
283+ buildSettings = {
284+ ALWAYS_SEARCH_USER_PATHS = NO;
285+ ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
286+ CLANG_ANALYZER_NONNULL = YES;
287+ CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
288+ CLANG_CXX_LANGUAGE_STANDARD = "gnu++20";
289+ CLANG_ENABLE_MODULES = YES;
290+ CLANG_ENABLE_OBJC_ARC = YES;
291+ CLANG_ENABLE_OBJC_WEAK = YES;
292+ CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
293+ CLANG_WARN_BOOL_CONVERSION = YES;
294+ CLANG_WARN_COMMA = YES;
295+ CLANG_WARN_CONSTANT_CONVERSION = YES;
296+ CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
297+ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
298+ CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
299+ CLANG_WARN_EMPTY_BODY = YES;
300+ CLANG_WARN_ENUM_CONVERSION = YES;
301+ CLANG_WARN_INFINITE_RECURSION = YES;
302+ CLANG_WARN_INT_CONVERSION = YES;
303+ CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
304+ CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
305+ CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
306+ CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
307+ CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
308+ CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
309+ CLANG_WARN_STRICT_PROTOTYPES = YES;
310+ CLANG_WARN_SUSPICIOUS_MOVE = YES;
311+ CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
312+ CLANG_WARN_UNREACHABLE_CODE = YES;
313+ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
314+ COPY_PHASE_STRIP = NO;
315+ CURRENT_PROJECT_VERSION = 1;
316+ DEBUG_INFORMATION_FORMAT = dwarf;
317+ ENABLE_STRICT_OBJC_MSGSEND = YES;
318+ ENABLE_TESTABILITY = YES;
319+ ENABLE_USER_SCRIPT_SANDBOXING = YES;
320+ GCC_C_LANGUAGE_STANDARD = gnu17;
321+ GCC_DYNAMIC_NO_PIC = NO;
322+ GCC_NO_COMMON_BLOCKS = YES;
323+ GCC_OPTIMIZATION_LEVEL = 0;
324+ GCC_PREPROCESSOR_DEFINITIONS = (
325+ "DEBUG=1",
326+ "$(inherited)",
327+ );
328+ GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
329+ GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
330+ GCC_WARN_UNDECLARED_SELECTOR = YES;
331+ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
332+ GCC_WARN_UNUSED_FUNCTION = YES;
333+ GCC_WARN_UNUSED_VARIABLE = YES;
334+ IPHONEOS_DEPLOYMENT_TARGET = 17.5;
335+ LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
336+ MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
337+ MTL_FAST_MATH = YES;
338+ ONLY_ACTIVE_ARCH = YES;
339+ SDKROOT = iphoneos;
340+ SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG $(inherited)";
341+ SWIFT_OPTIMIZATION_LEVEL = "-Onone";
342+ VERSIONING_SYSTEM = "apple-generic";
343+ VERSION_INFO_PREFIX = "";
344+ };
345+ name = Debug;
346+ };
347+ 5CCBC60E2CA1F04A00E958D0 /* Release */ = {
348+ isa = XCBuildConfiguration;
349+ buildSettings = {
350+ ALWAYS_SEARCH_USER_PATHS = NO;
351+ ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
352+ CLANG_ANALYZER_NONNULL = YES;
353+ CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
354+ CLANG_CXX_LANGUAGE_STANDARD = "gnu++20";
355+ CLANG_ENABLE_MODULES = YES;
356+ CLANG_ENABLE_OBJC_ARC = YES;
357+ CLANG_ENABLE_OBJC_WEAK = YES;
358+ CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
359+ CLANG_WARN_BOOL_CONVERSION = YES;
360+ CLANG_WARN_COMMA = YES;
361+ CLANG_WARN_CONSTANT_CONVERSION = YES;
362+ CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
363+ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
364+ CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
365+ CLANG_WARN_EMPTY_BODY = YES;
366+ CLANG_WARN_ENUM_CONVERSION = YES;
367+ CLANG_WARN_INFINITE_RECURSION = YES;
368+ CLANG_WARN_INT_CONVERSION = YES;
369+ CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
370+ CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
371+ CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
372+ CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
373+ CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
374+ CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
375+ CLANG_WARN_STRICT_PROTOTYPES = YES;
376+ CLANG_WARN_SUSPICIOUS_MOVE = YES;
377+ CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
378+ CLANG_WARN_UNREACHABLE_CODE = YES;
379+ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
380+ COPY_PHASE_STRIP = NO;
381+ CURRENT_PROJECT_VERSION = 1;
382+ DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
383+ ENABLE_NS_ASSERTIONS = NO;
384+ ENABLE_STRICT_OBJC_MSGSEND = YES;
385+ ENABLE_USER_SCRIPT_SANDBOXING = YES;
386+ GCC_C_LANGUAGE_STANDARD = gnu17;
387+ GCC_NO_COMMON_BLOCKS = YES;
388+ GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
389+ GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
390+ GCC_WARN_UNDECLARED_SELECTOR = YES;
391+ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
392+ GCC_WARN_UNUSED_FUNCTION = YES;
393+ GCC_WARN_UNUSED_VARIABLE = YES;
394+ IPHONEOS_DEPLOYMENT_TARGET = 17.5;
395+ LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
396+ MTL_ENABLE_DEBUG_INFO = NO;
397+ MTL_FAST_MATH = YES;
398+ SDKROOT = iphoneos;
399+ SWIFT_COMPILATION_MODE = wholemodule;
400+ VALIDATE_PRODUCT = YES;
401+ VERSIONING_SYSTEM = "apple-generic";
402+ VERSION_INFO_PREFIX = "";
403+ };
404+ name = Release;
405+ };
406+ 5CCBC6102CA1F04A00E958D0 /* Debug */ = {
407+ isa = XCBuildConfiguration;
408+ buildSettings = {
409+ BUILD_LIBRARY_FOR_DISTRIBUTION = YES;
410+ CLANG_ENABLE_MODULES = YES;
411+ CODE_SIGN_STYLE = Automatic;
412+ CURRENT_PROJECT_VERSION = 1;
413+ DEFINES_MODULE = YES;
414+ DYLIB_COMPATIBILITY_VERSION = 1;
415+ DYLIB_CURRENT_VERSION = 1;
416+ DYLIB_INSTALL_NAME_BASE = "@rpath";
417+ ENABLE_MODULE_VERIFIER = YES;
418+ GENERATE_INFOPLIST_FILE = YES;
419+ HEADER_SEARCH_PATHS = "";
420+ INFOPLIST_KEY_NSHumanReadableCopyright = "";
421+ INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
422+ LD_RUNPATH_SEARCH_PATHS = (
423+ "$(inherited)",
424+ "@executable_path/Frameworks",
425+ "@loader_path/Frameworks",
426+ );
427+ MARKETING_VERSION = 1.0;
428+ MODULE_VERIFIER_SUPPORTED_LANGUAGES = "objective-c objective-c++";
429+ MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu17 gnu++20";
430+ OTHER_LDFLAGS = "";
431+ PRODUCT_BUNDLE_IDENTIFIER = meta.llamatsack.LocalInferenceProvider;
432+ PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
433+ SKIP_INSTALL = YES;
434+ SWIFT_EMIT_LOC_STRINGS = YES;
435+ SWIFT_INSTALL_OBJC_HEADER = NO;
436+ SWIFT_OPTIMIZATION_LEVEL = "-Onone";
437+ SWIFT_VERSION = 5.0;
438+ TARGETED_DEVICE_FAMILY = "1,2";
439+ };
440+ name = Debug;
441+ };
442+ 5CCBC6112CA1F04A00E958D0 /* Release */ = {
443+ isa = XCBuildConfiguration;
444+ buildSettings = {
445+ BUILD_LIBRARY_FOR_DISTRIBUTION = YES;
446+ CLANG_ENABLE_MODULES = YES;
447+ CODE_SIGN_STYLE = Automatic;
448+ CURRENT_PROJECT_VERSION = 1;
449+ DEFINES_MODULE = YES;
450+ DYLIB_COMPATIBILITY_VERSION = 1;
451+ DYLIB_CURRENT_VERSION = 1;
452+ DYLIB_INSTALL_NAME_BASE = "@rpath";
453+ ENABLE_MODULE_VERIFIER = YES;
454+ GENERATE_INFOPLIST_FILE = YES;
455+ HEADER_SEARCH_PATHS = "";
456+ INFOPLIST_KEY_NSHumanReadableCopyright = "";
457+ INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
458+ LD_RUNPATH_SEARCH_PATHS = (
459+ "$(inherited)",
460+ "@executable_path/Frameworks",
461+ "@loader_path/Frameworks",
462+ );
463+ MARKETING_VERSION = 1.0;
464+ MODULE_VERIFIER_SUPPORTED_LANGUAGES = "objective-c objective-c++";
465+ MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu17 gnu++20";
466+ OTHER_LDFLAGS = "";
467+ PRODUCT_BUNDLE_IDENTIFIER = meta.llamatsack.LocalInferenceProvider;
468+ PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
469+ SKIP_INSTALL = YES;
470+ SWIFT_EMIT_LOC_STRINGS = YES;
471+ SWIFT_INSTALL_OBJC_HEADER = NO;
472+ SWIFT_VERSION = 5.0;
473+ TARGETED_DEVICE_FAMILY = "1,2";
474+ };
475+ name = Release;
476+ };
477+/* End XCBuildConfiguration section */
478+
479+/* Begin XCConfigurationList section */
480+ 5CCBC6022CA1F04A00E958D0 /* Build configuration list for PBXProject "LocalInferenceImpl" */ = {
481+ isa = XCConfigurationList;
482+ buildConfigurations = (
483+ 5CCBC60D2CA1F04A00E958D0 /* Debug */,
484+ 5CCBC60E2CA1F04A00E958D0 /* Release */,
485+ );
486+ defaultConfigurationIsVisible = 0;
487+ defaultConfigurationName = Release;
488+ };
489+ 5CCBC60F2CA1F04A00E958D0 /* Build configuration list for PBXNativeTarget "LocalInferenceImpl" */ = {
490+ isa = XCConfigurationList;
491+ buildConfigurations = (
492+ 5CCBC6102CA1F04A00E958D0 /* Debug */,
493+ 5CCBC6112CA1F04A00E958D0 /* Release */,
494+ );
495+ defaultConfigurationIsVisible = 0;
496+ defaultConfigurationName = Release;
497+ };
498+/* End XCConfigurationList section */
499+
500+/* Begin XCRemoteSwiftPackageReference section */
501+ 5CAF3DD62CA485740029CD2B /* XCRemoteSwiftPackageReference "llama-stack-client-swift" */ = {
502+ isa = XCRemoteSwiftPackageReference;
503+ repositoryURL = "https://github.com/meta-llama/llama-stack-client-swift";
504+ requirement = {
505+ branch = main;
506+ kind = branch;
507+ };
508+ };
509+ 5CCBC6732CA1F45800E958D0 /* XCRemoteSwiftPackageReference "executorch" */ = {
510+ isa = XCRemoteSwiftPackageReference;
511+ repositoryURL = "https://github.com/pytorch/executorch";
512+ requirement = {
513+ branch = latest;
514+ kind = branch;
515+ };
516+ };
517+ 5CCBC6912CA1F7D000E958D0 /* XCRemoteSwiftPackageReference "Stencil" */ = {
518+ isa = XCRemoteSwiftPackageReference;
519+ repositoryURL = "https://github.com/stencilproject/Stencil";
520+ requirement = {
521+ kind = upToNextMajorVersion;
522+ minimumVersion = 0.15.1;
523+ };
524+ };
525+/* End XCRemoteSwiftPackageReference section */
526+
527+/* Begin XCSwiftPackageProductDependency section */
528+ 5CADC7192CA471CC007662D2 /* LlamaStackClient */ = {
529+ isa = XCSwiftPackageProductDependency;
530+ productName = LlamaStackClient;
531+ };
532+ 5CAF3DD72CA485740029CD2B /* LlamaStackClient */ = {
533+ isa = XCSwiftPackageProductDependency;
534+ package = 5CAF3DD62CA485740029CD2B /* XCRemoteSwiftPackageReference "llama-stack-client-swift" */;
535+ productName = LlamaStackClient;
536+ };
537+ 5CCBC6742CA1F45800E958D0 /* executorch_debug */ = {
538+ isa = XCSwiftPackageProductDependency;
539+ package = 5CCBC6732CA1F45800E958D0 /* XCRemoteSwiftPackageReference "executorch" */;
540+ productName = executorch_debug;
541+ };
542+ 5CCBC6922CA1F7D000E958D0 /* Stencil */ = {
543+ isa = XCSwiftPackageProductDependency;
544+ package = 5CCBC6912CA1F7D000E958D0 /* XCRemoteSwiftPackageReference "Stencil" */;
545+ productName = Stencil;
546+ };
547+/* End XCSwiftPackageProductDependency section */
548+ };
549+ rootObject = 5CCBC5FF2CA1F04A00E958D0 /* Project object */;
550+}
added llama_stack/providers/impls/ios/inference/LocalInferenceImpl.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 −0
@@ -0,0 +1,7 @@
1+<?xml version="1.0" encoding="UTF-8"?>
2+<Workspace
3+ version = "1.0">
4+ <FileRef
5+ location = "self:">
6+ </FileRef>
7+</Workspace>
added llama_stack/providers/impls/ios/inference/LocalInferenceImpl.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 −0
@@ -0,0 +1,8 @@
1+<?xml version="1.0" encoding="UTF-8"?>
2+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+<plist version="1.0">
4+<dict>
5+ <key>IDEDidComputeMac32BitWarning</key>
6+ <true/>
7+</dict>
8+</plist>
added llama_stack/providers/impls/ios/inference/LocalInferenceImpl/LocalInference.h +16 −0
@@ -0,0 +1,16 @@
1+//
2+// LocalInference.h
3+// LocalInference
4+//
5+// Created by Dalton Flanagan on 9/23/24.
6+//
7+
8+#import <Foundation/Foundation.h>
9+
10+//! Project version number for LocalInference.
11+FOUNDATION_EXPORT double LocalInferenceVersionNumber;
12+
13+//! Project version string for LocalInference.
14+FOUNDATION_EXPORT const unsigned char LocalInferenceVersionString[];
15+
16+// In this header, you should import all the public headers of your framework using statements like #import <LocalInference/PublicHeader.h>
added llama_stack/providers/impls/ios/inference/LocalInferenceImpl/LocalInference.swift +167 −0
@@ -0,0 +1,167 @@
1+import Foundation
2+
3+import LLaMARunner
4+import LlamaStackClient
5+
6+class RunnerHolder: ObservableObject {
7+ var runner: Runner?
8+}
9+
10+public class LocalInference: Inference {
11+ private var runnerHolder = RunnerHolder()
12+ private let runnerQueue: DispatchQueue
13+
14+ public init (queue: DispatchQueue) {
15+ runnerQueue = queue
16+ }
17+
18+ public func loadModel(modelPath: String, tokenizerPath: String, completion: @escaping (Result<Void, Error>) -> Void) {
19+ runnerHolder.runner = runnerHolder.runner ?? Runner(
20+ modelPath: modelPath,
21+ tokenizerPath: tokenizerPath
22+ )
23+
24+
25+ runnerQueue.async {
26+ let runner = self.runnerHolder.runner
27+ do {
28+ try runner!.load()
29+ completion(.success(()))
30+ } catch let loadError {
31+ print("error: " + loadError.localizedDescription)
32+ completion(.failure(loadError))
33+ }
34+ }
35+ }
36+
37+ public func chatCompletion(request: Components.Schemas.ChatCompletionRequest) -> AsyncStream<Components.Schemas.ChatCompletionResponseStreamChunk> {
38+ return AsyncStream { continuation in
39+ runnerQueue.async {
40+ do {
41+ var tokens: [String] = []
42+
43+ let prompt = try encodeDialogPrompt(messages: prepareMessages(request: request))
44+ var stopReason: Components.Schemas.StopReason? = nil
45+ var buffer = ""
46+ var ipython = false
47+ var echoDropped = false
48+
49+ try self.runnerHolder.runner?.generate(prompt, sequenceLength: 4096) { token in
50+ buffer += token
51+
52+ // HACK: Workaround until LlamaRunner exposes echo param
53+ if (!echoDropped) {
54+ if (buffer.hasPrefix(prompt)) {
55+ buffer = String(buffer.dropFirst(prompt.count))
56+ echoDropped = true
57+ }
58+ return
59+ }
60+
61+ tokens.append(token)
62+
63+ if !ipython && (buffer.starts(with: "<|python_tag|>") || buffer.starts(with: "[") ) {
64+ ipython = true
65+ continuation.yield(
66+ Components.Schemas.ChatCompletionResponseStreamChunk(
67+ event: Components.Schemas.ChatCompletionResponseEvent(
68+ delta: .ToolCallDelta(Components.Schemas.ToolCallDelta(
69+ content: .case1(""),
70+ parse_status: Components.Schemas.ToolCallParseStatus.started
71+ )
72+ ),
73+ event_type: .progress
74+ )
75+ )
76+ )
77+
78+ if (buffer.starts(with: "<|python_tag|>")) {
79+ buffer = String(buffer.dropFirst("<|python_tag|>".count))
80+ }
81+ }
82+
83+ // TODO: Non-streaming lobprobs
84+
85+ var text = ""
86+ if token == "<|eot_id|>" {
87+ stopReason = Components.Schemas.StopReason.end_of_turn
88+ } else if token == "<|eom_id|>" {
89+ stopReason = Components.Schemas.StopReason.end_of_message
90+ } else {
91+ text = token
92+ }
93+
94+ var delta: Components.Schemas.ChatCompletionResponseEvent.deltaPayload
95+ if ipython {
96+ delta = .ToolCallDelta(Components.Schemas.ToolCallDelta(
97+ content: .case1(text),
98+ parse_status: .in_progress
99+ ))
100+ } else {
101+ delta = .case1(text)
102+ }
103+
104+ if stopReason == nil {
105+ continuation.yield(
106+ Components.Schemas.ChatCompletionResponseStreamChunk(
107+ event: Components.Schemas.ChatCompletionResponseEvent(
108+ delta: delta,
109+ event_type: .progress
110+ )
111+ )
112+ )
113+ }
114+ }
115+
116+ if stopReason == nil {
117+ stopReason = Components.Schemas.StopReason.out_of_tokens
118+ }
119+
120+ let message = decodeAssistantMessage(tokens: tokens.joined(), stopReason: stopReason!)
121+ // TODO: non-streaming support
122+
123+ let didParseToolCalls = message.tool_calls.count > 0
124+ if ipython && !didParseToolCalls {
125+ continuation.yield(
126+ Components.Schemas.ChatCompletionResponseStreamChunk(
127+ event: Components.Schemas.ChatCompletionResponseEvent(
128+ delta: .ToolCallDelta(Components.Schemas.ToolCallDelta(content: .case1(""), parse_status: .failure)),
129+ event_type: .progress
130+ )
131+ // TODO: stopReason
132+ )
133+ )
134+ }
135+
136+ for toolCall in message.tool_calls {
137+ continuation.yield(
138+ Components.Schemas.ChatCompletionResponseStreamChunk(
139+ event: Components.Schemas.ChatCompletionResponseEvent(
140+ delta: .ToolCallDelta(Components.Schemas.ToolCallDelta(
141+ content: .ToolCall(toolCall),
142+ parse_status: .success
143+ )),
144+ event_type: .progress
145+ )
146+ // TODO: stopReason
147+ )
148+ )
149+ }
150+
151+ continuation.yield(
152+ Components.Schemas.ChatCompletionResponseStreamChunk(
153+ event: Components.Schemas.ChatCompletionResponseEvent(
154+ delta: .case1(""),
155+ event_type: .complete
156+ )
157+ // TODO: stopReason
158+ )
159+ )
160+ }
161+ catch (let error) {
162+ print("Inference error: " + error.localizedDescription)
163+ }
164+ }
165+ }
166+ }
167+}
added llama_stack/providers/impls/ios/inference/LocalInferenceImpl/Parsing.swift +235 −0
@@ -0,0 +1,235 @@
1+import Foundation
2+
3+import LlamaStackClient
4+
5+func encodeHeader(role: String) -> String {
6+ return "<|start_header_id|>\(role)<|end_header_id|>\n\n"
7+}
8+
9+func encodeDialogPrompt(messages: [Components.Schemas.ChatCompletionRequest.messagesPayloadPayload]) -> String {
10+ var prompt = ""
11+
12+ prompt.append("<|begin_of_text|>")
13+ for message in messages {
14+ let msg = encodeMessage(message: message)
15+ prompt += msg
16+ }
17+
18+ prompt.append(encodeHeader(role: "assistant"))
19+
20+ return prompt
21+}
22+
23+func getRole(message: Components.Schemas.ChatCompletionRequest.messagesPayloadPayload) -> String {
24+ switch (message) {
25+ case .UserMessage(let m):
26+ return m.role.rawValue
27+ case .SystemMessage(let m):
28+ return m.role.rawValue
29+ case .ToolResponseMessage(let m):
30+ return m.role.rawValue
31+ case .CompletionMessage(let m):
32+ return m.role.rawValue
33+ }
34+}
35+
36+func encodeMessage(message: Components.Schemas.ChatCompletionRequest.messagesPayloadPayload) -> String {
37+ var prompt = encodeHeader(role: getRole(message: message))
38+
39+ switch (message) {
40+ case .CompletionMessage(let m):
41+ if (m.tool_calls.count > 0) {
42+ prompt += "<|python_tag|>"
43+ }
44+ default:
45+ break
46+ }
47+
48+ func _processContent(_ content: Any) -> String {
49+ func _process(_ c: Any) {
50+ if let str = c as? String {
51+ prompt += str
52+ }
53+ }
54+
55+ if let str = content as? String {
56+ _process(str)
57+ } else if let list = content as? [Any] {
58+ for c in list {
59+ _process(c)
60+ }
61+ }
62+
63+ return ""
64+ }
65+
66+ switch (message) {
67+ case .UserMessage(let m):
68+ prompt += _processContent(m.content)
69+ case .SystemMessage(let m):
70+ prompt += _processContent(m.content)
71+ case .ToolResponseMessage(let m):
72+ prompt += _processContent(m.content)
73+ case .CompletionMessage(let m):
74+ prompt += _processContent(m.content)
75+ }
76+
77+ var eom = false
78+
79+ switch (message) {
80+ case .UserMessage(let m):
81+ switch (m.content) {
82+ case .case1(let c):
83+ prompt += _processContent(c)
84+ case .case2(let c):
85+ prompt += _processContent(c)
86+ }
87+ case .CompletionMessage(let m):
88+ // TODO: Support encoding past tool call history
89+ // for t in m.tool_calls {
90+ // _processContent(t.)
91+ //}
92+ eom = m.stop_reason == Components.Schemas.StopReason.end_of_message
93+ case .SystemMessage(_):
94+ break
95+ case .ToolResponseMessage(_):
96+ break
97+ }
98+
99+ if (eom) {
100+ prompt += "<|eom_id|>"
101+ } else {
102+ prompt += "<|eot_id|>"
103+ }
104+
105+ return prompt
106+}
107+
108+func prepareMessages(request: Components.Schemas.ChatCompletionRequest) throws -> [Components.Schemas.ChatCompletionRequest.messagesPayloadPayload] {
109+ var existingMessages = request.messages
110+ var existingSystemMessage: Components.Schemas.ChatCompletionRequest.messagesPayloadPayload?
111+ // TODO: Existing system message
112+
113+ var messages: [Components.Schemas.ChatCompletionRequest.messagesPayloadPayload] = []
114+
115+ let defaultGen = SystemDefaultGenerator()
116+ let defaultTemplate = defaultGen.gen()
117+
118+ var sysContent = ""
119+
120+ // TODO: Built-in tools
121+
122+ sysContent += try defaultTemplate.render()
123+
124+ messages.append(.SystemMessage(Components.Schemas.SystemMessage(
125+ content: .case1(sysContent),
126+ role: .system))
127+ )
128+
129+ if request.tools?.isEmpty == false {
130+ // TODO: Separate built-ins and custom tools (right now everything treated as custom)
131+ let toolGen = FunctionTagCustomToolGenerator()
132+ let toolTemplate = try toolGen.gen(customTools: request.tools!)
133+ let tools = try toolTemplate.render()
134+ messages.append(.UserMessage(Components.Schemas.UserMessage(
135+ content: .case1(tools),
136+ role: .user)
137+ ))
138+ }
139+
140+ messages.append(contentsOf: existingMessages)
141+
142+ return messages
143+}
144+
145+struct FunctionCall {
146+ let name: String
147+ let params: [String: Any]
148+}
149+
150+public func maybeExtractCustomToolCalls(input: String) -> [Components.Schemas.ToolCall] {
151+ guard input.hasPrefix("[") && input.hasSuffix("]") else {
152+ return []
153+ }
154+
155+ do {
156+ let trimmed = input.trimmingCharacters(in: CharacterSet(charactersIn: "[]"))
157+ let calls = trimmed.components(separatedBy: "),").map { $0.hasSuffix(")") ? $0 : $0 + ")" }
158+
159+ var result: [Components.Schemas.ToolCall] = []
160+
161+ for call in calls {
162+ guard let nameEndIndex = call.firstIndex(of: "("),
163+ let paramsStartIndex = call.firstIndex(of: "{"),
164+ let paramsEndIndex = call.lastIndex(of: "}") else {
165+ return []
166+ }
167+
168+ let name = String(call[..<nameEndIndex]).trimmingCharacters(in: .whitespacesAndNewlines)
169+ let paramsString = String(call[paramsStartIndex...paramsEndIndex])
170+
171+ guard let data = paramsString.data(using: .utf8),
172+ let params = try? JSONSerialization.jsonObject(with: data, options: []) as? [String: Any] else {
173+ return []
174+ }
175+
176+ var props: [String : Components.Schemas.ToolCall.argumentsPayload.additionalPropertiesPayload] = [:]
177+ for (param_name, param) in params {
178+ switch (param) {
179+ case let value as String:
180+ props[param_name] = .case1(value)
181+ case let value as Int:
182+ props[param_name] = .case2(value)
183+ case let value as Double:
184+ props[param_name] = .case3(value)
185+ case let value as Bool:
186+ props[param_name] = .case4(value)
187+ default:
188+ return []
189+ }
190+ }
191+
192+ result.append(
193+ Components.Schemas.ToolCall(
194+ arguments: .init(additionalProperties: props),
195+ call_id: UUID().uuidString,
196+ tool_name: .case2(name) // custom_tool
197+ )
198+ )
199+ }
200+
201+ return result.isEmpty ? [] : result
202+ } catch {
203+ return []
204+ }
205+}
206+
207+func decodeAssistantMessage(tokens: String, stopReason: Components.Schemas.StopReason) -> Components.Schemas.CompletionMessage {
208+ var content = tokens
209+
210+ let roles = ["user", "system", "assistant"]
211+ for role in roles {
212+ let headerStr = encodeHeader(role: role)
213+ if content.hasPrefix(headerStr) {
214+ content = String(content.dropFirst(encodeHeader(role: role).count))
215+ }
216+ }
217+
218+ if content.hasPrefix("<|python_tag|>") {
219+ content = String(content.dropFirst("<|python_tag|>".count))
220+ }
221+
222+
223+ if content.hasSuffix("<|eot_id|>") {
224+ content = String(content.dropLast("<|eot_id|>".count))
225+ } else {
226+ content = String(content.dropLast("<|eom_id|>".count))
227+ }
228+
229+ return Components.Schemas.CompletionMessage(
230+ content: .case1(content),
231+ role: .assistant,
232+ stop_reason: stopReason,
233+ tool_calls: maybeExtractCustomToolCalls(input: content)
234+ )
235+}
added llama_stack/providers/impls/ios/inference/LocalInferenceImpl/PromptTemplate.swift +12 −0
@@ -0,0 +1,12 @@
1+import Foundation
2+import Stencil
3+
4+public struct PromptTemplate {
5+ let template: String
6+ let data: [String: Any]
7+
8+ public func render() throws -> String {
9+ let template = Template(templateString: self.template)
10+ return try template.render(self.data)
11+ }
12+}
added llama_stack/providers/impls/ios/inference/LocalInferenceImpl/SystemPrompts.swift +91 −0
@@ -0,0 +1,91 @@
1+import Foundation
2+
3+import LlamaStackClient
4+
5+func convertToNativeSwiftType(_ value: Any) -> Any {
6+ switch value {
7+ case let number as NSNumber:
8+ if CFGetTypeID(number) == CFBooleanGetTypeID() {
9+ return number.boolValue
10+ }
11+ if floor(number.doubleValue) == number.doubleValue {
12+ return number.intValue
13+ }
14+ return number.doubleValue
15+ case let string as String:
16+ return string
17+ case let array as [Any]:
18+ return array.map(convertToNativeSwiftType)
19+ case let dict as [String: Any]:
20+ return dict.mapValues(convertToNativeSwiftType)
21+ case is NSNull:
22+ return NSNull()
23+ default:
24+ return value
25+ }
26+}
27+
28+public class SystemDefaultGenerator {
29+ public init() {}
30+
31+ public func gen() -> PromptTemplate {
32+ let templateStr = """
33+ Cutting Knowledge Date: December 2023
34+ Today Date: {{ today }}
35+ """
36+
37+ let dateFormatter = DateFormatter()
38+ dateFormatter.dateFormat = "dd MMMM yyyy"
39+
40+ return PromptTemplate(
41+ template: templateStr,
42+ data: ["today": dateFormatter.string(from: Date())]
43+ )
44+ }
45+}
46+
47+
48+public class FunctionTagCustomToolGenerator {
49+ public init() {}
50+
51+ public func gen(customTools: [Components.Schemas.ToolDefinition]) throws -> PromptTemplate {
52+ // TODO: required params
53+ // TODO: {{#unless @last}},{{/unless}}
54+
55+ let templateStr = """
56+ You are an expert in composing functions. You are given a question and a set of possible functions.
57+ Based on the question, you will need to make one or more function/tool calls to achieve the purpose.
58+ If none of the function can be used, point it out. If the given question lacks the parameters required by the function,
59+ also point it out. You should only return the function call in tools call sections.
60+
61+ 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)]
62+ You SHOULD NOT include any other text in the response.
63+
64+ Here is a list of functions in JSON format that you can invoke.
65+
66+ [
67+ {% for t in custom_tools %}
68+ {
69+ "name": "{{t.tool_name}}",
70+ "description": "{{t.description}}",
71+ "parameters": {
72+ "type": "dict",
73+ "properties": { {{t.parameters}} }
74+ }
75+
76+ {{/let}}
77+ {% endfor -%}
78+ ]
79+ """
80+
81+ let encoder = JSONEncoder()
82+ return PromptTemplate(
83+ template: templateStr,
84+ data: ["custom_tools": try customTools.map {
85+ let data = try encoder.encode($0)
86+ let obj = try JSONSerialization.jsonObject(with: data)
87+ return convertToNativeSwiftType(obj)
88+ }]
89+ )
90+ }
91+}
added llama_stack/providers/impls/ios/inference/README.md +109 −0
@@ -0,0 +1,109 @@
1+# LocalInference
2+
3+LocalInference provides a local inference implementation powered by [executorch](https://github.com/pytorch/executorch/).
4+
5+Llama Stack currently supports on-device inference for iOS with Android coming soon. You can run on-device inference on Android today using [executorch](https://github.com/pytorch/executorch/tree/main/examples/demo-apps/android/LlamaDemo), PyTorch’s on-device inference library.
6+
7+## Installation
8+
9+We're working on making LocalInference easier to set up. For now, you'll need to import it via `.xcframework`:
10+
11+1. Clone the executorch submodule in this repo and its dependencies: `git submodule update --init --recursive`
12+1. Install [Cmake](https://cmake.org/) for the executorch build`
13+1. Drag `LocalInference.xcodeproj` into your project
14+1. Add `LocalInference` as a framework in your app target
15+1. Add a package dependency on https://github.com/pytorch/executorch (branch latest)
16+1. Add all the kernels / backends from executorch (but not exectuorch itself!) as frameworks in your app target:
17+ - backend_coreml
18+ - backend_mps
19+ - backend_xnnpack
20+ - kernels_custom
21+ - kernels_optimized
22+ - kernels_portable
23+ - kernels_quantized
24+1. In "Build Settings" > "Other Linker Flags" > "Any iOS Simulator SDK", add:
25+ ```
26+ -force_load
27+ $(BUILT_PRODUCTS_DIR)/libkernels_optimized-simulator-release.a
28+ -force_load
29+ $(BUILT_PRODUCTS_DIR)/libkernels_custom-simulator-release.a
30+ -force_load
31+ $(BUILT_PRODUCTS_DIR)/libkernels_quantized-simulator-release.a
32+ -force_load
33+ $(BUILT_PRODUCTS_DIR)/libbackend_xnnpack-simulator-release.a
34+ -force_load
35+ $(BUILT_PRODUCTS_DIR)/libbackend_coreml-simulator-release.a
36+ -force_load
37+ $(BUILT_PRODUCTS_DIR)/libbackend_mps-simulator-release.a
38+ ```
39+
40+1. In "Build Settings" > "Other Linker Flags" > "Any iOS SDK", add:
41+
42+ ```
43+ -force_load
44+ $(BUILT_PRODUCTS_DIR)/libkernels_optimized-simulator-release.a
45+ -force_load
46+ $(BUILT_PRODUCTS_DIR)/libkernels_custom-simulator-release.a
47+ -force_load
48+ $(BUILT_PRODUCTS_DIR)/libkernels_quantized-simulator-release.a
49+ -force_load
50+ $(BUILT_PRODUCTS_DIR)/libbackend_xnnpack-simulator-release.a
51+ -force_load
52+ $(BUILT_PRODUCTS_DIR)/libbackend_coreml-simulator-release.a
53+ -force_load
54+ $(BUILT_PRODUCTS_DIR)/libbackend_mps-simulator-release.a
55+ ```
56+
57+## Preparing a model
58+
59+1. Prepare a `.pte` file [following the executorch docs](https://github.com/pytorch/executorch/blob/main/examples/models/llama2/README.md#step-2-prepare-model)
60+2. Bundle the `.pte` and `tokenizer.model` file into your app
61+
62+## Using LocalInference
63+
64+1. Instantiate LocalInference with a DispatchQueue. Optionally, pass it into your agents service:
65+
66+```swift
67+ init () {
68+ runnerQueue = DispatchQueue(label: "org.meta.llamastack")
69+ inferenceService = LocalInferenceService(queue: runnerQueue)
70+ agentsService = LocalAgentsService(inference: inferenceService)
71+ }
72+```
73+
74+2. Before making any inference calls, load your model from your bundle:
75+
76+```swift
77+let mainBundle = Bundle.main
78+inferenceService.loadModel(
79+ modelPath: mainBundle.url(forResource: "llama32_1b_spinquant", withExtension: "pte"),
80+ tokenizerPath: mainBundle.url(forResource: "tokenizer", withExtension: "model"),
81+ completion: {_ in } // use to handle load failures
82+)
83+```
84+
85+3. Make inference calls (or agents calls) as you normally would with LlamaStack:
86+
87+```
88+for await chunk in try await agentsService.initAndCreateTurn(
89+ messages: [
90+ .UserMessage(Components.Schemas.UserMessage(
91+ content: .case1("Call functions as needed to handle any actions in the following text:\n\n" + text),
92+ role: .user))
93+ ]
94+) {
95+```
96+
97+## Troubleshooting
98+
99+If you receive errors like "missing package product" or "invalid checksum", try cleaning the build folder and resetting the Swift package cache:
100+
101+(Opt+Click) Product > Clean Build Folder Immediately
102+
103+```
104+rm -rf \
105+ ~/Library/org.swift.swiftpm \
106+ ~/Library/Caches/org.swift.swiftpm \
107+ ~/Library/Caches/com.apple.dt.Xcode \
108+ ~/Library/Developer/Xcode/DerivedData
109+```
added llama_stack/providers/impls/ios/inference/executorch +1 −0
@@ -0,0 +1,1 @@
1+Subproject commit 9b6d4b4a7b9b8f811bb6b269b0c2ce254e3a0c1b