Skip to content

Commit ee4bb26

Browse files
committed
black formatter
1 parent 46b86c4 commit ee4bb26

File tree

1 file changed

+23
-27
lines changed

1 file changed

+23
-27
lines changed

supporting-blog-content/using-openelm-models/using-openelm-models.ipynb

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,10 @@
226226
" client.options(request_timeout=5).inference.put(\n",
227227
" task_type=\"sparse_embedding\",\n",
228228
" inference_id=\"my-elser-model\",\n",
229-
" body={\"service\": \"elser\", \"service_settings\": {\n",
230-
" \"num_allocations\": 1, \"num_threads\": 1}},\n",
229+
" body={\n",
230+
" \"service\": \"elser\",\n",
231+
" \"service_settings\": {\"num_allocations\": 1, \"num_threads\": 1},\n",
232+
" },\n",
231233
" )\n",
232234
"except ConnectionTimeout:\n",
233235
" pass"
@@ -262,19 +264,16 @@
262264
"index_body = {\n",
263265
" \"mappings\": {\n",
264266
" \"properties\": {\n",
265-
" \"title\": {\n",
266-
" \"type\": \"text\",\n",
267-
" \"analyzer\": \"english\"\n",
268-
" },\n",
267+
" \"title\": {\"type\": \"text\", \"analyzer\": \"english\"},\n",
269268
" \"description\": {\n",
270269
" \"type\": \"text\",\n",
271270
" \"analyzer\": \"english\",\n",
272-
" \"copy_to\": \"semantic_field\"\n",
271+
" \"copy_to\": \"semantic_field\",\n",
273272
" },\n",
274273
" \"semantic_field\": {\n",
275274
" \"type\": \"semantic_text\",\n",
276-
" \"inference_id\": \"my-elser-model\"\n",
277-
" }\n",
275+
" \"inference_id\": \"my-elser-model\",\n",
276+
" },\n",
278277
" }\n",
279278
" }\n",
280279
"}\n",
@@ -295,32 +294,32 @@
295294
" \"_index\": index_name,\n",
296295
" \"_id\": \"email1\",\n",
297296
" \"title\": \"Team Meeting Agenda\",\n",
298-
" \"description\": \"Hello team, Let's discuss our project progress in tomorrow's meeting. Please prepare your updates. Best regards, Manager\"\n",
297+
" \"description\": \"Hello team, Let's discuss our project progress in tomorrow's meeting. Please prepare your updates. Best regards, Manager\",\n",
299298
" },\n",
300299
" {\n",
301300
" \"_index\": index_name,\n",
302301
" \"_id\": \"email2\",\n",
303302
" \"title\": \"Client Proposal Draft\",\n",
304-
" \"description\": \"Hi, I've attached the draft of our client proposal. Could you review it and provide feedback? Thanks, Colleague\"\n",
303+
" \"description\": \"Hi, I've attached the draft of our client proposal. Could you review it and provide feedback? Thanks, Colleague\",\n",
305304
" },\n",
306305
" {\n",
307306
" \"_index\": index_name,\n",
308307
" \"_id\": \"email3\",\n",
309308
" \"title\": \"Weekly Newsletter\",\n",
310-
" \"description\": \"This week in tech: AI advancements, new smartphone releases, and cybersecurity updates. Read more on our website!\"\n",
309+
" \"description\": \"This week in tech: AI advancements, new smartphone releases, and cybersecurity updates. Read more on our website!\",\n",
311310
" },\n",
312311
" {\n",
313312
" \"_index\": index_name,\n",
314313
" \"_id\": \"email4\",\n",
315314
" \"title\": \"Urgent: Project Deadline Update\",\n",
316-
" \"description\": \"Dear team, Due to recent developments, we need to move up our project deadline. The new submission date is next Friday. Please adjust your schedules accordingly and let me know if you foresee any issues. We'll discuss this in detail during our next team meeting. Best regards, Project Manager\"\n",
315+
" \"description\": \"Dear team, Due to recent developments, we need to move up our project deadline. The new submission date is next Friday. Please adjust your schedules accordingly and let me know if you foresee any issues. We'll discuss this in detail during our next team meeting. Best regards, Project Manager\",\n",
317316
" },\n",
318317
" {\n",
319318
" \"_index\": index_name,\n",
320319
" \"_id\": \"email5\",\n",
321320
" \"title\": \"Invitation: Company Summer Picnic\",\n",
322-
" \"description\": \"Hello everyone, We're excited to announce our annual company summer picnic! It will be held on Saturday, July 15th, at Sunny Park. There will be food, games, and activities for all ages. Please RSVP by replying to this email with the number of guests you'll be bringing. We look forward to seeing you there! Best, HR Team\"\n",
323-
" }\n",
321+
" \"description\": \"Hello everyone, We're excited to announce our annual company summer picnic! It will be held on Saturday, July 15th, at Sunny Park. There will be food, games, and activities for all ages. Please RSVP by replying to this email with the number of guests you'll be bringing. We look forward to seeing you there! Best, HR Team\",\n",
322+
" },\n",
324323
"]"
325324
]
326325
},
@@ -371,10 +370,12 @@
371370
"source": [
372371
"# https://github.com/riccardomusmeci/mlx-llm/blob/main/src/mlx_llm/prompt/openelm.py\n",
373372
"def build_prompt(question, elasticsearch_documents):\n",
374-
" docs_text = \"\\n\".join([\n",
375-
" f\"Subject: {doc['title']}\\nBody: {doc['description']}\"\n",
376-
" for doc in elasticsearch_documents\n",
377-
" ])\n",
373+
" docs_text = \"\\n\".join(\n",
374+
" [\n",
375+
" f\"Subject: {doc['title']}\\nBody: {doc['description']}\"\n",
376+
" for doc in elasticsearch_documents\n",
377+
" ]\n",
378+
" )\n",
378379
"\n",
379380
" prompt = f\"\"\"\n",
380381
" You are a helpful virtual assistant.\n",
@@ -392,12 +393,7 @@
392393
"def retrieve_documents(question):\n",
393394
" search_body = {\n",
394395
" \"size\": 1,\n",
395-
" \"query\": {\n",
396-
" \"semantic\": {\n",
397-
" \"query\": question,\n",
398-
" \"field\": \"semantic_field\"\n",
399-
" }\n",
400-
" }\n",
396+
" \"query\": {\"semantic\": {\"query\": question, \"field\": \"semantic_field\"}},\n",
401397
" }\n",
402398
" response = client.search(index=index_name, body=search_body)\n",
403399
" return [hit[\"_source\"] for hit in response[\"hits\"][\"hits\"]]"
@@ -586,10 +582,10 @@
586582
" prompt=prompt,\n",
587583
" model=MODEL,\n",
588584
" hf_access_token=HUGGINGFACE_TOKEN,\n",
589-
" generate_kwargs={\"repetition_penalty\": 1.2, \"prompt_lookup_num_tokens\": 10}\n",
585+
" generate_kwargs={\"repetition_penalty\": 1.2, \"prompt_lookup_num_tokens\": 10},\n",
590586
")\n",
591587
"print(\"-----GENERATION TIME-----\")\n",
592-
"print(f'\\033[92m {round(generation_time, 2)} \\033[0m')\n",
588+
"print(f\"\\033[92m {round(generation_time, 2)} \\033[0m\")\n",
593589
"print(\"-----RESPONSE-----\")\n",
594590
"print(output_text)"
595591
]

0 commit comments

Comments
 (0)