-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from dfinke/Integrate-my-PSAI-Agents-module
Integrate my PSAI Agents module #35
- Loading branch information
Showing
25 changed files
with
1,160 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<# | ||
.SYNOPSIS | ||
Converts a message to an OpenAPI message format. | ||
.DESCRIPTION | ||
The ConvertTo-OAIMessage function takes a message as input and converts it to an OpenAPI message format. It uses the ConvertTo-Json cmdlet to convert the message to JSON format and then uses the ConvertFrom-Json cmdlet with the -AsHashtable parameter to convert the JSON back to a hashtable. | ||
.PARAMETER Message | ||
The message to be converted. | ||
.EXAMPLE | ||
$m=[pscustomobject](New-ChatRequestAssistantMessage test) | ||
$m | ||
$m | ConvertTo-OAIMessage | ||
#> | ||
|
||
function ConvertTo-OAIMessage { | ||
[CmdletBinding()] | ||
param( | ||
[Parameter(ValueFromPipeline)] | ||
$Message | ||
) | ||
|
||
Process { | ||
$Message | ConvertTo-Json -Depth 5 | ConvertFrom-Json -AsHashtable -Depth 5 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<# | ||
.SYNOPSIS | ||
Retrieves a response from a PSAIAgent based on a given prompt. | ||
.DESCRIPTION | ||
The Get-AgentResponse function takes a prompt string and an agent object, validates the agent, and retrieves a response from the agent. The agent must be of type 'PSAIAgent'. | ||
.PARAMETER Prompt | ||
The prompt string to be sent to the agent. | ||
.PARAMETER Agent | ||
The agent object from which the response is to be retrieved. This parameter accepts input from the pipeline. | ||
.EXAMPLE | ||
PS C:\> Get-AgentResponse -Prompt "Hello, how are you?" -Agent $myAgent | ||
.EXAMPLE | ||
PS C:\> $myAgent | Get-AgentResponse -Prompt "What is the weather today?" | ||
.NOTES | ||
The agent object must be of type 'PSAIAgent'. If the agent is not valid, an error will be thrown. | ||
#> | ||
function Get-AgentResponse { | ||
[CmdletBinding()] | ||
param( | ||
[string]$Prompt, | ||
[Parameter(ValueFromPipeline)] | ||
$Agent | ||
) | ||
|
||
Process { | ||
if (!($agent.psobject.TypeNames -contains 'PSAIAgent')) { | ||
Write-Error "Agent is not a valid PSAIAgent" | ||
return | ||
} | ||
|
||
$agent.PrintResponse($Prompt) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<# | ||
.SYNOPSIS | ||
Invokes an interactive command-line interface (CLI) for a given PSAIAgent. | ||
.DESCRIPTION | ||
The Invoke-InteractiveCLI function initiates an interactive CLI session for a specified PSAIAgent object. | ||
It allows the user to send a message, specify a user, and optionally include an emoji and an exit condition. | ||
.PARAMETER Agent | ||
The PSAIAgent object that will be used to invoke the interactive CLI. This parameter accepts input from the pipeline. | ||
.PARAMETER Message | ||
The message to be displayed in the interactive CLI. | ||
.PARAMETER User | ||
The user associated with the interactive CLI session. | ||
.PARAMETER Emoji | ||
An optional emoji to be displayed in the interactive CLI. The default value is '😎'. | ||
.PARAMETER ExitOn | ||
An optional parameter that specifies the condition on which the interactive CLI should exit. | ||
.EXAMPLE | ||
PS C:\> $agent = Get-PSAIAgent | ||
PS C:\> Invoke-InteractiveCLI -Agent $agent -Message "Hello, World!" -User "Admin" | ||
This example invokes the interactive CLI for the specified PSAIAgent with the message "Hello, World!" and user "Admin". | ||
.NOTES | ||
The function checks if the provided Agent is a valid PSAIAgent object before invoking the interactive CLI. | ||
If the Agent is not valid, an error is written and the function returns without further execution. | ||
#> | ||
function Invoke-InteractiveCLI { | ||
[CmdletBinding()] | ||
param( | ||
[Parameter(ValueFromPipeline)] | ||
$Agent, | ||
$Message, | ||
$User, | ||
$Emoji = '😎', | ||
$ExitOn | ||
) | ||
|
||
Process { | ||
if (!($agent.psobject.TypeNames -contains 'PSAIAgent')) { | ||
Write-Error "Agent is not a valid PSAIAgent" | ||
return | ||
} | ||
|
||
$agent.InteractiveCLI($Message, $User, $Emoji, $ExitOn) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<# | ||
.SYNOPSIS | ||
Invokes the specified tool functions based on the response received. | ||
.DESCRIPTION | ||
The Invoke-OAIFunctionCall function is used to invoke the specified tool functions based on the response received. It iterates through the tool calls in the response and executes each tool function. | ||
.PARAMETER Response | ||
The response object containing the tool calls. | ||
#> | ||
function Invoke-OAIFunctionCall { | ||
[CmdletBinding()] | ||
param( | ||
$Response | ||
) | ||
|
||
$toolCalls = $Response.choices[0].message.tool_calls | ||
|
||
# Write-Verbose ($toolCalls | dumpJson) | ||
|
||
foreach ($toolCall in $toolCalls) { | ||
$toolCallId = $toolCall.id | ||
$toolFunctionName = $toolCall.function.name | ||
$toolFunctionArgs = $toolCall.function.arguments | ConvertFrom-Json -AsHashtable -Depth 5 | ||
|
||
Write-Verbose "$toolFunctionName $($toolFunctionArgs | ConvertTo-Json -Compress)" | ||
|
||
if (Get-Command $toolFunctionName -ErrorAction SilentlyContinue) { | ||
$result = & $toolFunctionName @toolFunctionArgs | ||
} | ||
else { | ||
$result = "Function $toolFunctionName not found" | ||
} | ||
|
||
New-ChatRequestToolMessage $toolCallId $toolFunctionName $result | ||
} | ||
} |
Oops, something went wrong.