From 5c642e9b57f8b37e21e5a0a06cc950918de547e8 Mon Sep 17 00:00:00 2001 From: Mike Wolfson Date: Thu, 1 Aug 2024 16:00:14 -0700 Subject: [PATCH] Add azure endpoint and also get ready for release --- multi_ai_hub.ipynb | 85 ++++++++++++++++++++++++++++++++++++++++------ setup.py | 2 +- 2 files changed, 76 insertions(+), 11 deletions(-) diff --git a/multi_ai_hub.ipynb b/multi_ai_hub.ipynb index 890507c..f15c19b 100644 --- a/multi_ai_hub.ipynb +++ b/multi_ai_hub.ipynb @@ -460,6 +460,74 @@ "# print(generate_text_anthropic(\"you are a pirate\" + \"say hello and return the message in uppercase\", \"claude-3-opus-20240229\"))" ] }, + { + "cell_type": "markdown", + "id": "8e65d052", + "metadata": {}, + "source": [ + "## Setup Azure\n", + "\n", + "Check the [docs](https://learn.microsoft.com/en-us/azure/ai-services/openai/how-to/create-resource?pivots=web-portal), and get a project setup.\n", + "\n", + "You will need an Project URI and an API_KEY and you should create environment variables for these, with the following names:\n", + "\n", + "- AZURE_ENDPOINT_URL\n", + "- AZURE_OPENAI_API_KEY\n", + "\n", + "### Import SDK \n", + "\n", + "There is no additional dependencies, because this uses the OpenAI SDK." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "dc95b9f5", + "metadata": {}, + "outputs": [], + "source": [ + "import os\n", + "from openai import AzureOpenAI\n", + "\n", + "endpoint = os.getenv('AZURE_ENDPOINT_URL')\n", + "apiKey = os.getenv('AZURE_OPENAI_API_KEY')\n", + " \n", + "client = AzureOpenAI(\n", + " azure_endpoint=endpoint,\n", + " api_key=apiKey,\n", + " api_version=\"2024-05-01-preview\",\n", + ")\n", + "\n", + "def generate_text_azure(pre, prompt, model=\"gpt-4\"):\n", + " completion = client.chat.completions.create(\n", + " model=model,\n", + " messages=[\n", + " {\"role\": \"system\", \"content\": pre},\n", + " {\"role\": \"user\", \"content\": prompt}\n", + " ]\n", + " )\n", + "\n", + " return completion.choices[0].message.content" + ] + }, + { + "cell_type": "markdown", + "id": "17b5d510", + "metadata": {}, + "source": [ + "### Test the Azure Endpoint directly" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ae52400c", + "metadata": {}, + "outputs": [], + "source": [ + "# print(generate_text_azure(\"you are a pirate\", \"say hello and return the message in uppercase\", \"gpt-4\"))" + ] + }, { "cell_type": "markdown", "id": "55e643db", @@ -488,6 +556,7 @@ "# Constants for the models - use the unique name of the model as defined in the SDK\n", "ANTHROPIC_OPUS = \"claude-3-opus-20240229\"\n", "ANTHROPIC_SONNET = \"claude-3-5-sonnet-20240620\"\n", + "AZURE_GPT4 = \"gpt-4\"\n", "GEMINI_PRO = \"gemini-pro\"\n", "GEMINI_FLASH = \"gemini-1.5-flash-latest\"\n", "OPEN_AI_GPT35TURBO = \"gpt-3.5-turbo\"\n", @@ -511,6 +580,10 @@ " response = generate_text_anthropic(system + user + output_style, ANTHROPIC_SONNET)\n", " return response\n", "\n", + "def action_azure_gpt4(system, user, output_style):\n", + " response = generate_text_azure(system, user + output_style, AZURE_GPT4)\n", + " return response\n", + "\n", "def action_gemini_pro(system, user, output_style,):\n", " response = generate_text_google(system + user + output_style, GEMINI_PRO)\n", " return response\n", @@ -559,6 +632,7 @@ "action_dict = {\n", " ANTHROPIC_OPUS: action_anthropic_opus,\n", " ANTHROPIC_SONNET: action_anthropic_sonnet,\n", + " AZURE_GPT4: action_azure_gpt4,\n", " GEMINI_PRO: action_gemini_pro,\n", " GEMINI_FLASH: action_gemini_flash,\n", " OPEN_AI_GPT35TURBO: action_openai_35turbo,\n", @@ -647,16 +721,7 @@ "source": [ "# models = [ \n", "# ANTHROPIC_OPUS,\n", - "# ANTHROPIC_SONNET,\n", - "# GEMINI_PRO,\n", - "# GEMINI_FLASH,\n", - "# OPEN_AI_GPT35TURBO,\n", - "# OPEN_AI_GPT4,\n", - "# OPEN_AI_GPT4O,\n", - "# OPEN_AI_GPT4PREVIEW,\n", - "# PPLX_LLAMA3_8B,\n", - "# PPLX_LLAMA3_70B,\n", - "# SONAR_MED_ONLINE\n", + "# AZURE_GPT4\n", "# ]\n", "\n", "# system = \"You are a pirate\"\n", diff --git a/setup.py b/setup.py index 0f446c1..d0e9c4e 100644 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ setup( name='multiaihub', - version='0.1.4', # Start with a version number + version='0.1.5', # Start with a version number description='Short description of your project', license='Apache License 2.0', long_description="MAH - Multi AI Hub is a project designed to make it easy to send the same prompt to multiple LLMs to help with testing and comparison.",