---
title: "Andrew Lawton (@Allawton) | Hashnode"
description: "Learning. Read the latest articles by Andrew Lawton on Hashnode."
url: "https://hashnode.com/@Allawton"
---

@Allawton

# Andrew Lawton

@Allawton · Joined June 2023

Learning

## Comments

[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); }); } }](https://hashnode.com/posts/integrating-open-ai-into-angular-application/63d3b2c3d4a6f74f06ffda8e/comment/648365709c8c4d5cffa222d7)

Comment · Article · Jun 9, 2023 · [Integrating Open AI into Angular application : Step by Step Guide](https://hashnode.com/posts/integrating-open-ai-into-angular-application/63d3b2c3d4a6f74f06ffda8e)

[I've read through this several times and there are some gaps. 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. I copied and pasted your "rxjs" code. It needs the import statement..which was not mentioned. "import { filter, from, map } from 'rxjs'";](https://hashnode.com/posts/integrating-open-ai-into-angular-application/63d3b2c3d4a6f74f06ffda8e/comment/64833aefdb33d65ccffe3065)

Comment · Article · Jun 9, 2023 · [Integrating Open AI into Angular application : Step by Step Guide](https://hashnode.com/posts/integrating-open-ai-into-angular-application/63d3b2c3d4a6f74f06ffda8e)
