I am new to python, I am trying to pass the API key to apifywrapper here in the notebook. I am getting this error:
ValidationError Traceback (most recent call last) in <cell line: 9>() 7 api_token = userdata.get("apify") 8 ----> 9 apify = ApifyWrapper(apify_api_token=api_token) 10 # Call the Actor to obtain text from the crawled webpages 11 loader = apify.call_actor(
/usr/local/lib/python3.10/dist-packages/pydantic/main.cpython-310-x86_64-linux-gnu.so in pydantic.main.BaseModel.init()
ValidationError: 1 validation error for ApifyWrapper root Did not find apify_api_token, please add an environment variable
APIFY_API_TOKENwhich contains it, or passapify_api_tokenas a named parameter. (type=value_error)
!pip install apify apify-client
from langchain.docstore.document import Document
from langchain.indexes import VectorstoreIndexCreator
from langchain.utilities import ApifyWrapper
import apify
api_token = userdata.get("apify")
apify = ApifyWrapper(apify_api_token=api_token)
# Call the Actor to obtain text from the crawled webpages
loader = apify.call_actor(
actor_id="apify/website-content-crawler",
run_input={"startUrls": [{"url": "https://python.langchain.com/docs/integrations/chat/"}]},
dataset_mapping_function=lambda item: Document(
page_content=item["text"] or "", metadata={"source": item["url"]}
),
)
Can explain to me what am I doing wrong and how can I fix this problem? Ty
The error "ValidationError: Did not find apify_api_token, please add an environment variable APIFY_API_TOKEN which contains it, or pass apify_api_token as a named parameter" is occurring because the APIFY_API_TOKEN environment variable is missing. To fix this, you can either set the APIFY_API_TOKEN environment variable or pass apify_api_token as a named parameter when creating an instance of the ApifyWrapper class. Here's how you can set the environment variable in Python: