Skip to content

Commit

Permalink
enabling other autentication scenarios for OpenAI
Browse files Browse the repository at this point in the history
  • Loading branch information
cmendible committed Jan 17, 2024
1 parent db29e1d commit b3de149
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 24 deletions.
9 changes: 0 additions & 9 deletions src/AIHub/Controllers/AudioTranscriptionController.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
namespace MVCWeb.Controllers;
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Microsoft.AspNetCore.Mvc;
using System.Net;
using Newtonsoft.Json.Linq;
using Microsoft.VisualBasic;

public class AudioTranscriptionController : Controller
{
Expand Down
16 changes: 13 additions & 3 deletions src/AIHub/Controllers/BrandAnalyzerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,19 @@ public async Task<IActionResult> AnalyzeCompany()
try
{

OpenAIClient client_oai = new OpenAIClient(
new Uri(AOAIendpoint),
new AzureKeyCredential(AOAIsubscriptionKey));
OpenAIClient client_oai = null;
if (string.IsNullOrEmpty(AOAIsubscriptionKey))
{
client_oai = new OpenAIClient(
new Uri(AOAIendpoint),
new DefaultAzureCredential());
}
else
{
client_oai = new OpenAIClient(
new Uri(AOAIendpoint),
new AzureKeyCredential(AOAIsubscriptionKey));
}

// ### If streaming is not selected
Response<ChatCompletions> responseWithoutStream = await client_oai.GetChatCompletionsAsync(
Expand Down
17 changes: 13 additions & 4 deletions src/AIHub/Controllers/CallCenterController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,19 @@ public async Task<IActionResult> AnalyzeCall()
}
try
{

OpenAIClient client_oai = new OpenAIClient(
new Uri(endpoint),
new AzureKeyCredential(subscriptionKey));
OpenAIClient client_oai = null;
if (string.IsNullOrEmpty(subscriptionKey))
{
client_oai = new OpenAIClient(
new Uri(endpoint),
new DefaultAzureCredential());
}
else
{
client_oai = new OpenAIClient(
new Uri(endpoint),
new AzureKeyCredential(subscriptionKey));
}

// ### If streaming is not selected
Response<ChatCompletions> responseWithoutStream = await client_oai.GetChatCompletionsAsync(
Expand Down
17 changes: 13 additions & 4 deletions src/AIHub/Controllers/FormAnalyzerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,19 @@ public async Task<IActionResult> AnalyzeForm(string image_url, string prompt)

try
{

OpenAIClient client_oai = new OpenAIClient(
new Uri(AOAIendpoint),
new AzureKeyCredential(AOAIsubscriptionKey));
OpenAIClient client_oai = null;
if (string.IsNullOrEmpty(AOAIsubscriptionKey))
{
client_oai = new OpenAIClient(
new Uri(AOAIendpoint),
new DefaultAzureCredential());
}
else
{
client_oai = new OpenAIClient(
new Uri(AOAIendpoint),
new AzureKeyCredential(AOAIsubscriptionKey));
}

// ### If streaming is not selected
Response<ChatCompletions> responseWithoutStream = await client_oai.GetChatCompletionsAsync(
Expand Down
17 changes: 13 additions & 4 deletions src/AIHub/Controllers/ImageAnalyzerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,19 @@ public async Task<IActionResult> DenseCaptionImage(string image_url)
//7. Describe Image GPT4
try
{

OpenAIClient client_oai = new OpenAIClient(
new Uri(AOAIendpoint),
new AzureKeyCredential(AOAIsubscriptionKey));
OpenAIClient client_oai = null;
if (string.IsNullOrEmpty(AOAIsubscriptionKey))
{
client_oai = new OpenAIClient(
new Uri(AOAIendpoint),
new DefaultAzureCredential());
}
else
{
client_oai = new OpenAIClient(
new Uri(AOAIendpoint),
new AzureKeyCredential(AOAIsubscriptionKey));
}

// ### If streaming is not selected
Response<ChatCompletions> responseWithoutStream = await client_oai.GetChatCompletionsAsync(
Expand Down
2 changes: 2 additions & 0 deletions src/AIHub/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
global using MVCWeb.Models;
global using Azure.AI.ContentSafety;
global using Azure;
global using Azure.Identity;
global using Azure.Storage.Blobs;
global using Azure.Storage.Blobs.Models;
global using Azure.AI.OpenAI;
global using System.Net.Http.Headers;
global using Newtonsoft.Json;
global using Newtonsoft.Json.Linq;
global using System.Text;
global using System.Text.Json;
global using System.Text.Json.Serialization;

0 comments on commit b3de149

Please sign in to comment.