Not able to get any response from openAI

Hi,
I’m new to Cloud development using Forge UI. I’ve made call to the OpenAI using fetch but for some reason it is not fetching any results/errors. Appreciate if you can help here

import api from "@forge/api";
import { checkResponse } from "./checkResponse";

const TASKS = 'completions'
const API_ENDPOINT = `https://api.openai.com/v1/chat/completions`;
//const MODEL = "gpt-3.5-turbo-0613";
const MODEL = "code-davinci-002";
const MAX_TOKENS = 131;
const TEMP = 0.5;
const OPENAI_API_KEY="sk-Bj7oSPXXXXXXXXXX";


export async function getAIAcceptCriteria(description) {
  const prompt= `Generate acceptance criteria for the following Jira issue summary: ${description.replace( /(<([^>]+)>)/ig, '')}`
  console.log(`Inside OpenaiApi getAIAcceptCriteria prompt = ${prompt}`);
  try{
  const aiResponse = await api.fetch(API_ENDPOINT, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'Authorization': 'Bearer ' + OPENAI_API_KEY.replace(/"/g, ''),
    },
    body: JSON.stringify({
      prompt,
      "model": MODEL,
      "temperature": TEMP,
      "max_tokens": MAX_TOKENS,
      "top_p": 1,
      "frequency_penalty": 0.51,
      "presence_penalty": 0.1,
    }
    )
  });
 // await checkResponse('getAIAcceptCriteria', codexResponse);

  const aiResponseJson = await aiResponse.json();
  console.log("aiResponseJson", aiResponseJson);
   await checkResponse("getAIAcceptCriteria", aiResponseJson);
  const { text, finish_reason } = aiResponseJson.choices[0];
  console.log("🚀text", text);
  const resText = prompt + text;
  console.log("resText", finish_reason, '\n', resText);

  return { text: resText, finish_reason };
}catch(error){
    log.error(" Error in openaiApi  ",error)
    }
}

From logs i see that the it is coming into the method but not fetching results. I’m able to get results using the CURL command , but not from UI. Is there any thing missing. I’ve added below lines to manifest. Please help me here

  external:
    fetch:
      backend:
        - https://api.openai.com
1 Like

Check out this article. It suggests the following in the permissions section.

permissions:
  external:
    fetch:
      backend:
        - https://api.openai.com

Yes,
Below is my manifest.yml content . But still it is not fetching any results nor error

permissions:
  scopes:
    - write:jira-work
    - write:issue:jira
    - read:jira-work
  external:
    fetch:
      backend:
        - https://api.openai.com