AzureDatabricks Streamlit VSCode

I can run several codes in Azure Databricks notebook. I used the same credentials and created .py file in order to run it with streamlit. I connect Databricks cluster through VSCode. The connection is enabled. The streamlit UI pops up, but gives error.

I am getting following error below. I am not sure if it is relevant to this environment settings I have. This was working in the databricks notebook. Why am I getting this error when i aim to create chotbot streamlit ui?

import openai
import streamlit as st
import os
from langchain.embeddings.openai import OpenAIEmbeddings
from langchain.text_splitter import CharacterTextSplitter, RecursiveCharacterTextSplitter
from langchain.vectorstores import DocArrayInMemorySearch
from langchain.document_loaders import PyPDFLoader
from langchain.chains import ConversationalRetrievalChain
from langchain.chat_models import ChatOpenAI
import tempfile
import shutil
import nltk
nltk.download(‘punkt’)
from dotenv import load_dotenv
load_dotenv()

Set up environment variables

OPENAI_API_KEY = “…”
OPENAI_API_TYPE = “azure”
OPENAI_API_BASE = “…”
OPENAI_API_VERSION = “2023-03-15-preview”
OPENAI_DEPLOYMENT=“text-embedding-ada-002”

embeddings = OpenAIEmbeddings(
    openai_api_key = os.getenv("OPENAI_API_KEY"),
    deployment = os.getenv("OPENAI_DEPLOYMENT"), 
    openai_api_base = os.getenv("OPENAI_API_BASE"),
    openai_api_type = os.getenv("OPENAI_API_TYPE"),
    openai_api_version = os.getenv("OPENAI_API_VERSION"), 
    chunk_size=1
)
qa = ConversationalRetrievalChain.from_llm(
    llm=ChatOpenAI(engine='gpt4', temperature=0),
    chain_type=chain_type,
    retriever=retriever,
    return_source_documents=True,
    return_generated_question=True
)
return qa

This is the error:

"D:\Users\yusuf.demir\AppData\Local\anaconda3\envs\uitest5\Lib\site-packages\langchain\embeddings\openai.py:320: UserWarning: If you have openai>=
1.0.0 installed and are using Azure, please use the AzureOpenAIEmbeddings class.
warnings.warn(
2023-12-02 23:23:46.621 Uncaught app exception
Traceback (most recent call last):
File “D:\Users\yusuf.demir\AppData\Local\anaconda3\envs\uitest5\Lib\site-packages\streamlit\runtime\scriptrunner\script_runner.py”, line 534, i
n _run_script
exec(code, module.dict)
File “D:\Users\yusuf.demir\streamlit\streamlit_app2.py”, line 127, in
main()
File “D:\Users\yusuf.demir\streamlit\streamlit_app2.py”, line 104, in main
qa = load_db(files, “stuff”, 4)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File “D:\Users\yusuf.demir\streamlit\streamlit_app2.py”, line 73, in load_db
db = DocArrayInMemorySearch.from_documents(docs, embeddings)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “D:\Users\yusuf.demir\AppData\Local\anaconda3\envs\uitest5\Lib\site-packages\langchain_core\vectorstores.py”, line 510, in from_documents
return cls.from_texts(texts, embedding, metadatas=metadatas, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “D:\Users\yusuf.demir\AppData\Local\anaconda3\envs\uitest5\Lib\site-packages\langchain\vectorstores\docarray\in_memory.py”, line 69, in fr
om_texts
store.add_texts(texts=texts, metadatas=metadatas)
File “D:\Users\yusuf.demir\AppData\Local\anaconda3\envs\uitest5\Lib\site-packages\langchain\vectorstores\docarray\base.py”, line 82, in add_tex
ts
embeddings = self.embedding.embed_documents(list(texts))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “D:\Users\yusuf.demir\AppData\Local\anaconda3\envs\uitest5\Lib\site-packages\langchain\embeddings\openai.py”, line 556, in embed_documents
return self._get_len_safe_embeddings(texts, engine=engine)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “D:\Users\yusuf.demir\AppData\Local\anaconda3\envs\uitest5\Lib\site-packages\langchain\embeddings\openai.py”, line 432, in _get_len_safe_e
mbeddings
response = embed_with_retry(
^^^^^^^^^^^^^^^^^
File “D:\Users\yusuf.demir\AppData\Local\anaconda3\envs\uitest5\Lib\site-packages\langchain\embeddings\openai.py”, line 107, in embed_with_retr
y
return embeddings.client.create(**kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “D:\Users\yusuf.demir\AppData\Local\anaconda3\envs\uitest5\Lib\site-packages\openai\resources\embeddings.py”, line 105, in create
return self._post(
^^^^^^^^^^^
File “D:\Users\yusuf.demir\AppData\Local\anaconda3\envs\uitest5\Lib\site-packages\openai_base_client.py”, line 1096, in post
return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “D:\Users\yusuf.demir\AppData\Local\anaconda3\envs\uitest5\Lib\site-packages\openai_base_client.py”, line 856, in request
return self._request(
^^^^^^^^^^^^^^
File “D:\Users\yusuf.demir\AppData\Local\anaconda3\envs\uitest5\Lib\site-packages\openai_base_client.py”, line 908, in _request
raise self._make_status_error_from_response(err.response) from None
openai.
NotFoundError: Error code: 404 - {‘error’: {‘code’: ‘404’, ‘message’: ‘Resource not found’}}"