clag 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 29a6ab190bdd6accfd67782655a99b3f255c0d5b217a18fa41ddd2bf1f837dea
4
- data.tar.gz: 6ad8f31dcebbcc91a8e17d1cb4a90de81ce93f91799de6a7e7e3abd721f15017
3
+ metadata.gz: 590439d5a481273f60f73e23d193490499a0bc6f9c400fa6239f00e790f31191
4
+ data.tar.gz: 2b35f0ef8b99e0185761275a405aa44363380df88a0f53449a3e3e1208159659
5
5
  SHA512:
6
- metadata.gz: b7751ed524c187b0925610419caaedce08605caaea43df5066def060dfd8fcb7ee112afa0c8185ef684103d9924f6b06d24475fe81d2ee552ebe9b698fad9336
7
- data.tar.gz: d6ba64383b5500c849179203b4aac5f4d88ecd048319b0a9ce2a87946cb8a8c7e558316b5763d660a329eb1a201fd6052278429fbb5a657f7cce0782df5295a2
6
+ metadata.gz: 87982f697b62eb353350fea66026841e8b0815bff79fea7407b7d3159ecc85aaefad4fab52a0c0f40dbd5389f5b83fa47b86dd6951de7fbd8ba33de58beae4a4
7
+ data.tar.gz: 637a5801e9e52443e7bd694fedbef83f1baa9fd624ad263c9abe00f2874760a4ec3bccb5205bf14e33e1d50df323dc921cc8a52df3541f22849fc7640ece90cf
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Sublayer
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -8,16 +8,28 @@ command with the help of an LLM!
8
8
 
9
9
  ## Installation
10
10
 
11
- * Get an API key from OpenAI for gpt4-turbo: https://platform.openai.com/
12
-
13
- * Set your API key as OPENAI\_API\_KEY in your environment
14
-
15
11
  * Install the gem
16
12
  `gem install clag`
17
13
 
18
14
  * Generate commands
19
15
  `clag g "create a new ruby on rails project using postgres and tailwindcss"`
20
16
 
17
+ ### Using OpenAI's GPT-4
18
+
19
+ * Get an API key from OpenAI for gpt4-turbo: https://platform.openai.com/
20
+
21
+ * Set your API key as OPENAI\_API\_KEY in your environment
22
+
23
+
24
+ ### Using Google's Gemini 1.0
25
+
26
+ * Get an API key from Google's AI Studio at https://ai.google.dev/
27
+
28
+ * Set your API key as GEMINI\_API\_KEY in your environment
29
+
30
+ * Select Gemini as your preferred LLM by setting CLAG\_LLM=gemini in your
31
+ environment
32
+
21
33
  ## Usage
22
34
 
23
35
  Currently support one command: "g".
@@ -28,3 +40,9 @@ Currently support one command: "g".
28
40
 
29
41
  Bug reports and pull requests are welcome on Github at
30
42
  https://github.com/sublayerapp/clag
43
+
44
+ ## Community
45
+
46
+ Like what you see, or looking for more people working on the future of
47
+ programming with LLMs? Come join us in the [Promptable Architecture
48
+ Discord](https://discord.gg/sjTJszPwXt)
data/clag.gemspec CHANGED
@@ -20,6 +20,7 @@ Gem::Specification.new do |spec|
20
20
  spec.add_dependency 'cli-kit', '~> 5'
21
21
  spec.add_dependency 'cli-ui', '~> 2.2.3'
22
22
  spec.add_dependency 'ruby-openai', '~> 6'
23
+ spec.add_dependency 'httparty', '~> 0.21'
23
24
  spec.add_dependency 'clipboard', '~> 1.3'
24
25
  spec.add_dependency 'activesupport'
25
26
 
data/lib/clag/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Clag
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
@@ -1,4 +1,5 @@
1
1
  require "openai"
2
+ require "httparty"
2
3
 
3
4
  module Sublayer
4
5
  module Capabilities
@@ -15,6 +16,53 @@ module Sublayer
15
16
  end
16
17
 
17
18
  def llm_generate
19
+ if ENV["CLAG_LLM"] == "gemini"
20
+ generate_with_gemini
21
+ else
22
+ generate_with_openai
23
+ end
24
+ end
25
+
26
+ private
27
+ def generate_with_gemini
28
+ gemini_prompt = adapt_prompt_for_gemini
29
+
30
+ response = HTTParty.post("https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent?key=#{ENV['GEMINI_API_KEY']}", body: gemini_prompt.to_json, headers: { 'Content-Type' => 'application/json' })
31
+
32
+ function_output = extract_function_output_from_gemini_response(response)
33
+
34
+ return function_output
35
+ end
36
+
37
+ def adapt_prompt_for_gemini
38
+ return({ tools: { function_declarations: [ self.class::OUTPUT_FUNCTION.to_hash ] }, contents: { role: "user", parts: { text: prompt } } })
39
+ end
40
+
41
+ def extract_function_output_from_gemini_response(response)
42
+ candidates = response.dig('candidates')
43
+ if candidates && candidates.size > 0
44
+ content = candidates[0].dig('content')
45
+ if content && content['parts'] && content['parts'].size > 0
46
+ part = content['parts'][0]
47
+
48
+ # Check if the part contains a function call
49
+ if part.key?('functionCall')
50
+ function_name = part['functionCall']['name']
51
+ args = part['functionCall']['args']
52
+
53
+ # Assuming the agent expects a single string parameter:
54
+ if args && args.key?(self.class::OUTPUT_FUNCTION.name)
55
+ return args[self.class::OUTPUT_FUNCTION.name]
56
+ end
57
+ else
58
+ # If it's not a function call, check for a direct string response
59
+ return part['text'] if part.key?('text')
60
+ end
61
+ end
62
+ end
63
+ end
64
+
65
+ def generate_with_openai
18
66
  client = OpenAI::Client.new(access_token: ENV["OPENAI_API_KEY"])
19
67
 
20
68
  response = client.chat(
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clag
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Werner
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-01-26 00:00:00.000000000 Z
11
+ date: 2024-02-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cli-kit
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: httparty
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.21'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.21'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: clipboard
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -105,6 +119,7 @@ extra_rdoc_files: []
105
119
  files:
106
120
  - ".gitignore"
107
121
  - Gemfile
122
+ - LICENSE
108
123
  - README.md
109
124
  - bin/testunit
110
125
  - clag.gemspec