Module: SmartPrompt::SiliconFlow::Text
- Included in:
- SmartPrompt::SiliconFlowAdapter
- Defined in:
- lib/smart_prompt/adapters/siliconflow/text.rb
Overview
Text chat + multimodal vision (OpenAI-compatible /chat/completions, SSE streaming, reasoning_content passthrough).
Constant Summary collapse
- CHAT_OPTIONAL_KEYS =
%w[ top_p top_k frequency_penalty presence_penalty max_tokens max_completion_tokens stop response_format enable_thinking thinking_budget min_p reasoning_effort seed ].freeze
Instance Method Summary collapse
-
#send_request(messages, model = nil, temperature = nil, tools = nil, proc = nil) ⇒ Object
Chat / multimodal.
Instance Method Details
#send_request(messages, model = nil, temperature = nil, tools = nil, proc = nil) ⇒ Object
Chat / multimodal. Non-streaming returns a full OpenAI-format hash (so last_response carries usage + reasoning_content); streaming calls proc with each OpenAI-shaped chunk and returns nil.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/smart_prompt/adapters/siliconflow/text.rb', line 15 def send_request(, model = nil, temperature = nil, tools = nil, proc = nil) model_name = model || @config["model"] body = build_chat_body(, model_name, temperature, tools) SmartPrompt.logger.info "SiliconFlowAdapter: chat request model=#{model_name} stream=#{!proc.nil?}" url = "#{@base_url}/chat/completions" if proc body["stream"] = true stream_chat(url, body) { |data| proc.call(build_stream_chunk(data), 0) } SmartPrompt.logger.info "SiliconFlowAdapter: streaming request finished" nil else raw = http_post_json(url, body) response = build_completion_response(raw) @last_response = response SmartPrompt.logger.info "SiliconFlowAdapter: received chat response" response end rescue LLMAPIError, Error raise rescue => e SmartPrompt.logger.error "SiliconFlow chat error: #{e.}" raise LLMAPIError, "Failed to call SiliconFlow chat: #{e.}" end |