AbdulElahGwaith commited on
Commit
9509169
·
verified ·
1 Parent(s): dc79e32

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +154 -0
README.md CHANGED
@@ -1,3 +1,10 @@
 
 
 
 
 
 
 
1
 
2
  ## دليل عملي: بناء محرك بحث دلالي (Semantic Search) باستخدام Node.js و Shopify Hydrogen
3
 
@@ -204,3 +211,150 @@ export function SemanticSearch() {
204
  [1] Hugging Face Inference API. [https://huggingface.co/docs/api-inference/index](https://huggingface.co/docs/api-inference/index)
205
  [2] Shopify Hydrogen. [https://shopify.dev/custom-storefronts/hydrogen](https://shopify.dev/custom-storefronts/hydrogen)
206
  [3] `sentence-transformers/all-MiniLM-L6-v2` model. [https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2](https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # دليل شامل: الذكاء الاصطناعي المتقدم في Node.js و Shopify Hydrogen
2
+
3
+ ## المقدمة
4
+
5
+ يقدم هذا الدليل الشامل رؤى عملية حول دمج تقنيات الذكاء الاصطناعي المتقدمة، بما في ذلك البحث الدلالي (Semantic Search) ونماذج اللغة الضخمة (LLMs)، في تطبيقات Node.js ومتاجر Shopify Hydrogen. يهدف هذا المرجع إلى تمكين المطورين من بناء تجارب تجارة إلكترونية أكثر ذكاءً وتخصيصًا، مما يعزز تفاعل العملاء ويزيد من الكفاءة التشغيلية.
6
+
7
+ ---
8
 
9
  ## دليل عملي: بناء محرك بحث دلالي (Semantic Search) باستخدام Node.js و Shopify Hydrogen
10
 
 
211
  [1] Hugging Face Inference API. [https://huggingface.co/docs/api-inference/index](https://huggingface.co/docs/api-inference/index)
212
  [2] Shopify Hydrogen. [https://shopify.dev/custom-storefronts/hydrogen](https://shopify.dev/custom-storefronts/hydrogen)
213
  [3] `sentence-transformers/all-MiniLM-L6-v2` model. [https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2](https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2)
214
+
215
+ ---
216
+
217
+ ## دليل عملي: تكامل نماذج اللغة الضخمة (LLMs) مع Node.js و Shopify Hydrogen
218
+
219
+ ### المقدمة
220
+
221
+ تُعد نماذج اللغة الضخمة (LLMs) مثل GPT-OSS-120B أدوات قوية لتوليد المحتوى، والإجابة على الأسئلة، وتحسين تجربة المستخدم. يوضح هذا الدليل كيفية دمج هذه النماذج مع تطبيقات Node.js، وخصوصًا في سياق متاجر Shopify Hydrogen، لإنشاء تجارب تسوق أكثر ذكاءً وتخصيصًا.
222
+
223
+ ### المكونات الأساسية
224
+
225
+ 1. **نموذج اللغة الضخم (LLM):** مثل `openai/gpt-oss-120b` أو أي نموذج آخر متاح عبر API.
226
+ 2. **Node.js Backend:** للتعامل مع استدعاءات API للنموذج، ومعالجة البيانات، وتوفير واجهات برمجة تطبيقات (APIs) للواجهة الأمامية.
227
+ 3. **Shopify Hydrogen Frontend:** لدمج الميزات التي تعمل بالذكاء الاصطناعي في واجهة المستخدم، مثل أوصاف المنتجات التلقائية، أو روبوتات الدردشة، أو توصيات المنتجات.
228
+
229
+ ### الخطوات التنفيذية
230
+
231
+ #### 1. الوصول إلى نموذج LLM
232
+
233
+ معظم نماذج LLM الضخمة يتم الوصول إليها عبر واجهات برمجة تطبيقات (APIs). سنفترض استخدام Hugging Face Inference API أو OpenAI API.
234
+
235
+ ```javascript
236
+ // llmService.js
237
+ import axios from 'axios';
238
+
239
+ const HF_INFERENCE_API_URL = "https://api-inference.huggingface.co/models/openai/gpt-oss-120b";
240
+ const HF_TOKEN = process.env.HF_TOKEN; // أو OPENAI_API_KEY
241
+
242
+ async function generateText(prompt, maxTokens = 100) {
243
+ try {
244
+ const response = await axios.post(
245
+ HF_INFERENCE_API_URL,
246
+ { inputs: prompt, parameters: { max_new_tokens: maxTokens } },
247
+ {
248
+ headers: {
249
+ Authorization: `Bearer ${HF_TOKEN}`,
250
+ },
251
+ }
252
+ );
253
+ return response.data[0].generated_text;
254
+ } catch (error) {
255
+ console.error("Error generating text:", error.response ? error.response.data : error.message);
256
+ throw error;
257
+ }
258
+ }
259
+
260
+ export { generateText };
261
+ ```
262
+
263
+ #### 2. بناء واجهة خلفية (Backend) في Node.js
264
+
265
+ يمكنك إنشاء نقطة نهاية (API Endpoint) في Node.js تستدعي خدمة LLM وتوفر المحتوى المولّد للواجهة الأمامية.
266
+
267
+ ```javascript
268
+ // api/llm.js (مثال باستخدام Express)
269
+ import express from 'express';
270
+ import { generateText } from '../llmService.js';
271
+
272
+ const app = express();
273
+ app.use(express.json());
274
+
275
+ app.post('/generate-product-description', async (req, res) => {
276
+ const { productName, keywords } = req.body;
277
+ if (!productName) {
278
+ return res.status(400).json({ error: 'Product name is required' });
279
+ }
280
+ const prompt = `اكتب وصفًا جذابًا للمنتج التالي: ${productName}. الكلمات المفتاحية: ${keywords || ''}.`;
281
+ try {
282
+ const description = await generateText(prompt, 150);
283
+ res.json({ description });
284
+ } catch (error) {
285
+ res.status(500).json({ error: 'Failed to generate description' });
286
+ }
287
+ });
288
+
289
+ app.listen(3002, () => console.log('LLM Integration API running on port 3002'));
290
+ ```
291
+
292
+ #### 3. دمج LLM في Shopify Hydrogen
293
+
294
+ يمكن لمكونات Hydrogen استدعاء نقطة النهاية الخلفية (Backend Endpoint) لتوليد المحتوى ديناميكيًا.
295
+
296
+ ```jsx
297
+ // components/ProductDescriptionGenerator.jsx (مثال في Hydrogen)
298
+ import React, { useState } from 'react';
299
+
300
+ export function ProductDescriptionGenerator({ productId, initialDescription }) {
301
+ const [description, setDescription] = useState(initialDescription);
302
+ const [loading, setLoading] = useState(false);
303
+ const [productName, setProductName] = useState('');
304
+ const [keywords, setKeywords] = useState('');
305
+
306
+ const handleGenerateDescription = async () => {
307
+ setLoading(true);
308
+ try {
309
+ const response = await fetch('http://localhost:3002/generate-product-description', {
310
+ method: 'POST',
311
+ headers: { 'Content-Type': 'application/json' },
312
+ body: JSON.stringify({ productName, keywords }),
313
+ });
314
+ const data = await response.json();
315
+ setDescription(data.description);
316
+ } catch (error) {
317
+ console.error('Error generating product description:', error);
318
+ } finally {
319
+ setLoading(false);
320
+ }
321
+ };
322
+
323
+ return (
324
+ <div>
325
+ <h2>توليد وصف المنتج بالذكاء الاصطناعي</h2>
326
+ <input
327
+ type="text"
328
+ value={productName}
329
+ onChange={(e) => setProductName(e.target.value)}
330
+ placeholder="اسم المنتج"
331
+ />
332
+ <input
333
+ type="text"
334
+ value={keywords}
335
+ onChange={(e) => setKeywords(e.target.value)}
336
+ placeholder="كلمات مفتاحية (اختياري)"
337
+ />
338
+ <button onClick={handleGenerateDescription} disabled={loading}>
339
+ {loading ? 'جاري التوليد...' : 'توليد الوصف'}
340
+ </button>
341
+ {description && (
342
+ <div>
343
+ <h3>الوصف المولّد:</h3>
344
+ <p>{description}</p>
345
+ </div>
346
+ )}
347
+ </div>
348
+ );
349
+ }
350
+ ```
351
+
352
+ ### الخلاصة
353
+
354
+ من خلال دمج نماذج اللغة الضخمة مع Node.js و Shopify Hydrogen، يمكن للمتاجر الإلكترونية تقديم تجارب مخصصة وديناميكية للعملاء، بدءًا من توليد أوصاف المنتجات وحتى توفير مساعدين افتراضيين. هذا يفتح آفاقًا جديدة للابتكار في التجارة الإلكترونية.
355
+
356
+ ### المراجع
357
+
358
+ [1] Hugging Face Inference API. [https://huggingface.co/docs/api-inference/index](https://huggingface.co/docs/api-inference/index)
359
+ [2] Shopify Hydrogen. [https://shopify.dev/custom-storefronts/hydrogen](https://shopify.dev/custom-storefronts/hydrogen)
360
+ [3] `openai/gpt-oss-120b` model. [https://huggingface.co/openai/gpt-oss-120b](https://huggingface.co/openai/gpt-oss-120b)