Skip to content

Commit

Permalink
feat(example): add lora comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jhen0409 committed Nov 20, 2024
1 parent 86fb239 commit 121bc46
Showing 1 changed file with 34 additions and 7 deletions.
41 changes: 34 additions & 7 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export default function App() {

const handleInitContext = async (
file: DocumentPickerResponse,
loraFile?: DocumentPickerResponse,
loraFile: DocumentPickerResponse | null,
) => {
await handleReleaseContext()
await getModelInfo(file.uri)
Expand Down Expand Up @@ -179,19 +179,26 @@ export default function App() {
return file
}

const pickLora = async () => {
let loraFile
const loraRes = await DocumentPicker.pick({
type: Platform.OS === 'ios' ? 'public.data' : 'application/octet-stream',
}).catch((e) => console.log('No lora file picked, error: ', e.message))
if (loraRes?.[0]) loraFile = await copyFileIfNeeded('lora', loraRes[0])
return loraFile
}

const handlePickModel = async () => {
const modelRes = await DocumentPicker.pick({
type: Platform.OS === 'ios' ? 'public.data' : 'application/octet-stream',
}).catch((e) => console.log('No model file picked, error: ', e.message))
if (!modelRes?.[0]) return
const modelFile = await copyFileIfNeeded('model', modelRes?.[0])

let loraFile
let loraFile = null
// Example: Apply lora adapter (Currently only select one lora file) (Uncomment to use)
// const loraRes = await DocumentPicker.pick({
// type: Platform.OS === 'ios' ? 'public.data' : 'application/octet-stream',
// }).catch(e => console.log('No lora file picked, error: ', e.message))
// if (loraRes?.[0]) loraFile = await copyFileIfNeeded('lora', loraRes[0])
// loraFile = await pickLora()
loraFile = null

handleInitContext(modelFile, loraFile)
}
Expand Down Expand Up @@ -278,6 +285,26 @@ export default function App() {
addSystemMessage(`Session load failed: ${e.message}`)
})
return
case '/lora':
pickLora()
.then((loraFile) => {
if (loraFile)
context.applyLoraAdapters([{ path: loraFile.uri }])
})
.then(context.getLoadedLoraAdapters)
.then((loraList) =>
addSystemMessage(
`Loaded lora adapters: ${JSON.stringify(loraList)}`,
),
)
return
case '/lora-list':
context.getLoadedLoraAdapters().then((loraList) => {
addSystemMessage(
`Loaded lora adapters: ${JSON.stringify(loraList)}`,
)
})
return
}
}
const textMessage: MessageType.Text = {
Expand Down Expand Up @@ -417,7 +444,7 @@ export default function App() {
dry_base: 1.75,
dry_allowed_length: 2,
dry_penalty_last_n: -1,
dry_sequence_breakers: ["\n", ":", "\"", "*"],
dry_sequence_breakers: ['\n', ':', '"', '*'],
mirostat: 0,
mirostat_tau: 5,
mirostat_eta: 0.1,
Expand Down

0 comments on commit 121bc46

Please sign in to comment.