Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
QilongTang committed Mar 7, 2024
1 parent 8ccfeba commit 827c287
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/DynamoAssistantViewExtension/DynamoAssistantWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,12 @@ internal async void SendMessage(string msg)
string response = await conversation.GetResponseFromChatbotAsync();
// Display the chatbot's response
Messages.Add("Copilot:\n" + response + "\n");

var responseToLower = response.ToLower();
// Use Regex to split only the Python code from the response
CreatePythonNode(response);
if (responseToLower.Contains("python script") || responseToLower.Contains("python node"))
{
CreatePythonNode(response);
}

// create a Dynamo note example
// CreateNote((new Guid()).ToString(), "This is a sample Note.", 0, 0, true);
Expand All @@ -83,9 +86,20 @@ internal async void SendMessage(string msg)
/// <summary>
/// Create a python node in Dynamo, use latest Nuget package for this
/// </summary>
/// <param name="pythonScript"></param>
internal void CreatePythonNode(string pythonScript)
/// <param name="response"></param>
internal void CreatePythonNode(string response)
{
string pythonScript = string.Empty;
if (response.Contains("```python"))
{
pythonScript = response.Split("```python")[1];
if(pythonScript.Contains("```"))
{
pythonScript = pythonScript.Split("```")[0];
}
}
else return;

var pythonNode = new PythonNodeModels.PythonNode
{
Script = pythonScript
Expand Down

0 comments on commit 827c287

Please sign in to comment.