Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: removed feedback endpoint #1

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions examples/submit_feedback_tool.py

This file was deleted.

3 changes: 1 addition & 2 deletions langchain_scrapegraph/tools/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from .credits import GetCreditsTool
from .feedback import SubmitFeedbackTool
from .smartscraper import SmartscraperTool

__all__ = ["SmartscraperTool", "GetCreditsTool", "SubmitFeedbackTool"]
__all__ = ["SmartscraperTool", "GetCreditsTool"]
66 changes: 0 additions & 66 deletions langchain_scrapegraph/tools/feedback.py

This file was deleted.

46 changes: 4 additions & 42 deletions tests/integration_tests/test_tools.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,25 @@
"""Integration tests for ScrapeGraph AI tools.

To run these tests, you need a ScrapeGraph AI API key.
To run these tests, you need a ScrapeGraphAI API key.
You can get a test key from https://scrapegraphai.com

Set the SGAI_API_KEY environment variable to run these tests.
"""

import os
from typing import ClassVar, Type
from typing import Type

import pytest
from dotenv import load_dotenv
from langchain_tests.integration_tests import ToolsIntegrationTests

from langchain_scrapegraph.tools import (
GetCreditsTool,
SmartscraperTool,
SubmitFeedbackTool,
)
from langchain_scrapegraph.tools import GetCreditsTool, SmartscraperTool

# Load environment variables from .env file
load_dotenv()


class TestSmartscraperToolIntegration(ToolsIntegrationTests):
request_id: ClassVar[str] = "" # Class variable to store request_id

@property
def tool_constructor(self) -> Type[SmartscraperTool]:
return SmartscraperTool
Expand All @@ -40,19 +34,10 @@ def tool_constructor_params(self) -> dict:
@property
def tool_invoke_params_example(self) -> dict:
return {
"user_prompt": "TEST. Extract the main heading.",
"user_prompt": "Extract the main heading.",
"website_url": "https://example.com",
}

@pytest.mark.xfail(reason="Overridden to capture request_id for feedback test")
def test_invoke_matches_output_schema(self) -> None:
"""Override to capture request_id"""
tool = self.get_tool()
result = tool._run(**self.tool_invoke_params_example)
# Store the request_id for use in feedback test
TestSmartscraperToolIntegration.request_id = result.get("request_id", "")
assert isinstance(result, dict)


class TestGetCreditsToolIntegration(ToolsIntegrationTests):
@property
Expand All @@ -69,26 +54,3 @@ def tool_constructor_params(self) -> dict:
@property
def tool_invoke_params_example(self) -> dict:
return {} # GetCredits doesn't require any parameters


class TestSubmitFeedbackToolIntegration(ToolsIntegrationTests):
@property
def tool_constructor(self) -> Type[SubmitFeedbackTool]:
return SubmitFeedbackTool

@property
def tool_constructor_params(self) -> dict:
api_key = os.getenv("SGAI_API_KEY")
if not api_key:
pytest.skip("SGAI_API_KEY environment variable not set")
return {"api_key": api_key}

@property
def tool_invoke_params_example(self) -> dict:
if not TestSmartscraperToolIntegration.request_id:
pytest.skip("No request_id available from smartscraper test")
return {
"request_id": TestSmartscraperToolIntegration.request_id,
"rating": 5,
"feedback_text": "Test feedback",
}
35 changes: 1 addition & 34 deletions tests/unit_tests/mocks.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
from datetime import datetime
from typing import Any, Dict, Optional
from uuid import uuid4

from langchain_core.tools import BaseTool
from pydantic import BaseModel, Field
Expand All @@ -10,12 +8,11 @@ class MockSyncClient:
def __init__(self, api_key: str = None, *args, **kwargs):
"""Initialize with mock methods that return proper response structures"""
self._api_key = api_key
self._request_id = str(uuid4()) # Generate a consistent request_id for tests

def smartscraper(self, website_url: str, user_prompt: str) -> dict:
"""Mock smartscraper method"""
return {
"request_id": self._request_id,
"request_id": "test-id",
"status": "completed",
"website_url": website_url,
"user_prompt": user_prompt,
Expand All @@ -30,15 +27,6 @@ def get_credits(self) -> dict:
"""Mock get_credits method"""
return {"remaining_credits": 50, "total_credits_used": 543}

def submit_feedback(self, request_id: str, rating: int, feedback_text: str) -> dict:
"""Mock submit_feedback method"""
return {
"feedback_id": str(uuid4()),
"request_id": request_id,
"message": "Feedback submitted successfully",
"feedback_timestamp": datetime.now().isoformat(),
}

def close(self) -> None:
"""Mock close method"""
pass
Expand Down Expand Up @@ -68,24 +56,3 @@ class MockGetCreditsTool(BaseTool):

def _run(self, **kwargs: Any) -> Dict:
return {"remaining_credits": 50, "total_credits_used": 543}


class MockSubmitFeedbackInput(BaseModel):
request_id: str = Field(description="Test request ID")
rating: int = Field(description="Test rating")
feedback_text: str = Field(description="Test feedback")


class MockSubmitFeedbackTool(BaseTool):
name: str = "SubmitFeedback"
description: str = "Test description"
args_schema: type[BaseModel] = MockSubmitFeedbackInput
client: Optional[MockSyncClient] = None
api_key: str

def _run(self, **kwargs: Any) -> Dict:
return {
"feedback_id": "test-id",
"message": "Success",
"feedback_timestamp": "2024-01-01T00:00:00",
}
26 changes: 1 addition & 25 deletions tests/unit_tests/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,10 @@

from langchain_tests.unit_tests import ToolsUnitTests

from langchain_scrapegraph.tools import (
GetCreditsTool,
SmartscraperTool,
SubmitFeedbackTool,
)
from langchain_scrapegraph.tools import GetCreditsTool, SmartscraperTool
from tests.unit_tests.mocks import (
MockGetCreditsTool,
MockSmartscraperTool,
MockSubmitFeedbackTool,
MockSyncClient,
)

Expand Down Expand Up @@ -49,22 +44,3 @@ def tool_constructor_params(self) -> dict:
@property
def tool_invoke_params_example(self) -> dict:
return {}


class TestSubmitFeedbackToolUnit(ToolsUnitTests):
@property
def tool_constructor(self) -> Type[SubmitFeedbackTool]:
return MockSubmitFeedbackTool

@property
def tool_constructor_params(self) -> dict:
with patch("langchain_scrapegraph.tools.feedback.SyncClient", MockSyncClient):
return {"api_key": "sgai-test-api-key"}

@property
def tool_invoke_params_example(self) -> dict:
return {
"request_id": "test-request-id",
"rating": 5,
"feedback_text": "Test feedback",
}
Loading