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 +4 -4
- data/CHANGELOG.md +4 -10
- data/VERSION +1 -1
- data/lib/prompt_builder/errors.rb +3 -0
- data/lib/prompt_builder/serializers/base.rb +16 -0
- data/lib/prompt_builder/serializers/chat_completion/response.rb +2 -0
- data/lib/prompt_builder/serializers/converse/response.rb +3 -0
- data/lib/prompt_builder/serializers/gemini/response.rb +3 -0
- data/lib/prompt_builder/serializers/messages/request.rb +1 -2
- data/lib/prompt_builder/serializers/messages/response.rb +3 -0
- data/lib/prompt_builder/serializers/open_responses/response.rb +3 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2572a48b69686a8b061f84fd174dfc164adbfe0c613894bfcbb26fd0039d5108
|
|
4
|
+
data.tar.gz: c5382987c1d85d31b6cef3f6bb90cc1e4491d1e27d1dd2587d08f2d099360c4f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
-
##
|
|
7
|
+
## 0.1.1
|
|
8
8
|
|
|
9
9
|
### Changed
|
|
10
10
|
|
|
11
|
-
-
|
|
12
|
-
|
|
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
|
|
14
|
+
## 0.1.0
|
|
21
15
|
|
|
22
16
|
### Added
|
|
23
17
|
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.1.
|
|
1
|
+
0.1.1
|
|
@@ -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
|
|
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)
|