0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

cscの作法 その269

Posted at

概要

cscの作法、調べてみた。
「Chaplus API」使って、みた。
練習問題やってみた。

練習問題

人工無脳を実装せよ。

サンプルコード

using System.Collections;
using System.IO;
using System;
using System.Text;
using LitJson;
using System.Net;

namespace app
{
	class test0 {
		static void Main() {
			ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
			do
			{
				string str = Console.ReadLine();
				if (str == null)
				{
					break;
				}
				WebClient wc = new WebClient();
				string json = "{\"utterance\": \"" + str + "\",\"username\": \"太郎\", \"addition\": {\"utterancePairs\": [{\"utterance\": \"\"}],\"ngWords\": [\"NGワード\"],\"options\": [\"\"]},\"agentState\": {\"agentName\": \"エージェント\",\"age\":\"10歳\",\"tone\": \"normal\"}}";
				wc.Encoding = System.Text.Encoding.UTF8;
				wc.Headers[HttpRequestHeader.ContentType] = "application/json";
				string response = wc.UploadString("https://www.chaplus.jp/v1/chat?apikey=*****", "POST", json);
				LitJson.JsonData data = LitJson.JsonMapper.ToObject(response);
				Console.WriteLine(data["bestResponse"]["utterance"]);
			} while (true);
		}
	}
}


実行結果

>chat2
お掃除します
片付いていない部屋にいると、心が落ち着かない気がしますよね。
今日は晴れ
愛に出来ることはまだあるかい
明日は
晴れますように
貴方は
どうかお気持ちをお鎮めください。私の非力さゆえにご。
私は
・・・・・・・・・・・・・・・・・・・・・・・
私は誰
太郎です。
ここはどこ
癒しの世界
いつ
: 時は金なり

以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?