Skip to content

Commit

Permalink
Merge pull request #15 from mwolfson/add_azure_endpoints
Browse files Browse the repository at this point in the history
Add azure endpoint and also get ready for release
  • Loading branch information
mwolfson authored Aug 1, 2024
2 parents c328705 + 5c642e9 commit 6601c61
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 11 deletions.
85 changes: 75 additions & 10 deletions multi_ai_hub.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
"## <a name=\"azure_api\"></a>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",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down

0 comments on commit 6601c61

Please sign in to comment.