From f443f1737a13f7d081773a98b9620161a8923173 Mon Sep 17 00:00:00 2001 From: Raj Sharma Date: Wed, 6 Mar 2024 19:12:26 +0530 Subject: [PATCH] init --- .gitignore | 2 + untitled.xcodeproj/project.pbxproj | 117 ++++++- .../xcshareddata/swiftpm/Package.resolved | 302 ++++++++++++++++++ .../xcdebugger/Breakpoints_v2.xcbkptlist | 24 ++ .../xcschemes/xcschememanagement.plist | 42 +++ .../AccentColor.colorset/Contents.json | 4 + untitled/Components/ErrorView.swift | 20 ++ untitled/Components/LoadingView.swift | 18 ++ untitled/ContentView.swift | 24 -- untitled/Helpers/Constants.swift | 14 + untitled/Helpers/Extensions.swift | 19 ++ untitled/Info.plist | 5 + untitled/Models/ResponseModel.swift | 17 + untitled/Services/APIService.swift | 38 +++ untitled/Services/ModelInferenceService.swift | 35 ++ untitled/ViewModels/ContentViewModel.swift | 48 +++ untitled/Views/ContentView.swift | 38 +++ 17 files changed, 742 insertions(+), 25 deletions(-) create mode 100644 .gitignore create mode 100644 untitled.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved create mode 100644 untitled.xcodeproj/xcuserdata/raj.sharma.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist create mode 100644 untitled/Components/ErrorView.swift create mode 100644 untitled/Components/LoadingView.swift delete mode 100644 untitled/ContentView.swift create mode 100644 untitled/Helpers/Constants.swift create mode 100644 untitled/Helpers/Extensions.swift create mode 100644 untitled/Info.plist create mode 100644 untitled/Models/ResponseModel.swift create mode 100644 untitled/Services/APIService.swift create mode 100644 untitled/Services/ModelInferenceService.swift create mode 100644 untitled/ViewModels/ContentViewModel.swift create mode 100644 untitled/Views/ContentView.swift diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f490a6c --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +env.txt +.env diff --git a/untitled.xcodeproj/project.pbxproj b/untitled.xcodeproj/project.pbxproj index 98c2364..4f33004 100644 --- a/untitled.xcodeproj/project.pbxproj +++ b/untitled.xcodeproj/project.pbxproj @@ -11,6 +11,16 @@ 110760672B960D58004E8F2B /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 110760662B960D58004E8F2B /* ContentView.swift */; }; 110760692B960D59004E8F2B /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 110760682B960D59004E8F2B /* Assets.xcassets */; }; 1107606C2B960D59004E8F2B /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 1107606B2B960D59004E8F2B /* Preview Assets.xcassets */; }; + 110760752B961315004E8F2B /* ResponseModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 110760742B961315004E8F2B /* ResponseModel.swift */; }; + 110760782B96134A004E8F2B /* ContentViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 110760772B96134A004E8F2B /* ContentViewModel.swift */; }; + 1107607B2B96137B004E8F2B /* APIService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1107607A2B96137B004E8F2B /* APIService.swift */; }; + 1107607E2B9613AD004E8F2B /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1107607D2B9613AD004E8F2B /* Constants.swift */; }; + 110760802B9613B8004E8F2B /* Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1107607F2B9613B8004E8F2B /* Extensions.swift */; }; + 110760852B9613EC004E8F2B /* ErrorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 110760842B9613EC004E8F2B /* ErrorView.swift */; }; + 110760872B961448004E8F2B /* LoadingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 110760862B961448004E8F2B /* LoadingView.swift */; }; + 112D8BBD2B97671400F18798 /* LangChain in Frameworks */ = {isa = PBXBuildFile; productRef = 112D8BBC2B97671400F18798 /* LangChain */; }; + 112D8BBF2B97681B00F18798 /* env.txt in Resources */ = {isa = PBXBuildFile; fileRef = 112D8BBE2B97681B00F18798 /* env.txt */; }; + 11FA40B72B976B78001A1443 /* ModelInferenceService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11FA40B62B976B78001A1443 /* ModelInferenceService.swift */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -19,6 +29,16 @@ 110760662B960D58004E8F2B /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; 110760682B960D59004E8F2B /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 1107606B2B960D59004E8F2B /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; }; + 110760742B961315004E8F2B /* ResponseModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ResponseModel.swift; sourceTree = ""; }; + 110760772B96134A004E8F2B /* ContentViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentViewModel.swift; sourceTree = ""; }; + 1107607A2B96137B004E8F2B /* APIService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = APIService.swift; sourceTree = ""; }; + 1107607D2B9613AD004E8F2B /* Constants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = ""; }; + 1107607F2B9613B8004E8F2B /* Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Extensions.swift; sourceTree = ""; }; + 110760842B9613EC004E8F2B /* ErrorView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ErrorView.swift; sourceTree = ""; }; + 110760862B961448004E8F2B /* LoadingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadingView.swift; sourceTree = ""; }; + 110760882B962035004E8F2B /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = ""; }; + 112D8BBE2B97681B00F18798 /* env.txt */ = {isa = PBXFileReference; explicitFileType = text; fileEncoding = 4; lineEnding = 0; name = env.txt; path = untitled/env.txt; sourceTree = SOURCE_ROOT; }; + 11FA40B62B976B78001A1443 /* ModelInferenceService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModelInferenceService.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -26,6 +46,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 112D8BBD2B97671400F18798 /* LangChain in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -51,10 +72,17 @@ 110760632B960D58004E8F2B /* untitled */ = { isa = PBXGroup; children = ( + 110760882B962035004E8F2B /* Info.plist */, + 110760812B9613C3004E8F2B /* Components */, + 1107607C2B96139B004E8F2B /* Helpers */, + 110760792B96136C004E8F2B /* Services */, + 110760762B961338004E8F2B /* ViewModels */, + 110760732B9612F7004E8F2B /* Models */, + 110760722B96128E004E8F2B /* Views */, 110760642B960D58004E8F2B /* untitledApp.swift */, - 110760662B960D58004E8F2B /* ContentView.swift */, 110760682B960D59004E8F2B /* Assets.xcassets */, 1107606A2B960D59004E8F2B /* Preview Content */, + 112D8BBE2B97681B00F18798 /* env.txt */, ); path = untitled; sourceTree = ""; @@ -67,6 +95,57 @@ path = "Preview Content"; sourceTree = ""; }; + 110760722B96128E004E8F2B /* Views */ = { + isa = PBXGroup; + children = ( + 110760662B960D58004E8F2B /* ContentView.swift */, + ); + path = Views; + sourceTree = ""; + }; + 110760732B9612F7004E8F2B /* Models */ = { + isa = PBXGroup; + children = ( + 110760742B961315004E8F2B /* ResponseModel.swift */, + ); + path = Models; + sourceTree = ""; + }; + 110760762B961338004E8F2B /* ViewModels */ = { + isa = PBXGroup; + children = ( + 110760772B96134A004E8F2B /* ContentViewModel.swift */, + ); + path = ViewModels; + sourceTree = ""; + }; + 110760792B96136C004E8F2B /* Services */ = { + isa = PBXGroup; + children = ( + 1107607A2B96137B004E8F2B /* APIService.swift */, + 11FA40B62B976B78001A1443 /* ModelInferenceService.swift */, + ); + path = Services; + sourceTree = ""; + }; + 1107607C2B96139B004E8F2B /* Helpers */ = { + isa = PBXGroup; + children = ( + 1107607D2B9613AD004E8F2B /* Constants.swift */, + 1107607F2B9613B8004E8F2B /* Extensions.swift */, + ); + path = Helpers; + sourceTree = ""; + }; + 110760812B9613C3004E8F2B /* Components */ = { + isa = PBXGroup; + children = ( + 110760842B9613EC004E8F2B /* ErrorView.swift */, + 110760862B961448004E8F2B /* LoadingView.swift */, + ); + path = Components; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -83,6 +162,9 @@ dependencies = ( ); name = untitled; + packageProductDependencies = ( + 112D8BBC2B97671400F18798 /* LangChain */, + ); productName = untitled; productReference = 110760612B960D58004E8F2B /* untitled.app */; productType = "com.apple.product-type.application"; @@ -111,6 +193,9 @@ Base, ); mainGroup = 110760582B960D58004E8F2B; + packageReferences = ( + 112D8BBB2B97671400F18798 /* XCRemoteSwiftPackageReference "langchain-swift" */, + ); productRefGroup = 110760622B960D58004E8F2B /* Products */; projectDirPath = ""; projectRoot = ""; @@ -125,6 +210,7 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + 112D8BBF2B97681B00F18798 /* env.txt in Resources */, 1107606C2B960D59004E8F2B /* Preview Assets.xcassets in Resources */, 110760692B960D59004E8F2B /* Assets.xcassets in Resources */, ); @@ -137,8 +223,16 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 110760782B96134A004E8F2B /* ContentViewModel.swift in Sources */, + 1107607B2B96137B004E8F2B /* APIService.swift in Sources */, 110760672B960D58004E8F2B /* ContentView.swift in Sources */, + 110760752B961315004E8F2B /* ResponseModel.swift in Sources */, 110760652B960D58004E8F2B /* untitledApp.swift in Sources */, + 11FA40B72B976B78001A1443 /* ModelInferenceService.swift in Sources */, + 1107607E2B9613AD004E8F2B /* Constants.swift in Sources */, + 110760852B9613EC004E8F2B /* ErrorView.swift in Sources */, + 110760802B9613B8004E8F2B /* Extensions.swift in Sources */, + 110760872B961448004E8F2B /* LoadingView.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -274,6 +368,7 @@ DEVELOPMENT_ASSET_PATHS = "\"untitled/Preview Content\""; ENABLE_PREVIEWS = YES; GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_FILE = untitled/Info.plist; INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; INFOPLIST_KEY_UILaunchScreen_Generation = YES; @@ -302,6 +397,7 @@ DEVELOPMENT_ASSET_PATHS = "\"untitled/Preview Content\""; ENABLE_PREVIEWS = YES; GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_FILE = untitled/Info.plist; INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; INFOPLIST_KEY_UILaunchScreen_Generation = YES; @@ -342,6 +438,25 @@ defaultConfigurationName = Release; }; /* End XCConfigurationList section */ + +/* Begin XCRemoteSwiftPackageReference section */ + 112D8BBB2B97671400F18798 /* XCRemoteSwiftPackageReference "langchain-swift" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/buhe/langchain-swift"; + requirement = { + kind = upToNextMajorVersion; + minimumVersion = 0.48.0; + }; + }; +/* End XCRemoteSwiftPackageReference section */ + +/* Begin XCSwiftPackageProductDependency section */ + 112D8BBC2B97671400F18798 /* LangChain */ = { + isa = XCSwiftPackageProductDependency; + package = 112D8BBB2B97671400F18798 /* XCRemoteSwiftPackageReference "langchain-swift" */; + productName = LangChain; + }; +/* End XCSwiftPackageProductDependency section */ }; rootObject = 110760592B960D58004E8F2B /* Project object */; } diff --git a/untitled.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/untitled.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved new file mode 100644 index 0000000..57f3bfb --- /dev/null +++ b/untitled.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -0,0 +1,302 @@ +{ + "pins" : [ + { + "identity" : "async-http-client", + "kind" : "remoteSourceControl", + "location" : "https://github.com/swift-server/async-http-client.git", + "state" : { + "revision" : "291438696abdd48d2a83b52465c176efbd94512b", + "version" : "1.20.1" + } + }, + { + "identity" : "feedkit", + "kind" : "remoteSourceControl", + "location" : "https://github.com/nmdias/FeedKit", + "state" : { + "revision" : "68493a33d862c33c9a9f67ec729b3b7df1b20ade", + "version" : "9.1.2" + } + }, + { + "identity" : "functions-swift", + "kind" : "remoteSourceControl", + "location" : "https://github.com/supabase-community/functions-swift", + "state" : { + "revision" : "d2fac1980cf5b589077b635d4e18249f7939a9db", + "version" : "1.1.1" + } + }, + { + "identity" : "generative-ai-swift", + "kind" : "remoteSourceControl", + "location" : "https://github.com/google/generative-ai-swift", + "state" : { + "revision" : "e2cebcd90645a3a94c0c823696e510a176bc384a", + "version" : "0.4.8" + } + }, + { + "identity" : "get", + "kind" : "remoteSourceControl", + "location" : "https://github.com/kean/Get", + "state" : { + "revision" : "12830cc64f31789ae6f4352d2d51d03a25fc3741", + "version" : "2.1.6" + } + }, + { + "identity" : "getextensions", + "kind" : "remoteSourceControl", + "location" : "https://github.com/binaryscraping/GetExtensions", + "state" : { + "revision" : "aa20f38721142eb6592b2c8f11179d32d7d70ae3", + "version" : "1.0.0" + } + }, + { + "identity" : "gotrue-swift", + "kind" : "remoteSourceControl", + "location" : "https://github.com/supabase-community/gotrue-swift", + "state" : { + "revision" : "e53731e21569b2e9ce6f58763ad0fbce8e2e7603", + "version" : "1.3.0" + } + }, + { + "identity" : "keychainaccess", + "kind" : "remoteSourceControl", + "location" : "https://github.com/kishikawakatsumi/KeychainAccess", + "state" : { + "revision" : "84e546727d66f1adc5439debad16270d0fdd04e7", + "version" : "4.2.2" + } + }, + { + "identity" : "langchain-swift", + "kind" : "remoteSourceControl", + "location" : "https://github.com/buhe/langchain-swift", + "state" : { + "revision" : "d2c945cfbb0b1b9bc571dc5121fbaa264bb42bd6", + "version" : "0.48.0" + } + }, + { + "identity" : "openai-kit", + "kind" : "remoteSourceControl", + "location" : "https://github.com/buhe/openai-kit", + "state" : { + "revision" : "f0c785d22dd14f71a42ad83cedbbddc02591aadb", + "version" : "1.8.5" + } + }, + { + "identity" : "postgrest-swift", + "kind" : "remoteSourceControl", + "location" : "https://github.com/supabase-community/postgrest-swift", + "state" : { + "revision" : "2afb40a2f91ba881db8f04131e1b5146001813a5", + "version" : "1.0.3" + } + }, + { + "identity" : "realtime-swift", + "kind" : "remoteSourceControl", + "location" : "https://github.com/supabase-community/realtime-swift.git", + "state" : { + "revision" : "0b985c687fe963f6bd818ff77a35c27247b98bb4", + "version" : "0.0.2" + } + }, + { + "identity" : "similarity-search-kit", + "kind" : "remoteSourceControl", + "location" : "https://github.com/buhe/similarity-search-kit", + "state" : { + "revision" : "39bbd0b5c2662728792ee9be132212e5fd4a49e2", + "version" : "0.0.16" + } + }, + { + "identity" : "storage-swift", + "kind" : "remoteSourceControl", + "location" : "https://github.com/supabase-community/storage-swift.git", + "state" : { + "revision" : "65cae9e1156711043cbdebb27b4df93cbef46a1b", + "version" : "0.1.4" + } + }, + { + "identity" : "supabase-swift", + "kind" : "remoteSourceControl", + "location" : "https://github.com/supabase-community/supabase-swift", + "state" : { + "revision" : "7088b85247c8e56317f0b22b9d60655e8f762fec", + "version" : "0.3.0" + } + }, + { + "identity" : "swift-algorithms", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-algorithms", + "state" : { + "revision" : "f6919dfc309e7f1b56224378b11e28bab5bccc42", + "version" : "1.2.0" + } + }, + { + "identity" : "swift-atomics", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-atomics.git", + "state" : { + "revision" : "cd142fd2f64be2100422d658e7411e39489da985", + "version" : "1.2.0" + } + }, + { + "identity" : "swift-collections", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-collections.git", + "state" : { + "revision" : "94cf62b3ba8d4bed62680a282d4c25f9c63c2efb", + "version" : "1.1.0" + } + }, + { + "identity" : "swift-filestore", + "kind" : "remoteSourceControl", + "location" : "https://github.com/juyan/swift-filestore", + "state" : { + "revision" : "61aa52c514e39a70c17ce6421d70807f46282154", + "version" : "0.7.0" + } + }, + { + "identity" : "swift-http-types", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-http-types", + "state" : { + "revision" : "12358d55a3824bd5fed310b999ea8cf83a9a1a65", + "version" : "1.0.3" + } + }, + { + "identity" : "swift-log", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-log.git", + "state" : { + "revision" : "e97a6fcb1ab07462881ac165fdbb37f067e205d5", + "version" : "1.5.4" + } + }, + { + "identity" : "swift-nio", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-nio.git", + "state" : { + "revision" : "635b2589494c97e48c62514bc8b37ced762e0a62", + "version" : "2.63.0" + } + }, + { + "identity" : "swift-nio-extras", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-nio-extras.git", + "state" : { + "revision" : "a3b640d7dc567225db7c94386a6e71aded1bfa63", + "version" : "1.22.0" + } + }, + { + "identity" : "swift-nio-http2", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-nio-http2.git", + "state" : { + "revision" : "0904bf0feb5122b7e5c3f15db7df0eabe623dd87", + "version" : "1.30.0" + } + }, + { + "identity" : "swift-nio-ssl", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-nio-ssl.git", + "state" : { + "revision" : "7c381eb6083542b124a6c18fae742f55001dc2b5", + "version" : "2.26.0" + } + }, + { + "identity" : "swift-nio-transport-services", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-nio-transport-services.git", + "state" : { + "revision" : "6cbe0ed2b394f21ab0d46b9f0c50c6be964968ce", + "version" : "1.20.1" + } + }, + { + "identity" : "swift-numerics", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-numerics.git", + "state" : { + "revision" : "0a5bc04095a675662cf24757cc0640aa2204253b", + "version" : "1.0.2" + } + }, + { + "identity" : "swift-system", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-system.git", + "state" : { + "revision" : "025bcb1165deab2e20d4eaba79967ce73013f496", + "version" : "1.2.1" + } + }, + { + "identity" : "swiftsoup", + "kind" : "remoteSourceControl", + "location" : "https://github.com/scinfu/SwiftSoup", + "state" : { + "revision" : "1d39e56d364cba79ce43b341f9661b534cccb18d", + "version" : "2.7.1" + } + }, + { + "identity" : "swiftyjson", + "kind" : "remoteSourceControl", + "location" : "https://github.com/SwiftyJSON/SwiftyJSON", + "state" : { + "revision" : "b3dcd7dbd0d488e1a7077cb33b00f2083e382f07", + "version" : "5.0.1" + } + }, + { + "identity" : "swiftynotion", + "kind" : "remoteSourceControl", + "location" : "https://github.com/buhe/SwiftyNotion", + "state" : { + "revision" : "61af40905bfd5eb8cad454e02095dfbdea0498cb", + "version" : "0.1.3" + } + }, + { + "identity" : "swxmlhash", + "kind" : "remoteSourceControl", + "location" : "https://github.com/drmohundro/SWXMLHash", + "state" : { + "revision" : "a853604c9e9a83ad9954c7e3d2a565273982471f", + "version" : "7.0.2" + } + }, + { + "identity" : "urlqueryencoder", + "kind" : "remoteSourceControl", + "location" : "https://github.com/kean/URLQueryEncoder", + "state" : { + "revision" : "4ce950479707ea109f229d7230ec074a133b15d7", + "version" : "0.2.1" + } + } + ], + "version" : 2 +} diff --git a/untitled.xcodeproj/xcuserdata/raj.sharma.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/untitled.xcodeproj/xcuserdata/raj.sharma.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist new file mode 100644 index 0000000..6f39774 --- /dev/null +++ b/untitled.xcodeproj/xcuserdata/raj.sharma.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -0,0 +1,24 @@ + + + + + + + + + diff --git a/untitled.xcodeproj/xcuserdata/raj.sharma.xcuserdatad/xcschemes/xcschememanagement.plist b/untitled.xcodeproj/xcuserdata/raj.sharma.xcuserdatad/xcschemes/xcschememanagement.plist index 04ba4a4..308b575 100644 --- a/untitled.xcodeproj/xcuserdata/raj.sharma.xcuserdatad/xcschemes/xcschememanagement.plist +++ b/untitled.xcodeproj/xcuserdata/raj.sharma.xcuserdatad/xcschemes/xcschememanagement.plist @@ -4,6 +4,48 @@ SchemeUserState + Playground (Playground) 1.xcscheme + + isShown + + orderHint + 10 + + Playground (Playground) 2.xcscheme + + isShown + + orderHint + 11 + + Playground (Playground).xcscheme + + isShown + + orderHint + 9 + + SWXMLHashPlayground (Playground) 1.xcscheme + + isShown + + orderHint + 7 + + SWXMLHashPlayground (Playground) 2.xcscheme + + isShown + + orderHint + 8 + + SWXMLHashPlayground (Playground).xcscheme + + isShown + + orderHint + 6 + untitled.xcscheme_^#shared#^_ orderHint diff --git a/untitled/Assets.xcassets/AccentColor.colorset/Contents.json b/untitled/Assets.xcassets/AccentColor.colorset/Contents.json index eb87897..4bf40ac 100644 --- a/untitled/Assets.xcassets/AccentColor.colorset/Contents.json +++ b/untitled/Assets.xcassets/AccentColor.colorset/Contents.json @@ -1,6 +1,10 @@ { "colors" : [ { + "color" : { + "platform" : "universal", + "reference" : "systemIndigoColor" + }, "idiom" : "universal" } ], diff --git a/untitled/Components/ErrorView.swift b/untitled/Components/ErrorView.swift new file mode 100644 index 0000000..9165a7e --- /dev/null +++ b/untitled/Components/ErrorView.swift @@ -0,0 +1,20 @@ +// +// ErrorView.swift +// untitled +// +// Created by Raj Sharma on 04/03/24. +// + +import SwiftUI + +struct ErrorView: View { + let errorText: String + var body: some View { + Text(errorText) + .foregroundColor(Color.red) + } +} + +#Preview { + ErrorView(errorText:"example error") +} diff --git a/untitled/Components/LoadingView.swift b/untitled/Components/LoadingView.swift new file mode 100644 index 0000000..f6477a4 --- /dev/null +++ b/untitled/Components/LoadingView.swift @@ -0,0 +1,18 @@ +// +// LoadingView.swift +// untitled +// +// Created by Raj Sharma on 04/03/24. +// + +import SwiftUI + +struct LoadingView: View { + var body: some View { + Text(/*@START_MENU_TOKEN@*/"Loading..."/*@END_MENU_TOKEN@*/) + } +} + +#Preview { + LoadingView() +} diff --git a/untitled/ContentView.swift b/untitled/ContentView.swift deleted file mode 100644 index d023af8..0000000 --- a/untitled/ContentView.swift +++ /dev/null @@ -1,24 +0,0 @@ -// -// ContentView.swift -// untitled -// -// Created by Raj Sharma on 04/03/24. -// - -import SwiftUI - -struct ContentView: View { - var body: some View { - VStack { - Image(systemName: "globe") - .imageScale(.large) - .foregroundStyle(.tint) - Text("Hello, world!") - } - .padding() - } -} - -#Preview { - ContentView() -} diff --git a/untitled/Helpers/Constants.swift b/untitled/Helpers/Constants.swift new file mode 100644 index 0000000..e4dab3e --- /dev/null +++ b/untitled/Helpers/Constants.swift @@ -0,0 +1,14 @@ +// +// Constants.swift +// untitled +// +// Created by Raj Sharma on 04/03/24. +// + +import Foundation + +struct Constants { + static let apiEndpoint = "https://official-joke-api.appspot.com/jokes/programming/random" + static let server = "official-joke-api.appspot.com" +} + diff --git a/untitled/Helpers/Extensions.swift b/untitled/Helpers/Extensions.swift new file mode 100644 index 0000000..2413114 --- /dev/null +++ b/untitled/Helpers/Extensions.swift @@ -0,0 +1,19 @@ +// +// Extensions.swift +// untitled +// +// Created by Raj Sharma on 04/03/24. +// + +import SwiftUI + +extension View { + // Example of a custom modifier + func customModifier() -> some View { + self.padding(10) + .background(Color.blue) + .foregroundColor(.white) + .cornerRadius(5) + } +} + diff --git a/untitled/Info.plist b/untitled/Info.plist new file mode 100644 index 0000000..0c67376 --- /dev/null +++ b/untitled/Info.plist @@ -0,0 +1,5 @@ + + + + + diff --git a/untitled/Models/ResponseModel.swift b/untitled/Models/ResponseModel.swift new file mode 100644 index 0000000..d2a10cf --- /dev/null +++ b/untitled/Models/ResponseModel.swift @@ -0,0 +1,17 @@ +// +// ResponseModel.swift +// untitled +// +// Created by Raj Sharma on 04/03/24. +// + +import Foundation + +struct ResponseModel: Codable { + let ha_response: String +} + + +struct AiResponseModel: Codable { + let result: String +} diff --git a/untitled/Services/APIService.swift b/untitled/Services/APIService.swift new file mode 100644 index 0000000..ee2052c --- /dev/null +++ b/untitled/Services/APIService.swift @@ -0,0 +1,38 @@ +// +// APIService.swift +// untitled +// +// Created by Raj Sharma on 04/03/24. +// + +import Foundation + +class APIService: NSObject { + lazy var urlSession: URLSession = { + let configuration = URLSessionConfiguration.default + configuration.urlCache = nil // Disable caching for this session + configuration.requestCachePolicy = .reloadIgnoringLocalCacheData // Ignore local cache + return URLSession(configuration: configuration, delegate: self, delegateQueue: nil) + }() + + func fetchData() async throws -> ResponseModel { + let url = URL(string: Constants.apiEndpoint)! + let (data, _) = try await urlSession.data(from: url) + let responseModel = try JSONDecoder().decode(ResponseModel.self, from: data) + return responseModel + } +} + +extension APIService: URLSessionDelegate { + func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) { + // WARNING: Using .useCredential without validating the certificate poses a security risk + if challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust, + let serverTrust = challenge.protectionSpace.serverTrust { + let credential = URLCredential(trust: serverTrust) + completionHandler(.useCredential, credential) + } else { + completionHandler(.performDefaultHandling, nil) + } + } +} + diff --git a/untitled/Services/ModelInferenceService.swift b/untitled/Services/ModelInferenceService.swift new file mode 100644 index 0000000..43e65b5 --- /dev/null +++ b/untitled/Services/ModelInferenceService.swift @@ -0,0 +1,35 @@ +// +// AiService.swift +// untitled +// +// Created by Raj Sharma on 05/03/24. +// + +import Foundation +import LangChain + +class TranslationService { + let template = """ + Translate all input to hinglish (hindi in english). + + {history} + Human: {human_input} + Assistant: + """ + + lazy var chatgpt_chain: LLMChain = { + LLMChain( + llm: OpenAI(), + prompt: PromptTemplate(input_variables: ["history", "human_input"], partial_variable: [:], template: template), + memory: ConversationBufferWindowMemory() + ) + }() + + func translate(text: String) async throws -> String { + let input = text + // Assuming `chatgpt_chain.predict` returns a String and might throw an error. + guard let response = await chatgpt_chain.predict(args: ["human_input": input]) else { return "Failed" } + return response + } + +} diff --git a/untitled/ViewModels/ContentViewModel.swift b/untitled/ViewModels/ContentViewModel.swift new file mode 100644 index 0000000..15ff426 --- /dev/null +++ b/untitled/ViewModels/ContentViewModel.swift @@ -0,0 +1,48 @@ +// +// ContentViewModel.swift +// untitled +// +// Created by Raj Sharma on 04/03/24. +// + +import SwiftUI + +class ContentViewModel: ObservableObject { + @Published var responseString: String? + @Published var translatedText: String? + @Published var isLoading = false + @Published var error: Error? + + private var apiService = APIService() + private var translationService = TranslationService() + + func fetchData() async { + isLoading = true + do { + let responseModel = try await apiService.fetchData() + responseString = responseModel.ha_response + isLoading = false + } catch { + self.error = error + isLoading = false + } + } + + func updateUIWithTranslation(for text: String) async { + isLoading = true // Assuming you want to indicate loading state for translation as well. + do { + let translatedText = try await translationService.translate(text: text) + DispatchQueue.main.async { + // No longer needs Task, updates directly in the async context. + self.translatedText = translatedText + self.isLoading = false + } + } catch { + DispatchQueue.main.async { + self.error = error + self.isLoading = false + } + } + } +} + diff --git a/untitled/Views/ContentView.swift b/untitled/Views/ContentView.swift new file mode 100644 index 0000000..f4316e3 --- /dev/null +++ b/untitled/Views/ContentView.swift @@ -0,0 +1,38 @@ +// +// ContentView.swift +// untitled +// +// Created by Raj Sharma on 04/03/24. +// + +import SwiftUI + +struct ContentView: View { + @StateObject var viewModel = ContentViewModel() + + var body: some View { + VStack { + if viewModel.isLoading { + // Replace with a custom loading view if needed + LoadingView() + } else if let responseString = viewModel.translatedText { + Text(responseString) + } else if let error = viewModel.error { + // Replace with a custom error view if needed + ErrorView(errorText:error.localizedDescription) + } + }.padding() + .onAppear { + Task { + await viewModel.updateUIWithTranslation(for: "Hello mom") + } + } + } +} + + + +#Preview { + ContentView() +} +