promptspec 0.0.5 → 0.0.6
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/lib/promptspec.rb +25 -23
- data/promptspec.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ff9862c476f10363aff3327d9f365b0dce6a3d09967569d6336bdd78b7897571
|
4
|
+
data.tar.gz: 33b50174079b344a29d8d230ba844bc363fd43cb8fb2d63f9fdf70c11ad48821
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cebe769d93847ca3e7383283a6cddd37d0235f53de7d6595b4c9ce642f4626b92d5e46dd25dd200d9a75ee6025e9e4172c8b932f3e47cdd38af75457eaee4c7a
|
7
|
+
data.tar.gz: ca1d578071ceeefcaffe5af466d974327fe99faa75289aa3590df3f6065aec45c1b60734ca7ada1db979ab2c18e0c49db15a5c8e96dedb8d4f9c8e42b274dedd
|
data/lib/promptspec.rb
CHANGED
@@ -6,7 +6,7 @@ require 'net/http'
|
|
6
6
|
require 'uri'
|
7
7
|
|
8
8
|
class PromptSpec
|
9
|
-
attr_reader :file_path, :validate_required_params
|
9
|
+
attr_reader :file_path, :validate_required_params, :parameters, :yaml_content
|
10
10
|
|
11
11
|
def initialize(file_path, validate_required_params: true)
|
12
12
|
@file_path = file_path
|
@@ -15,8 +15,9 @@ class PromptSpec
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def call(**parameters)
|
18
|
-
|
19
|
-
|
18
|
+
@parameters = parameters
|
19
|
+
validate_required_inputs! if @validate_required_params
|
20
|
+
parse_prompt_messages
|
20
21
|
construct_endpoint_request
|
21
22
|
end
|
22
23
|
|
@@ -30,21 +31,20 @@ class PromptSpec
|
|
30
31
|
raise ParseError, "YAML parsing error: #{e.message}"
|
31
32
|
end
|
32
33
|
|
33
|
-
def validate_required_inputs!
|
34
|
+
def validate_required_inputs!
|
34
35
|
required_params = @yaml_content.dig('parameters', 'required') || []
|
35
|
-
missing_params = required_params - parameters.keys.map(&:to_s)
|
36
|
+
missing_params = required_params - @parameters.keys.map(&:to_s)
|
36
37
|
raise RequiredParameterError, "Missing required parameters: #{missing_params.join(', ')}" unless missing_params.empty?
|
37
38
|
end
|
38
39
|
|
39
|
-
def parse_prompt_messages
|
40
|
-
|
40
|
+
def parse_prompt_messages
|
41
|
+
@yaml_content['prompt']['messages'].each do |message|
|
41
42
|
content = message['content']
|
42
|
-
parameters.each do |key, value|
|
43
|
-
content.gsub!("{#{key}}", value.to_s)
|
43
|
+
@parameters.each do |key, value|
|
44
|
+
content.gsub!("{#{key}}", value.to_s) if content.include?("{#{key}}")
|
44
45
|
end
|
45
|
-
|
46
|
+
message['content'] = content
|
46
47
|
end
|
47
|
-
@yaml_content['prompt']['messages'] = messages
|
48
48
|
end
|
49
49
|
|
50
50
|
def construct_endpoint_request
|
@@ -67,7 +67,7 @@ class PromptSpec
|
|
67
67
|
end
|
68
68
|
|
69
69
|
def construct_default_endpoint
|
70
|
-
@model
|
70
|
+
@model ||= @yaml_content['prompt']['model']
|
71
71
|
case @model
|
72
72
|
when 'gpt-4', 'gpt-4-0613', 'gpt-4-32k', 'gpt-4-32k-0613', 'gpt-3.5-turbo', 'gpt-3.5-turbo-16k', 'gpt-3.5-turbo-0613', 'gpt-3.5-turbo-16k-0613'
|
73
73
|
'https://api.openai.com/v1/chat/completions'
|
@@ -77,18 +77,20 @@ class PromptSpec
|
|
77
77
|
end
|
78
78
|
|
79
79
|
def construct_headers
|
80
|
-
|
80
|
+
@headers ||= begin
|
81
|
+
headers = @yaml_content.fetch('headers', {})
|
81
82
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
83
|
+
if headers.empty?
|
84
|
+
case @model
|
85
|
+
when 'gpt-4', 'gpt-4-0613', 'gpt-4-32k', 'gpt-4-32k-0613', 'gpt-3.5-turbo', 'gpt-3.5-turbo-16k', 'gpt-3.5-turbo-0613', 'gpt-3.5-turbo-16k-0613'
|
86
|
+
api_key = ENV['OPENAI_API_KEY']
|
87
|
+
headers['Authorization'] = "Bearer #{api_key}" if api_key
|
88
|
+
# Add more cases here for other providers
|
89
|
+
end
|
88
90
|
end
|
89
|
-
end
|
90
91
|
|
91
|
-
|
92
|
-
|
92
|
+
headers['Content-Type'] = 'application/json' unless headers.key?('Content-Type')
|
93
|
+
headers
|
94
|
+
end
|
93
95
|
end
|
94
|
-
end
|
96
|
+
end
|
data/promptspec.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: promptspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hyperaide, John Paul, Daniel Paul
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-11-
|
11
|
+
date: 2023-11-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: yaml
|