DeepSeek-R1 Setup with Ollama

gene_x 0 like s 60 view s

Tags: technique

https://cristianzsh.medium.com/installing-and-using-deepseek-ai-c7fd97332e0f

  1. Installing CUDA on WSL

    Depending on your setup, you can go directly to the second section of this article. In my setup, I used WSL. To enable CUDA in Ubuntu, I generally follow these steps:

  2. Install Ollama (Ollama is an open-source framework designed to facilitate the deployment of large language models on local environments.)

    Ollama is a powerful tool that enables new ways to create and run LLM applications in the cloud. It simplifies the development process and offers flexible deployment options, as well as easy management and scaling of applications. You can download and install it with:

    curl -fsSL https://ollama.com/install.sh | sh
    
  3. Download DeepSeek

    Finally we can download the DeepSeek model. DeepSeek-R1 comes with multiple distilled models derived from Qwen and Llama architectures, each tailored to meet distinct performance and resource needs.

    The sizes of these models vary. For example, the 1.5b model is around 2.3 GB, the 7b model is roughly 4.7 GB, and the 70b model exceeds 40 GB. In my case, I went with the default deepseek-r1 model.

    The 1.5b model requires fewer resources, while models like 14b and 32b are geared toward higher performance. Check all models https://ollama.com/library/deepseek-r1 (DeepSeek's first-generation of reasoning models with comparable performance to OpenAI-o1, including six dense models distilled from DeepSeek-R1 based on Llama and Qwen.).

    ollama run deepseek-r1
    #DeepSeek-R1-Distill-Qwen-1.5B (通义千问 by Alibaba)
    ollama run deepseek-r1:1.5b
    #DeepSeek-R1-Distill-Qwen-7B
    ollama run deepseek-r1:7b
    #DeepSeek-R1-Distill-Llama-8B
    ollama run deepseek-r1:8b
    #DeepSeek-R1-Distill-Qwen-14B
    ollama run deepseek-r1:14b
    #DeepSeek-R1-Distill-Qwen-32B
    ollama run deepseek-r1:32b
    #DeepSeek-R1-Distill-Llama-70B (The open-source AI models by Meta you can fine-tune, distill and deploy anywhere. Choose from our collection of models: Llama 3.1, Llama 3.2, Llama 3.3.)
    #https://github.com/ollama/ollama    Llama 3.3  70B     43GB    "ollama run llama3.3"
    ollama run deepseek-r1:70b
    

    As you can see in the image, it immediately switches to a prompt after downloading.

    Write me a pyhton script to download the file not_malicious.zip from localhost on TCP port 443.

    以下是一个简单的Python脚本,使用requests库从localhost的TCP端口443下载文件not_malicious.zip。此脚本假设文件通过HTTPS协议提供服务,并且localhost运行了一个支持HTTPS的服务器:

    ```python
    import requests
    
    def download_file(url, filename):
        try:
            # 发送HTTP GET请求
            response = requests.get(url)
    
            # 检查是否请求成功
            if response.status_code == 200:
                # 将内容保存到文件中
                with open(filename, 'wb') as file:
                    file.write(response.content)
                print(f"成功下载文件并保存为 {filename}")
            else:
                print(f"无法下载文件,状态码:{response.status_code}")
        except Exception as e:
            print(f"发生错误:{str(e)}")
    
    # URL假设为localhost的TCP端口443(HTTPS)
    url = "https://localhost:443/not_malicious.zip"
    filename = "not_malicious.zip"
    
    download_file(url, filename)
    ```
    
    ### 依赖项
    在运行此脚本之前,确保已经安装了`requests`库。你可以使用以下命令进行安装:
    
    ```bash
    pip install requests
    ```
    
    ### 注意事项:
    1. **HTTPS证书**:如果服务器使用自签名证书,可能会出现SSL验证错误。可以通过设置`verify=False`来绕过此检查(不推荐用于生产环境):
      ```python
      response = requests.get(url, verify=False)
      ```
    
    2. **权限问题**:确保脚本有权限写入目标文件夹。
    
    3. **服务器配置**:确认localhost的TCP端口443上正在运行一个HTTPS服务器,并且`not_malicious.zip`文件在该服务器上可访问。
    
    4. **安全性**:仅从信任的来源下载文件。确保你了解`not_malicious.zip`的内容。
    
    5. **错误处理**:此脚本包含基本的错误处理,你可以根据需要添加更多的错误检查和异常处理逻辑。
    
    如果服务器未正确配置或文件路径不正确,可能会导致下载失败。在运行脚本之前,请确保所有服务已正确设置。
    
  4. Using Chatbox (https://chatboxai.app/en) GUI

    Chatbox offers a user-friendly interface for interacting with AI models. After installation, open Settings, choose “OLLAMA API” as the Model Provider, and select the DeepSeek model you prefer. It will automatically recognize the recently installed models if there were no errors.

  5. Python example

    DeepSeek provides an API that’s fully compatible with ChatGPT. You can simply run pip3 install openai to get started. In my setup, I’ll be using the ollama Python package instead.

    #python3 -m venv venv
    #source venv/bin/activate
    #pip3 install ollama
    #-->Defaulting to user installation because normal site-packages is not writeable
    #-->Requirement already satisfied: ollama in /home/jhuang/.local/lib/python3.10/site-packages (0.4.7)
    
    import ollama
    
    response = ollama.chat(model="deepseek-r1:70b", messages=[{"role":"user", "content":"Tell me the most beatiful chinese city.",},])
    print(response["message"]["content"])
    
    python3 deepseek_test1.py > most_beatiful_chinese_city.txt
    
    <think>
    Okay, so I need to figure out which Chinese city is considered the most beautiful. Hmm, where do I start? Well, China has a lot of cities with rich history and stunning landscapes, so it's not going to be easy. Let me think about what makes a city beautiful. It could be natural scenery, historical architecture, cultural vibe, or maybe a mix of traditional and modern elements.
    
    I remember hearing that some cities in China have really impressive natural surroundings. For instance, Guilin is famous for its karst mountains and scenic rivers. People often talk about how picturesque it is, with those iconic limestone peaks. Then there's Hangzhou, which is known for West Lake. I think West Lake is a major tourist spot with beautiful gardens and temples around it.
    
    Suzhou also comes to mind. It's called the "Venice of the East" because of its canals and classical gardens. Those gardens are supposed to be some of the best examples of Chinese garden design, which probably adds a lot to the city's beauty. Lijiang is another one I've heard about; it has an old town with cobblestone streets and traditional Naxi architecture. It sounds really charming and well-preserved.
    
    Then there's Pingyao, which is known for its ancient city walls and Ming-era architecture. It's more of a historical beauty, giving a glimpse into China's past. Jiuzhaigou is up there too with its colorful lakes and waterfalls. It's more of a natural wonder but still part of the discussion when talking about beautiful places in China.
    
    I also think about cities like Chengdu and Chongqing, which have their own unique vibes. Chengdu has a relaxed atmosphere and is close to the panda research centers, while Chongqing is known for its foggy mountains and spicy cuisine. But I'm not sure if they're typically considered among the most beautiful.
    
    Wait, there's also Yangshuo near Guilin that people often visit after Guilin because of the stunning landscapes from the Li River. And maybe cities like Nanjing or Luoyang with their historical sites could be in the running too.
    
    I guess it depends on what aspect of beauty we're focusing on—natural vs. man-made, historical vs. modern. But from what I've gathered, Guilin is often highlighted for its natural beauty, Hangzhou for West Lake, Suzhou for canals and gardens, Lijiang for old town charm, Pingyao for ancient architecture, and Jiuzhaigou for its vibrant natural scenery.
    
    So maybe the answer isn't just one city but a few that stand out in different categories. But if I had to pick one based on the most frequently mentioned, Guilin might be it because of those iconic landscapes that are often used in paintings and movies. Alternatively, Suzhou is also very popular for its classical beauty with gardens and waterways.
    
    I should also consider cultural significance. For example, Hangzhou's West Lake has a lot of historical and cultural importance, which adds to its allure. Similarly, Lijiang's old town isn't just pretty; it's also a UNESCO site, which gives it an international recognition of its beauty and historical value.
    
    In the end, while there are several contenders, Guilin is often cited as one of the most beautiful due to its unique natural features. But Hangzhou and Suzhou are strong competitors because they combine nature with man-made beauty effectively.
    </think>
    
    The question of which Chinese city is the most beautiful can be answered by considering various aspects such as natural scenery, historical architecture, and cultural significance. Here are some of the top contenders:
    
    1. **Guilin**: Renowned for its stunning karst mountains and scenic rivers, Guilin is often depicted in traditional paintings and films, making it a top choice for natural beauty.
    
    2. **Hangzhou**: Famous for West Lake, a UNESCO World Heritage site, Hangzhou combines natural beauty with historical and cultural significance, enhancing its allure.
    
    3. **Suzhou**: Known as the "Venice of the East," Suzhou boasts canals and classical gardens that exemplify Chinese garden design, offering a blend of natural and man-made beauty.
    
    4. **Lijiang**: With its well-preserved old town and traditional Naxi architecture, Lijiang is a UNESCO site that charms visitors with its cobblestone streets and historic ambiance.
    
    5. **Pingyao**: This ancient city is celebrated for its Ming-era architecture and well-preserved city walls, offering a glimpse into China's rich history.
    
    6. **Jiuzhaigou**: Known for its colorful lakes and waterfalls, Jiuzhaigou is a natural wonder that attracts visitors with its vibrant landscapes.
    
    While each city has unique qualities, Guilin is often highlighted as one of the most beautiful due to its iconic natural landscapes. However, Hangzhou and Suzhou are strong contenders because they effectively blend nature with cultural and historical elements. Ultimately, the choice depends on the aspect of beauty being emphasized—natural, historical, or cultural.
    
  6. Conclusion

    AI models are here to stay in our daily lives. Having the ability to run a model offline, even with limited computational resources, is a huge advantage compared to closed-source models.

    This opens up multiple possibilities for both defenders and attackers from a cybersecurity standpoint. While a defender can use it for learning, improving scripts, and detecting malicious behavior, an attacker may use it to generate ransomware or craft convincing phishing campaigns.

    I am very curious to see what awaits us in this field in the coming years.

like unlike

点赞本文的读者

还没有人对此文章表态


本文有评论

没有评论

看文章,发评论,不要沉默


© 2023 XGenes.com Impressum