Skip to content

Commit

Permalink
black formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
llermaly committed Oct 10, 2024
1 parent 46b86c4 commit ee4bb26
Showing 1 changed file with 23 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,10 @@
" client.options(request_timeout=5).inference.put(\n",
" task_type=\"sparse_embedding\",\n",
" inference_id=\"my-elser-model\",\n",
" body={\"service\": \"elser\", \"service_settings\": {\n",
" \"num_allocations\": 1, \"num_threads\": 1}},\n",
" body={\n",
" \"service\": \"elser\",\n",
" \"service_settings\": {\"num_allocations\": 1, \"num_threads\": 1},\n",
" },\n",
" )\n",
"except ConnectionTimeout:\n",
" pass"
Expand Down Expand Up @@ -262,19 +264,16 @@
"index_body = {\n",
" \"mappings\": {\n",
" \"properties\": {\n",
" \"title\": {\n",
" \"type\": \"text\",\n",
" \"analyzer\": \"english\"\n",
" },\n",
" \"title\": {\"type\": \"text\", \"analyzer\": \"english\"},\n",
" \"description\": {\n",
" \"type\": \"text\",\n",
" \"analyzer\": \"english\",\n",
" \"copy_to\": \"semantic_field\"\n",
" \"copy_to\": \"semantic_field\",\n",
" },\n",
" \"semantic_field\": {\n",
" \"type\": \"semantic_text\",\n",
" \"inference_id\": \"my-elser-model\"\n",
" }\n",
" \"inference_id\": \"my-elser-model\",\n",
" },\n",
" }\n",
" }\n",
"}\n",
Expand All @@ -295,32 +294,32 @@
" \"_index\": index_name,\n",
" \"_id\": \"email1\",\n",
" \"title\": \"Team Meeting Agenda\",\n",
" \"description\": \"Hello team, Let's discuss our project progress in tomorrow's meeting. Please prepare your updates. Best regards, Manager\"\n",
" \"description\": \"Hello team, Let's discuss our project progress in tomorrow's meeting. Please prepare your updates. Best regards, Manager\",\n",
" },\n",
" {\n",
" \"_index\": index_name,\n",
" \"_id\": \"email2\",\n",
" \"title\": \"Client Proposal Draft\",\n",
" \"description\": \"Hi, I've attached the draft of our client proposal. Could you review it and provide feedback? Thanks, Colleague\"\n",
" \"description\": \"Hi, I've attached the draft of our client proposal. Could you review it and provide feedback? Thanks, Colleague\",\n",
" },\n",
" {\n",
" \"_index\": index_name,\n",
" \"_id\": \"email3\",\n",
" \"title\": \"Weekly Newsletter\",\n",
" \"description\": \"This week in tech: AI advancements, new smartphone releases, and cybersecurity updates. Read more on our website!\"\n",
" \"description\": \"This week in tech: AI advancements, new smartphone releases, and cybersecurity updates. Read more on our website!\",\n",
" },\n",
" {\n",
" \"_index\": index_name,\n",
" \"_id\": \"email4\",\n",
" \"title\": \"Urgent: Project Deadline Update\",\n",
" \"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",
" \"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",
" },\n",
" {\n",
" \"_index\": index_name,\n",
" \"_id\": \"email5\",\n",
" \"title\": \"Invitation: Company Summer Picnic\",\n",
" \"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",
" }\n",
" \"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",
" },\n",
"]"
]
},
Expand Down Expand Up @@ -371,10 +370,12 @@
"source": [
"# https://github.com/riccardomusmeci/mlx-llm/blob/main/src/mlx_llm/prompt/openelm.py\n",
"def build_prompt(question, elasticsearch_documents):\n",
" docs_text = \"\\n\".join([\n",
" f\"Subject: {doc['title']}\\nBody: {doc['description']}\"\n",
" for doc in elasticsearch_documents\n",
" ])\n",
" docs_text = \"\\n\".join(\n",
" [\n",
" f\"Subject: {doc['title']}\\nBody: {doc['description']}\"\n",
" for doc in elasticsearch_documents\n",
" ]\n",
" )\n",
"\n",
" prompt = f\"\"\"\n",
" You are a helpful virtual assistant.\n",
Expand All @@ -392,12 +393,7 @@
"def retrieve_documents(question):\n",
" search_body = {\n",
" \"size\": 1,\n",
" \"query\": {\n",
" \"semantic\": {\n",
" \"query\": question,\n",
" \"field\": \"semantic_field\"\n",
" }\n",
" }\n",
" \"query\": {\"semantic\": {\"query\": question, \"field\": \"semantic_field\"}},\n",
" }\n",
" response = client.search(index=index_name, body=search_body)\n",
" return [hit[\"_source\"] for hit in response[\"hits\"][\"hits\"]]"
Expand Down Expand Up @@ -586,10 +582,10 @@
" prompt=prompt,\n",
" model=MODEL,\n",
" hf_access_token=HUGGINGFACE_TOKEN,\n",
" generate_kwargs={\"repetition_penalty\": 1.2, \"prompt_lookup_num_tokens\": 10}\n",
" generate_kwargs={\"repetition_penalty\": 1.2, \"prompt_lookup_num_tokens\": 10},\n",
")\n",
"print(\"-----GENERATION TIME-----\")\n",
"print(f'\\033[92m {round(generation_time, 2)} \\033[0m')\n",
"print(f\"\\033[92m {round(generation_time, 2)} \\033[0m\")\n",
"print(\"-----RESPONSE-----\")\n",
"print(output_text)"
]
Expand Down

0 comments on commit ee4bb26

Please sign in to comment.