dorian-chat 0.0.1 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/bin/chat +24 -12
  3. metadata +5 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6e93227b593517fb81d60f539d02759c628300eeb04923c12bd4bf1be57031b7
4
- data.tar.gz: a557457332e7778428aa14d24b779f8e054abd5ed44474564b3e138f2c2e3407
3
+ metadata.gz: 942196d991d2bf60c3c7d6f31cff83d8b4268704bddb83065d635781156ce2c1
4
+ data.tar.gz: 9c3cc8703df9de25c5f405989a0e48b0918729faedb766b75a7a93f058c9cfaa
5
5
  SHA512:
6
- metadata.gz: 8e46b8a4c8bd6a3b3009b3dbfb4e5decc331c9d1d713551127e0c2af9f0f690768e24b2b7cc53a26ed338f81985547ce3715a1aa4cc84d36930535e9c847a054
7
- data.tar.gz: 33f1d04ca566f9626d7b60a7725f74d695f87d9c5104b0dd68431607dcd6fa109c5bcba61905fed8f1cf0b00a27cfb0af0743b8d978e4062b09fc73b2a8e322c
6
+ metadata.gz: 3c3d6e7881a94e60c9e01a5f6a32f89b2be579373799ddcf8c2cc09d3fce5e06c86bc540d24445a0b9bb48e80d168b05bac83e7e018c10fad2ea809d70318310
7
+ data.tar.gz: 5efa5a06de910c7d5513569ff46fdd6b8a0e0ddb353c2b50820f7a28af7cfdb43206b653f24d7f6587a3f569cd60e3fd7231ff3505432280d61734f0b1f6da04
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,12 +45,17 @@ request =
38
45
 
39
46
  request.body = {
40
47
  model: "gpt-4o",
41
- messages: [
42
- { role: "user", content: INPUT }
43
- ]
48
+ messages: [{ role: "user", content: }]
44
49
  }.to_json
45
50
 
46
51
  response = http.request(request)
52
+
47
53
  json = JSON.parse(response.body)
48
- output = json.dig("choices", 0, "message", "content").strip
49
- 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,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dorian-chat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
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-16 00:00:00.000000000 Z
11
+ date: 2024-08-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: git
14
+ name: dorian-arguments
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
@@ -24,10 +24,7 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
- description: |-
28
- chat with openai api
29
-
30
- e.g. `chat`
27
+ description: chat with ai
31
28
  email: dorian@dorianmarie.com
32
29
  executables:
33
30
  - chat
@@ -58,5 +55,5 @@ requirements: []
58
55
  rubygems_version: 3.5.11
59
56
  signing_key:
60
57
  specification_version: 4
61
- summary: chat with openai api
58
+ summary: chat with ai
62
59
  test_files: []