Skip to content

Commit

Permalink
Use OpenAI dependency instead of own RestSharp code
Browse files Browse the repository at this point in the history
  • Loading branch information
QilongTang committed Mar 5, 2024
1 parent 5db1e09 commit 2932bec
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 85 deletions.
80 changes: 0 additions & 80 deletions src/DynamoAssistantViewExtension/ChatGPTClient.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<PackageReference Include="DynamoVisualProgramming.DynamoServices" Version="3.1.0-beta4081" />
<PackageReference Include="DynamoVisualProgramming.WpfUILibrary" Version="3.1.0-beta4081" />
<PackageReference Include="DynamoVisualProgramming.ZeroTouchLibrary" Version="3.1.0-beta4081" />
<PackageReference Include="OpenAI" Version="1.10.0" />
<PackageReference Include="RestSharp" Version="108.0.1" />
</ItemGroup>
<ItemGroup>
Expand Down
19 changes: 14 additions & 5 deletions src/DynamoAssistantViewExtension/DynamoAssistantWindowViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using Dynamo.Core;
using Dynamo.Extensions;
using Dynamo.UI.Commands;
using OpenAI_API;
using OpenAI_API.Chat;
using OpenAI_API.Models;
using System;
using System.Collections.ObjectModel;
using System.Windows.Input;
Expand All @@ -11,8 +14,9 @@ public class DynamoAssistantWindowViewModel : NotificationObject, IDisposable
{
private string userInput;
private readonly ReadyParams readyParams;
private readonly ChatGPTClient chatGPTClient;
private static readonly string apikey = "Your API";
private readonly OpenAIAPI chatGPTClient;
private readonly Conversation conversation;
private static readonly string apikey = "Your API Key";

/// <summary>
///
Expand All @@ -39,15 +43,20 @@ public DynamoAssistantWindowViewModel(ReadyParams p)
readyParams = p;

// Create a ChatGPTClient instance with the API key
chatGPTClient = new ChatGPTClient(apikey);
chatGPTClient = new OpenAIAPI(new APIAuthentication(apikey));
// ChatGPT lets you start a new chat.
conversation = chatGPTClient.Chat.CreateConversation();
conversation.Model = Model.DefaultChatModel;
conversation.RequestParameters.Temperature = 0;
// Display a welcome message
Messages.Add("Assistant:\nWelcome to Dynamo world and ask me anything to get started!");
}

internal void SendMessage(string msg)
internal async void SendMessage(string msg)
{
// Send the user's input to the ChatGPT API and receive a response
string response = chatGPTClient?.SendMessage(msg);
conversation?.AppendUserInput(msg);
string response = await conversation.GetResponseFromChatbotAsync();
// Display user message first
Messages.Add("You:\n" + msg);
// Display the chatbot's response
Expand Down

0 comments on commit 2932bec

Please sign in to comment.