CyberChaos(さいばかおす)

プログラミング言語、トランスパイラ、RPA、ChatGPT、データマイニング、リバースエンジニアリングのための忘備録

AutoCADで簡易チャットボットをやってみたwww

2024-04-20 15:41:42 | Autocad

ソースコードはVB.NET。








Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Runtime

Public Class ChatBotCommands

<CommandMethod("CHATBOT")>
Public Sub StartChatBot()
Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor

While True
Dim userInput As String = GetUserInput("You: ")
Dim response As String = GetResponse(userInput)
ed.WriteMessage($"Bot: {response}" & vbCrLf)
End While
End Sub

Private Function GetUserInput(prompt As String) As String
Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
Dim options As PromptStringOptions = New PromptStringOptions(prompt)
options.AllowSpaces = True
Dim result As PromptResult = ed.GetString(options)
If result.Status = PromptStatus.OK Then
Return result.StringResult
Else
Return String.Empty
End If
End Function

Private Function GetResponse(input As String) As String
' ユーザーの入力に応じて適切な応答を生成
Select Case input.ToLower()
Case "hello", "hi"
Return "Hello! How can I help you?"
Case "how are you?"
Return "I'm just a program, so I don't have feelings, but thanks for asking!"
Case "bye", "exit", "quit"
Return "Goodbye! Have a great day!"
Case Else
Return "I'm sorry, I didn't understand that."
End Select
End Function

End Class

Case1「 "hello", "hi"」と入力すると

Return "Hello! How can I help you?"


Case2 「"how are you?"」と入力すると

Return "I'm just a program, so I don't have feelings, but thanks for asking!"


Case3 "bye", "exit", "quit"

Return "Goodbye! Have a great day!"

Case Else 例えばFuck You!と入力すると・・・


Return "I'm sorry, I didn't understand that."

それ以外も同様となる。なかなか面白かった。

ちなみに、三角錐とか円錐とか、立方体を円柱でくり抜くとかちょっと高度なコードをChatGPTにコード生成させたらエラーばっかで全然だめだったので、チャットボットにしてみた。テトリスはAUTOLISPでは動いたが、VB.NETではだめだった。インベーダーゲームも試したがだめだった。



最新の画像もっと見る