mirror of
https://github.com/neocities/neocities.git
synced 2025-07-20 01:26:03 +02:00
start on the coding assistant
This commit is contained in:
parent
8f6a85d81d
commit
8ba6005c67
546 changed files with 54575 additions and 12 deletions
|
@ -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
|
Loading…
Add table
Add a link
Reference in a new issue