prompt_builder 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3b3f2f981ac5ffaacac8d0f46d3cde5b2429042f34846b36b6a0154fee9858f4
4
- data.tar.gz: 7aceebc0337cd9f6f201ccbf822caca50d53ff23e3d2ed165bd7d114c9d9120f
3
+ metadata.gz: 2572a48b69686a8b061f84fd174dfc164adbfe0c613894bfcbb26fd0039d5108
4
+ data.tar.gz: c5382987c1d85d31b6cef3f6bb90cc1e4491d1e27d1dd2587d08f2d099360c4f
5
5
  SHA512:
6
- metadata.gz: 0fdf71137c15a30e7e2cc5740bfa5fc4b7b9a2d31b9959821f84e879b718150dbfd054e15b19e13f53caead242d70ddaaf06e315e79044f77dce1500c6e374cf
7
- data.tar.gz: 935a2ac05da1aa179f6107d46e0d37b80b79762111f95f16cda73924e9d9a48733cff1761413b4a8dedb56b8f880b517ed2cd9e196f5ea648e5ae13d909c9e10
6
+ metadata.gz: 75ac02437e15581cf45c13c592605b6434c0634141bda6d86324e87bb65c59502e1de00f7459c49fb6b3f432a8a2ec2c5487eab4f73de1609c26625bdb37c510
7
+ data.tar.gz: 3c39ea80cbdb488a63926357601ce47b97cd5940c8ee95742b31b4df30e4b4519cf98dec931e11929ddb80569a0a469736a37aa6337af44dc53092f433051714
data/CHANGELOG.md CHANGED
@@ -4,20 +4,14 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
5
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
- ## Unreleased
7
+ ## 0.1.1
8
8
 
9
9
  ### Changed
10
10
 
11
- - Serializers now silently omit unsupported features from the serialized output
12
- instead of raising `UnsupportedFormatError`. Unsupported session fields, content
13
- types, enum values, sub-keys, `tool_choice` variants, and `Compaction`/`ItemReference`
14
- items are dropped from request payloads; unrecognized blocks, candidates, and choices
15
- are skipped when parsing responses. `UnsupportedFormatError` is still raised for
16
- missing required data (e.g. no `model`, no messages, a `json_schema` format without a
17
- schema), structural problems, genuine conflicts, unparseable function-call arguments,
18
- and streaming response chunks.
11
+ - Responses will now raise an `UnsupportedFormatError` if the response shape is missing key elements.
12
+ - Removed the default `max_tokens` value of 4096 from the request serializer. If `max_output_tokens` is not set on the session, the request will simply omit the `max_tokens` parameter, allowing the API to apply its own defaults.
19
13
 
20
- ## 1.0.0
14
+ ## 0.1.0
21
15
 
22
16
  ### Added
23
17
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -15,4 +15,7 @@ module PromptBuilder
15
15
 
16
16
  # Raised when an operation is invalid for the current session state.
17
17
  class InvalidStateError < Error; end
18
+
19
+ # Raised when a response payload does not match the expected shape.
20
+ class UnexpectedPayloadError < Error; end
18
21
  end
@@ -31,6 +31,22 @@ module PromptBuilder
31
31
  def deserialize_response(_hash)
32
32
  raise NotImplementedError
33
33
  end
34
+
35
+ # Ensure a response payload is a Hash containing the key that identifies
36
+ # it as a well-formed response for this format. Raised before parsing so
37
+ # malformed bodies (e.g. provider error envelopes) fail loudly with the
38
+ # offending body rather than producing a silently empty Response.
39
+ #
40
+ # @param hash [Object] the raw response payload
41
+ # @param key [String] a key that must be present in a valid payload
42
+ # @raise [UnexpectedPayloadError] if the key is missing
43
+ def require_response_key!(hash, key)
44
+ return if hash.is_a?(Hash) && hash.key?(key)
45
+
46
+ body = JSON.generate(hash)[0..200]
47
+ raise UnexpectedPayloadError,
48
+ "unexpected response payload, missing #{key.inspect}: #{body}"
49
+ end
34
50
  end
35
51
  end
36
52
  end
@@ -109,6 +109,8 @@ module PromptBuilder
109
109
  if hash["object"] == "chat.completion.chunk"
110
110
  raise UnsupportedFormatError, "Chat Completions streaming chunks are not supported"
111
111
  end
112
+ require_response_key!(hash, "choices")
113
+ require_response_key!(hash, "model")
112
114
  # Responses with multiple choices have no canonical multi-candidate
113
115
  # representation; only the first choice is parsed (handled by the
114
116
  # caller using choices[0]).
@@ -11,6 +11,9 @@ module PromptBuilder
11
11
  private
12
12
 
13
13
  def deserialize_response(hash)
14
+ require_response_key!(hash, "output")
15
+ require_response_key!(hash, "stopReason")
16
+
14
17
  usage_hash = hash["usage"]
15
18
  usage = if usage_hash
16
19
  cache_read = usage_hash["cacheReadInputTokens"]
@@ -64,6 +64,9 @@ module PromptBuilder
64
64
  private
65
65
 
66
66
  def deserialize_response(hash)
67
+ require_response_key!(hash, "candidates")
68
+ require_response_key!(hash, "modelVersion")
69
+
67
70
  usage = build_usage(hash["usageMetadata"])
68
71
 
69
72
  # Only the first candidate is parsed; additional candidates have no
@@ -71,7 +71,6 @@ module PromptBuilder
71
71
  # - +anthropic-beta+ headers and API versioning (this gem produces no HTTP
72
72
  # request — set headers in your HTTP client)
73
73
  class Request < Base
74
- DEFAULT_MAX_TOKENS = 4096
75
74
  SUPPORTED_METADATA_KEYS = ["user_id"].freeze
76
75
  EFFORT_LEVELS = ["low", "medium", "high", "xhigh", "max"].freeze
77
76
  SUPPORTED_THINKING_TYPES = ["adaptive", "disabled", "enabled"].freeze
@@ -85,7 +84,7 @@ module PromptBuilder
85
84
  raise UnsupportedFormatError, "Messages format requires session.model" unless session.model
86
85
 
87
86
  h["model"] = session.model
88
- h["max_tokens"] = session.max_output_tokens || DEFAULT_MAX_TOKENS
87
+ h["max_tokens"] = session.max_output_tokens if session.max_output_tokens
89
88
  h["temperature"] = session.temperature if session.temperature
90
89
  h["top_p"] = session.top_p if session.top_p
91
90
  effective_metadata = build_effective_metadata(session)
@@ -11,6 +11,9 @@ module PromptBuilder
11
11
  private
12
12
 
13
13
  def deserialize_response(hash)
14
+ require_response_key!(hash, "content")
15
+ require_response_key!(hash, "stop_reason")
16
+
14
17
  usage_hash = hash["usage"]
15
18
  usage = build_usage(usage_hash) if usage_hash
16
19
 
@@ -9,6 +9,9 @@ module PromptBuilder
9
9
  private
10
10
 
11
11
  def deserialize_response(hash)
12
+ require_response_key!(hash, "status")
13
+ require_response_key!(hash, "object")
14
+
12
15
  PromptBuilder::Response.from_h(hash)
13
16
  end
14
17
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prompt_builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Durand