This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ChatResponsesController < ApplicationController | |
include ActionController::Live | |
def show | |
response.headers['Content-Type'] = 'text/event-stream' | |
response.headers['Last-Modified'] = Time.now.httpdate | |
# handle message event | |
sse = SSE.new(response.stream, event: "message") | |
# connect to OpenAI API | |
client = OpenAI::Client.new(access_token: ENV["OPENAI_ACCESS_TOKEN"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {Controller} from "@hotwired/stimulus" | |
// Connects to data-controller="chat" | |
export default class extends Controller { | |
static targets = ["prompt", "conversation"] | |
disconnect() { | |
if (this.eventSource) { | |
this.eventSource.close() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div data-controller="chat" class="chat-container"> | |
<h1>ChatGPT</h1> | |
<section data-chat-target="conversation" class="chat-conversation"> | |
</section> | |
# send a message to the server | |
<%= form_with data: { action: "chat#generateResponse" } do |form| %> | |
<div class="chat-input"> | |
<%= form.text_area :message, | |
id: 'prompt', | |
data: { chat_target: "prompt" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://huggingface.co/spaces/vincentlovehiking/text_to_speech_v3 | |
我完成的 AI speech to text web app | |
https://youtu.be/uyVRPEXOqzw?si=-elM8UrqFRCwf2UE | |
我就是看這個影片,然後照著做,就完成上述的 web app 了 | |
by the way, 影片當中的人,就是 Elixir language 與 livebook 的作者 José Valim | |
https://livebook.dev/ | |
影片中使用的開發工具 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class='pac-man' /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
main() { | |
greet('vincent'); | |
} | |
void greet(String name) { | |
print('hello $name'); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'csv' | |
array_107 = [] | |
array_108 = [] | |
results = [] | |
csv_text_107 = File.read("tmp/107.csv") | |
csv = CSV.parse(csv_text_107, headers: false) | |
csv.each do |row| | |
array_107 << row |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# customer order a burger | |
class Order | |
def burger | |
raise NotImplementedError | |
end | |
end | |
class Cook < Order | |
def burger |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
aws_region = ENV['aws_region'].dup | |
aws_access_key_id = ENV['aws_access_key_id'].dup | |
aws_secret_access_key = ENV['aws_secret_access_key'].dup | |
aws_instance_id = ENV['aws_instance_id'].dup | |
aws_owner_id = ENV['aws_owner_id'].dup | |
image_name = "backup-brandinlans-#{Time.now.year}-#{Time.now.month}-#{Time.now.day}-#{Time.now.hour}-#{Time.now.min}" | |
image_description= image_name | |
namespace :ec2 do | |
desc 'get all my ec2 instances' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Update and install dependencies | |
sudo apt-get -y update | |
sudo apt-get -y install build-essential zlib1g-dev libssl-dev libreadline-dev libyaml-dev libcurl4-openssl-dev curl git-core python-software-properties | |
# install mysql | |
sudo echo "mysql-server-5.5 mysql-server/root_password_again password vincent90152900" | debconf-set-selections | |
sudo echo "mysql-server-5.5 mysql-server/root_password password vincent90152900" | debconf-set-selections | |
sudo apt-get -y install mysql-server | |
sudo apt-get install mysql-client | |
sudo apt-get install libmysqlclient-dev |
NewerOlder