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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/promptspec.rb +25 -23
  3. data/promptspec.gemspec +1 -1
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b8344f339aa0ef8a57c14422dc2f50046a203076ec9c2daee525c4432f57f6bf
4
- data.tar.gz: 96014c0bc00da57d4b0289df8c39fa4a3c8505dc6a0b6814a717a31f735ad591
3
+ metadata.gz: ff9862c476f10363aff3327d9f365b0dce6a3d09967569d6336bdd78b7897571
4
+ data.tar.gz: 33b50174079b344a29d8d230ba844bc363fd43cb8fb2d63f9fdf70c11ad48821
5
5
  SHA512:
6
- metadata.gz: 1516fbdb9607f0724faa3c10081269b3d99c243145b1f31a19588faec6a5b7602120d536acba56fd1629b7afc1b6bd9f2d25f7cd18e4491687bceb66964c0534
7
- data.tar.gz: 611b943f18480666c2d9da0a157eb186f0a4392ee876897af67d4c026829391a701882abcf19c1e9343eca7e8d35aee2131de888887537fbbf0fd96e075caf37
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
- validate_required_inputs!(parameters) if @validate_required_params
19
- parse_prompt_messages(parameters)
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!(parameters)
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(parameters)
40
- messages = @yaml_content['prompt']['messages'].map do |message|
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
- { role: message['role'], content: content }
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 = @yaml_content['prompt']['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
- headers = @yaml_content['headers'] || {}
80
+ @headers ||= begin
81
+ headers = @yaml_content.fetch('headers', {})
81
82
 
82
- if headers.empty?
83
- case @model
84
- 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'
85
- api_key = ENV['OPENAI_API_KEY']
86
- headers['Authorization'] = "Bearer #{api_key}" if api_key
87
- # Add more cases here for other providers
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
- headers['Content-Type'] = 'application/json' unless headers.key?('Content-Type')
92
- headers
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
@@ -1,7 +1,7 @@
1
1
  # promptspec.gemspec
2
2
  Gem::Specification.new do |spec|
3
3
  spec.name = "promptspec"
4
- spec.version = "0.0.5"
4
+ spec.version = "0.0.6"
5
5
  spec.authors = ["Hyperaide, John Paul, Daniel Paul"]
6
6
  spec.email = ["jp@hyperaide.com"]
7
7
 
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.5
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-03 00:00:00.000000000 Z
11
+ date: 2023-11-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: yaml