---
title: "Discussion on \"Integrating Open AI into Angular application : Step by Step Guide\" | Hashnode"
description: "Discussion on \"Integrating Open AI into Angular application : Step by Step Guide\". Check out our article to learn how to integrate ChatGPT into an angular application in three simple steps."
url: "https://hashnode.com/posts/integrating-open-ai-into-angular-application/63d3b2c3d4a6f74f06ffda8e"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Integrating Open AI into Angular application : Step by Step Guide](https://vishugosain.hashnode.dev/integrating-open-ai-into-angular-application?utm_source=hashnode&utm_medium=feed)

Check out our article to learn how to integrate ChatGPT into an angular application in three simple steps.

Jan 27, 2023 · 5 min read · vishugosain.hashnode.dev  
Updated Aug 26, 2023  
Read the article

-   [#javascript](https://hashnode.com/tag/javascript)
-   [#angularjs](https://hashnode.com/tag/angularjs)
-   [#web-development](https://hashnode.com/tag/web-development)
-   [#openai](https://hashnode.com/tag/openai)
-   [#npm](https://hashnode.com/tag/npm)

## Written by

[Vishal Gosain](https://hashnode.com/@vishugosain)

@vishugosain · India

  
[View profile](https://hashnode.com/@vishugosain)

Building a better online experience, one website at a time.

I am a seasoned frontend developer from India with over 6 years of experience in the industry. My expertise lies in technologies such as HTML, JavaScript, Angular, and RxJS.

## Responses 3

Markdown supported · ⌘↵ to post

[Gordon Thomas Cumming](https://hashnode.com/@DynamiteTom)

[Jun 27, 2023](https://hashnode.com/posts/integrating-open-ai-into-angular-application/63d3b2c3d4a6f74f06ffda8e/comment/649aa7665244606d9b6012a0)

When I npm install chatgpt-api

But if I import { ChatGPT } from 'chatgpt-api';

It complains - What am I doing wrong

[Andrew Lawton](https://hashnode.com/@Allawton)

[Jun 9, 2023](https://hashnode.com/posts/integrating-open-ai-into-angular-application/63d3b2c3d4a6f74f06ffda8e/comment/648365709c8c4d5cffa222d7)

Here's my environment.prod.ts

export const OPENAI\_API\_KEY = "sk-XXXXXXXXXXXX"

Here's my service.ts file

import { Injectable } from '@angular/core'; import { Configuration, OpenAIApi } from 'openai'; import { filter, from, map } from 'rxjs'; import { environment, OPENAI\_API\_KEY } from 'src/environments/environment';

@Injectable({ providedIn: 'root' })

export class OpenAiService {

constructor(){}

readonly configuration = new Configuration({

apiKey: OPENAI\_API\_KEY });

readonly openai = new OpenAIApi(this.configuration);

async getDataFromOpenAPI(text: string) { const completion = await this.openai.createCompletion({ model: "text-davinci-002", prompt: text, }); console.log(completion.data.choices\[0\].text); } getDataFromOpenAI(text: string) { from(this.openai.createCompletion({ model: "text-davinci-003", prompt: text, max\_tokens: 256 })).pipe( filter((resp: { data: any; }) => !!resp && !!resp.data), map(resp => resp.data), filter((data: any) => data.choices && data.choices.length > 0 && data.choices\[0\].text), map(data => data.choices\[0\].text) ).subscribe(data => { console.log(data); }); }

}

[Andrew Lawton](https://hashnode.com/@Allawton)

[Jun 9, 2023](https://hashnode.com/posts/integrating-open-ai-into-angular-application/63d3b2c3d4a6f74f06ffda8e/comment/64833aefdb33d65ccffe3065)

I've read through this several times and there are some gaps.

1.  This line "apiKey: environment.OPENAI\_API\_KEY" throws a "Property 'OPENAI\_API\_KEY' does not exist on type" ...... Error. I am searching for a resolution and have been unsuucessful.
    
2.  I copied and pasted your "rxjs" code. It needs the import statement..which was not mentioned. "import { filter, from, map } from 'rxjs'";
