Skip to content

Commit 922b824

Browse files
jakmroJakubGonera
authored andcommitted
feat: pre-commit code formatting (#107)
## Description Add pre-commit code formatting ### Type of change - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] Documentation update (improves or adds clarity to existing documentation) ### Tested on - [x] iOS - [x] Android ### Checklist - [x] I have performed a self-review of my code - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have updated the documentation accordingly - [x] My changes generate no new warnings
1 parent 71af65a commit 922b824

File tree

274 files changed

+9994
-11753
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

274 files changed

+9994
-11753
lines changed

.github/ISSUE_TEMPLATE/bug-report.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,4 +163,4 @@ body:
163163
options:
164164
- 'Yes'
165165
validations:
166-
required: true
166+
required: true

.github/ISSUE_TEMPLATE/feature-request.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,4 @@ body:
4747
description: >
4848
Add any other relevant context, code examples, or screenshots that should be considered.
4949
validations:
50-
required: false
50+
required: false

.github/pull_request_template.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,38 @@
11
## Description
2+
23
<!-- Provide a concise and descriptive summary of the changes implemented in this PR. -->
34

45
### Type of change
6+
57
- [ ] Bug fix (non-breaking change which fixes an issue)
68
- [ ] New feature (non-breaking change which adds functionality)
79
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
810
- [ ] Documentation update (improves or adds clarity to existing documentation)
911

1012
### Tested on
13+
1114
- [ ] iOS
1215
- [ ] Android
1316

1417
### Testing instructions
18+
1519
<!-- Provide step-by-step instructions on how to test your changes. Include setup details if necessary. -->
1620

1721
### Screenshots
22+
1823
<!-- Add screenshots here, if applicable -->
1924

2025
### Related issues
26+
2127
<!-- Link related issues here using #issue-number -->
2228

2329
### Checklist
30+
2431
- [ ] I have performed a self-review of my code
2532
- [ ] I have commented my code, particularly in hard-to-understand areas
2633
- [ ] I have updated the documentation accordingly
2734
- [ ] My changes generate no new warnings
2835

2936
### Additional notes
30-
<!-- Include any additional information, assumptions, or context that reviewers might need to understand this PR. -->
37+
38+
<!-- Include any additional information, assumptions, or context that reviewers might need to understand this PR. -->

.github/workflows/build-ios-llama-example.yml

+2-3
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ on:
1717
jobs:
1818
build:
1919
if: github.repository == 'software-mansion/react-native-executorch'
20-
name: "Example app iOS build check"
20+
name: 'Example app iOS build check'
2121
runs-on: macos-latest
2222
steps:
2323
- name: Check out Git repository
2424
uses: actions/checkout@v4
25-
25+
2626
- name: Install node dependencies
2727
working-directory: examples/llama
2828
run: yarn
@@ -42,4 +42,3 @@ jobs:
4242
-destination 'platform=iOS Simulator,name=iPhone 16 Pro' \
4343
build \
4444
CODE_SIGNING_ALLOWED=NO | xcbeautify
45-

.github/workflows/docs-build-check.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ jobs:
3131
run: mkdir -p .yarn/cache && yarn
3232
- name: Generate docs
3333
working-directory: ${{ env.WORKING_DIRECTORY }}
34-
run: yarn build
34+
run: yarn build

.watchmanconfig

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{}
1+
{}

.yarnrc.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ nmHoistingLimits: workspaces
33

44
plugins:
55
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
6-
spec: "@yarnpkg/plugin-interactive-tools"
6+
spec: '@yarnpkg/plugin-interactive-tools'
77
- path: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs
8-
spec: "@yarnpkg/plugin-workspace-tools"
8+
spec: '@yarnpkg/plugin-workspace-tools'
99

1010
yarnPath: .yarn/releases/yarn-3.6.1.cjs
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,36 @@
11
package com.swmansion.rnexecutorch
22

33
import android.util.Log
4+
import com.facebook.react.bridge.Arguments
45
import com.facebook.react.bridge.Promise
56
import com.facebook.react.bridge.ReactApplicationContext
7+
import com.facebook.react.bridge.WritableMap
68
import com.swmansion.rnexecutorch.models.classification.ClassificationModel
79
import com.swmansion.rnexecutorch.utils.ETError
810
import com.swmansion.rnexecutorch.utils.ImageProcessor
911
import org.opencv.android.OpenCVLoader
10-
import com.facebook.react.bridge.Arguments
11-
import com.facebook.react.bridge.WritableMap
12-
13-
class Classification(reactContext: ReactApplicationContext) :
14-
NativeClassificationSpec(reactContext) {
1512

13+
class Classification(
14+
reactContext: ReactApplicationContext,
15+
) : NativeClassificationSpec(reactContext) {
1616
private lateinit var classificationModel: ClassificationModel
1717

1818
companion object {
1919
const val NAME = "Classification"
20+
2021
init {
21-
if(!OpenCVLoader.initLocal()){
22+
if (!OpenCVLoader.initLocal()) {
2223
Log.d("rn_executorch", "OpenCV not loaded")
2324
} else {
2425
Log.d("rn_executorch", "OpenCV loaded")
2526
}
2627
}
2728
}
2829

29-
override fun loadModule(modelSource: String, promise: Promise) {
30+
override fun loadModule(
31+
modelSource: String,
32+
promise: Promise,
33+
) {
3034
try {
3135
classificationModel = ClassificationModel(reactApplicationContext)
3236
classificationModel.loadModel(modelSource)
@@ -36,24 +40,25 @@ class Classification(reactContext: ReactApplicationContext) :
3640
}
3741
}
3842

39-
override fun forward(input: String, promise: Promise) {
43+
override fun forward(
44+
input: String,
45+
promise: Promise,
46+
) {
4047
try {
4148
val image = ImageProcessor.readImage(input)
4249
val output = classificationModel.runModel(image)
4350

4451
val writableMap: WritableMap = Arguments.createMap()
45-
52+
4653
for ((key, value) in output) {
4754
writableMap.putDouble(key, value.toDouble())
4855
}
4956

5057
promise.resolve(writableMap)
51-
}catch(e: Exception){
58+
} catch (e: Exception) {
5259
promise.reject(e.message!!, e.message)
5360
}
5461
}
5562

56-
override fun getName(): String {
57-
return NAME
58-
}
63+
override fun getName(): String = NAME
5964
}

android/src/main/java/com/swmansion/rnexecutorch/ETModule.kt

+28-19
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,26 @@ import org.pytorch.executorch.EValue
1111
import org.pytorch.executorch.Module
1212
import java.net.URL
1313

14-
class ETModule(reactContext: ReactApplicationContext) : NativeETModuleSpec(reactContext) {
14+
class ETModule(
15+
reactContext: ReactApplicationContext,
16+
) : NativeETModuleSpec(reactContext) {
1517
private lateinit var module: Module
16-
private var reactApplicationContext = reactContext;
17-
override fun getName(): String {
18-
return NAME
19-
}
18+
private var reactApplicationContext = reactContext
19+
20+
override fun getName(): String = NAME
2021

21-
override fun loadModule(modelSource: String, promise: Promise) {
22+
override fun loadModule(
23+
modelSource: String,
24+
promise: Promise,
25+
) {
2226
module = Module.load(URL(modelSource).path)
2327
promise.resolve(0)
2428
}
2529

26-
override fun loadMethod(methodName: String, promise: Promise) {
30+
override fun loadMethod(
31+
methodName: String,
32+
promise: Promise,
33+
) {
2734
val result = module.loadMethod(methodName)
2835
if (result != 0) {
2936
promise.reject("Method loading failed", result.toString())
@@ -37,35 +44,37 @@ class ETModule(reactContext: ReactApplicationContext) : NativeETModuleSpec(react
3744
inputs: ReadableArray,
3845
shapes: ReadableArray,
3946
inputTypes: ReadableArray,
40-
promise: Promise
47+
promise: Promise,
4148
) {
4249
val inputEValues = ArrayList<EValue>()
4350
try {
4451
for (i in 0 until inputs.size()) {
45-
val currentInput = inputs.getArray(i)
46-
?: throw Exception(ETError.InvalidArgument.code.toString())
47-
val currentShape = shapes.getArray(i)
48-
?: throw Exception(ETError.InvalidArgument.code.toString())
52+
val currentInput =
53+
inputs.getArray(i)
54+
?: throw Exception(ETError.InvalidArgument.code.toString())
55+
val currentShape =
56+
shapes.getArray(i)
57+
?: throw Exception(ETError.InvalidArgument.code.toString())
4958
val currentInputType = inputTypes.getInt(i)
5059

51-
val currentEValue = TensorUtils.getExecutorchInput(
52-
currentInput,
53-
ArrayUtils.createLongArray(currentShape),
54-
currentInputType
55-
)
60+
val currentEValue =
61+
TensorUtils.getExecutorchInput(
62+
currentInput,
63+
ArrayUtils.createLongArray(currentShape),
64+
currentInputType,
65+
)
5666

5767
inputEValues.add(currentEValue)
5868
}
5969

60-
val forwardOutputs = module.forward(*inputEValues.toTypedArray());
70+
val forwardOutputs = module.forward(*inputEValues.toTypedArray())
6171
val outputArray = Arguments.createArray()
6272

6373
for (output in forwardOutputs) {
6474
val arr = ArrayUtils.createReadableArrayFromTensor(output.toTensor())
6575
outputArray.pushArray(arr)
6676
}
6777
promise.resolve(outputArray)
68-
6978
} catch (e: IllegalArgumentException) {
7079
// The error is thrown when transformation to Tensor fails
7180
promise.reject("Forward Failed Execution", ETError.InvalidArgument.code.toString())

android/src/main/java/com/swmansion/rnexecutorch/LLM.kt

+18-12
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,23 @@ import android.util.Log
44
import com.facebook.react.bridge.Promise
55
import com.facebook.react.bridge.ReactApplicationContext
66
import com.facebook.react.bridge.ReadableArray
7+
import com.swmansion.rnexecutorch.utils.ArrayUtils
78
import com.swmansion.rnexecutorch.utils.llms.ChatRole
89
import com.swmansion.rnexecutorch.utils.llms.ConversationManager
910
import com.swmansion.rnexecutorch.utils.llms.END_OF_TEXT_TOKEN
1011
import org.pytorch.executorch.LlamaCallback
1112
import org.pytorch.executorch.LlamaModule
12-
import com.swmansion.rnexecutorch.utils.ArrayUtils
1313
import java.net.URL
1414

15-
class LLM(reactContext: ReactApplicationContext) : NativeLLMSpec(reactContext), LlamaCallback {
16-
15+
class LLM(
16+
reactContext: ReactApplicationContext,
17+
) : NativeLLMSpec(reactContext),
18+
LlamaCallback {
1719
private var llamaModule: LlamaModule? = null
1820
private var tempLlamaResponse = StringBuilder()
1921
private lateinit var conversationManager: ConversationManager
2022

21-
override fun getName(): String {
22-
return NAME
23-
}
23+
override fun getName(): String = NAME
2424

2525
override fun initialize() {
2626
super.initialize()
@@ -41,12 +41,15 @@ class LLM(reactContext: ReactApplicationContext) : NativeLLMSpec(reactContext),
4141
systemPrompt: String,
4242
messageHistory: ReadableArray,
4343
contextWindowLength: Double,
44-
promise: Promise
44+
promise: Promise,
4545
) {
4646
try {
47-
this.conversationManager = ConversationManager(
48-
contextWindowLength.toInt(), systemPrompt, ArrayUtils.createMapArray<String>(messageHistory)
49-
)
47+
this.conversationManager =
48+
ConversationManager(
49+
contextWindowLength.toInt(),
50+
systemPrompt,
51+
ArrayUtils.createMapArray<String>(messageHistory),
52+
)
5053
llamaModule = LlamaModule(1, URL(modelSource).path, URL(tokenizerSource).path, 0.7f)
5154
this.tempLlamaResponse.clear()
5255
promise.resolve("Model loaded successfully")
@@ -55,7 +58,10 @@ class LLM(reactContext: ReactApplicationContext) : NativeLLMSpec(reactContext),
5558
}
5659
}
5760

58-
override fun runInference(input: String, promise: Promise) {
61+
override fun runInference(
62+
input: String,
63+
promise: Promise,
64+
) {
5965
this.conversationManager.addResponse(input, ChatRole.USER)
6066
val conversation = this.conversationManager.getConversation()
6167

@@ -66,7 +72,7 @@ class LLM(reactContext: ReactApplicationContext) : NativeLLMSpec(reactContext),
6672
// generated sequence length is larger than specified in the JNI callback, hence we check if EOT
6773
// is there and if not, we append it to the output and emit the EOT token to the JS side.
6874
if (!this.tempLlamaResponse.endsWith(END_OF_TEXT_TOKEN)) {
69-
this.onResult(END_OF_TEXT_TOKEN);
75+
this.onResult(END_OF_TEXT_TOKEN)
7076
}
7177

7278
// We want to add the LLM response to the conversation once all the tokens are generated.

0 commit comments

Comments
 (0)