dorian-chat 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/chat +49 -0
- metadata +62 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6e93227b593517fb81d60f539d02759c628300eeb04923c12bd4bf1be57031b7
|
4
|
+
data.tar.gz: a557457332e7778428aa14d24b779f8e054abd5ed44474564b3e138f2c2e3407
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8e46b8a4c8bd6a3b3009b3dbfb4e5decc331c9d1d713551127e0c2af9f0f690768e24b2b7cc53a26ed338f81985547ce3715a1aa4cc84d36930535e9c847a054
|
7
|
+
data.tar.gz: 33f1d04ca566f9626d7b60a7725f74d695f87d9c5104b0dd68431607dcd6fa109c5bcba61905fed8f1cf0b00a27cfb0af0743b8d978e4062b09fc73b2a8e322c
|
data/bin/chat
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "json"
|
5
|
+
require "net/http"
|
6
|
+
require "uri"
|
7
|
+
require "git"
|
8
|
+
|
9
|
+
if ARGV.first == "--help" || ARGV.first == "-h"
|
10
|
+
abort "USAGE: chat INPUT, ... | chat"
|
11
|
+
end
|
12
|
+
|
13
|
+
TOKEN_FILE = File.join(Dir.home, ".chat")
|
14
|
+
|
15
|
+
if File.exist?(TOKEN_FILE)
|
16
|
+
TOKEN = File.read(TOKEN_FILE).strip
|
17
|
+
else
|
18
|
+
print "token: "
|
19
|
+
TOKEN = gets.strip
|
20
|
+
File.write(TOKEN_FILE, TOKEN)
|
21
|
+
puts "token written to #{TOKEN_FILE}"
|
22
|
+
end
|
23
|
+
|
24
|
+
INPUT = ARGV.any? ? ARGV.join(" ") : $stdin.each_line.to_a.join
|
25
|
+
|
26
|
+
uri = URI("https://api.openai.com/v1/chat/completions")
|
27
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
28
|
+
http.use_ssl = true
|
29
|
+
|
30
|
+
request =
|
31
|
+
Net::HTTP::Post.new(
|
32
|
+
uri.path,
|
33
|
+
{
|
34
|
+
"Content-Type" => "application/json",
|
35
|
+
"Authorization" => "Bearer #{TOKEN}"
|
36
|
+
}
|
37
|
+
)
|
38
|
+
|
39
|
+
request.body = {
|
40
|
+
model: "gpt-4o",
|
41
|
+
messages: [
|
42
|
+
{ role: "user", content: INPUT }
|
43
|
+
]
|
44
|
+
}.to_json
|
45
|
+
|
46
|
+
response = http.request(request)
|
47
|
+
json = JSON.parse(response.body)
|
48
|
+
output = json.dig("choices", 0, "message", "content").strip
|
49
|
+
puts output
|
metadata
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dorian-chat
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dorian Marié
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-08-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: git
|
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'
|
27
|
+
description: |-
|
28
|
+
chat with openai api
|
29
|
+
|
30
|
+
e.g. `chat`
|
31
|
+
email: dorian@dorianmarie.com
|
32
|
+
executables:
|
33
|
+
- chat
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- bin/chat
|
38
|
+
homepage: https://github.com/dorianmariecom/dorian-chat
|
39
|
+
licenses:
|
40
|
+
- MIT
|
41
|
+
metadata:
|
42
|
+
rubygems_mfa_required: 'true'
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options: []
|
45
|
+
require_paths:
|
46
|
+
- lib
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
requirements: []
|
58
|
+
rubygems_version: 3.5.11
|
59
|
+
signing_key:
|
60
|
+
specification_version: 4
|
61
|
+
summary: chat with openai api
|
62
|
+
test_files: []
|