How to use Azure opneai api with scrapegraph-ai
dwk601 opened this issue · comments
from langchain_openai import AzureChatOpenAI
from langchain_openai import AzureOpenAIEmbeddings
import os
llm_model_instance = AzureChatOpenAI(
openai_api_version=os.environ["AZURE_OPENAI_API_VERSION"],
azure_deployment=os.environ["AZURE_OPENAI_CHAT_DEPLOYMENT_NAME"],
)
embedder_model_instance = AzureOpenAIEmbeddings(
openai_api_version = os.environ["AZURE_OPENAI_API_VERSION"],
azure_deployment=os.environ["AZURE_OPENAI_EMBEDDINGS_DEPLOYMENT_NAME"],
)
graph_config = {
"llm": {
"model_instance": llm_model_instance,
},
"embeddings": {
"model_instance": embedder_model_instance,
}
}
from scrapegraphai.graphs import SmartScraperGraph
from scrapegraphai.utils import prettify_exec_info
smart_scraper_graph = SmartScraperGraph(
prompt="List me all the projects with their description.",
# also accepts a string with the already downloaded HTML code
source="https://perinim.github.io/projects",
config=graph_config
)
result = smart_scraper_graph.run()
print(result)
Exception has occurred: KeyError
'AZURE_OPENAI_EMBEDDINGS_DEPLOYMENT_NAME'
KeyError: b'AZURE_OPENAI_EMBEDDINGS_DEPLOYMENT_NAME'
During handling of the above exception, another exception occurred:
File "/home/dongwook/Project/UniApi/main.py", line 12, in
azure_deployment=os.environ["AZURE_OPENAI_EMBEDDINGS_DEPLOYMENT_NAME"],
KeyError: 'AZURE_OPENAI_EMBEDDINGS_DEPLOYMENT_NAME'
@dwk601, This is because it is not able to access required .env variables.
# required environment variable in .env
# AZURE_OPENAI_ENDPOINT
# AZURE_OPENAI_CHAT_DEPLOYMENT_NAME
# MODEL_NAME
# AZURE_OPENAI_API_KEY
# OPENAI_API_TYPE
# AZURE_OPENAI_API_VERSION
# AZURE_OPENAI_EMBEDDINGS_DEPLOYMENT_NAME
And then load these variables by using:
from dotenv import load_dotenv
load_dotenv()