Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
138 changes: 138 additions & 0 deletions notebooks/example_javascript.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Loading checkpoint shards: 100%|██████████| 2/2 [00:00<00:00, 3.38it/s]\n",
"Special tokens have been added in the vocabulary, make sure the associated word embeddings are fine-tuned or trained.\n",
"Loading checkpoint shards: 100%|██████████| 2/2 [00:00<00:00, 3.42it/s]\n",
"Special tokens have been added in the vocabulary, make sure the associated word embeddings are fine-tuned or trained.\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Creating DFA mask store for LlamaTokenizerFast and javascript, may take more than 10 minutes. Caching at /home/shubham/syncode/cache/mask_stores/LlamaTokenizerFast/grammar_strict_2806037986_32000.pkl.\n",
"Ignore whitespace tokens is True\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|██████████| 385/385 [06:38<00:00, 1.04s/it]\n"
]
}
],
"source": [
"from syncode import Syncode\n",
"\n",
"import warnings\n",
"warnings.filterwarnings('ignore')\n",
"\n",
"model_name = \"microsoft/Phi-3-mini-128k-instruct\"\n",
"\n",
"# Load the unconstrained original model\n",
"llm = Syncode(model=model_name, mode='original', max_new_tokens=200)\n",
"\n",
"# Load the Syncode augmented model\n",
"syn_llm = Syncode(model=model_name, mode='grammar_strict', grammar='javascript', parse_output_only=True, max_new_tokens=200)"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"You are not running the flash-attention implementation, expect numerical differences.\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"LLM output:\n",
"Certainly! Below is a JavaScript function that takes a string as input and returns the reversed version of that string. This function efficiently utilizes JavaScript's built-in methods to achieve the desired outcome, ensuring optimal time and space complexity for this specific task.\n",
"\n",
"```javascript\n",
"function reverseString(str) {\n",
" // Check if the input is a string, if not, return an empty string or a relevant message\n",
" if (typeof str !== 'string') {\n",
" return \"Input must be a string\";\n",
" }\n",
"\n",
" // Use the built-in split(), reverse(), and join() methods to reverse the string\n",
" return str.split('').reverse().join('');\n",
"}\n",
"\n",
"// Example usage:\n",
"const originalString = \"Hello, World!\";\n",
"const reversedString = reverseString(originalString);\n",
"console.log(reversedString); // Output: \"!dlroW ,ol\n",
"\n"
]
}
],
"source": [
"prompt = \"Write a javascript function that takes a string as input and returns the string reversed.\"\n",
"output = llm.infer(prompt)[0]\n",
"print(f\"LLM output:\\n{output}\\n\")"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"LLM output:\n",
"Certainly! Below is a JavaScript function thattakesastringasinputandreturnsitsreversedversionusinganefficientapproachforthispurposewithminimalmemoryandtimecomplexityimpactsusuallyacharactersthefunctionwillhandlecorrectlyforstringsandnotforbinarydataorothercomplextypesensitivelyhandlingtheseedgecasesisnottheprimaryfocusbutitisconsideredinthisimplementationcontextforgeneralpurposeuseandunderstandabilitythefunctionisdesignedtobeefficientandstraightforwardforitsintendedusecasehereisthefunctioncodeimplementingthislogicwithcommentsforclarityandunderstandinghereisthefunctioncodewithinthiscontextandimplementationdetailsconsideredforgeneraluseandunderstandabilityinjavascriptlanguagefunctionreverseString(inputString) {\n",
" // Check if the input is a string\n",
" if (typeof inputString !== 'string') {\n",
" throw new Error('Input must\n",
"\n"
]
}
],
"source": [
"output = syn_llm.infer(prompt)[0]\n",
"print(f\"LLM output:\\n{output}\\n\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "codex",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.4"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
6 changes: 0 additions & 6 deletions syncode/larkm/__pyinstaller/__init__.py

This file was deleted.

14 changes: 0 additions & 14 deletions syncode/larkm/__pyinstaller/hook-lark.py

This file was deleted.

Loading