-
Notifications
You must be signed in to change notification settings - Fork 854
feat: Ai foundry #2398
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Ai foundry #2398
Conversation
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2398 +/- ##
==========================================
+ Coverage 84.47% 84.49% +0.02%
==========================================
Files 331 332 +1
Lines 17217 17242 +25
Branches 1541 1547 +6
==========================================
+ Hits 14544 14569 +25
Misses 2673 2673 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
| @@ -0,0 +1 @@ | |||
| {"cells":[{"cell_type":"markdown","source":["# Chat Completion with Azure AI Foundry model\n","\n","[Azure AI Foundry](https://learn.microsoft.com/en-us/azure/ai-foundry/what-is-azure-ai-foundry) enables the execution of a wide range of natural language tasks using the Completion API. Its integration with SynapseML simplifies leveraging the Apache Spark distributed computing framework to handle large volumes of prompts across various models, including those from Deepseek, Meta, Microsoft, xAI, and others. For a full list of [supported models](https://learn.microsoft.com/en-us/azure/ai-foundry/foundry-models/concepts/models), refer to Azure AI Foundry documentation.\n","Note: To use OpenAI models, integration is available through the OpenAIChatCompletion class. Refer to the relevant documentation for details on [using OpenAI models](https://microsoft.github.io/SynapseML/docs/Explore%20Algorithms/OpenAI/).\n"],"metadata":{"nteract":{"transient":{"deleting":false}}},"id":"6b268f55-cda1-49c1-ae84-0d6f38d0946a"},{"cell_type":"markdown","source":["## Prerequisites\n","The key prerequisites for this quickstart include \n","\n","- An [Azure subscription](https://azure.microsoft.com/en-us/pricing/purchase-options/azure-account)\n","\n","- A working Azure AI Foundry project resource and a model deployed\n"," * Sign in to the [Azure AI foundry portal](https://ai.azure.com/)\n"," * Select a chat completion model. We use Phi-4-mini-instruct model as an example. \n"," * \n","\n"," \n"," * On the model details page, select Use this model.\n"," * Fill in a name to use for your project and select Create.\n","\n","- An Apache Spark cluster with SynapseML installed."],"metadata":{"nteract":{"transient":{"deleting":false}}},"id":"3f705336-0fd0-4b08-930a-1c5f7aa684de"},{"cell_type":"markdown","source":["# Fill in service information\n","Next, edit the cell in the notebook to point to your service. \n","\n","In particular set the service_name, api_version to match them to your AI Foundry model.\n","To get your service_name, api_version and api_key, Select My Asset, Find Target URI. API version is also in target URI.\n","\n","\n"],"metadata":{"nteract":{"transient":{"deleting":false}}},"id":"75ad6753-02ee-4190-b993-4825a76d5f07"},{"cell_type":"code","source":["from synapse.ml.core.platform import find_secret\n","\n","# Fill in the following lines with your service information\n","service_name = \"synapseml-ai-foundry-resource\"\n","api_verion = \"2024-05-01-preview\"\n","model = \"Phi-4-mini-instruct\"\n","api_key = find_secret(\n"," secret_name=\"synapseml-ai-foundry-resource-key\", keyvault=\"mmlspark-build-keys\"\n",") # please replace this line with your key as a string\n","\n","assert api_key is not None and service_name is not None"],"outputs":[],"execution_count":null,"metadata":{"microsoft":{"language":"python","language_group":"synapse_pyspark"}},"id":"d65e5ef6-dc64-44e4-ae59-10ed8d8c1811"},{"cell_type":"markdown","source":["## Chat Completion\n","\n","Models such as Phi-4 and llama are capable of understanding chats instead of single prompts. The `AIFoundryChatCompletion` transformer exposes this functionality at scale."],"metadata":{"nteract":{"transient":{"deleting":false}},"microsoft":{"language":"python","language_group":"synapse_pyspark"}},"id":"886323f0-22c9-49c9-9c26-ca164c273c04"},{"cell_type":"code","source":["from synapse.ml.services.aifoundry import AIFoundryChatCompletion\n","from pyspark.sql import Row\n","from pyspark.sql.types import *\n","\n","\n","def make_message(role, content):\n"," return Row(role=role, content=content, name=role)\n","\n","\n","chat_df = spark.createDataFrame(\n"," [\n"," (\n"," [\n"," make_message(\n"," \"system\", \"You are an AI chatbot with red as your favorite color\"\n"," ),\n"," make_message(\"user\", \"Whats your favorite color\"),\n"," ],\n"," ),\n"," (\n"," [\n"," make_message(\"system\", \"You are very excited\"),\n"," make_message(\"user\", \"How are you today\"),\n"," ],\n"," ),\n"," ]\n",").toDF(\"messages\")\n","\n","\n","chat_completion = (\n"," AIFoundryChatCompletion()\n"," .setSubscriptionKey(api_key)\n"," .setCustomServiceName(service_name)\n"," .setModel(model)\n"," .setApiVersion(\"2024-05-01-preview\")\n"," .setMessagesCol(\"messages\")\n"," .setErrorCol(\"error\")\n"," .setOutputCol(\"chat_completions\")\n",")\n","\n","display(\n"," chat_completion.transform(chat_df).select(\n"," \"messages\", \"chat_completions.choices.message.content\"\n"," )\n",")"],"outputs":[],"execution_count":null,"metadata":{"microsoft":{"language":"python","language_group":"synapse_pyspark"},"collapsed":false},"id":"d4491222-78c6-4136-8711-8f837915b2a9"}],"metadata":{"language_info":{"name":"python"},"kernel_info":{"name":"synapse_pyspark"},"kernelspec":{"display_name":"synapse_pyspark","language":null,"name":"synapse_pyspark"},"a365ComputeOptions":null,"sessionKeepAliveTimeout":0,"microsoft":{"language":"python","language_group":"synapse_pyspark","ms_spell_check":{"ms_spell_check_language":"en"}},"nteract":{"version":"[email protected]"},"spark_compute":{"compute_id":"/trident/default","session_options":{"conf":{"spark.synapse.nbs.session.timeout":"1200000"}}},"synapse_widget":{"version":"0.1","state":{}},"dependencies":{"lakehouse":null}},"nbformat":4,"nbformat_minor":5} No newline at end of file | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we can format this so its multiline that will make it a bit easier to comment on
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
No description provided.