Scrapegraph-ai icon indicating copy to clipboard operation
Scrapegraph-ai copied to clipboard

Adding message parameter support for OpenAI models

Open Hkllopp opened this issue 1 year ago • 5 comments

OpenAI models uses the message parameter for the prompt. ScrapegraphAI also use this parameter to link to the prompt argument on scrapper invocation. However, sometimes when using openAI models, we need to make multiple prompts to better guide the response (like in this article and this documentation).

Is it possible to replace the standart scrapGraphAI prompt when providing message argument in the graph_config ?

Example :

import os
from scrapegraphai.graphs import SmartScraperGraph

OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")

system_prompt = "Provide output in valid JSON."
user_prompt = "List me all the news article with a brief description for each one."

graph_config = {
    "llm": {
        "api_key": OPENAI_API_KEY,
        "model": "gpt-3.5-turbo",
        "response_format": {"type": "json_object"},
        "seed": 0,
        "temperature": 0,
        "messages": [
            {"role": "system", "content": system_prompt},
            {"role": "user", "content": user_prompt},
        ],
    },
    "verbose": True,
}

smart_scraper_graph = SmartScraperGraph(
    prompt=user_prompt,
    # also accepts a string with the already downloaded HTML code
    source="https://perinim.github.io/projects",
    config=graph_config,
)

# TypeError: openai.resources.chat.completions.Completions.create() got multiple values for keyword argument 'messages'```

Hkllopp avatar Jun 14 '24 10:06 Hkllopp

ok, it could be an idea but please provide me a use case for the system prompt. The output is already in the json format

VinciGit00 avatar Jun 14 '24 18:06 VinciGit00

Screenshot 2024-06-14 at 3 19 56 p m Well, another example is that users that want to use groq with llama3-70b they need to mention the word JSON in the system-prompt message, its mandatory.

ehecatl avatar Jun 14 '24 21:06 ehecatl

Even if the output format is in json?

VinciGit00 avatar Jun 15 '24 06:06 VinciGit00

Yes, according to the groq playground, the system message should contain the word JSON

El El sáb, 15 de jun de 2024 a la(s) 12:38 a.m., Marco Vinciguerra < @.***> escribió:

Even if the output format is in json?

— Reply to this email directly, view it on GitHub https://github.com/VinciGit00/Scrapegraph-ai/issues/382#issuecomment-2169163134, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADSHIVDNBCXIYAE2PY3ZGLZHPOPNAVCNFSM6AAAAABJKD63P6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNRZGE3DGMJTGQ . You are receiving this because you commented.Message ID: @.***>

ehecatl avatar Jun 17 '24 17:06 ehecatl

give me an example please

VinciGit00 avatar Jun 18 '24 07:06 VinciGit00

Hi, @Hkllopp. I'm Dosu, and I'm helping the Scrapegraph-ai team manage their backlog. I'm marking this issue as stale.

Issue Summary:

  • You requested support for the 'messages' parameter in OpenAI models to enhance multi-prompt responses.
  • Encountered a TypeError due to conflicting arguments when using this parameter.
  • @VinciGit00 asked for a use case for the system prompt.
  • @ehecatl provided an example involving the word "JSON" in the system-prompt message.
  • Discussion continued with @VinciGit00 requesting further examples.

Next Steps:

  • Please confirm if this issue is still relevant to the latest version of the Scrapegraph-ai repository by commenting here.
  • If there is no further activity, this issue will be automatically closed in 7 days.

Thank you for your understanding and contribution!

dosubot[bot] avatar Jan 09 '25 16:01 dosubot[bot]