mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-04 20:46:45 +00:00
community[patch]: update apify integration to attribute API activity to langchain (#21909)
**Description:** Add `Origin/langchain` to Apify's client's user-agent to attribute API activity to LangChain (at Apify, we aim to monitor our integrations to evaluate whether we should invest more in the LangChain integration regarding functionality and content) **Issue:** None **Dependencies:** None **Twitter handle:** None
This commit is contained in:
@@ -83,7 +83,7 @@
|
|||||||
"source": [
|
"source": [
|
||||||
"loader = apify.call_actor(\n",
|
"loader = apify.call_actor(\n",
|
||||||
" actor_id=\"apify/website-content-crawler\",\n",
|
" actor_id=\"apify/website-content-crawler\",\n",
|
||||||
" run_input={\"startUrls\": [{\"url\": \"https://python.langchain.com/en/latest/\"}]},\n",
|
" run_input={\"startUrls\": [{\"url\": \"https://python.langchain.com\"}]},\n",
|
||||||
" dataset_mapping_function=lambda item: Document(\n",
|
" dataset_mapping_function=lambda item: Document(\n",
|
||||||
" page_content=item[\"text\"] or \"\", metadata={\"source\": item[\"url\"]}\n",
|
" page_content=item[\"text\"] or \"\", metadata={\"source\": item[\"url\"]}\n",
|
||||||
" ),\n",
|
" ),\n",
|
||||||
|
@@ -60,7 +60,11 @@ class ApifyDatasetLoader(BaseLoader, BaseModel):
|
|||||||
try:
|
try:
|
||||||
from apify_client import ApifyClient
|
from apify_client import ApifyClient
|
||||||
|
|
||||||
values["apify_client"] = ApifyClient()
|
client = ApifyClient()
|
||||||
|
if httpx_client := getattr(client.http_client, "httpx_client"):
|
||||||
|
httpx_client.headers["user-agent"] += "; Origin/langchain"
|
||||||
|
|
||||||
|
values["apify_client"] = client
|
||||||
except ImportError:
|
except ImportError:
|
||||||
raise ImportError(
|
raise ImportError(
|
||||||
"Could not import apify-client Python package. "
|
"Could not import apify-client Python package. "
|
||||||
|
@@ -31,8 +31,18 @@ class ApifyWrapper(BaseModel):
|
|||||||
try:
|
try:
|
||||||
from apify_client import ApifyClient, ApifyClientAsync
|
from apify_client import ApifyClient, ApifyClientAsync
|
||||||
|
|
||||||
values["apify_client"] = ApifyClient(apify_api_token)
|
client = ApifyClient(apify_api_token)
|
||||||
values["apify_client_async"] = ApifyClientAsync(apify_api_token)
|
if httpx_client := getattr(client.http_client, "httpx_client"):
|
||||||
|
httpx_client.headers["user-agent"] += "; Origin/langchain"
|
||||||
|
|
||||||
|
async_client = ApifyClientAsync(apify_api_token)
|
||||||
|
if httpx_async_client := getattr(
|
||||||
|
async_client.http_client, "httpx_async_client"
|
||||||
|
):
|
||||||
|
httpx_async_client.headers["user-agent"] += "; Origin/langchain"
|
||||||
|
|
||||||
|
values["apify_client"] = client
|
||||||
|
values["apify_client_async"] = async_client
|
||||||
except ImportError:
|
except ImportError:
|
||||||
raise ImportError(
|
raise ImportError(
|
||||||
"Could not import apify-client Python package. "
|
"Could not import apify-client Python package. "
|
||||||
|
Reference in New Issue
Block a user