Comment on page

Bringing an AI partner

Learn how to use machine learning models as an interface to your content
We have seen some examples of how to benefit from a spatial interface. In this tutorial, we'll explore what happens when you share this session with an artificial intelligent agent (AI agent).
In this context, we'll refer to AI agents as computational systems that are trained to respond to human's actions in a way that would be perceived as intelligent.
More specifically, we'll consider these systems to be powered by a large language model, such as GPT-3 from OpenAI or LaMDA from Google. These models can generate text as an output from a given text prompt by being trained on enormous amounts of text data.
As an open example to try out these models, we have Open AI GPT-3 Playground. There we can play with different prepared prompts or we can create our own ones. Then, we'll get the model respond based on the content we provided to it.
Playing with GPT-3 Playground
Great, we have a playground to explore and generate content based on given inputs. We can even fine-tune model's answers by exploring different prompting techniques (GPT-3 documentation is a recommended reading for that). Then the next question is how can we bring these generative capabilities to our Fermat spaces? The answer is simple, let's make a tool for that.
Similar to the Submit button from OpenAI Playground, we can embed its generative capabilities within a UI element within Fermat, i.e: a button block. To do that we have to define an API call to GPT-3 model which has to include at least the following parameters:
  • Prompt: what's the task that you want the model to generate a response from. It's basically the text you put in OpenAI Playground.
  • Model: which model is responsible of the completion. We recommend either using DaVinci or Curie but you can check out all the available models.
  • Temperature: controls randomness of the responses. For creative or generative tasks you can use higher values since the model will offer more unexpected responses. For applications that need a well-defined answer, lower these values.
  • Max_tokens: how many words will the model generate. This corresponds to the text highlighted in green when using OpenAI Playground. One token is around 4-5 English words.
GPT-3 parameters for an API call
In addition, you'll also need to provide an API key when making the call which can be created within your account.
Similar to our previous tutorial you can fetch an URL and wait for a response, usually in JSON format. This also applies to GPT-3 so we can directly edit the behaviour of a button block to call their API when clicked. In the following video we can see what we are looking for.
Using GPT-3 to generate ideas for different prompts
To achieve these results we must consider two aspects: fine-tune the prompt with different content from Fermat's blocks and place the generated response in the space. Then, to use different prompts when clicking a button we can define an inner property me.prompt containing the general structure of the prompt and a function askGPT3 that allows us to use different parameters to change the original prompt:
  • Topic: the text we want to use for our prompt that will be added to the general structure.
  • ReferenceBlock: a block reference we will use this reference to position GPT-3 response within the canvas.
set me.prompt to "Generate ideas for this topic"
set me.temperature to 0.7
set me.maxTokens to 256
set model to "text-curie-001"
set yourApiKey to "YOUR_API_KEY"
set me.askGPT3 to (topic, referenceBlock):
set me.inputs to {
"prompt" to ""+me.prompt + " :\n"+ topic+".\n"
"temperature" to me.temperature
"max_tokens" to me.maxTokens }
set query to {
"method" to "POST"
"url" to "https://api.openai.com/v1/engines/"+model+"/completions"
"headers" to {
"content-type" to "application/json"
"Authorization" to "Bearer " + "YOUR_API_KEY_GOES_HERE"}
"body" to me.inputs}
do fetch query then (response) :
set me.result to do parseJson(response)
do positionResponse with me.result["choices"][0]["text"] and referenceBlock
Once we have defined the behavior to call GPT-3 API we only need to control the content we want to use. This can be easily done using our Selection API which gives us access to our current selected elements. We use it to fill out our topic parameter and also use the selected block as our referenceBlock for later positioning (me.selected[0])
when click me:
set topic to ""
set me.selected to selection
for each in me.selected (i):
set topic to topic + " " + i.value
set me.value to "Generating"
do me.askGPT3 with topic and me.selected[0]
Finally, we can decide where to put GPT-3 responses since the content is not linear. To do that, we simply use the referenceBlock position and create a new text next to it filling out its value with the generated response.
set me.positionResponse to (text, referenceBlock):
new "text" with {
"position" to [referenceBlock.position[0]+referenceBlock.size[0],referenceBlock.position[1]]
"value" to text
"size" to [400,100]
"reflow-content" to false
"background" to "#F3E6B5"
A good practice while exploring different prompts and GPT-3 responses is to use the Inspector anytime to check out if either the prompt structure or the parameters used for the generation are the expected ones.
Example of prompt and results
We can also explore different prompting techniques to better control GPT-3 responses. As an example, you can download Idea Generator Tool which can create different Text blocks from a single given prompt.
Idea Generator using GPT-3
To achieve that, we provide a few examples of how we expect the output and then we are able to process it accordingly:
generate 3 ideas to improve climate change:
ideas:{[Improve public transportation options to make it easier for people to reduce their reliance on cars.;
Encourage people to use less energy in their homes by providing incentives or tax breaks.;
Increase the use of renewable energy sources such as solar and wind power.]}
generate 3 ideas to "your topic":
We use different prompting techniques in other tools such as the SWOT Analyser which generates outputs in 4 categories (Strengths / Weaknesses / Opportunities / Threads ).
SWOT Analyser creates different outputs to help the user decide
Feel free to explore different GPT-3 powered tools within the toolbox. You'll find different prompting techniques and different ways to place content over the space. Have fun 😄!