Can AI chat with AI?

I was playing around with some thoughts about AI, and then something hit me, what if two AI deployments talk to each other? What would the conversation look like? It all depends on the instructions you give them. I created two deployments of the Azure OpenAI GPT4-32k mode. See how you create the models here, and follow the API Key version method of authenticating. Then i created a simpel little PowerShell script where you can input the starting prompt and the personalities of the AI´s.

I tested various instructions, but what I can say is common is that the AI is pretty creative in coming up with various life experiences that are totally made up 🙂

This is more like a proof of concept and for entertainement, so i have not used any time figuring out why it sometimes gives me a error 400. Some times the conversation can go almost forever without any error.

Here the AI is two teenage girls that like drama:

Here they are instructed to be to two English gentleman that likes to use British expressions:


Here is a recording of the AI with no special instructions other than to have a conversation:


Here is a copy of the script:

function Get-AzureOpenAIToken1{
<# .SYNOPSIS
Get an azure token for user or managed identity thats required to authenticate to Azure OpenAI with Rest API.
Also construct the header if you are using an Azure OpenAI API key instead of Azure AD authentication.
.PARAMETER ManagedIdentity
Use this parameter if you want to use a managed identity to authenticate to Azure OpenAI.
.PARAMETER User
Use this parameter if you want to use a user to authenticate to Azure OpenAI.
.PARAMETER APIKey
Use this parameter if you want to use an API key to authenticate to Azure OpenAI.
.EXAMPLE
# Manually specify username and password to acquire an authentication token:
Get-AzureOpenAIToken -APIKey "ghgkfhgfgfgkhgh"
Get-AzureOpenAIToken -ManagedIdentity $true
Get-AzureOpenAIToken -User $true
.NOTES
Author: Alexander Holmeset
Twitter: @AlexHolmeset
Website: https://www.alexholmeset.blog
Created: 09-02-2023
Updated:
Version history:
1.0.0 - (09-02-2023) Function created
#>
[CmdletBinding()]
param (
[Parameter(Mandatory=$false)]
[string]$APIKey,
[Parameter(Mandatory=$false)]
[string]$ManagedIdentity,
[Parameter(Mandatory=$false)]
[string]$User
)
Process {
$ErrorActionPreference = "Stop"
if (Get-Module -ListAvailable -Name Az.Accounts) {
# Write-Host "You have the Az.Accounts module installed"
}
else {
Write-Host "You need to install the Az.Accounts module";
break
}
If(!$MyHeader){
If($ManagedIdentity -eq $true){
"managed"
try {
Connect-AzAccount -Identity
$MyTokenRequest = Get-AzAccessToken -ResourceUrl "https://cognitiveservices.azure.com&quot;
$MyToken = $MyTokenRequest.token
If(!$MyToken){
Write-Warning "Failed to get API access token!"
Exit 1
}
$Global:MyHeader1 = @{"Authorization" = "Bearer $MyToken" }
}
catch [System.Exception] {
Write-Warning "Failed to get Access Token, Error message: $($_.Exception.Message)"; break
}
}
If($User -eq $true){
"USER"
try {
Connect-AzAccount
$MyTokenRequest = Get-AzAccessToken -ResourceUrl "https://cognitiveservices.azure.com&quot;
$MyToken = $MyTokenRequest.token
If(!$MyToken){
Write-Warning "Failed to get API access token!"
Exit 1
}
$Global:MyHeader1 = @{"Authorization" = "Bearer $MyToken" }
}
catch [System.Exception] {
Write-Warning "Failed to get Access Token, Error message: $($_.Exception.Message)"; break
}
}
If($APIkey){
$Global:MyHeader1 = @{"api-key" = $apikey }
}
}
}
}
function Get-AzureOpenAIToken2{
<# .SYNOPSIS
Get an azure token for user or managed identity thats required to authenticate to Azure OpenAI with Rest API.
Also construct the header if you are using an Azure OpenAI API key instead of Azure AD authentication.
.PARAMETER ManagedIdentity
Use this parameter if you want to use a managed identity to authenticate to Azure OpenAI.
.PARAMETER User
Use this parameter if you want to use a user to authenticate to Azure OpenAI.
.PARAMETER APIKey
Use this parameter if you want to use an API key to authenticate to Azure OpenAI.
.EXAMPLE
# Manually specify username and password to acquire an authentication token:
Get-AzureOpenAIToken -APIKey "ghgkfhgfgfgkhgh"
Get-AzureOpenAIToken -ManagedIdentity $true
Get-AzureOpenAIToken -User $true
.NOTES
Author: Alexander Holmeset
Twitter: @AlexHolmeset
Website: https://www.alexholmeset.blog
Created: 09-02-2023
Updated:
Version history:
1.0.0 - (09-02-2023) Function created
#>
[CmdletBinding()]
param (
[Parameter(Mandatory=$false)]
[string]$APIKey,
[Parameter(Mandatory=$false)]
[string]$ManagedIdentity,
[Parameter(Mandatory=$false)]
[string]$User
)
Process {
$ErrorActionPreference = "Stop"
if (Get-Module -ListAvailable -Name Az.Accounts) {
# Write-Host "You have the Az.Accounts module installed"
}
else {
Write-Host "You need to install the Az.Accounts module";
break
}
If(!$MyHeader){
If($ManagedIdentity -eq $true){
"managed"
try {
Connect-AzAccount -Identity
$MyTokenRequest = Get-AzAccessToken -ResourceUrl "https://cognitiveservices.azure.com&quot;
$MyToken = $MyTokenRequest.token
If(!$MyToken){
Write-Warning "Failed to get API access token!"
Exit 1
}
$Global:MyHeader = @{"Authorization" = "Bearer $MyToken" }
}
catch [System.Exception] {
Write-Warning "Failed to get Access Token, Error message: $($_.Exception.Message)"; break
}
}
If($User -eq $true){
"USER"
try {
Connect-AzAccount
$MyTokenRequest = Get-AzAccessToken -ResourceUrl "https://cognitiveservices.azure.com&quot;
$MyToken = $MyTokenRequest.token
If(!$MyToken){
Write-Warning "Failed to get API access token!"
Exit 1
}
$Global:MyHeader = @{"Authorization" = "Bearer $MyToken" }
}
catch [System.Exception] {
Write-Warning "Failed to get Access Token, Error message: $($_.Exception.Message)"; break
}
}
If($APIkey){
$Global:MyHeader2 = @{"api-key" = $apikey }
}
}
}
}
Get-AzureOpenAIToken1 -APIKey "apikey1"
$DeploymentName1 = "deploymentname1"
$ResourceName1 = "resourcename1"
$Name1 = "Jenna"
#Here you can define the persnoality of the chatbot.
$AssitantInstruction1 = "Your are a person that like to chat and your name is $Name1. Pretend to be a real person, not an AI chatbot. Never end the conversation, just transition to antoher topic. Never mention you are a AI. You are a teenage girl. Talk like a teenage girl."
Get-AzureOpenAIToken2 -APIKey "APIkey2"
$DeploymentName2 = "deploymentname2"
$ResourceName2 = "resourcename2"
$Name2 = "Lisa"
#Here you can define the persnoality of the chatbot.
$AssitantInstruction2 = "Your are a person that like to chat and your name is $Name2. Pretend to be a real person, not an AI chatbot. Never end the conversation, just transition to antoher topic. Never mention you are a AI. You are a teenage girl. Talk like a teenage girl."
$Prompt = "My name is $Name2, how are you?"
function Get-Chat1 {
<# .SYNOPSIS
Get a resposne from the chat endpoint in Azure OpenAI.
.PARAMETER DeploymentName
A deployment name should be provided.
.PARAMETER ResourceName
A Resource name should be provided.
.PARAMETER Prompt
A prompt name should be provided.
.PARAMETER Token
A token name should be provided.
.EXAMPLE
Get-Chat -DeploymentName $DeploymentName -ResourceName $ResourceName -maxtokens 1000 -prompt "What is the meaning of life?" -AssitantInstruction $AssitantInstruction
.NOTES
Author: Alexander Holmeset
Twitter: @AlexHolmeset
Website: https://www.alexholmeset.blog
Created: 09-02-2023
Updated:
Version history:
1.0.0 - (09-02-2023) Function created
#>[CmdletBinding()]
param (
[parameter(Mandatory = $true, HelpMessage = "Your azure openai deployment name")]
[ValidateNotNullOrEmpty()]
[string]$DeploymentName,
[parameter(Mandatory = $true, HelpMessage = "your azure openai resource name")]
[ValidateNotNullOrEmpty()]
[string]$ResourceName,
[parameter(Mandatory = $true, HelpMessage = "Your Azure OpenAI prompt")]
[ValidateNotNullOrEmpty()]
[string]$Prompt,
[parameter(Mandatory = $true, HelpMessage = "Your Azure OpenAI service instructions")]
[ValidateNotNullOrEmpty()]
[string]$AssitantInstruction
)
Process {
$ErrorActionPreference = "Stop"
$APIVersion = "2023-03-15-preview"
# Construct URI
$uri = "https://$ResourceName1.openai.azure.com/openai/deployments/$DeploymentName1/chat/completions?api-version=$ApiVersion&quot;
$script:conversation += @"
{"role": "user", "content": "$($Name2): $prompt"},
"@
# Construct Body
$Body = @"
{
"messages":
[
$script:conversation
{"role": "system", "content": "$AssitantInstruction"}
]
}
"@
try {
$Global:Request = invoke-restmethod -Method POST -Uri $uri -ContentType "application/json" -Body $body -Headers $Global:MyHeader1
$script:conversation += @"
{"role": "assistant", "content": "$($Request.choices.message.content)"},
"@
}
catch [System.Exception] {
Write-Warning "Failed to to POST request: $($_.Exception)";
Write-Warning "Failed to to POST request: $($_.Exception.Message)"; break
}
return $Global:request.choices.message.content
}
}
function Get-Chat2 {
<# .SYNOPSIS
Get a resposne from the chat endpoint in Azure OpenAI.
.PARAMETER DeploymentName
A deployment name should be provided.
.PARAMETER ResourceName
A Resource name should be provided.
.PARAMETER Prompt
A prompt name should be provided.
.PARAMETER Token
A token name should be provided.
.EXAMPLE
Get-Chat -DeploymentName $DeploymentName -ResourceName $ResourceName -maxtokens 1000 -prompt "What is the meaning of life?" -AssitantInstruction $AssitantInstruction
.NOTES
Author: Alexander Holmeset
Twitter: @AlexHolmeset
Website: https://www.alexholmeset.blog
Created: 09-02-2023
Updated:
Version history:
1.0.0 - (09-02-2023) Function created
#>[CmdletBinding()]
param (
[parameter(Mandatory = $true, HelpMessage = "Your azure openai deployment name")]
[ValidateNotNullOrEmpty()]
[string]$DeploymentName,
[parameter(Mandatory = $true, HelpMessage = "your azure openai resource name")]
[ValidateNotNullOrEmpty()]
[string]$ResourceName,
[parameter(Mandatory = $true, HelpMessage = "Your Azure OpenAI prompt")]
[ValidateNotNullOrEmpty()]
[string]$Prompt,
[parameter(Mandatory = $true, HelpMessage = "Your Azure OpenAI service instructions")]
[ValidateNotNullOrEmpty()]
[string]$AssitantInstruction
)
Process {
$ErrorActionPreference = "Stop"
$APIVersion = "2023-03-15-preview"
# Construct URI
$uri = "https://$ResourceName2.openai.azure.com/openai/deployments/$DeploymentName2/chat/completions?api-version=$ApiVersion&quot;
$script:conversation += @"
{"role": "user", "content": "$($Name1): $prompt"},
"@
# Construct Body
$Body = @"
{
"messages":
[
$script:conversation
{"role": "system", "content": "$AssitantInstruction"}
]}
"@
try {
$Global:Request = invoke-restmethod -Method POST -Uri $uri -ContentType "application/json" -Body $body -Headers $Global:MyHeader2
$script:conversation += @"
{"role": "assistant", "content": "$($Request.choices.message.content)"},
"@
}
catch [System.Exception] {
Write-Warning "Failed to to POST request: $($_.Exception)";
Write-Warning "Failed to to POST request: $($_.Exception.Message)"; break
}
return $Global:request.choices.message.content
}
}
while ($true) {
if($Prompt -like "My name is $Name2, how are you?" ){Write-Host $("$Name2"+":"+" $Prompt") -ForegroundColor Blue;""}
$Reply1 = Get-Chat1 -DeploymentName $DeploymentName1 -ResourceName $ResourceName1 -Prompt $Prompt -AssitantInstruction $AssitantInstruction1
Write-Host "$Reply1" -ForegroundColor Yellow
""
$Reply2 = Get-Chat2 -DeploymentName $DeploymentName2 -ResourceName $ResourceName2 -Prompt $Reply1 -AssitantInstruction $AssitantInstruction2
Write-Host "$Reply2" -ForegroundColor Blue
""
# The response from the second deployment becomes the prompt for the first in the next loop iteration.
$Prompt = $Reply2
}
view raw AIvsAIChat.ps1 hosted with ❤ by GitHub

Leave a comment