Skip to content

Commit

Permalink
Some adjustements
Browse files Browse the repository at this point in the history
  • Loading branch information
elandini84 committed Sep 27, 2023
1 parent e3d8581 commit 92d4b07
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ bool GoogleDialogFlowCxChatBot::open(yarp::os::Searchable &config)
yCWarning(GOOGLEDIALOGFLOWCXBOT) << "Time" << yarp::os::Time::now() - oldTime;
yCWarning(GOOGLEDIALOGFLOWCXBOT) << "Siamo qui 5" << m_location;

// Cerca l'agente con il display name specificato.
for (const auto& agent : agentsList) {
yCWarning(GOOGLEDIALOGFLOWCXBOT) << "Siamo qui 6" << agent.ok() <<"wait for 30 seconds";
std::this_thread::sleep_for(30s);
Expand Down Expand Up @@ -127,17 +126,10 @@ bool GoogleDialogFlowCxChatBot::interact(const std::string& messageIn, std::stri
YARP_UNUSED(messageOut);
dialogFlow_cx_v3::DetectIntentRequest req;

//ChatGPT solution ---------------------------------------------------------------------- START

// Set your Dialogflow CX agent's display name

// Create a Dialogflow CX SessionsClient

// Create a query input
dialogFlow_cx_v3::QueryInput query_input;
auto parameters = query_input.mutable_language_code();
*parameters = m_languageCode;
yCError(GOOGLEDIALOGFLOWCXBOT) << "Code:" << query_input.language_code();
dialogFlow_cx_v3::TextInput* text_input = query_input.mutable_text();
text_input->set_text(messageIn);

Expand Down Expand Up @@ -166,8 +158,6 @@ bool GoogleDialogFlowCxChatBot::interact(const std::string& messageIn, std::stri
yCError(GOOGLEDIALOGFLOWCXBOT) << "Failed to detect intent. Error: " << status.error_message();
return false;
}
//ChatGPT solution ------------------------------------------------------------------------ END


return true;
}
Expand Down
73 changes: 8 additions & 65 deletions src/devices/googleDialogflowCxChatBot/GoogleDialogFlowCxChatBot.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,33 +30,33 @@
* |:--------------:|:------------:|:-------:|:--------------:|:-------------:|:--------:|:----------------------------------------------------------------:|:-----:|
* | project | - | string | - | - | Yes | The name of the Google cloud project the wanted agent belongs to | |
* | location | - | string | - | - | Yes | The world region specified for the wanted agent | |
* | display_name | - | string | - | - | Yes | The human readable name of the agent | |
* | agent_name | - | string | - | - | Yes | The name of the agent | |
* | language_code | - | string | - | en-US | No | The language code to use for the interaction with the bot | |
*
*
* example of xml file with a fake odometer
*
* \code{.unparsed}
* <?xml version="1.0" encoding="UTF-8"?>
* <!DOCTYPE robot PUBLIC "-//YARP//DTD yarprobotinterface 3.0//EN" "http://www.yarp.it/DTD/yarprobotinterfaceV3.0.dtd">
* <robot name="googleTest" build="2" portprefix="/googleSynth" xmlns:xi="http://www.w3.org/2001/XInclude">
* <robot name="googleTest" build="2" portprefix="/googleBot" xmlns:xi="http://www.w3.org/2001/XInclude">
* <devices>
* <device name="googleDialogCx" type="googleDialogFlowCxChatBot">
* <param name="project">
* hsp-speech-interaction-dev
* <!-- Insert project name here -->
* </param>
* <param name="location">
* global
* <!-- Insert location id here -->
* </param>
* <param name="display_name">
* HSP_Agent_Object_retrieval
* <param name="agent_name">
* <!-- Insert agent display name here -->
* </param>
* </device>
*
* <device name="dialogWrap" type="chatBot_nws_yarp">
* <action phase="startup" level="5" type="attach">
* <paramlist name="networks">
* <elem name="subdeviceGoogle">
* googleSynth
* googleDialogCx
* </elem>
* </paramlist>
* </action>
Expand All @@ -68,63 +68,6 @@
*/




/*
```cpp
#include <iostream>
#include <google/cloud/dialogflow/cx/v3/sessions.grpc.pb.h>
#include <google/cloud/dialogflow/cx/v3/sessions.pb.h>
#include <grpcpp/grpcpp.h>
using namespace google::cloud::dialogflow::cx::v3;
int main() {
// Initialize the gRPC channel with your Dialogflow CX API endpoint.
std::shared_ptr<grpc::Channel> channel = grpc::CreateChannel("YOUR_API_ENDPOINT", grpc::GoogleDefaultCredentials());
// Create a session client.
Sessions::Stub stub(channel);
// Set your Dialogflow CX project ID and session ID.
std::string project_id = "YOUR_PROJECT_ID";
std::string location_id = "YOUR_LOCATION_ID"; // The location ID of your agent
std::string agent_id = "YOUR_AGENT_ID"; // The ID of your agent
std::string session_id = "YOUR_SESSION_ID";
// Create a session name.
SessionName session_name(project_id, location_id, agent_id, session_id);
// Create a query input.
TextInput text_input;
text_input.set_text("Hello, chatbot!");
// Create a query parameters.
QueryParameters query_parameters;
// Create a detect intent request.
DetectIntentRequest request;
request.set_session(session_name.ToString());
*request.mutable_query_input()->mutable_text() = text_input;
*request.mutable_query_params() = query_parameters;
// Send the request to Dialogflow CX.
DetectIntentResponse response;
grpc::Status status = stub.DetectIntent(&request, &response);
if (status.ok()) {
std::cout << "Response: " << response.query_result().response_messages(0).text().text() << std::endl;
} else {
std::cerr << "Error: " << status.error_message() << std::endl;
}
return 0;
}
```
*/



class GoogleDialogFlowCxChatBot :
public yarp::dev::DeviceDriver,
public yarp::dev::IChatBot
Expand Down

0 comments on commit 92d4b07

Please sign in to comment.