User:Phlsph7/WikiChatbot

WikiChatbot is a user script chatbot to assist editors and reviewers. It can summarize, reformulate, copyedit, and provide suggestions on additional topics, images, and wikilinks. It is used by selecting text in an article and then clicking one of the buttons on the right to enquire about the selected text. For example, the editor may select 3 paragraphs and then press the button "Summarize" to get a concise summary of the selected text. The responses are shown in the chat panel on the left bottom. This panel can also be used to type more specific questions about the selected text or the topic in general. WikiChatbot only provides ideas and suggestions. It does not make any changes to articles.

The script uses an AI model called GPT-4o by OpenAI. It sends the queries to the AI model and prints its responses in the chat window. Editors should be very careful when making edits to articles based on these responses. They often contain false information in the form of so-called hallucinations. There is a high risk of introducing original research into the article since the claims are frequently not verifiable. For these reasons, editors should always double-check the responses and should only use the script for topics and tasks with which they are very familiar. If text added to the article was generated by the chatbot, this has to be mentioned in the edit summary.

To use the script, an OpenAI account is required. New users get free limited access for the first 3 months but have to purchase OpenAI credit afterward.

The script can be used on regular articles, drafts, and pages in the user space. It also works when previewing changes. Additionally, it can be used to some extent on the project namespace and the help namespace.

Installation
To install this script, go to your common.js and add the following line:

Once the script is installed, it can be activated (and deactivated) via the toolbar by clicking on the link "Activate WikiChatbot".

To get responses from the chatbot, a so-called API key from OpenAI is required. To obtain an API key, first create an OpenAI account.
 * 1) Go to https://platform.openai.com/signup and follow the process. It is free but a phone number is required for verification.
 * 2) Once you have an account, you can generate an API key. To do so, go to https://platform.openai.com/account/api-keys and click on "Create new secret key".
 * 3) The API key starts with "sk-....". Copy it to use it for the script.
 * 4) Activate WikiChatbot. On the right control panel, click on the last button called "Set API key" and enter your API key. You can also use this button to change or remove your API key.

Please make sure that you do not share your API key with anyone. The script saves the API key locally on your device. It does not share it with Wikipedia or anyone else. It will only use it for your queries to the AI model.

After creating a new OpenAI account, users can use their API key for free for the first 3 months. The free account is limited by how many queries can be used per minute and in total. The script will display an error message if trying to access it after the limits of the free account are temporarily reached or if the 3 months have passed. Afterward, users have to buy credit from OpenAI to use the API key. The current cost per query afterward varies a lot depending on its length and the AI model used, from a fraction of a cent when using GPT-3.5 to over a cent for long queries with GPT-4o. For paid accounts, a credit card is required. It is recommended that you set up a monthly limit for your usage at https://platform.openai.com/account/billing/limits. More details on free and paid accounts can be found at https://openai.com/pricing.

If you run into problems or have suggestions on how to improve the script, please discuss them at User_talk:Phlsph7/WikiChatbot.

Usage and purpose
The script has 2 panels on the bottom of the page: a chat panel on the left and a control panel with buttons on the right. The size of the panels can be changed by dragging their corners if they are too small or get in the way. The script can be used by first selecting text in the article and then clicking on one of the buttons. After a few seconds, a response will be displayed in the chat panel. Each button has a different function. For example, the button "Copyedit" performs copyediting on the selected text and displays the results in the chat panel. Hovering the mouse over a button opens a short description of its functions.

The following functions are present:
 * Copyedit: Copyedit the selected text.
 * Check spelling/grammar: Assess the spelling and grammar of the selected text.
 * Reformulate: Reformulate the selected text.
 * Simplify: Simplify the selected text to make it more accessible.
 * Summarize: Summarize the selected text.
 * Explain: Explain the selected text in simple terms.
 * Provide example: Provide an example to illustrate the main point of the selected text.
 * Suggest expansion: Suggest ideas how the selected text could be expanded.
 * Suggest images: Describe images that could be used to illustrate the selected text.
 * Suggest wikilinks: Suggest terms in the selected text that could get a wikilink to another article.
 * Suggest DYK questions: Suggest questions for the "Did you know" section on the * Wikipedia main page based on the selected text.
 * Alternative article outline: Writes a general outline of the topic of this article. Ignores the content of the article and the selected text.

Please note that the chatbot is more suitable for some tasks than for others. For example, when reformulating or summarizing a text, it may include new information or introduce biases. When asking to provide an example or to suggest expansion ideas, its responses should always be considered original research. They can be useful for brainstorming but they should never be included directly in the article. The chatbot is not aware of many Wikipedia policies and may include inappropriate section headings when asked to produce an article outline, such as the heading "Conclusion" for the last section. If you have ideas on additional functions, please suggest them at User_talk:Phlsph7/WikiChatbot.

The checkbox "Use advanced AI model" switches between the old AI model (GPT-3.5 turbo) and the new one (GPT-4o). GPT-4o is more expensive but its responses are better and it is able to process much more text at the same time, making it possible to select full sections or the whole article when using functions or asking questions.

The chat panel can also be used to ask one's own questions. To do so, click on the text area in the bottom left, type in your question, and click the button "Send". It can be used to ask questions about the selected text or about the article and topic in general. For example, if a paragraph contains a technical term with which the user is not familiar, they may select this paragraph and ask the chatbot to explain this term to them.

The responses of the chatbot differ from one time to the next even if the same input is used. So if you are not happy with a response, you can try to use the same input again to get a slightly different result. If the responses to the same question vary a lot and contradict each other then you should not trust any of them. For specific questions, the response is often more accurate if only a short text is selected. For example, the chatbot is more likely to spot a false date if only the relevant sentence is selected. If the selection encompasses many paragraphs, it's more likely that it will miss it. However, you have to ensure that all the relevant context is selected. For example, if a sentence mentions personal pronouns like "he", the chatbot may misinterpret it if the previous sentences are not selected.

The chatbot usually ignores the English variant used in the article and responds in American English. To change the english variant of a passage to British English, you can select it and enter the command "Change the selected text to British English" in the chat panel.

Please be aware that the chatbot responds in regular text and ignores wikitext markup in the selection (like wikilinks). Its responses need to be wikified before they can be used in the article.

If text generated or modified by the chatbot is added to the article, this should be mentioned in the edit summary. For example, an editor may use the chatbot to rewrite and simplify an overly difficult paragraph in the article. After carefully ensuring that the new text complies with Wikipedia policies, they replace the old paragraph with the simplified version. As an edit summary, they could add something like the following:
 * I used GPT-4o to simplify a difficult paragraph
 * a difficult paragraph was edited for simplicity and clarity; User:Phlsph7/WikiChatbot.js was used in the process
 * with the help of a chatbot powered by OpenAI, I edited a convoluted paragraph to make it easier to understand

The chatbot is not only intended for editors and reviewers but can also be helpful to general readers. For example, the button "Explain" can be used to get an explanation of difficult passages. The button "Provide example" is helpful when trying to understand abstract concepts and theories.

Limitations and dangers
The technology of the underlying AI model is very new and has many serious limitations. It was not designed for writing encyclopedic articles and should be used with extreme caution. The chatbot responses may be well-written and sound convincing but they often contain false information in the form of so-called hallucinations. There is a high risk of introducing original research into the article since the claims are frequently not verifiable. This also applies to references to books, academic papers, and websites, which the chatbot often fabricates. Chatbot responses may also be biased and violate copyrights. For these reasons, editors should not add text to articles if the text was obtained by asking the chatbot to write original content or generate references. But also when modifying preexisting text, editors should always rigorously scrutinize the chatbot responses before making any changes to articles.

Editors should only use the script for topics and tasks with which they are very familiar. For example, if an editor is not well informed on the topic of Poecilotheria metallica, they should not add or remove claims from this article only because the chatbot suggested it. Such changes should always be based on reliable sources. If the editor does not have access to reliable sources or lacks time and background knowledge to consult them, they may use the talk page of the article to raise the issue and ask for feedback from other editors. Besides a good knowledge of the article's topic, editors should also thoroughly familiarize themselves with the limitations and dangers of the underlying AI technology and how its responses may violate Wikipedia policies. This information can be found at WP:LLM. This script should never be used to semi-automatically make changes to articles. A thorough and detailed human evaluation is always required.

Besides these general limitations of AI models, the script also has various more specific limitations. It can only process a limited number of words in each query. It is always aware of the first 2-3 paragraphs of the article in the lead section. It is also aware of the text that was selected. But it is not aware of the article as a whole. So asking questions like "Is the section 'Influence' comprehensive?" is not likely to result in a meaningful answer if the text of this section was not selected before. The word limit also means that it is not possible to select several long sections at once. An error message is displayed if the selected text was too long. The chatbot is aware of some parts of the chat history but not of the full chat history. This means that its responses may sometimes make no sense if one refers to parts of the conversation that happened several steps ago.

Examples
Button: Simplify "After the Roman conquest of the Nabataean Empire and the Roman naval presence at Aden to curb pillaging, Somali and Gulf Arab merchants by agreement barred Indian ships from trading in the free port cities of the Arabian peninsula to protect the interests of Somali and Arab merchants in the extremely lucrative ancient Red Sea–Mediterranean Sea commerce, However Indian merchants continued to trade in the port cities of the Somali peninsula, which was free from Roman interference." "After the Romans conquered the Nabataean Empire and established a naval presence in Aden to prevent plundering, Somali and Gulf Arab merchants made an agreement to prevent Indian ships from trading in the free port cities of the Arabian peninsula. This was done to safeguard the interests of Somali and Arab merchants involved in the highly profitable trade between the Red Sea and the Mediterranean Sea. However, Indian merchants still carried on with trading in the port cities of the Somali peninsula, as these areas were not under Roman control."
 * Page: Draft:Ancient Somali City-States
 * Selected text:
 * Bot response:

Button: Short summary "The earliest traces of mathematical knowledge in the Indian subcontinent appear with the Indus Valley Civilisation (c. 4th millennium BCE ~ c. 3rd millennium BCE). The people of this civilization made bricks whose dimensions were in the proportion 4:2:1, which is favorable for the stability of a brick structure. They also tried to standardize measurement of length to a high degree of accuracy. They designed a ruler—the Mohenjo-daro ruler—whose unit of length (approximately 1.32 inches or 3.4 centimetres) was divided into ten equal parts. Bricks manufactured in ancient Mohenjo-daro often had dimensions that were integral multiples of this unit of length.
 * Page: History of science
 * Selected text:

Indian astronomer and mathematician Aryabhata (476–550), in his Aryabhatiya (499) introduced the sine function in trigonometry. In 628 CE, Brahmagupta suggested that gravity was a force of attraction. He also lucidly explained the use of zero as both a placeholder and a decimal digit, along with the Hindu–Arabic numeral system now used universally throughout the world. Arabic translations of the two astronomers' texts were soon available in the Islamic world, introducing what would become Arabic numerals to the Islamic world by the 9th century. During the 14th–16th centuries, the Kerala school of astronomy and mathematics made significant advances in astronomy and especially mathematics, including fields such as trigonometry and analysis. In particular, Madhava of Sangamagrama is considered the 'founder of mathematical analysis'.

In the Tantrasangraha treatise, Nilakantha Somayaji's updated the Aryabhatan model for the interior planets, Mercury, and Venus and the equation that he specified for the center of these planets was more accurate than the ones in European or Islamic astronomy until the time of Johannes Kepler in the 17th century.

The first textual mention of astronomical concepts comes from the Vedas, religious literature of India. According to Sarma (2008): 'One finds in the Rigveda intelligent speculations about the genesis of the universe from nonexistence, the configuration of the universe, the spherical self-supporting earth, and the year of 360 days divided into 12 equal parts of 30 days each with a periodical intercalary month.'. The first 12 chapters of the Siddhanta Shiromani, written by Bhāskara in the 12th century, cover topics such as: mean longitudes of the planets; true longitudes of the planets; the three problems of diurnal rotation; syzygies; lunar eclipses; solar eclipses; latitudes of the planets; risings and settings; the moon's crescent; conjunctions of the planets with each other; conjunctions of the planets with the fixed stars; and the patas of the sun and moon. The 13 chapters of the second part cover the nature of the sphere, as well as significant astronomical and trigonometric calculations based on it." "The Indian subcontinent has a rich history of mathematical and astronomical contributions. The Indus Valley Civilization developed standardized measurements and used a ruler with a unit of length divided into ten equal parts. Aryabhata introduced the sine function in trigonometry, while Brahmagupta explained the use of zero and the Hindu-Arabic numeral system. The Kerala school of astronomy and mathematics made advancements in trigonometry and analysis. Nilakantha Somayaji's model for the interior planets was more accurate than European or Islamic astronomy. The Vedas contain early astronomical concepts, and Bhāskara's Siddhanta Shiromani covers various topics in astronomy and trigonometry."
 * Bot response:

Button: Check spelling/grammar "According to DiMartino and Koneitzo, there currently no plans for projects based on Avatar novels or comic books, througth they did noted the expanded material is considered 'mostly canon' and that they would retcon certain elements when necessary." "Yes, there are a few spelling and grammar issues in the selected text. Here is the corrected version:
 * Page: Draft:Avatar Studios
 * Selected text:
 * Bot response:

'According to DiMartino and Konietzko, there are currently no plans for projects based on Avatar novels or comic books, though they did note that the expanded material is considered 'mostly canon' and that they would retcon certain elements when necessary.'

Please note the following corrections: - 'Koneitzo' should be corrected to 'Konietzko.' - 'througth' should be corrected to 'though.' - 'there currently no plans' should be corrected to 'there are currently no plans.' - 'they did noted' should be corrected to 'they did note.'

Let me know if you need help with anything else!"

Button: Suggest images "Archaeology is the study of human activity in the past, primarily through the recovery and analysis of the material culture and environmental data that they have left behind, which includes artifacts, architecture, biofacts (also known as eco-facts) and cultural landscapes (the archaeological record)." "Here are some possible images that could be used to illustrate the text:
 * Page: History of archaeology
 * Selected text:
 * Bot response:

1. An archaeologist excavating a site: This image could show an archaeologist carefully digging and uncovering artifacts from the ground, highlighting the process of recovery in archaeology.

2. Artifacts: This image could showcase a collection of various artifacts such as pottery, tools, or ancient jewelry, representing the material culture that archaeologists study.

3. Architectural ruins: This image could depict the remains of an ancient structure, such as a temple or a palace, showcasing the architectural aspect of archaeology.

4. Fossilized remains: This image could show the fossilized bones or footprints of ancient humans or animals, representing biofacts or eco-facts that provide insights into past environments and human activity.

5. Cultural landscape: This image could portray a landscape with visible archaeological features, such as ancient ruins or earthworks, highlighting the concept of cultural landscapes and the archaeological record.

These images would help visually convey the different aspects of archaeology mentioned in the text."

Button: Suggest wikilinks "According to Frankfurt, not every entity with a mind is a person. He refers to such entities as 'wantons'. Wantons have desires and follow them but do not care about their own will. In this regard, they are indifferent to which of their desires become effective and are translated into action. Frankfurt holds that personhood is an important feature of humans but not of other animals. However, even some humans may be wantons at times. Various of Frankfurt's examples of such cases involve some forms of akrasia in which a person acts according to a first-order desire that he/she does not want to have on the second order. For example, a struggling drug addict may follow his/her first-order desire to take drugs despite having a second-order desire to stop wanting drugs." "In the selected text, the following terms should have wikilinks to another Wikipedia article:
 * Page: Harry Frankfurt
 * Selected text:
 * Bot response:

1. 'personhood': This term can be linked to the Wikipedia article on 'Personhood', which discusses the concept and various perspectives on what it means to be a person.

2. 'animals': This term can be linked to the Wikipedia article on 'Animals', which provides information about the classification, characteristics, and behavior of animals.

3. 'akrasia': This term can be linked to the Wikipedia article on 'Akrasia', which explains the philosophical concept of acting against one's better judgment or having a lack of self-control.

4. 'drug addict': This term can be linked to the Wikipedia article on 'Substance dependence', which provides information about addiction, its causes, symptoms, and treatment options.

Please note that these suggestions are based on the assumption that relevant Wikipedia articles exist for these terms."

Button: Write new article outline "I. Introduction A. Definition and overview of the United States    B. Brief historical background    C. Importance and global influence of the United States
 * Page: United States
 * Bot response:

II. History A. Pre-colonial era 1. Native American civilizations 2. European exploration and early settlements

B. Colonial period 1. British colonization and the Thirteen Colonies 2. American Revolution and the birth of the United States

C. Expansion and westward movement 1. Louisiana Purchase and Lewis and Clark Expedition 2. Manifest Destiny and territorial acquisitions 3. Civil War and Reconstruction

D. Industrialization and modernization 1. Gilded Age and the rise of big business 2. Progressive Era and social reforms 3. World War I and the Roaring Twenties

E. Global superpower status 1. Great Depression and New Deal 2. World War II and the Cold War 3. Civil Rights Movement and social change

F. Recent history 1. Post-Cold War era and globalization 2. War on Terror and the 21st century challenges 3. Recent political developments and controversies

III. Geography and Climate A. Overview of the United States' geographical location B. Major landforms and natural features C. Climate variations across different regions D. Environmental concerns and conservation efforts

IV. Government and Politics A. Constitutional framework 1. Separation of powers and federalism 2. Bill of Rights and individual liberties

B. Political system 1. Overview of the three branches of government 2. Electoral system and political parties 3. Checks and balances

C. Major political issues and debates 1. Healthcare and social welfare 2. Immigration and border control 3. Gun control and Second Amendment rights 4. Climate change and environmental policies

V. Economy A. Overview of the United States' economy B. Key sectors and industries 1. Manufacturing and technology 2. Agriculture and farming 3. Financial services and Wall Street 4. Entertainment and media

C. Economic challenges and inequality 1. Income disparity and poverty 2. Racial and gender wage gaps 3. Economic recessions and financial crises

VI. Demographics A. Population size and growth trends B. Ethnic and racial composition C. Immigration patterns and immigrant communities D. Religious diversity and major faiths E. Urbanization and rural areas

VII. Culture A. Overview of American culture B. Language and literature C. Music, film, and popular entertainment D. Sports and recreational activities E. Cuisine and regional specialties

VIII. Education and Science A. Education system and levels B. Notable universities and research institutions C. Scientific advancements and contributions

IX. Infrastructure and Transportation A. Transportation networks 1. Roadways and highways 2. Railways and public transportation 3. Airports and aviation 4. Waterways and ports

B. Energy infrastructure and sources 1. Fossil fuels and renewable energy 2. Electricity generation and distribution

X. Tourism and Landmarks A. Popular tourist destinations B. National parks and protected areas C. Historic landmarks and cultural sites

XI. International Relations A. Overview of the United States' foreign policy B. Major alliances and international organizations C. Key diplomatic relationships and conflicts

XII. Conclusion A. Recap of the United States' significance and global impact B. Future challenges and opportunities C. Closing thoughts on the United States' ongoing role in the world"