dorian-chat 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/chat +24 -10
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 942196d991d2bf60c3c7d6f31cff83d8b4268704bddb83065d635781156ce2c1
|
4
|
+
data.tar.gz: 9c3cc8703df9de25c5f405989a0e48b0918729faedb766b75a7a93f058c9cfaa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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:
|
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
|
-
|
47
|
-
|
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.
|
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-
|
12
|
-
dependencies:
|
11
|
+
date: 2024-08-22 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:
|