Module: SmartPrompt::ZhipuAI::Text
- Included in:
- SmartPrompt::ZhipuAIAdapter
- Defined in:
- lib/smart_prompt/adapters/zhipu/text.rb
Overview
Text chat + vision (OpenAI-compatible /chat/completions, SSE streaming, reasoning_content passthrough). CodeGeeX/coding models use a separate base.
Constant Summary collapse
- CHAT_OPTIONAL_KEYS =
%w[ top_p max_tokens do_sample stop presence_penalty frequency_penalty thinking ].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.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/smart_prompt/adapters/zhipu/text.rb', line 13 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 "ZhipuAIAdapter: chat request model=#{model_name} stream=#{!proc.nil?}" url = chat_url_for(model_name) if proc body["stream"] = true stream_chat(url, body) { |data| proc.call(build_stream_chunk(data), 0) } SmartPrompt.logger.info "ZhipuAIAdapter: streaming request finished" nil else raw = http_post_json(url, body) response = build_completion_response(raw) @last_response = response SmartPrompt.logger.info "ZhipuAIAdapter: received chat response" response end rescue LLMAPIError, Error raise rescue => e SmartPrompt.logger.error "Zhipu chat error: #{e.}" raise LLMAPIError, "Failed to call Zhipu chat: #{e.}" end |