Skip to content

Commit

Permalink
feat(example): add convert demo (commented)
Browse files Browse the repository at this point in the history
  • Loading branch information
jhen0409 committed Aug 14, 2023
1 parent e50af05 commit bae6e69
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion example/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { DocumentPickerResponse } from 'react-native-document-picker'
import { Chat, darkTheme } from '@flyerhq/react-native-chat-ui'
import type { MessageType } from '@flyerhq/react-native-chat-ui'
// eslint-disable-next-line import/no-unresolved
import { initLlama, LlamaContext } from 'llama.rn'
import { initLlama, LlamaContext, convertJsonSchemaToGrammar } from 'llama.rn'

const randId = () => Math.random().toString(36).substr(2, 9)

Expand Down Expand Up @@ -184,6 +184,47 @@ export default function App() {
// })
}

let grammar
{
// Test JSON Schema -> grammar
const schema = {
oneOf: [
{
type: 'object',
properties: {
function: { const: 'create_event' },
arguments: {
type: 'object',
properties: {
title: { type: 'string' },
date: { type: 'string' },
time: { type: 'string' },
},
},
},
},
{
type: 'object',
properties: {
function: { const: 'image_search' },
arguments: {
type: 'object',
properties: {
query: { type: 'string' },
},
},
},
},
],
}

const converted = convertJsonSchemaToGrammar({ schema, propOrder: { function: 0, arguments: 1 } })
if (false) console.log('Converted grammar:', converted)

Check warning on line 222 in example/App.tsx

View workflow job for this annotation

GitHub Actions / lint

Unexpected constant condition

Check failure on line 222 in example/App.tsx

View workflow job for this annotation

GitHub Actions / lint

Unreachable code detected.
grammar = undefined
// Uncomment to test:
// grammar = converted
}

context
?.completion(
{
Expand All @@ -203,6 +244,7 @@ export default function App() {
mirostat_eta: 0.1, // learning rate
n_probs: 0, // Show probabilities
stop: ['</s>', 'llama:', 'User:'],
grammar,
// n_threads: 4,
// logit_bias: [[15043,1.0]],
},
Expand Down

0 comments on commit bae6e69

Please sign in to comment.