Skip to content

Commit 3a5bf56

Browse files
Init
1 parent d9eb409 commit 3a5bf56

File tree

6 files changed

+153
-0
lines changed

6 files changed

+153
-0
lines changed

.env.example

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
OPENAI_API_KEY=

Gemfile

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# frozen_string_literal: true
2+
3+
ruby "3.3.4"
4+
5+
source "https://rubygems.org"
6+
7+
gem "langchainrb", git: "https://github.com/patterns-ai-core/langchainrb.git", branch: "main"
8+
gem "ruby-openai"
9+
gem "pry-byebug"
10+
gem "dotenv"

Gemfile.lock

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
GIT
2+
remote: https://github.com/patterns-ai-core/langchainrb.git
3+
revision: ff699356068bd7d6bc768e5518f6b4fdcbdfc90f
4+
branch: main
5+
specs:
6+
langchainrb (0.14.0)
7+
baran (~> 0.1.9)
8+
colorize (~> 1.1.0)
9+
json-schema (~> 4)
10+
matrix
11+
pragmatic_segmenter (~> 0.3.0)
12+
to_bool (~> 2.0.0)
13+
zeitwerk (~> 2.5)
14+
15+
GEM
16+
remote: https://rubygems.org/
17+
specs:
18+
addressable (2.8.7)
19+
public_suffix (>= 2.0.2, < 7.0)
20+
baran (0.1.12)
21+
byebug (11.1.3)
22+
coderay (1.1.3)
23+
colorize (1.1.0)
24+
dotenv (3.1.2)
25+
event_stream_parser (1.0.0)
26+
faraday (2.10.1)
27+
faraday-net_http (>= 2.0, < 3.2)
28+
logger
29+
faraday-multipart (1.0.4)
30+
multipart-post (~> 2)
31+
faraday-net_http (3.1.1)
32+
net-http
33+
json-schema (4.3.1)
34+
addressable (>= 2.8)
35+
logger (1.6.0)
36+
matrix (0.4.2)
37+
method_source (1.1.0)
38+
multipart-post (2.4.1)
39+
net-http (0.4.1)
40+
uri
41+
pragmatic_segmenter (0.3.23)
42+
unicode
43+
pry (0.14.2)
44+
coderay (~> 1.1)
45+
method_source (~> 1.0)
46+
pry-byebug (3.10.1)
47+
byebug (~> 11.0)
48+
pry (>= 0.13, < 0.15)
49+
public_suffix (6.0.1)
50+
ruby-openai (7.1.0)
51+
event_stream_parser (>= 0.3.0, < 2.0.0)
52+
faraday (>= 1)
53+
faraday-multipart (>= 1)
54+
to_bool (2.0.0)
55+
unicode (0.4.4.5)
56+
uri (0.13.0)
57+
zeitwerk (2.6.17)
58+
59+
PLATFORMS
60+
arm64-darwin-23
61+
ruby
62+
63+
DEPENDENCIES
64+
dotenv
65+
langchainrb!
66+
pry-byebug
67+
ruby-openai
68+
69+
RUBY VERSION
70+
ruby 3.3.4p94
71+
72+
BUNDLED WITH
73+
2.5.11

classifier.rb

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
require "bundler/setup"
2+
require "dotenv/load"
3+
Bundler.require
4+
5+
# Require Langchain.rb library
6+
require "./tools/classifier_tool"
7+
8+
# Load the prompt template from a YAML file
9+
prompt_template = Langchain::Prompt.load_from_path(
10+
file_path: "prompts/blog-post-classifier-prompt.yml"
11+
)
12+
13+
# Run below to confirm which variables are required
14+
prompt_template.input_variables
15+
#=> ["blog_post"]
16+
17+
# Output the prompt to be sent to the AI model
18+
prompt = prompt_template.format(blog_post: [
19+
# Source: https://medium.com/feed/minneapolis-institute-of-art
20+
'<h4>For nearly half a century, the modern Games included artistic competitions. What happened?</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*OHmKKlnN0ScJvgLX_ZwRMw.jpeg" /><figcaption>“Two Fencers” by Harold Edgerton, 1938, gelatin silver print, collection of the Minneapolis Institute of Art. ©The Harold &amp; Esther Edgerton Foundation</figcaption></figure><p><em>By Rob Bedeaux</em></p><p>Since the inception of the <a href="https://stillmed.olympic.org/media/Document%20Library/OlympicOrg/Documents/Document-Set-Teachers-The-Main-Olympic-Topics/The-Modern-Olympic-Games.pdf">modern Olympic Games</a>, in 1896, over 130 sports have been contested. Everyone knows the standards (gymnastics, track and field, swimming) and perhaps some of the oddities that have come and gone (tug-o-war, live pigeon shooting!). But did you know that between 1912 and 1952, several different types of art competitions were included as part of the Games? During those forty years, over 150 medals were awarded across fine arts disciplines — the only requirement was that entries had to be inspired by athletic endeavors. How was it that the early modern Games included art events in its programming?</p><h3>Art in the Ancient Games</h3><p>In ancient Greece, art and sport went hand in hand, and exercising both body and mind was considered the ideal way to achieve harmony. From 776 BCE through 393 CE, the Olympic program included sporting events like running, jumping, boxing, and chariot racing as well as art, music, and <a href="https://www.cnn.com/2004/SPORT/06/03/olympics.facts/">heraldry competitions</a>. For the Greeks, there was a direct connection between sport and art. This was such an ingrained part of Greek life that the military used music to improve the coordination and movement of their troops.</p><h3>The Push for an Art Program</h3><p>Baron Pierre de Coubertin, the Frenchman who spearheaded the revival of the Olympics in the 1890s, argued that the arts should be an integral part of any modern Games.</p><p>As Richard Stanton, author of <em>The Forgotten Olympic Art Competitions</em>, shared with <em>Smithsonian</em> magazine, “[Courbertin] was raised and educated classically, and he was particularly impressed with the idea of what it meant to be a true Olympian — someone who was not only athletic but skilled in music and literature. He felt that in order to recreate the events in modern times, it would be incomplete to not include some aspect of the arts.”</p><p>Conversations began at the IVth Olympic Congress, held in Paris in May 1906, where Courbertin directed the International Olympic Committee (IOC) to “come and study to what extent and in what way art and literature could be included in the celebration of the modern Olympiads.”</p><p>Eventually, the IOC selected five art forms to be included in the Games, with the stipulation that each piece submitted must be inspired by sport. The categories included architecture, literature, music, painting, and sculpture.</p><h3>The V Olympiad–Sweden, 1912</h3><p>It then took Coubertin several years and much negotiation to implement his plan. First, art wasn’t seen through the same lens as sport; it wasn’t something someone did competitively — it was to enrich the mind and the soul. Also, as always, there were internal politics. As Sweden prepared to host the V Olympiad, in 1912, Coubertin encountered pushback from the Swedish Games Committee, which felt the mandate to include arts was an intrusion into “their” Games. However, Coubertin persisted, noting, “In the high times of Olympia … the fine arts were combined harmoniously with the Olympic Games to create their glory. This is to become reality once again.” Coubertin went so far as to tell the Swedish contingent that the IOC would ignore their Games unless they complied with his request.</p><p>Sweden complied, and the five categories of art were included. The rules were a mere six, comprising less than 200 words. Those first Olympic art competitions occupied twelve rooms at the Games and included around 300 artworks. Across all competitions, five gold medals and one silver were awarded.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/855/0*QG6E2R561o5xlb-_.jpg" /><figcaption><em>Artwork by Open Painting Gold Medalist Carlo Pellegrini</em></figcaption></figure><p>Walter Winans was a notable American gold medalist in this first iteration, being a skilled marksman and horse breeder as well as a sculptor and painter. In addition to the gold medal for his sculpture <a href="https://www.researchgate.net/figure/An-American-Trotter-Walter-Winans-USA-Sculpture-Gold-Medal-Stockholm-1912_fig2_283790722"><em>An American Trotter</em></a><em>,</em> he medaled in shooting in 1908 and 1912. He was also a prolific author, publishing ten books during his lifetime.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/0*fEtbTLm8FOapaKvg.jpg" /><figcaption><em>“An American Trotter,” Sculpture Gold Medalist, Walter Winans</em></figcaption></figure><p>After the medals were awarded, questions were raised about the actual judges. Documentation shows that the Swedish Olympic Committee gave 5,000 Francs to the International Olympic Committee to determine the jury, and the art pieces were sent to Pierre Courbertin’s home in France for judging. However, there are no accurate records containing a list of judges, so Coubertin likely was the sole judge for these Games.</p><p>Curiously, Courbetin later claimed that the winner of the literature competition, a duo called Georges Hohrod and Martin Eschbach, was actually a pseudonym—for himself. (Hohrod and Eschbach are villages near the home of Courbetin’s in-laws.) Curiouser still, the winning essay, <a href="https://www.cabinetmagazine.org/issues/56/hohrod_eschbach.php"><em>Ode to Sport</em></a><em>, </em>was submitted in German—a language in which Courbetin was not fluent, though perhaps he had it translated as part of his subterfuge.</p><h3>The VII Olympiad and Beyond</h3><p>The VI Olympiad, scheduled for 1916, was canceled because of World War I, so it wasn’t until 1920 that the arts competitions were held again as part of the VII Olympiad in Belgium. The program continued to struggle for legitimacy within the IOC and the organizing countries. Its judging and rules were chaotic. Sometimes medals wouldn’t be awarded because of the lack of “quality” entries, sometimes only a silver medal would be awarded — no gold.</p><p>Regardless, the public was enthusiastic. At the X Olympiad, in 1932, nearly 400,000 people visited the Los Angeles Museum of History, Science, and Art to see the works presented.</p><p>Eventually, however, no amount of public enthusiasm could overcome the internal politics. Artists, too, looked at the program with distrust. Stanton noted that many artists felt the competition could damage their reputation in the art world. Organizers struggled to get preeminent names to participate.</p><p>As interest from artists waned and support from the IOC was lukewarm at best, the arts competitions ended after 1952. The technical reason offered by the IOC was that most artists were “professionals” in their field, violating the rule of <a href="https://www.cnn.com/2012/07/22/opinion/greene-olympics-amateurs/index.html">amateurism</a> at the Olympics. (Interestingly, the rule of amateurism was rescinded in 1992 to allow Team USA to field a professional basketball team, known as the “Dream Team,” though of course that hasn’t led to the reinstatement of the arts.)</p><h3>Art and the Olympics Today</h3><p>Over the forty years of art at the Olympics, thirty-three art categories with 1,873 participants were contested. And while medals are no longer awarded today, the infusion and influence of art can still be seen in the <a href="https://olympics.com/museum/explore/programmes/olympic-art-posters">poster art</a>, <a href="https://standardsmanual.com/products/guidelines-and-standards-for-the-visual-design-the-games-of-the-xx-olympiad-munich-1972">graphic design systems</a>, <a href="https://olympics.com/en/olympic-games/grenoble-1968/mascot">mascots</a>, and other elements of the Games that are the descendants of the idea that art and sport coexist in the same space. At the 2024 Paris Olympic Games, visitors can participate in the <a href="https://www.artbasel.com/stories/art-sports-exhibitions-paris-olympics?lang=en">Cultural Olympiad</a>, where they can see exhibitions that link art and sports.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=da2136f793a8" width="1" height="1" alt=""><hr><p><a href="https://medium.com/minneapolis-institute-of-art/when-art-was-an-olympic-sport-da2136f793a8">When Art was an Olympic “Sport”</a> was originally published in <a href="https://medium.com/minneapolis-institute-of-art">Minneapolis Institute of Art</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>'
21+
])
22+
23+
# Instantiate the LLM to be used: OpenAI or any other Langchain::LLM::* class
24+
llm = Langchain::LLM::OpenAI.new(
25+
api_key: ENV["OPENAI_API_KEY"],
26+
default_options: { chat_completion_model_name: "gpt-4o-mini" }
27+
)
28+
29+
# Instantiate the assistant with the LLM and tools
30+
assistant = Langchain::Assistant.new(
31+
llm: llm,
32+
tools: [
33+
ClassifierTool.new
34+
]
35+
)
36+
37+
# Add the prompt to the assistant and run it
38+
assistant.add_message(content: prompt)
39+
messages = assistant.run
40+
41+
puts("Classifications: #{messages.last.tool_calls}")
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
_type: prompt
2+
input_variables:
3+
- blog_post
4+
template: |
5+
Please classify the following blog post into topics and interests:
6+
7+
{blog_post}

tools/classifier_tool.rb

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class ClassifierTool
2+
extend Langchain::ToolDefinition
3+
4+
define_function :classify_topics, description: "Classify blog post by topics" do
5+
property :topics,
6+
type: "array",
7+
description: "List of topics to classify blog post into",
8+
required: true do
9+
item type: "string", enum: ["technology", "business", "health", "lifestyle", "politics", "sports", "entertainment"]
10+
end
11+
end
12+
13+
define_function :classify_interests, description: "Classify blog post by interests" do
14+
property :interests,
15+
type: "array",
16+
description: "List of interests to classify blog post into",
17+
required: true do
18+
item type: "string", enum: ["fashion", "food", "travel", "music", "movies", "books", "art", "gaming"]
19+
end
20+
end
21+
end

0 commit comments

Comments
 (0)