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

Even a simplest request with schema doesn't work #788

Open
pkit opened this issue Nov 4, 2024 · 9 comments
Open

Even a simplest request with schema doesn't work #788

pkit opened this issue Nov 4, 2024 · 9 comments

Comments

@pkit
Copy link

pkit commented Nov 4, 2024

import json

from pydantic import BaseModel
from scrapegraphai.graphs import SmartScraperGraph

# Define the configuration for the scraping pipeline
graph_config = {
    "llm": {
        "api_key": "sk-key",
        "model": "openai/gpt-4o-mini",
    },
    "verbose": True,
    "headless": True,
}

class CompanyDetails(BaseModel):
    name: str
    description: str
    email: str


# Create the SmartScraperGraph instance
smart_scraper_graph = SmartScraperGraph(
    prompt="Find some information about what does the company do, the name and a contact email.",
    source="https://theraiderteam.com/",
    config=graph_config,
    schema=CompanyDetails,
)

# Run the pipeline
result = smart_scraper_graph.run()
print(json.dumps(result, indent=4))

Fails miserably with

Traceback (most recent call last):
  File "/..../test.py", line 31, in <module>
    result = smart_scraper_graph.run()
             ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/..../.venv/lib/python3.11/site-packages/scrapegraphai/graphs/smart_scraper_graph.py", line 212, in run
    self.final_state, self.execution_info = self.graph.execute(inputs)
                                            ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/..../.venv/lib/python3.11/site-packages/scrapegraphai/graphs/base_graph.py", line 327, in execute
    return self._execute_standard(initial_state)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/..../.venv/lib/python3.11/site-packages/scrapegraphai/graphs/base_graph.py", line 274, in _execute_standard
    raise e
  File "/..../.venv/lib/python3.11/site-packages/scrapegraphai/graphs/base_graph.py", line 247, in _execute_standard
    result, node_exec_time, cb_data = self._execute_node(
                                      ^^^^^^^^^^^^^^^^^^^
  File "/..../.venv/lib/python3.11/site-packages/scrapegraphai/graphs/base_graph.py", line 172, in _execute_node
    result = current_node.execute(state)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/..../.venv/lib/python3.11/site-packages/scrapegraphai/nodes/generate_answer_node.py", line 129, in execute
    answer = output_parser.parse(raw_response.content)
             ^^^^^^^^^^^^^^^^^^^
AttributeError: 'function' object has no attribute 'parse'
@44510709
Copy link

44510709 commented Nov 5, 2024

image

@44510709
Copy link

44510709 commented Nov 5, 2024

"Has it been resolved?" How to solve it

@VinciGit00
Copy link
Collaborator

does it work the test example?

@bezineb5
Copy link
Contributor

bezineb5 commented Nov 8, 2024

@pkit Same issue, it seems the last working version was 1.27.0.
The error is here: https://github.com/ScrapeGraphAI/Scrapegraph-ai/blame/b400cc5a666e1670948cd50f284a2ccba3d136ee/scrapegraphai/nodes/generate_answer_node.py#L84
This line returns a function, whereas other code path return an object with a parse method.
also, it seems that's incorrect for Mistral, even fixing the bug doesn't help:

  File "/venv/lib/python3.12/site-packages/scrapegraphai/nodes/generate_answer_node.py", line 87, in execute
    raise NotImplementedError("Structured output is not implemented for ChatOpenAI")
NotImplementedError: Structured output is not implemented for ChatOpenAI

@VinciGit00
Copy link
Collaborator

Can you make the pull request please?

@VinciGit00
Copy link
Collaborator

@bezineb5 just updated. please upload to the new version

@silgon
Copy link

silgon commented Nov 15, 2024

Is this solved in 1.30.0? because I get the same error 🫤.

@FayzulSaimun
Copy link

FayzulSaimun commented Nov 16, 2024

I got the same error with the schema yesterday when using the new version.

@silgon
Copy link

silgon commented Nov 16, 2024

I downgraded to 1.27.0, it works there =)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants