Skip to content

Latest commit

 

History

History
133 lines (94 loc) · 5.41 KB

File metadata and controls

133 lines (94 loc) · 5.41 KB

استخدام Phi-4-mini-mm لتوليد الأكواد

Phi-4-mini تواصل تقديم قدرات البرمجة القوية لعائلة Phi. يمكنك استخدام Prompt لطرح أسئلة متعلقة بالبرمجة. وبالطبع، بعد إضافة القدرة على التفكير المنطقي القوي، أصبحت لديها إمكانيات برمجية أقوى، مثل توليد المشاريع بناءً على المتطلبات. على سبيل المثال، توليد مشاريع بناءً على المتطلبات، مثل:

المتطلبات

إنشاء تطبيق عربة تسوق

  • إنشاء واجهة برمجة تطبيقات Rest تحتوي على الطرق التالية:
    • الحصول على قائمة بالأنواع المختلفة من البيرة باستخدام الإزاحة والحد.
    • الحصول على تفاصيل البيرة باستخدام المعرف.
    • البحث عن البيرة باستخدام الاسم، الوصف، الشعار، الأطعمة المتوافقة، والسعر.
  • إنشاء قائمة بالمنتجات على الصفحة الرئيسية.
    • إنشاء شريط بحث لتصفية المنتجات.
    • الانتقال إلى صفحة الوصف عندما ينقر المستخدم على منتج.
  • (اختياري) أداة لتصفية المنتجات حسب السعر.
  • إنشاء عربة تسوق.
    • إضافة المنتجات إلى العربة.
    • إزالة المنتجات من العربة.
    • حساب السعر الإجمالي للمنتجات في العربة.

عينة كود - Python

import requests
import torch
from PIL import Image
import soundfile
from transformers import AutoModelForCausalLM, AutoProcessor, GenerationConfig,pipeline,AutoTokenizer

model_path = 'Your Phi-4-mini-mm-instruct'

kwargs = {}
kwargs['torch_dtype'] = torch.bfloat16

processor = AutoProcessor.from_pretrained(model_path, trust_remote_code=True)

model = AutoModelForCausalLM.from_pretrained(
    model_path,
    trust_remote_code=True,
    torch_dtype='auto',
    _attn_implementation='flash_attention_2',
).cuda()

generation_config = GenerationConfig.from_pretrained(model_path, 'generation_config.json')

user_prompt = '<|user|>'
assistant_prompt = '<|assistant|>'
prompt_suffix = '<|end|>'

requirement = """

Create a Shopping Cart App

- Create an API Rest with the following methods:
    - Get a list of beers using page offset and limit.
    - Get beer details by id.
    - Search for beer by name, description, tagline, food pairings, and price.
- Create a list of products on the main page.
    - Create a search bar to filter products.
    - Navigate to the description page when the user clicks on a product.
- (Optional) Slicer to filter products by price.
- Create a shopping cart.
    - Add products to the cart.
    - Remove products from the cart.
    - Calculate the total price of the products in the cart."""

note = """ 

            Note:

            1. Use Python Flask to create a Repository pattern based on the following structure to generate the files

            |- models
            |- controllers
            |- repositories
            |- views

            2. For the view page, please use SPA + VueJS + TypeScript to build

            3. Firstly use markdown to output the generated project structure (including directories and files), and then generate the  file names and corresponding codes step by step, output like this 

               ## Project Structure

                    |- models
                        | - user.py
                    |- controllers
                        | - user_controller.py
                    |- repositories
                        | - user_repository.py
                    |- templates
                        | - index.html

               ## Backend
                 
                   #### `models/user.py`
                   ```python

                   ```
                   .......
               

               ## Frontend
                 
                   #### `templates/index.html`
                   ```html

                   ```
                   ......."""

prompt = f'{user_prompt}Please create a project with Python and Flask according to the following requirements:\n{requirement}{note}{prompt_suffix}{assistant_prompt}'

inputs = processor(prompt, images=None, return_tensors='pt').to('cuda:0')

generate_ids = model.generate(
    **inputs,
    max_new_tokens=2048,
    generation_config=generation_config,
)

generate_ids = generate_ids[:, inputs['input_ids'].shape[1] :]

response = processor.batch_decode(
    generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False
)[0]

print(response)

إخلاء المسؤولية:
تم ترجمة هذا المستند باستخدام خدمات ترجمة آلية تعتمد على الذكاء الاصطناعي. بينما نسعى لتحقيق الدقة، يرجى العلم أن الترجمات الآلية قد تحتوي على أخطاء أو عدم دقة. يجب اعتبار المستند الأصلي بلغته الأصلية هو المصدر الرسمي. للحصول على معلومات حساسة أو مهمة، يُوصى بالاستعانة بترجمة بشرية احترافية. نحن غير مسؤولين عن أي سوء فهم أو تفسيرات خاطئة ناتجة عن استخدام هذه الترجمة.