# AI Prompting at Runtime

To fully understand how to use AI prompting in play mode, ask your Sloyd contact (or email <hello@sloyd.ai>) for the example file "SloydAiExampleIntegration.unitypackage" and look at the scene called "**AIPromptExample"**

## Exposing AI Prompting In Play Mode

1. Open Scene **AIPromptExample**
2. Inside you can see a very rudimental UI and object ExampleAIPrompt ![](https://t20484704.p.clickup-attachments.com/t20484704/130a1daa-0693-4894-adb3-d9ad9192c91c/Screenshot%202024-02-19%20at%2011.49.03.png)
3. For Spawning an object we need two things:
   1. SloydAICredentials (we created that in Setup phase)
   2. SloydCachedTemplates (we will talk about this later)
4. This script is very simple all it does is takes text from Input field and passes it to SloydSDK when button is pressed.
5. This is done via **SloydAIRuntime class** *(all runtime functionalities are packed in this class, for editor functionalities we have SloydAIEditor)*

```
public async void Awake()
{
    await SloydAIRuntime.Authenticate(_credentials);
    _button.onClick.AddListener(OnButtonClicked);
}

private void OnButtonClicked()
{
    Prompt(_inputField.text);
}
public async void Prompt(string prompt)
{
    SloydObject sloydObject = await SloydAIRuntime.RequestSloydObject(prompt, _cachedTemplates);
}
```

6. On Awake we authenticate (you can put this method on your **application start**).
7. Then on button click we pass prompt to helper class that returns SloydObject with which you can work

***

##

## Exposing AI Editing In Play Mode

To fully understand how to use AI prompting in play mode, ask your Sloyd contact (<hello@sloyd.ai>) for an example file: SloydAiExampleIntegration.unitypackage. and look at the scene called "**AIEditExample".**

1. Open Scene **AIPromptExample**
2. Inside you can see a very rudimental UI and object ExampleAIEdit ![](https://t20484704.p.clickup-attachments.com/t20484704/9c046680-377d-488b-a81e-955a4e6d9d4c/image.png)
3. For Spawning an object we need two things:
   1. SloydAICredentials (we created that in Setup phase)
   2. SloydObjectContainer (on object where we will perform edits)
4. This script is very simple all it does is takes text from Input field and passes it to SloydSDK when button is pressed.
5. This is done via **SloydAIRuntime class** *(all runtime functionalities are packed in this class, for editor functionalities we have SloydAIEditor)*

```
public async void Awake()
{
    await SloydAIRuntime.Authenticate(_credentials);
    _button.onClick.AddListener(OnButtonClicked);
}

private void OnButtonClicked()
{
    AIEdit(_inputField.text);
}

private async void AIEdit(string prompt)
{
    _statusText.text = "Ok I am working on it";
    string humanMessage = await SloydAIRuntime.AiEditingRequest(prompt, _container);
    _statusText.text = humanMessage;
    await _container.SloydObject.RebuildMesh();
}
```

6. On Awake we authenticate (you can put this method on your **application start**).
7. Then on button click we pass prompt to helper class that changes properties SloydObject. And then we need to rebuild mesh with this new properties

## Configuring AI to also color the object based on prompt

By default AI prompting does not understand color information. For example if you ask for a "Yellow school bus" you'll get the shape of a school bus but the color might be a different default color. If you want the AI to also change colors based on the prompt you need to enable it, here's how:

```
await SloydAIHelper.RecolorSloydObject(sloydObject, textPrompt, nogResponse.objectId, _paletteCollectionScriptableObject, authorizationToken); 
```

And you'll get a response like this:

```python
SloydAIHelper.NogOutput nogResponse = await SloydAIHelper.ClipRequest(input.Prompt, input.Token).Value;
```
