community[patch]: update sambastudio embeddings (#23133)

Description: update sambastudio embeddings integration, now compatible
with generic endpoints and CoE endpoints
This commit is contained in:
Jorge Piedrahita Ortiz
2024-06-19 12:26:56 -05:00
committed by GitHub
parent db6f46c1a6
commit e162893d7f
2 changed files with 179 additions and 27 deletions

View File

@@ -43,12 +43,14 @@
"import os\n",
"\n",
"sambastudio_base_url = \"<Your SambaStudio environment URL>\"\n",
"sambastudio_base_uri = \"<Your SambaStudio environment URI>\"\n",
"sambastudio_project_id = \"<Your SambaStudio project id>\"\n",
"sambastudio_endpoint_id = \"<Your SambaStudio endpoint id>\"\n",
"sambastudio_api_key = \"<Your SambaStudio endpoint API key>\"\n",
"\n",
"# Set the environment variables\n",
"os.environ[\"SAMBASTUDIO_EMBEDDINGS_BASE_URL\"] = sambastudio_base_url\n",
"os.environ[\"SAMBASTUDIO_EMBEDDINGS_BASE_URI\"] = sambastudio_base_uri\n",
"os.environ[\"SAMBASTUDIO_EMBEDDINGS_PROJECT_ID\"] = sambastudio_project_id\n",
"os.environ[\"SAMBASTUDIO_EMBEDDINGS_ENDPOINT_ID\"] = sambastudio_endpoint_id\n",
"os.environ[\"SAMBASTUDIO_EMBEDDINGS_API_KEY\"] = sambastudio_api_key"
@@ -79,6 +81,50 @@
"results = embeddings.embed_documents(texts)\n",
"print(results)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You can manually pass the endpoint parameters and manually set the batch size you have in your SambaStudio embeddings endpoint"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"embeddings = SambaStudioEmbeddings(\n",
" sambastudio_embeddings_base_url=sambastudio_base_url,\n",
" sambastudio_embeddings_base_uri=sambastudio_base_uri,\n",
" sambastudio_embeddings_project_id=sambastudio_project_id,\n",
" sambastudio_embeddings_endpoint_id=sambastudio_endpoint_id,\n",
" sambastudio_embeddings_api_key=sambastudio_api_key,\n",
" batch_size=32,\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Or You can use an embedding model expert included in your deployed CoE"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"embeddings = SambaStudioEmbeddings(\n",
" batch_size=1,\n",
" model_kwargs={\n",
" \"select_expert\": \"e5-mistral-7b-instruct\",\n",
" },\n",
")"
]
}
],
"metadata": {