ElisaTrippetti commited on
Commit
0aa2f7f
·
verified ·
1 Parent(s): 314cbda

Upload 8 files

Browse files
static/chat-engine.jsx CHANGED
@@ -1,5 +1,5 @@
1
  // chat-engine.jsx — Fetch Good Boi chat logic.
2
- // Response pipeline: keyword lookup → docker model / fallbacks.
3
  // Backends:
4
  // "local" — keyword lookup + fallback only (works offline, no server)
5
  // "docker" — POST /api/chat to the FastAPI backend serving BlenderBot
@@ -56,6 +56,17 @@ const SUGGESTIONS = [
56
  "Tell me about the husky breed",
57
  ];
58
 
 
 
 
 
 
 
 
 
 
 
 
59
  const INITIAL_GREETING = "Hi there! Ask me something simple, ideally about dogs.";
60
 
61
  function retrieveFact(query) {
@@ -82,6 +93,10 @@ async function callDockerBackend({ userInput, history }) {
82
  }
83
 
84
  async function generateReply({ userInput, history, backend }) {
 
 
 
 
85
  const fact = retrieveFact(userInput);
86
 
87
  if (backend === "docker") {
@@ -133,7 +148,7 @@ function useFetchChat({ backend = "local" } = {}) {
133
 
134
  setMessages(prev => prev.map(m =>
135
  m.id === placeholderId
136
- ? { ...m, content: text, pending: false, fact, ts: Date.now() }
137
  : m
138
  ));
139
  setDebug(prev => [
 
1
  // chat-engine.jsx — Fetch Good Boi chat logic.
2
+ // Response pipeline: identity intent → keyword lookup → docker model / fallbacks.
3
  // Backends:
4
  // "local" — keyword lookup + fallback only (works offline, no server)
5
  // "docker" — POST /api/chat to the FastAPI backend serving BlenderBot
 
56
  "Tell me about the husky breed",
57
  ];
58
 
59
+ // Identity intent — BlenderBot has no knowledge of its own name or persona,
60
+ // so intercept name/identity questions before they reach the model.
61
+ const IDENTITY_INTENT = {
62
+ patterns: [/what('?s| is) your name/i, /who are you/i, /what are you/i, /introduce yourself/i],
63
+ response: "I'm Fetch — a dog-loving chatbot powered by BlenderBot-400M-distill. Ask me something about dogs!",
64
+ };
65
+
66
+ function matchIdentity(query) {
67
+ return IDENTITY_INTENT.patterns.some(p => p.test(query || ""));
68
+ }
69
+
70
  const INITIAL_GREETING = "Hi there! Ask me something simple, ideally about dogs.";
71
 
72
  function retrieveFact(query) {
 
93
  }
94
 
95
  async function generateReply({ userInput, history, backend }) {
96
+ if (matchIdentity(userInput)) {
97
+ return { text: IDENTITY_INTENT.response, fact: null, source: "intent" };
98
+ }
99
+
100
  const fact = retrieveFact(userInput);
101
 
102
  if (backend === "docker") {
 
148
 
149
  setMessages(prev => prev.map(m =>
150
  m.id === placeholderId
151
+ ? { ...m, content: text, pending: false, fact, source, ts: Date.now() }
152
  : m
153
  ));
154
  setDebug(prev => [
static/debug-panel.jsx CHANGED
@@ -89,7 +89,7 @@ function DebugLog({ debug, palette }) {
89
  {d.user}
90
  </div>
91
  <div style={{ marginBottom: 4 }}>
92
- <span style={{ color: palette.accent }}>reply&gt; </span>
93
  {d.reply}
94
  </div>
95
  <div style={{ color: palette.dim, fontSize: 12 }}>
 
89
  {d.user}
90
  </div>
91
  <div style={{ marginBottom: 4 }}>
92
+ <span style={{ color: palette.accent }}>fetch&gt; </span>
93
  {d.reply}
94
  </div>
95
  <div style={{ color: palette.dim, fontSize: 12 }}>
static/index.html CHANGED
@@ -34,9 +34,9 @@
34
 
35
  <div id="root"></div>
36
 
37
- <script type="text/babel" src="chat-engine.jsx"></script>
38
- <script type="text/babel" src="debug-panel.jsx"></script>
39
- <script type="text/babel" src="variant-editorial.jsx"></script>
40
 
41
  <script type="text/babel" data-presets="react">
42
  // Docker build: editorial variant + BlenderBot backend via /api/chat.
 
34
 
35
  <div id="root"></div>
36
 
37
+ <script type="text/babel" src="chat-engine.jsx?v=3"></script>
38
+ <script type="text/babel" src="debug-panel.jsx?v=3"></script>
39
+ <script type="text/babel" src="variant-editorial.jsx?v=3"></script>
40
 
41
  <script type="text/babel" data-presets="react">
42
  // Docker build: editorial variant + BlenderBot backend via /api/chat.
static/variant-editorial.jsx CHANGED
@@ -91,16 +91,10 @@ function EditorialVariant({ backend, density, accent, fontPair, bubble }) {
91
  <p style={{
92
  fontFamily: fontPair.body, fontSize: 14.5, lineHeight: 1.65,
93
  color: palette.secondary, maxWidth: 520, letterSpacing: "0.015em",
94
- margin: "0 0 8px",
95
- }}>
96
- And it's a <em style={{ fontStyle: "italic" }}>Good Boi</em>. Four-turn memory · Keyword lookup layer · Powered by BlenderBot-400M-distill
97
- </p>
98
- <p style={{
99
- fontFamily: fontPair.body, fontSize: 14, lineHeight: 1.55,
100
- color: palette.secondary, maxWidth: 520, letterSpacing: "0.02em",
101
  margin: "0 0 28px",
102
  }}>
103
- Fetch Good Boi runs on CPU, so responses may take a few seconds.
 
104
  </p>
105
 
106
  <div style={{
@@ -212,7 +206,7 @@ function EditorialTurn({ msg, palette, fontPair, fontSize, gap, isFirst, radii }
212
  display: "flex", alignItems: "center", gap: 10,
213
  }}>
214
  <span>{isUser ? "You" : "Fetch"}</span>
215
- {!isUser && msg.fact && !msg.pending && (
216
  <span style={{
217
  background: palette.accent, color: palette.paper,
218
  padding: "2px 7px", borderRadius: radii,
@@ -234,7 +228,7 @@ function EditorialTurn({ msg, palette, fontPair, fontSize, gap, isFirst, radii }
234
 
235
  function EditorialSuggestions({ suggestions, onPick, palette, fontPair, pending }) {
236
  return (
237
- <div style={{ display: "flex", gap: 8, flexWrap: "nowrap", overflow: "hidden" }}>
238
  {suggestions.map((s, i) => (
239
  <button
240
  key={s}
@@ -242,12 +236,10 @@ function EditorialSuggestions({ suggestions, onPick, palette, fontPair, pending
242
  onClick={() => onPick(s)}
243
  disabled={pending}
244
  style={{
245
- flex: "1 1 0", minWidth: 0,
246
- overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap",
247
  border: `1px solid ${palette.rule}`,
248
  background: "transparent", color: palette.ink,
249
  fontFamily: fontPair.body, fontSize: 13,
250
- padding: "7px 12px", borderRadius: 999,
251
  cursor: pending ? "default" : "pointer",
252
  opacity: pending ? 0.5 : 1,
253
  animation: `fetch-fadein .4s ease ${i * 60}ms both`,
 
91
  <p style={{
92
  fontFamily: fontPair.body, fontSize: 14.5, lineHeight: 1.65,
93
  color: palette.secondary, maxWidth: 520, letterSpacing: "0.015em",
 
 
 
 
 
 
 
94
  margin: "0 0 28px",
95
  }}>
96
+ And it's a <em style={{ fontStyle: "italic" }}>Good Boi</em>.<br/>
97
+ Runs on BlenderBot-400M-distill · Four-turn memory · Keyword lookup layer
98
  </p>
99
 
100
  <div style={{
 
206
  display: "flex", alignItems: "center", gap: 10,
207
  }}>
208
  <span>{isUser ? "You" : "Fetch"}</span>
209
+ {!isUser && msg.fact && msg.source === "fact" && !msg.pending && (
210
  <span style={{
211
  background: palette.accent, color: palette.paper,
212
  padding: "2px 7px", borderRadius: radii,
 
228
 
229
  function EditorialSuggestions({ suggestions, onPick, palette, fontPair, pending }) {
230
  return (
231
+ <div style={{ display: "flex", flexWrap: "wrap", gap: 8 }}>
232
  {suggestions.map((s, i) => (
233
  <button
234
  key={s}
 
236
  onClick={() => onPick(s)}
237
  disabled={pending}
238
  style={{
 
 
239
  border: `1px solid ${palette.rule}`,
240
  background: "transparent", color: palette.ink,
241
  fontFamily: fontPair.body, fontSize: 13,
242
+ padding: "7px 14px", borderRadius: 999,
243
  cursor: pending ? "default" : "pointer",
244
  opacity: pending ? 0.5 : 1,
245
  animation: `fetch-fadein .4s ease ${i * 60}ms both`,