watson-developer-cloud / ruby-sdk Goto Github PK
View Code? Open in Web Editor NEW:diamonds: Ruby SDK to use the IBM Watson services.
License: Apache License 2.0
:diamonds: Ruby SDK to use the IBM Watson services.
License: Apache License 2.0
Errno::EPIPE: Broken pipe
File "/app/vendor/ruby-2.3.0/lib/ruby/2.3.0/openssl/buffering.rb", line 379, in syswrite_nonblock
File "/app/vendor/ruby-2.3.0/lib/ruby/2.3.0/openssl/buffering.rb", line 379, in write_nonblock
File "/app/vendor/bundle/ruby/2.3.0/gems/http-3.3.0/lib/http/timeout/per_operation.rb", line 89, in block in write
File "/app/vendor/bundle/ruby/2.3.0/gems/http-3.3.0/lib/http/timeout/per_operation.rb", line 88, in loop
File "/app/vendor/bundle/ruby/2.3.0/gems/http-3.3.0/lib/http/timeout/per_operation.rb", line 88, in write
File "/app/vendor/bundle/ruby/2.3.0/gems/http-3.3.0/lib/http/request/writer.rb", line 99, in write
File "/app/vendor/bundle/ruby/2.3.0/gems/http-3.3.0/lib/http/request/writer.rb", line 72, in block in send_request
File "/app/vendor/bundle/ruby/2.3.0/gems/http-3.3.0/lib/http/request/body.rb", line 35, in each
File "/app/vendor/bundle/ruby/2.3.0/gems/http-3.3.0/lib/http/request/writer.rb", line 70, in send_request
File "/app/vendor/bundle/ruby/2.3.0/gems/http-3.3.0/lib/http/request/writer.rb", line 38, in stream
File "/app/vendor/bundle/ruby/2.3.0/gems/http-3.3.0/lib/http/request.rb", line 115, in stream
File "/app/vendor/bundle/ruby/2.3.0/gems/http-3.3.0/lib/http/connection.rb", line 76, in send_request
File "/app/vendor/bundle/ruby/2.3.0/gems/http-3.3.0/lib/http/client.rb", line 70, in perform
File "/app/vendor/bundle/ruby/2.3.0/gems/newrelic_rpm-4.0.0.332/lib/new_relic/agent/instrumentation/http.rb", line 29, in perform_with_newrelic_trace
File "/app/vendor/bundle/ruby/2.3.0/gems/http-3.3.0/lib/http/client.rb", line 30, in request
File "/app/vendor/bundle/ruby/2.3.0/gems/ibm_watson-0.1.2/lib/ibm_watson/watson_service.rb", line 160, in request
File "/app/vendor/bundle/ruby/2.3.0/gems/ibm_watson-0.1.2/lib/ibm_watson/speech_to_text_v1.rb", line 148, in request
File "/app/vendor/bundle/ruby/2.3.0/gems/ibm_watson-0.1.2/lib/ibm_watson/speech_to_text_v1.rb", line 800, in create_job
My method call looks something like...
IBMWatson::SpeechToTextV1.new(<creds>).create_job(
audio: <very large StringIO buffer contents>,
...
)
Any ideas why this consistently leads to a broken pipe but only for some (perhaps large) audio files ?
Description
After using IAM keys (from "Manage" page) and JSON creds (from "Service Credentials" file) I still get IBMCloudSdkCore::ApiException (Error: Unauthorized, Code: 401, Information: {})
error.
To Reproduce
Steps to reproduce the behavior:
iam_api_creds = {
iam_url: "https://gateway.watsonplatform.net/natural-language-understanding/api",
iam_apikey: "XXXXXXX",
version: "2019-07-12"
}
json_service_creds = {
apikey: "XXXXXXX",
iam_apikey_description: "Auto-generated for key XXXXXXX",
iam_apikey_name: "Auto-generated service credentials",
iam_role_crn: "crn:v1:bluemix:public:iam::::serviceRole:Manager",
iam_serviceid_crn: "crn:v1:bluemix:public:iam-identity::a/XXXXXXX::serviceid:ServiceId-XXXXXXX-51d4-429e-95b1-XXXXXXX",
url: "https://gateway.watsonplatform.net/natural-language-understanding/api"
}
natural_language_understanding = IBMWatson::NaturalLanguageUnderstandingV1.new(iam_api_creds)
response = natural_language_understanding.analyze(
text: "Bruce Banner is the Hulk and Bruce Wayne is BATMAN!", features: { "entities" => {} }
).result # Getting IBMCloudSdkCore::ApiException#Unauthorized exception here
natural_language_understanding = IBMWatson::NaturalLanguageUnderstandingV1.new(json_service_creds)
response = natural_language_understanding.analyze(
text: "Bruce Banner is the Hulk and Bruce Wayne is BATMAN!", features: { "entities" => {} }
).result # Getting IBMCloudSdkCore::ApiException#Unauthorized exception here
Expected behavior
Result of NLP processing.
Actual behavior
Getting following error
IBMCloudSdkCore::ApiException (Error: Unauthorized, Code: 401, Information: {})
Desktop (please complete the following information):
Additional context
Approximately half of a year I got this running with version 0.12
The code currently gives a deprecation warning for recognize_using_websocket
Kernel.warn("[DEPRECATION]
recognize_with_websocketis deprecated and will be removed in the next major release. Please use
recognize_using_websocket instead.")
in file https://github.com/watson-developer-cloud/ruby-sdk/blob/master/lib/ibm_watson/speech_to_text_v1.rb
This is redundant / confusing
Describe the bug
Authentication always fails when trying to use the downloaded ibm-credentials.env file.
To Reproduce
Create a IBM_CREDENTIALS_FILE environment variable and point to the downloaded credentials file. Simple create a service using only the version parameter, and it will fail to authenticate.
Expected behavior
No authentication errors.
Problem Resolution
The bug is pretty simple to fix. The ibm_cloud_sdk_core uses the display_name parameter to load the authentication variables from the file. If this parameter is not set, then the credentials file is not loaded.
All of the initialization routines in this package set the display_name parameter AFTER the call to super, so the value is never passed to the super class (ibm_cloud_sdk_core). The display_name parameter needs to be set before calling super.
As a side comment, even though this fixes the loading and parsing of the credentials file, code is missing from the base_service module to actually use the apikey and url read from the credentials file. It looks like this functionality was never actually finished.
Hi -
I'm using version 1.1.2 of ruby-sdk-core in a rails app alonside version 2.1 of ruby-sdk to access the NLU API and I could use a tip on authenticator lifecycle if you have a minute. I'm not sure if this is a bug or I'm just doing it wrong (likely the latter:)) In a rails app on service startup, I initialize an IBMWatson::Authenticators::IamAuthenticator
and keep a reference to it:
config.authenticator = IBMWatson::Authenticators::IamAuthenticator.new(
apikey: config.service_access_key
)
which goes fine. Then, as requests come into the app, as part of handling each request I initialize a new Watson API client object, and pass it the reference to the IamAuthenticator object:
@watson = IBMWatson::NaturalLanguageUnderstandingV1.new(
authenticator: @configuration.authenticator,
version: "2020-08-01"
)
@watson.service_url = @configuration.service_url
@watson.configure_http_client(timeout: { global: @configuration.timeout } )
which also works great at first. But then at some point I start getting 401s back. This has been happening fairly regularly. I think it's after a period of inactivity - the time span between a successful attempt at 2:08PM and the next attempt (which failed) at 3:13PM was over an hour. Here's a log entry (apologies for my json format):
E, [2021-07-01T15:44:31.726112 #76077] ERROR -- : [a57cdfe7-a5c2-47d2-8eb7-7005dbdb7eb9] Error: Unauthorized, Code: 401, Information: {"trace"=>"ba11b8d2-802c-46a8-b910-43b37b4a03ec", "more_info"=>"https://cloud.ibm.com/docs/watson?topic=watson-authorization-error"}, X-dp-watson-tran-id: ba11b8d2-802c-46a8-b910-43b37b4a03ec, X-global-transaction-id: ba11b8d2-802c-46a8-b910-43b37b4a03ec
It won't work again until I restart the service. I think I read that the authenticator would renew the token as needed which I interpreted as meaning I don't ever need to re-initialize an authenticator as part of normal operation. But should I be? I could just wrap the client requests in a handler that renews the authenticator if there's a 401 but I want to make sure I'm not doing something wrong here.
Thanks for any insight!
I am trying to test out watson NLU features, and I keep getting this error:
LoadError (cannot load such file -- ibm_watson/authenticators):
app/controllers/concerns/watson.rb:2:in `<module:Watson>'
app/controllers/concerns/watson.rb:1:in `<main>'
app/controllers/messages_controller.rb:2:in `<class:MessagesController>'
app/controllers/messages_controller.rb:1:in `<main>'
Started POST "/messages" for ::1 at 2020-01-16 14:57:36 -0500
My ruby version is 2.6.2 and I am running on Rails 6.0.1
Please help
the code is as follows:
require "ibm_watson/authenticators"
require "ibm_watson/natural_language_understanding_v1"
include IBMWatson
def parse_messages()
authenticator = IBMWatson::Authenticators::IamAuthenticator.new(
apikey: ENV['API_KEY'],
)
natural_language_understanding = NaturalLanguageUnderstandingV1.new(
version: "2019-07-12",
authenticator: authenticator
)
natural_language_understanding.service_url = ENV['API_URL']
response = natural_language_understanding.analyze(
url: "www.ibm.com",
features: {categories: {limit:3}}
)
puts JSON.pretty_generate(response.result)
end
Example shows:
File.open("./fruitbowl.jpg") do |images_file|
classes = visual_recognition.classify(
images_file: images_file,
threshold: "0.6",
classifier_ids: "dogsx2018x03x17_1725181949,Connectors_424118776"
)
should be classifier_ids: ["dogsx2018x03x17_1725181949", "Connectors_424118776"]
Describe the bug
Can not call Tone Analyzer API
To Reproduce
Steps to reproduce the behavior:
authenticator = IBMWatson::Authenticators::IamAuthenticator.new(apikey: "API KEY")
service = IBMWatson::ToneAnalyzerV3.new(version: "2017-09-21", authenticator: authenticator)
service.service_url = "https://api.us-south.tone-analyzer.watson.cloud.ibm.com/instances/<some_id>/v3/tone_chat?version=2017-09-21"
text = "Team, I know that times are tough! Product sales have been disappointing for the past three quarters. We have a competitive product, but we need to do a better job of selling it!"
tone = service.tone( tone_input: {text: text}, content_type: "application/json")
Expected behavior
Can call API successfully
Actual behavior
A clear and concise description of what you expected to happen.
IBMCloudSdkCore::ApiException (Error: Invalid JSON input at line 1, column 10, Code: 400, Information: {"sub_code"=>"C00012"}, X-dp-watson-tran-id: 9d10aa5e-888a-4a0f-b2f9-688a2d51abf6, X-global-transaction-id: 9d10aa5e-888a-4a0f-b2f9-688a2d51abf6)
Desktop (please complete the following information):
** Additional Context**
Two or more connection with speech to text websocket (Real-Time) recognition using ruby-sdk is disable. (Single connection is enable.)
I researched the reason of this issue, and discover two things.
1. From second connection, "action:start" parameter is not sent for starting real-time recognition.
#before
EM&.reactor_thread&.join
#after
#EM&.reactor_thread&.join
Why does two or more connection disable? In addition, please fix it to enable real-time recognition of two or more connection.
We discover to have occured TypeError in STT real-time recognition, and disconnect websocket connection. Error logs as below.
TypeError - [82, 73, 70, 70, 32, 64, 1, 0, 87, 65, 86, 69, 102, 109, 116, 32, 16, 0, 0, 0, 1, 0, 1, 0, 68, 172, 0, 0, 136, 88, 1, 0, 2, 0, 16, 0, 100, 97, 116, 97, 0, 64, 1, 0, 0, 0, 0, ... 0, 0, 0] is not a symbol nor a string]:
/home/centos/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/ibm_watson-0.10.0/lib/ibm_watson/websocket/speech_to_text_websocket_listener.rb:156:in `send_chunk' | /home/centos/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/ibm_watson-0.10.0/lib/ibm_watson/websocket/speech_to_text_websocket_listener.rb:119:in `send_audio' | /home/centos/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/ibm_watson-0.10.0/lib/ibm_watson/websocket/speech_to_text_websocket_listener.rb:136:in `block in send_audio' | /home/centos/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/eventmachine-1.2.7/lib/eventmachine.rb:195:in `run_machine' | /home/centos/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/eventmachine-1.2.7/lib/eventmachine.rb:195:in `run'
Please research its issue.
Describe the bug
"language_customization_id" does not work.
Additional context
I found a typo at speech_to_text_v1.rb line 557.
"langauge_customization_id" => language_customization_id,
https://github.com/watson-developer-cloud/ruby-sdk/blob/master/lib/ibm_watson/speech_to_text_v1.rb
Dependency | License | url |
---|---|---|
concurrent-ruby ~> 1.0 | MIT | https://github.com/ruby-concurrency/concurrent-ruby |
eventmachine ~> 1.2 | GPL-2 | https://github.com/eventmachine/eventmachine/blob/master/LICENSE |
faye-websocket ~> 0.10 | No License |
faye/faye-websocket-node#68 |
http ~> 3.3 | MIT | |
bundler ~> 1.16 | MIT | |
codecov ~> 0.1 | Apache-2.0 | |
dotenv ~> 2.4 | MIT | |
httplog ~> 1.0 | MIT | |
minitest ~> 5.11 | MIT | |
minitest-hooks ~> 1.5 | MIT | |
minitest-reporters ~> 1.3 | MIT | |
minitest-retry ~> 0.1 | MIT | |
rake ~> 12.3 | MIT | |
rubocop ~> 0.57 | MIT | |
simplecov ~> 0.16 | MIT | |
webmock ~> 3.4 | MIT |
When using real-time recognition using websocket, my application sends below request parameters including "speaker_labels: true," to Watson STT.
However, my application cannot receive "speaker" (speaker ID) from Watson STT.
ws = speech_to_text.recognize_using_websocket(
recognize_callback: mycallback,
content_type: "audio/l16;rate=44100",
chunk_data: true,
model: 'ja-JP BroadbandModel',
language_customization_id: nil,
acoustic_customization_id: nil,
interim_results: true,
timestamps: true,
inactivity_timeout: -1,
speaker_labels: true,
profanity_filter: true
)
Please research and fix its issue.
Hi everyone,
I was experiencing some unusual behaviour on a project where, by simply adding the ibm-watson
gem to the Gemfile
I would get several requests to fail with a 400 Bad request
error message.
Digging through the code I found out that IAMTokenManager is declaring constants outside the class scope, so they are being leaked to the rest of the application.
This was causing issues for me because Faraday uses the value of CONTENT_TYPE
as the header key, so my requests were sending a ill-formed Application/x-Www-Form-Urlencoded: application/x-www-form-urlencoded
header.
The fix should be simple enough, since I don't think these values are referenced outside this class.
Ruby-sdk cannot delete custom word of Full-size (double byte) alphanumeric.
I research this issue, and discover to change Full-size alphanumeric to Half-size alphanumeric for normalization.
Base Model: ja-JP_BroadbandModel
Target word example: ABC
Please research and fix its issue.
Hi,
I have an error on parsing an API response error.
`<TITLE>Access Denied</TITLE>
You don't have permission to access "http://api.eu-gb.assistant.watson.cloud.ibm.com/v2/assistants/fa41d158-9382-4da6-9db8-7c47fb92e141/sessions/e9283ba2-2cc3-450d-9688-0450c8d5856c/message?" on this server.
Reference #18.be3e2217.1674809815.1927c3e
json-2.3.1/lib/json/common.rb:263:in parse' ibm_cloud_sdk_core/api_exception.rb:15:in
initialize'
ibm_cloud_sdk_core/base_service.rb:113:in new' ibm_cloud_sdk_core/base_service.rb:113:in
request'
Service Status
OK
Describe the bug
When trying to access to Watson API, we have an error unmanaged by the gem
To Reproduce
Use Ngrok, lauch a console and call the message function
Expected behavior
We expect to parse correctly the message
Actual behavior
JSON::ParserError: 784: unexpected token at '
Screenshots
Desktop (please complete the following information):
Additional context
Describe the bug
Speech to text is not working with websockets. Works fine with synchronous recognize.
To Reproduce
Here is the code:
#!/usr/bin/env ruby
require "ibm_watson/speech_to_text_v1"
require "ibm_watson/websocket/recognize_callback"
require "ibm_watson/authenticators"
require "json"
authenticator = IBMWatson::Authenticators::IamAuthenticator.new(
apikey: ENV['API_KEY']
)
speech_to_text = IBMWatson::SpeechToTextV1.new(
authenticator: authenticator
)
speech_to_text.service_url = ENV['API_URL']
File.open(Dir.getwd + "/resources/speech.wav") do |audio_file|
recognition = speech_to_text.recognize(
audio: audio_file,
content_type: "audio/wav",
timestamps: true,
word_confidence: true
).result
puts JSON.pretty_generate(recognition)
end
# Example using websockets
class MyRecognizeCallback < IBMWatson::RecognizeCallback
def initialize
super
end
def on_transcription(transcript:)
puts JSON.pretty_generate(transcript)
end
def on_connected
puts "Connection was successful"
end
def on_error(error:)
puts "Error received: #{error}"
puts "Error message: #{error.message}"
end
def on_inactivity_timeout(error:)
puts "Inactivity timeout: #{error}"
end
def on_listening
puts "Service is listening"
end
def on_transcription_complete
puts "Transcription completed"
end
def on_hypothesis(hypothesis:)
puts hypothesis.to_s
end
def on_data(data:)
puts data.to_s
end
end
mycallback = MyRecognizeCallback.new
File.open(Dir.getwd + "/resources/speech.wav") do |audio_file|
speech_to_text.recognize_using_websocket(
audio: audio_file,
recognize_callback: mycallback,
content_type: "audio/wav"
).start
end
Expected behavior
I am expecting to see a successful connected message from the recognize callback.
Actual behavior
Error received: #<Faye::WebSocket::API::ErrorEvent:0x00000000029eaa28>
Error message: Error during WebSocket handshake: Unexpected response code: 401
Desktop (please complete the following information):
Additional context
By adding the authentication step before sending websocket request I was able to make it work:
diff --git a/lib/ibm_watson/speech_to_text_v1.rb b/lib/ibm_watson/speech_to_text_v1.rb
index 7451924..ba3c20a 100644
--- a/lib/ibm_watson/speech_to_text_v1.rb
+++ b/lib/ibm_watson/speech_to_text_v1.rb
@@ -567,6 +567,7 @@ module IBMWatson
require_relative("./websocket/speech_to_text_websocket_listener.rb")
headers = {}
+ @authenticator.authenticate(headers)
headers = conn.default_options.headers.to_hash unless conn.default_options.headers.to_hash.empty?
service_url = @service_url.gsub("https:", "wss:")
params = {
Thanks!
IBM Watson Ruby SDK is still in beta, We planning to release v1 in September and goal of this issue is to establish timeline add goals for the v1 release.
Would welcome some community feedback on some of these goals - do people want these things? Are there other implementations/packages we should be looking at? Any comments are appreciated!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.