Artificial intelligence
Folder examples/Artificial Intelligence. Which preconditions a Needs line refers to is explained in the
overview; the Prompt is a request for the agent.
Tell a fortune​
Beginner examples/Artificial Intelligence/Tell a fortune
Reads a list of adjectives row by row. For every adjective a language model, instructed as a fortune teller from the 15th century, writes a fortune ("Tell me a spooky fortune."), and the answer is appended to a CSV file. If the model fails for one word, the diagram goes on with the next.
Needs: a language model; the example data examples/Data/wordlists/adjectives.csv.
Prompt
Create a diagram that reads the word list examples/Data/wordlists/adjectives.csv (column adjective) row by row. For every adjective ask the language model with the system prompt "You are a fortune teller from the 15th century." and the user prompt "Tell me a
${variable.adjective}fortune." (temperature 0, top p 0) and append the answer to a CSV file. If the model fails for a word, continue with the next one. End when no row is left.
Search Engine Optimization of product descriptions​
Beginner examples/Artificial Intelligence/Search Engine Optimization of product descriptions
Reads products (category, name, description) from the example shop data. A language model writes a search-engine-optimized description for each product, and the result is written to a CSV file together with the original columns. A good first look at what a loop over a table with an AI step in it does.
Needs: a language model; the example data examples/Data/eCommerce/ECommerce dataset.csv.
Prompt
Create a diagram that reads the products of examples/Data/eCommerce/ECommerce dataset.csv (columns Category, Name, Description) row by row. For every product ask the language model to write a search engine optimized description from the category and the description: no paraphrasing, no quotes around the answer, temperature 0.5. Append the AI result together with category, name and description to a CSV file. End when no row is left.
Sentiment Detection​
Beginner examples/Artificial Intelligence/Sentiment Detection
Reads the products and rates the description of each with the sentiment detection
node (VADER). Three outgoing edges, positive, negative and neutral, lead to three CSV files that also contain the
scores. No language model is needed: the method runs on your server.
Needs: the example data examples/Data/eCommerce/ECommerce dataset.csv.
Prompt
Create a diagram that reads examples/Data/eCommerce/ECommerce dataset.csv (columns Category, Name, Description) row by row and rates the Description with the sentiment detection node (VADER). Depending on the result append the row with its sentiment scores to positive.csv, negative.csv or neutral.csv. End when no row is left.
Conversation​
Intermediate examples/Artificial Intelligence/Conversation
A chat with memory, shown as a web page. An input page shows the conversation so far
and asks for the next question, with the buttons ask, new conversation and exit (the edges of the decision behind
it). ask sends the question and the whole history to the language model and comes back to the page. new conversation
starts with an empty history. If nobody answers in time, the edge timeout ends the diagram. The run waits at the page;
its link is in the task list.
Needs: a language model.
Prompt
Build a chat with memory. An input mask with one required text field "question" whose header shows the conversation so far (every message of the variable ai.prompt.history). Behind the mask a decision with the edges "ask", "new conversation", "exit" and "timeout", where "exit" and "timeout" end the diagram. "ask" sends the variable question to the language model with the whole history (chat.history = -1), clears the variable question and returns to the input mask. "new conversation" sets ai.prompt.history to an empty list, clears question and returns to the input mask. Set ai.prompt.history to an empty list at the start as well.
Answer from a Document​
Intermediate examples/Artificial Intelligence/Answer from a Document
Answers questions from one document and from nothing else. The text of the document is stored in the variable document
by the node Load the document; a sample handbook of a fictional shop is in it, replace it by your own text. An
input page asks for a question and shows the last answer; the language model
gets the document and the question in one prompt and answers in one round. The rules are in the system prompt: use only
the document, answer exactly The document does not say. when the answer is not in it, and quote the passage that
supports the answer. The temperature is 0.
This is the pattern for "ask my handbook", an FAQ, a policy or a contract. Try the questions How long do I have to return a jacket? and Do you ship to Austria? (in the document), then Do you sell tents? (not in the document: the answer must be that the document does not say). If it makes something up, the model is too small for the task, see Local models.
Your own document. Open the node Load the document and replace the text. The whole document is part of every prompt, so it must fit into the context window together with the question and the answer: a few pages work with a local model, a long manual does not. For longer texts select the relevant passages first (for example the rows of a CSV file with one passage per row that match a keyword) and put only those into the prompt, an idea known as retrieval-augmented generation. What belongs into such a prompt is explained in Context and prompts.
Needs: a language model. The sample document is part of the diagram, no further data is needed.
Prompt
Create a diagram that answers questions from one document and from nothing else. A variable node "Load the document" stores the text of the document (I will paste it) in the variable document. A second variable node sets ai.prompt.result to an empty text. Then an input mask with one required text field "question" whose header shows the last answer
${variable.ai.prompt.result}. Behind the mask a decision with the edges "ask", "exit" and "timeout"; "exit" and "timeout" end the diagram. "ask" sends one prompt to the language model (temperature 0, top p 1): the system prompt says "You answer questions about the document in the user message and use nothing else. If the document does not contain the answer, reply exactly: The document does not say. Otherwise answer in one or two sentences and quote the passage that supports the answer. Answer in the language of the question." and the user prompt contains the label DOCUMENT with${variable.document}, then the label QUESTION with${variable.question}. Then clear the variable question and return to the input mask.
Telegram Chat​
Intermediate examples/Artificial Intelligence/Telegram Chat
A Telegram chatbot with a session per chat. Every incoming message starts the diagram with the text in
telegram.message_text, a language model answers it with the last 30 messages as context, and the answer goes back to the
chat. Then the dialog sleeps: a new message continues it, and after five minutes without a message a goodbye is sent and
the chat ends. See Incoming Telegram Chat.
Needs: a language model; a Telegram bot (token in the system settings, the name of the bot in the event node,
@yourbot is a placeholder); the server must reach Telegram.
Prompt
Build a Telegram chatbot with sessions. An event node for the bot @yourbot (only the name of the bot, the token comes from the system settings). Each incoming message goes to the language model with
${variable.telegram.message_text}as user prompt, a system prompt that tells the model the nickname of the person (telegram.message_from_username) and the last 30 messages as chat history. Send the answer back to the chat, then put the dialog to sleep with a wake-up timer of 5 minutes: a new message continues the dialog, when the timer fires send "Good bye, chat finished due to inactivity." and finish.
Escalate Angry Customers​
Intermediate examples/Artificial Intelligence/Escalate Angry Customers
Starts with every new e-mail. Sentiment detection judges the text. A negative mail is forwarded to a manager with the
subject [URGENT] Unhappy customer: ...; every other mail gets a friendly answer drafted by a language model and sent
to the sender. The use case is described in Escalate angry customers.
Needs: a language model; a mailbox (the event) and mail sending; replace manager@example.com.
Prompt
Create a diagram that starts on every new e-mail in the inbox, judges the mood of the mail text with sentiment detection (VADER) and branches on the sentiment class: if it is "negative", send an e-mail to manager@example.com with the subject "[URGENT] Unhappy customer:
${email.subject}" that says who wrote and what. Otherwise let the language model write a short, friendly answer to the message and send it to the sender with the subject "Re:${email.subject}". Name the condition edge "unhappy" and put the condition in its parameter. Make the diagram end cleanly if the language model fails.