Class: PhaseoAgentSdk::GatewayAgentClient
- Inherits:
-
Object
- Object
- PhaseoAgentSdk::GatewayAgentClient
- Defined in:
- lib/phaseo_agent_sdk.rb
Instance Method Summary collapse
- #generate(request) ⇒ Object
-
#initialize(client: nil, api_key: nil, base_url: nil, model: nil, preset: nil, provider: nil, reasoning: nil, temperature: nil, max_output_tokens: nil, parallel_tool_calls: nil, metadata: nil, user: nil, response_format: nil, include_meta: nil, web_search_options: nil, plugins: nil, gateway_tools: nil, tool_choice: nil, provider_options: nil, prompt_cache_key: nil, request_options: nil) ⇒ GatewayAgentClient
constructor
A new instance of GatewayAgentClient.
- #stream(request) ⇒ Object
Constructor Details
#initialize(client: nil, api_key: nil, base_url: nil, model: nil, preset: nil, provider: nil, reasoning: nil, temperature: nil, max_output_tokens: nil, parallel_tool_calls: nil, metadata: nil, user: nil, response_format: nil, include_meta: nil, web_search_options: nil, plugins: nil, gateway_tools: nil, tool_choice: nil, provider_options: nil, prompt_cache_key: nil, request_options: nil) ⇒ GatewayAgentClient
Returns a new instance of GatewayAgentClient.
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/phaseo_agent_sdk.rb', line 75 def initialize(client: nil, api_key: nil, base_url: nil, model: nil, preset: nil, provider: nil, reasoning: nil, temperature: nil, max_output_tokens: nil, parallel_tool_calls: nil, metadata: nil, user: nil, response_format: nil, include_meta: nil, web_search_options: nil, plugins: nil, gateway_tools: nil, tool_choice: nil, provider_options: nil, prompt_cache_key: nil, request_options: nil) api_key ||= ENV["PHASEO_API_KEY"] @client = client || PhaseoSdk::Phaseo.new( api_key: api_key, base_path: base_url || ENV.fetch("PHASEO_BASE_URL", "https://api.phaseo.app/v1") ) @model = model @preset = preset @provider = provider @reasoning = reasoning @temperature = temperature @max_output_tokens = max_output_tokens @parallel_tool_calls = parallel_tool_calls @metadata = @user = user @response_format = response_format @include_meta = @web_search_options = @plugins = plugins @gateway_tools = gateway_tools || [] @tool_choice = tool_choice @provider_options = @prompt_cache_key = prompt_cache_key @request_options = || {} end |
Instance Method Details
#generate(request) ⇒ Object
104 105 106 107 |
# File 'lib/phaseo_agent_sdk.rb', line 104 def generate(request) response = @client.create_response(payload(request)) model_response(response) end |
#stream(request) ⇒ Object
109 110 111 112 113 114 115 116 |
# File 'lib/phaseo_agent_sdk.rb', line 109 def stream(request) return enum_for(__method__,request) unless block_given? @client.stream_response(payload(request).merge(stream:true)).each do |line| next unless line.start_with?("data:");data=line.delete_prefix("data:").strip;next if data.empty?||data=="[DONE]";begin;raw=JSON.parse(data);rescue JSON::ParserError;next;end;type=raw["type"].to_s;delta=raw["delta"].is_a?(String)?raw["delta"]:(raw["text"].is_a?(String)?raw["text"]:nil) if type=="response.completed";yield(type:"response.completed",response:model_response(raw["response"].is_a?(Hash)?raw["response"]:raw),raw:raw);return;end yield(type:"response.item",item:raw["item"],raw:raw) if raw.key?("item");yield(type:type.include?("reasoning")?"response.reasoning.delta":"response.output_text.delta",delta:delta,raw:raw) if delta end end |