User:SpinachBot - Wikidata
Jump to content
From Wikidata
Wikidata Bot

PythonPywikibot

This user account is a bot with a bot flag. The bot is operated by HTriedman (WMF).
  • Block this bot if it is malfunctioning.
  • Check its work.
  • Contact the operator about mistakes.
  • See all Requests for Permissions related to this bot: 1
  • Type of execution: periodically
  • Source: Wikimedia Gitlab repo

This bot is an auto-responding SPARQL generation and question answering bot created by User:HTriedman (WMF) and Stanford's Open Virtual Assistant Lab (OVAL) — specifically Shicheng Liu, Sina Semnani, Jialiang Xu, Isaac Dan Zhao, and Monica Lam.

When tagged and prompted by you, SpinachBot will try to write a SPARQL query based on your input request and send it to Wikidata Query Service. It will then post its response — either a query and result set, or a list of steps it tried that failed. You can tag it to provide feedback on the query and it will iteratively refine the query.

Presently, this agent runs on OpenAI's GPT-4o model. In the future, we may offer a choice of various models and/or distill a smaller, faster local model for this purpose.

You can also interact with the bot in a chat format at https://spinach.genie.stanford.edu/.

User guide

[edit]

SpinachBot supports both one-off question answering and conversational back-and-forth with users on-wiki. You can trigger a response from the bot as follows:

  1. On any Wikidata page where you have a question to ask of SpinachBot, enclose your question in the spinachbot top and spinachbot bottom templates, tag SpinachBot, and hit publish.
  2. In 10-20 minutes, SpinachBot will respond to your query with its best guess of a SPARQL query that answers your question and a set of results from that query. If it cannot answer your question, it will summarize the steps it took and some potential future directions to explore. All SpinachBot responses will be wrapped in spinachbot response and spinachbot response end templates.
  3. Every SpinachBot response will include a link to a "trace of reasonings and actions" page for that query, which shows the query that the bot received and lists every single step it took, as well as intermediate results. Here's an example of a trace of reasonings and actions page.
  4. If you aren't satisfied with the results of the response from SpinachBot or would like to suggest a new direction for the bot to explore, just add a new line to your spinachbot top/bottom block tagging SpinachBot and telling it what you'd like it to do next. It will get back to you soon!

Example

[edit]

Below is an example of a back and forth between a user and SpinachBot. In it, you can see an initial query, an initial response from the bot, a slight amendment to that query, and an updated response from the bot.

SpinachBot conversation example

@SpinachBot Give me a list of the last 7 French prime ministers. HTriedman (WMF) (talk) 17:28, 8 July 2024 (UTC)

Here is the SPARQL query and the result for the last seven French prime ministers:

SPARQL Query:

[edit]
SELECT ?pm ?pmLabel ?start_date ?end_date WHERE {
  ?pm p:P39 ?statement.
  ?statement ps:P39 wd:Q1587677;
    pq:P580 ?start_date.
  OPTIONAL { ?statement pq:P582 ?end_date. }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
ORDER BY DESC (?start_date)
LIMIT 7

Result:

[edit]
pm pmLabel start_date end_date
Q30339350 Gabriel Attal 2024-01-09T00:00:00Z -
Q20020731 Élisabeth Borne 2022-05-16T00:00:00Z 2024-01-09T00:00:00Z
Q3171170 Jean Castex 2020-07-03T00:00:00Z 2022-05-16T00:00:00Z
Q3579995 Édouard Philippe 2017-05-15T00:00:00Z 2020-07-03T00:00:00Z
Q560890 Bernard Cazeneuve 2016-12-06T00:00:00Z 2017-05-10T00:00:00Z
Q10287 Manuel Valls 2014-03-31T00:00:00Z 2016-12-06T00:00:00Z
Q7711 Jean-Marc Ayrault 2012-05-15T00:00:00Z 2014-03-31T00:00:00Z

This list includes the last seven individuals who held the position of Prime Minister of France, ordered by the start date of their term.

Here's my chain of thought for this request so you can see how I came to this conclusion. SpinachBot (talk) 21:33, 8 July 2024 (UTC)

@User:SpinachBot This is pretty cool, but could you actually include the party of each prime minister as well as their name and time in office? HTriedman (WMF) (talk) 21:37, 8 July 2024 (UTC)

Here is the SPARQL query and the result for the last seven French prime ministers, including their political party:

SPARQL Query:

[edit]
SELECT ?pm ?pmLabel ?start_date ?end_date (SAMPLE(?party) AS ?party) (SAMPLE(?partyLabel) AS ?partyLabel) WHERE {
  ?pm p:P39 ?statement.
  ?statement ps:P39 wd:Q1587677;
    pq:P580 ?start_date.
  OPTIONAL { ?statement pq:P582 ?end_date. }
  OPTIONAL { ?pm wdt:P102 ?party. }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
GROUP BY ?pm ?pmLabel ?start_date ?end_date
ORDER BY DESC (?start_date)
LIMIT 7

Result:

[edit]
pm pmLabel start_date end_date party partyLabel
Q30339350 Gabriel Attal 2024-01-09T00:00:00Z - Q170972 Socialist Party
Q20020731 Élisabeth Borne 2022-05-16T00:00:00Z 2024-01-09T00:00:00Z Q23731823 Renaissance
Q3171170 Jean Castex 2020-07-03T00:00:00Z 2022-05-16T00:00:00Z Q23731823 Renaissance
Q3579995 Édouard Philippe 2017-05-15T00:00:00Z 2020-07-03T00:00:00Z Q170972 Socialist Party
Q560890 Bernard Cazeneuve 2016-12-06T00:00:00Z 2017-05-10T00:00:00Z Q170972 Socialist Party
Q10287 Manuel Valls 2014-03-31T00:00:00Z 2016-12-06T00:00:00Z Q170972 Socialist Party
Q7711 Jean-Marc Ayrault 2012-05-15T00:00:00Z 2014-03-31T00:00:00Z Q170972 Socialist Party

This list includes the last seven individuals who held the position of Prime Minister of France, ordered by the start date of their term, along with their political party.

Here's my chain of thought for this request so you can see how I came to this conclusion. SpinachBot (talk) 21:39, 8 July 2024 (UTC)

More examples:

Background

[edit]

SpinachBot is the result of a collaboration between User:HTriedman (WMF) and Stanford's Open Virtual Assistant Lab (OVAL). It uses a large language model (LLM) combined with a limited set of executable actions on Wikidata to achieve agentic behavior in searching Wikidata and creating high-quality SPARQL queries.

SpinachBot is only the latest in a line of Wikimedia project-based LLMs and agents. Under the direction of Monica Lam, OVAL has produced Wikichat (an LLM grounded in Wikipedia content), STORM (an agent that creates Wikipedia-like reports on subjects), and SpinachBot. This bot is the first project that is the result of informal collaboration between the Wikimedia Foundation and OVAL.