start on the coding assistant

This commit is contained in:
Kyle Drake 2024-03-24 17:13:22 -05:00
parent 8f6a85d81d
commit 8ba6005c67
546 changed files with 54575 additions and 12 deletions

View file

@ -226,4 +226,34 @@ end
get '/site_files/mount_info' do
@title = 'Site Mount Information'
erb :'site_files/mount_info'
end
post '/site_files/chat' do
require_login
dont_browser_cache
# Ensure the request is treated as a stream
stream do |out|
url = 'https://api.anthropic.com/v1/messages'
headers = {
"anthropic-version" => "2023-06-01",
"anthropic-beta" => "messages-2023-12-15",
"content-type" => "application/json",
"x-api-key" => $config['anthropic_api_key']
}
body = {
model: "claude-3-haiku-20240307",
messages: [{role: "user", content: params[:message]}],
max_tokens: 4096,
stream: true
}.to_json
res = HTTP.headers(headers).post(url, body: body)
while(buffer = res.body.readpartial)
out << buffer
end
end
end