Simplify our docs with complicated functions into utils (#1807)
Co-authored-by: Chayenne <zhaochenyang@ucla.edu>
This commit is contained in:
@@ -28,42 +28,16 @@
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"import subprocess\n",
|
||||
"import time\n",
|
||||
"import requests\n",
|
||||
"\n",
|
||||
"# Equivalent to running this in the shell:\n",
|
||||
"# python -m sglang.launch_server --model-path Alibaba-NLP/gte-Qwen2-7B-instruct --port 30010 --host 0.0.0.0 --is-embedding --log-level error\n",
|
||||
"embedding_process = subprocess.Popen(\n",
|
||||
" [\n",
|
||||
" \"python\",\n",
|
||||
" \"-m\",\n",
|
||||
" \"sglang.launch_server\",\n",
|
||||
" \"--model-path\",\n",
|
||||
" \"Alibaba-NLP/gte-Qwen2-7B-instruct\",\n",
|
||||
" \"--port\",\n",
|
||||
" \"30010\",\n",
|
||||
" \"--host\",\n",
|
||||
" \"0.0.0.0\",\n",
|
||||
" \"--is-embedding\",\n",
|
||||
" \"--log-level\",\n",
|
||||
" \"error\",\n",
|
||||
" ],\n",
|
||||
" text=True,\n",
|
||||
" stdout=subprocess.DEVNULL,\n",
|
||||
" stderr=subprocess.DEVNULL,\n",
|
||||
")\n",
|
||||
"from sglang.utils import execute_shell_command, wait_for_server, terminate_process\n",
|
||||
"\n",
|
||||
"while True:\n",
|
||||
" try:\n",
|
||||
" response = requests.get(\n",
|
||||
" \"http://localhost:30010/v1/models\",\n",
|
||||
" headers={\"Authorization\": \"Bearer None\"},\n",
|
||||
" )\n",
|
||||
" if response.status_code == 200:\n",
|
||||
" break\n",
|
||||
" except requests.exceptions.RequestException:\n",
|
||||
" time.sleep(1)\n",
|
||||
"embedding_process = execute_shell_command(\"\"\"\n",
|
||||
"python -m sglang.launch_server --model-path Alibaba-NLP/gte-Qwen2-7B-instruct \\\n",
|
||||
" --port 30010 --host 0.0.0.0 --is-embedding --log-level error\n",
|
||||
"\"\"\")\n",
|
||||
"\n",
|
||||
"wait_for_server(\"http://localhost:30010\")\n",
|
||||
"\n",
|
||||
"print(\"Embedding server is ready. Proceeding with the next steps.\")"
|
||||
]
|
||||
@@ -134,6 +108,15 @@
|
||||
"embedding = response.data[0].embedding[:10]\n",
|
||||
"print(embedding)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"terminate_process(embedding_process)"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
|
||||
Reference in New Issue
Block a user