dorian-chat 0.0.2 → 1.0.0

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 (3) hide show
  1. checksums.yaml +4 -4
  2. data/bin/chat +24 -10
  3. metadata +17 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4487cb27857e0698a7b1a062da2c3a6c4499457c3559f27811381d67e7a1ba90
4
- data.tar.gz: 122ecf22f01afcb2aaf4b2c3ffc16f55fa98b9509e0b552b540fb8e23010add9
3
+ metadata.gz: f8c4f6f45c3b45a25cacc444464857cc0fa22f81cde15cbf1a9f2c42cf9aefc0
4
+ data.tar.gz: ab51c45310c4a86c6401587bbffbdee0abb6e51ddd44baf634d4360856dae3c4
5
5
  SHA512:
6
- metadata.gz: f71eea8e3e6be55032475ad67b0a44cbb204fedafabb0ef64f95b22206fbd2ebce43ba1b4d1b7c88a6abd2f16235e6c20d502b17c406e91f7e064d09c3c0572f
7
- data.tar.gz: 0512f34769f49f82c01682219ba78e6d6d70a7534584297f1aeb37ffcc96081ad040cafc96ecc609a2404f994f80fe4964bbcd3eb164c8b6ade44d831acc0ad2
6
+ metadata.gz: 9e1abdaa1e0015133a68bb9854616573b5a1987a10dd1f423a9dd7c85d494d05ad292e29310991774fdef93698deeb43b7bff4037adcc4f562f30cf3a1fe801e
7
+ data.tar.gz: 6df5960c0979c6f5997f5615e10d66804f75692cbd94539a5967a20e70ea11c56c5dbf175d824d650ce5b600a97d3ac010397bb99e854b4363a0ba5aea49125a
data/bin/chat CHANGED
@@ -1,14 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
+ require "dorian/arguments"
4
5
  require "json"
5
6
  require "net/http"
6
7
  require "uri"
7
- require "git"
8
-
9
- if ARGV.first == "--help" || ARGV.first == "-h"
10
- abort "USAGE: chat INPUT, ... | chat"
11
- end
12
8
 
13
9
  TOKEN_FILE = File.join(Dir.home, ".chat")
14
10
 
@@ -21,9 +17,20 @@ else
21
17
  puts "token written to #{TOKEN_FILE}"
22
18
  end
23
19
 
24
- INPUT = ARGV.any? ? ARGV.join(" ") : $stdin.each_line.to_a.join
20
+ parsed = Dorian::Arguments.parse(version: { alias: :v }, help: { alias: :h })
21
+
22
+ abort parsed.help if parsed.options.help
23
+
24
+ if parsed.options.version
25
+ abort File.read(File.expand_path("../../VERSION", __FILE__))
26
+ end
27
+
28
+ content = parsed.arguments.join(" ")
29
+ content += parsed.files.map { |file| File.read(file) }.join("\n")
30
+ content = $stdin.each_line.to_a.join if content.strip.empty?
31
+
32
+ uri = URI.parse("https://api.openai.com/v1/chat/completions")
25
33
 
26
- uri = URI("https://api.openai.com/v1/chat/completions")
27
34
  http = Net::HTTP.new(uri.host, uri.port)
28
35
  http.use_ssl = true
29
36
 
@@ -38,10 +45,17 @@ request =
38
45
 
39
46
  request.body = {
40
47
  model: "gpt-4o",
41
- messages: [{ role: "user", content: INPUT }]
48
+ messages: [{ role: "user", content: }]
42
49
  }.to_json
43
50
 
44
51
  response = http.request(request)
52
+
45
53
  json = JSON.parse(response.body)
46
- output = json.dig("choices", 0, "message", "content").strip
47
- puts output
54
+
55
+ output = json.dig("choices", 0, "message", "content")
56
+
57
+ if output
58
+ puts output.strip
59
+ else
60
+ puts JSON.pretty_generate(json)
61
+ end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dorian-chat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dorian Marié
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-08-18 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2024-08-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: dorian-arguments
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  description: chat with ai
14
28
  email: dorian@dorianmarie.com
15
29
  executables: