Class: Xfyun::Spark::Client
- Inherits:
-
Object
- Object
- Xfyun::Spark::Client
- Includes:
- Request
- Defined in:
- lib/xfyun/spark/client.rb
Constant Summary collapse
- CONFIG_KEYS =
%i[appid api_key api_secret model host request_timeout logger].freeze
Instance Method Summary collapse
- #chat(header: {}, parameter: {}, payload: {}, stream: nil) ⇒ Object
- #default_header ⇒ Object
- #default_parameter ⇒ Object
-
#initialize(config = {}) ⇒ Client
constructor
A new instance of Client.
- #logging(level, msg) ⇒ Object
Methods included from Request
Constructor Details
#initialize(config = {}) ⇒ Client
Returns a new instance of Client.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/xfyun/spark/client.rb', line 9 def initialize(config = {}) CONFIG_KEYS.each do |key| instance_variable_set("@#{key}", config[key] || Xfyun::Spark.configuration.send(key)) end @request_version = { "V1.5" => "v1.1", "V2" => "v2.1", }.fetch(@model) @request_domain = { "V1.5" => "general", "V2" => "generalv2", }.fetch(@model) end |
Instance Method Details
#chat(header: {}, parameter: {}, payload: {}, stream: nil) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/xfyun/spark/client.rb', line 25 def chat(header: {}, parameter: {}, payload: {}, stream: nil) header = default_header.merge(header) parameter = default_parameter.map do |k, v| [k, v.merge(parameter[k] || {})] end.to_h request(path: "/chat", parameters: { header: header, parameter: parameter, payload: payload, }, stream: stream) end |
#default_header ⇒ Object
37 38 39 |
# File 'lib/xfyun/spark/client.rb', line 37 def default_header {app_id: @appid} end |
#default_parameter ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/xfyun/spark/client.rb', line 41 def default_parameter { chat: { domain: @request_domain, } } end |
#logging(level, msg) ⇒ Object
49 50 51 |
# File 'lib/xfyun/spark/client.rb', line 49 def logging(level, msg) @logger.send(level, msg) if @logger != nil end |