mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-05-02 07:42:40 +00:00
improve
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
from crewai.tools import BaseTool
|
from crewai.tools import BaseTool
|
||||||
from pydantic import Field
|
from pydantic import Field
|
||||||
from typing import Any
|
from typing import Any, Dict, List
|
||||||
|
import os
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from langchain_apify import ApifyActorsTool as _ApifyActorsTool
|
from langchain_apify import ApifyActorsTool as _ApifyActorsTool
|
||||||
@@ -38,6 +39,14 @@ class ApifyActorsTool(BaseTool):
|
|||||||
*args: Any,
|
*args: Any,
|
||||||
**kwargs: Any
|
**kwargs: Any
|
||||||
) -> None:
|
) -> None:
|
||||||
|
if not os.environ.get("APIFY_API_TOKEN"):
|
||||||
|
msg = (
|
||||||
|
"APIFY_API_TOKEN environment variable is not set. "
|
||||||
|
"Please set it to your API key, to learn how to get it, "
|
||||||
|
"see https://docs.apify.com/platform/integrations/api"
|
||||||
|
)
|
||||||
|
raise ValueError(msg)
|
||||||
|
|
||||||
actor_tool = _ApifyActorsTool(actor_name)
|
actor_tool = _ApifyActorsTool(actor_name)
|
||||||
|
|
||||||
kwargs.update(
|
kwargs.update(
|
||||||
@@ -50,7 +59,15 @@ class ApifyActorsTool(BaseTool):
|
|||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
self.actor_tool = actor_tool
|
self.actor_tool = actor_tool
|
||||||
|
|
||||||
def _run(self, run_input: dict) -> list[dict]:
|
def _run(self, run_input: Dict[str, Any]) -> List[Dict[str, Any]]:
|
||||||
|
"""Run the Actor tool with the given input.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
List[Dict[str, Any]]: Results from the actor execution.
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
ValueError: If 'actor_tool' is not initialized.
|
||||||
|
"""
|
||||||
if self.actor_tool is None:
|
if self.actor_tool is None:
|
||||||
msg = "ApifyActorsToolCrewAI is not initialized"
|
msg = "ApifyActorsToolCrewAI is not initialized"
|
||||||
raise ValueError(msg)
|
raise ValueError(msg)
|
||||||
|
|||||||
Reference in New Issue
Block a user