The following file is absolutely right, I double checked it. The name matches the Azure website, the API Key is in there, why am I getting no response at all when trying to use this on Postman as a GET?
//https://disney-clone-portfolio.azurewebsites.net/api/getaisuggestion?term=action
import {
app,
HttpRequest,
HttpResponseInit,
InvocationContext,
} from "@azure/functions";
import OpenAI from "openai";
const openAI = new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
});
export async function getAISuggestion(
request: HttpRequest,
context: InvocationContext
): Promise<HttpResponseInit> {
context.log(`Http function processed request for url "${request.url}"`);
const term = request.query.get("term");
const completion = await openAI.chat.completions.create({
messages: [
{
role: "system",
content: `You are a digital video assistant working for services such as Netflix, Disney Plus & Amazon Prime Video. Your job is to provide suggestions based on the videos the user specifies. Provide an quirky breakdown of what the user should watch next! It should only list the names of the films after the introduction. Keep the response short and sweet! Always list at least 3 films as suggestions. If the user mentions a genre, you should provide a suggestion based on that genre.`,
},
{
role: "user",
content: `I like: ${term}`,
},
],
model: "gpt-3.5-turbo-16k",
});
return {
body: completion.choices[0].message.content || "No suggestions found",
};
}
app.http("getAISuggestion", {
methods: ["GET"],
authLevel: "anonymous",
handler: getAISuggestion,
});
import { app, HttpRequest, HttpResponseInit, InvocationContext } from "@azure/functions";
import OpenAI from "openai";
const apiVersion = '2024-02-15-preview';
const apiKey = process.env.OPENAI_API_KEY;
const openAI = new OpenAI({
apiKey: apiKey,
baseURL: process.env.OPENAI_BASE_URL,
defaultQuery: { 'api-version': apiVersion },
defaultHeaders: { 'api-key': apiKey },
});
export async function getAISuggestion(
request: HttpRequest,
context: InvocationContext
): Promise<HttpResponseInit> {
context.log(`Http function processed request for url "${request.url}"`);
const term = request.query.get("term");
const completion = await openAI.chat.completions.create({
messages: [
{
role: 'user',
content: `You are a digital video assistant working for services such as Netflix, Disney Plus & Amazon Prime Video. Your job is to provide suggestions based on the videos the user specifies. Provide an quirky breakdown of what the user should watch next! It should only list the names of the films after the introduction. Keep the response short and sweet! Always list at least 3 films as suggestions. If the user mentions a genre, you should provide a suggestion based on that genre.`,
},
{
role: "user",
content: `I like: ${term}`,
},
],
model: "gpt-35-turbo-16k",
});
return {
body: completion.choices[0].message.content || "No suggestions found",
};
};
app.http('getAISuggestion', {
methods: ['GET'],
authLevel: 'anonymous',
handler: getAISuggestion
});
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "node",
"AzureWebJobsFeatureFlags": "EnableWorkerIndexing",
"OPENAI_API_KEY": "a0ee****2a3",
"OPENAI_BASE_URL": "https://{resource_name}.openai.azure.com/openai/deployments/{model}"
}
}
func azure functionapp publish {func-app-name}
command too.