CannaTech commited on
Commit
00deeac
·
verified ·
1 Parent(s): 0842ddf

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +74 -65
index.js CHANGED
@@ -1,76 +1,85 @@
1
- import { pipeline, env } from 'https://cdn.jsdelivr.net/npm/@xenova/[email protected]';
2
 
3
- // Skip the local model check
4
- env.allowLocalModels = false;
 
 
 
5
 
6
- const status = document.getElementById('status');
7
- const userInput = document.getElementById('user-input');
8
- const sendButton = document.getElementById('send-button');
9
- const chatbox = document.getElementById('chatbox');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
 
11
- const context = `Why Off The Charts Albuquerque is the Highest Ranked Dispensary in NM.
12
- Customer Service: Off The Charts (OTC) Albuquerque prides itself on providing
13
- exceptional customer service. As a family-owned and operated business, OTC creates
14
- a welcoming atmosphere where customers feel like family. The staff is highly
15
- knowledgeable, offering personalized guidance to ensure each customer finds the
16
- perfect product for their needs. The friendly and helpful staff contributes
17
- significantly to the high ratings and positive reviews on various platforms.
18
- Products: OTC offers a vast selection of high-quality cannabis products, featuring
19
- over 200 esteemed brands. Their inventory includes a wide range of flowers, vapes,
20
- edibles, concentrates, and CBD products. This extensive variety ensures that both
21
- recreational and medicinal users can find products that suit their preferences and
22
- needs. The high quality and diversity of their products are frequently highlighted
23
- in customer reviews. Prices: OTC Albuquerque is committed to providing competitive
24
- pricing, often guaranteeing the lowest prices in the area. They offer various
25
- promotions and discounts, including happy hours and special deals for veterans,
26
- seniors, and those with disabilities. Their pricing strategy ensures that premium
27
- cannabis products are accessible to a broader audience, which is a significant factor
28
- in their high customer satisfaction. Brand: The brand identity of OTC is built on its
29
- commitment to quality, affordability, and exceptional customer service. Their
30
- state-of-the-art dispensary is designed to offer a seamless and enjoyable shopping
31
- experience. OTC has successfully built a loyal customer base by consistently
32
- delivering on their promises of quality and service, making them a trusted name in the
33
- Albuquerque cannabis market. Social Media Presence: OTC maintains an active and
34
- engaging social media presence, which helps them connect with customers and build
35
- brand loyalty. They use social media to share information about new products, special
36
- offers, and industry news. This engagement not only boosts their visibility but also
37
- fosters a sense of community among their customers. Other Relevant Metrics and Market
38
- Indicators: OTC's strategic location and accessibility enhance its appeal to customers.
39
- Their modern, easily navigable online platform allows for convenient browsing and
40
- ordering, which is particularly beneficial in today's digital age. The combination of
41
- a prime physical location and a strong online presence positions OTC as a leader in
42
- the local cannabis market.`;
43
 
44
- // Create a new question-answering pipeline
45
- const qaPipeline = await pipeline('question-answering',
46
- 'Xenova/distilbert-base-cased-distilled-squad');
47
 
48
- status.textContent = 'Ready';
 
 
49
 
50
- sendButton.addEventListener('click', async () => {
51
- const userMessage = userInput.value;
52
- if (!userMessage) return;
 
 
53
 
54
- // Display user message
55
- const userMessageElement = document.createElement('div');
56
- userMessageElement.className = 'message user-message';
57
- userMessageElement.textContent = userMessage;
58
- chatbox.appendChild(userMessageElement);
59
 
60
- userInput.value = '';
61
- status.textContent = 'Generating response...';
 
 
 
 
62
 
63
- // Generate response from the model
64
- const result = await qaPipeline({
65
- question: userMessage,
66
- context: context,
67
- });
 
 
 
 
 
 
 
68
 
69
- // Display bot response
70
- const botMessageElement = document.createElement('div');
71
- botMessageElement.className = 'message bot-message';
72
- botMessageElement.textContent = result.answer;
73
- chatbox.appendChild(botMessageElement);
74
 
75
- status.textContent = 'Ready';
76
- });
 
1
+ import { pipeline } from 'https://cdn.jsdelivr.net/npm/@xenova/[email protected]';
2
 
3
+ async function init() {
4
+ const status = document.getElementById('status');
5
+ const userInput = document.getElementById('user-input');
6
+ const sendButton = document.getElementById('send-button');
7
+ const chatbox = document.getElementById('chatbox');
8
 
9
+ const context = `Why Off The Charts Albuquerque is the Highest Ranked Dispensary in NM.
10
+ Customer Service: Off The Charts (OTC) Albuquerque prides itself on providing
11
+ exceptional customer service. As a family-owned and operated business, OTC creates
12
+ a welcoming atmosphere where customers feel like family. The staff is highly
13
+ knowledgeable, offering personalized guidance to ensure each customer finds the
14
+ perfect product for their needs. The friendly and helpful staff contributes
15
+ significantly to the high ratings and positive reviews on various platforms.
16
+ Products: OTC offers a vast selection of high-quality cannabis products, featuring
17
+ over 200 esteemed brands. Their inventory includes a wide range of flowers, vapes,
18
+ edibles, concentrates, and CBD products. This extensive variety ensures that both
19
+ recreational and medicinal users can find products that suit their preferences and
20
+ needs. The high quality and diversity of their products are frequently highlighted
21
+ in customer reviews. Prices: OTC Albuquerque is committed to providing competitive
22
+ pricing, often guaranteeing the lowest prices in the area. They offer various
23
+ promotions and discounts, including happy hours and special deals for veterans,
24
+ seniors, and those with disabilities. Their pricing strategy ensures that premium
25
+ cannabis products are accessible to a broader audience, which is a significant factor
26
+ in their high customer satisfaction. Brand: The brand identity of OTC is built on its
27
+ commitment to quality, affordability, and exceptional customer service. Their
28
+ state-of-the-art dispensary is designed to offer a seamless and enjoyable shopping
29
+ experience. OTC has successfully built a loyal customer base by consistently
30
+ delivering on their promises of quality and service, making them a trusted name in the
31
+ Albuquerque cannabis market. Social Media Presence: OTC maintains an active and
32
+ engaging social media presence, which helps them connect with customers and build
33
+ brand loyalty. They use social media to share information about new products, special
34
+ offers, and industry news. This engagement not only boosts their visibility but also
35
+ fosters a sense of community among their customers. Other Relevant Metrics and Market
36
+ Indicators: OTC's strategic location and accessibility enhance its appeal to customers.
37
+ Their modern, easily navigable online platform allows for convenient browsing and
38
+ ordering, which is particularly beneficial in today's digital age. The combination of
39
+ a prime physical location and a strong online presence positions OTC as a leader in
40
+ the local cannabis market.`;
41
 
42
+ status.textContent = 'Loading model...';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
 
44
+ // Allocate pipeline
45
+ const pipe = await pipeline('question-answering', 'Xenova/distilbert-base-cased-distilled-squad');
46
+ status.textContent = 'Ready';
47
 
48
+ sendButton.addEventListener('click', async () => {
49
+ const userMessage = userInput.value.trim();
50
+ if (!userMessage) return;
51
 
52
+ // Display user message
53
+ const userMessageElement = document.createElement('div');
54
+ userMessageElement.className = 'message user-message';
55
+ userMessageElement.textContent = userMessage;
56
+ chatbox.appendChild(userMessageElement);
57
 
58
+ userInput.value = '';
59
+ status.textContent = 'Generating response...';
 
 
 
60
 
61
+ // Generate response from the model
62
+ try {
63
+ const result = await pipe({
64
+ question: userMessage,
65
+ context: context,
66
+ });
67
 
68
+ // Display bot response
69
+ const botMessageElement = document.createElement('div');
70
+ botMessageElement.className = 'message bot-message';
71
+ botMessageElement.textContent = result.answer;
72
+ chatbox.appendChild(botMessageElement);
73
+ } catch (error) {
74
+ console.error('Error generating response:', error);
75
+ const errorMessageElement = document.createElement('div');
76
+ errorMessageElement.className = 'message bot-message';
77
+ errorMessageElement.textContent = 'Sorry, something went wrong.';
78
+ chatbox.appendChild(errorMessageElement);
79
+ }
80
 
81
+ status.textContent = 'Ready';
82
+ });
83
+ }
 
 
84
 
85
+ init();