首页 > 其他分享 >ollama安装和运行llama3.1 8b

ollama安装和运行llama3.1 8b

时间:2024-08-09 16:31:05浏览次数:9  
标签:arr right 8b llama3.1 int ollama

ollama安装和运行llama3.1 8b

conda create -n ollama python=3.11 -y
conda activate ollama
curl -fsSL https://ollama.com/install.sh | sh
ollama run songfy/llama3.1:8b

就这么简单就能运行起来了.

我们可以在命令行中与他交互.

image-20240809005919882

当然我们也可以用接口访问:

curl http://localhost:11434/api/generate -d '{
  "model": "songfy/llama3.1:8b",
  "prompt":"Why is the sky blue?"
}'
curl http://localhost:11434/api/chat -d '{
  "model": "songfy/llama3.1:8b",
  "messages": [
    { "role": "user", "content": "why is the sky blue?" }
  ]
}'

安装open-webui

vim /etc/systemd/system/ollama.service, 增加Environment

vim /etc/systemd/system/ollama.service

########## 内容 ###########################################################
[Unit]
Description=Ollama Service
After=network-online.target

[Service]
Environment="OLLAMA_HOST=0.0.0.0:11434"
ExecStart=/usr/local/bin/ollama serve
User=ollama
Group=ollama
Restart=always
RestartSec=3
Environment="PATH=/root/anaconda3/envs/ollama/bin:/root/anaconda3/condabin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin"

[Install]
WantedBy=default.target
systemctl daemon-reload
systemctl enable ollama
systemctl restart ollama
docker run -d -p 8801:8080 --add-host=host.docker.internal:host-gateway -v open-webui:/app/backend/data --name open-webui --restart always ghcr.io/open-webui/open-webui:main

这个8801是我们开放的端口之一.

image-20240809011755858

启动以后, 我们就可以用: ip: 对应外网端口访问.

我们会看到一个注册页面:

image-20240809024103192

因为是私服, 直接随便注册一个, 登录进去:

image-20240809024150277

然后就可以使用了:

image-20240809024452273

就这样, 也没啥大用.

生成openai兼容的api

端口转发:

cat > /etc/yum.repos.d/nux-misc.repo << EOF
[nux-misc]
name=Nux Misc
baseurl=http://li.nux.ro/download/nux/misc/el7/x86_64/
enabled=0
gpgcheck=1
gpgkey=http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro
EOF
yum -y --enablerepo=nux-misc install redir

redir --lport=8802 --caddr=0.0.0.0 --cport=11434

这样就可以使用python进行调用

from openai import OpenAI

client = OpenAI(
    base_url='http://{ip}:{port}/v1/',
    api_key='ollama',  # 此处的api_key为必填项,但在ollama中会被忽略
)

completion = client.chat.completions.create(
model="songfy/llama3.1:8b",
messages=[
{"role": "user", "content": "写一个c++快速排序代码"}
])

print(completion.choices[0].message.content)

返回:

​```cpp
#include <iostream>

void swap(int &a, int &b) {
    int temp = a;
    a = b;
    b = temp;
}

void quickSort(int arr[], int left, int right) {
    if (left < right) {
        int pivotIndex = partition(arr, left, right);
        
        // Recursively sort subarrays
        quickSort(arr, left, pivotIndex - 1);
        quickSort(arr, pivotIndex + 1, right);
    }
}

int partition(int arr[], int left, int right) {
    int pivot = arr[right]; 
    int i = left - 1;

    for (int j = left; j < right; j++) {
        if (arr[j] <= pivot) {
            i++;
            swap(arr[i], arr[j]);
        }
    }

    swap(arr[i + 1], arr[right]);

    return i + 1;
}

void printArray(int arr[], int size) {
    for (int i = 0; i < size; i++)
        std::cout << arr[i] << " ";
    std::cout << "\n";
}

// Example usage
int main() {
    int arr[] = {5, 2, 8, 1, 9};
    int n = sizeof(arr) / sizeof(arr[0]);

    quickSort(arr, 0, n - 1);

    printArray(arr, n);
    return 0;
}
​```
输出:
 `1 2 5 8 9`

快速排序是基于两个下降数组 partitioned,然后递归地对每个子数组进行相似的操作的算法。`partition()`函数根据列表中最小或最大值来划分数据,并在每次重复时,将列表分割为左边较大的值和右边较小的值。

标签:arr,right,8b,llama3.1,int,ollama
From: https://www.cnblogs.com/songfy/p/18350954

相关文章

  • Ollama 与 RAG 一起用于本地使用以与 pdf 聊天
    我正在尝试通过使用RAG在本地计算机上与pdf聊天来构建ollama用法。我遵循了这个GitHub存储库:https://github.com/tonykipkemboi/ollama_pdf_rag/tree/main问题是当我运行代码时,没有错误,但代码将在嵌入时停止并会之后停止。我已附上所有可能的日志以及ollama......
  • 笔记:从Aurora 8b/10b 到Aurora 64b/66b (三):自定义PHY层收发
    相较于8/10来说没那么复杂,需要考虑的情况只有八种;但是gearbox的控制需要额外的心思:每三十二周期所有操作都需要停止;这一点在收发都需要注意;RX:核心思想是利用header做检测,将夹杂在数据流中的控制包滤除掉;modulegt_phy_rx(inputwirei_rx_clk......
  • VannaAI(带有 Ollama 和 ChromaDB)示例程序在训练模型步骤失败
    我开始测试VannaAI,并且我正在运行一个基于使用Ollama、ChromaDB为Postgres生成SQL的示例程序:fromvanna.ollamaimportOllamafromvanna.chromadbimportChromaDB_VectorStoreclassMyVanna(ChromaDB_VectorStore,Ollama):def__init__(self,confi......
  • Langchain、Ollama 和 Llama 3 提示和响应
    目前,我正在返回多个响应,或者模型不知道何时结束响应,并且似乎在响应中重复系统提示(?)。我只想得到一个回复​​。我的设置非常简单,所以我想我缺少实现细节,但是我该怎么做才能只返回单个响应?fromlangchain_community.llmsimportOllamallm=Ollama(model="llama3")defget_m......
  • wsl docker里运行ollama并使用nvidia gpu的一些记录
     1、安装wsl2具体过程网上一搜一把,这里就先略过了,只有wsl2能用哈2、wsl里装docker,及相关配置装dockerwget https://download.docker.com/linux/static/stable/aarch64/docker-23.0.6.tgzcd/mydata/tmp/tar -zxvf docker-23.0.6.tgzmvdocker/*/usr/bin/mvdock......
  • Continue-AI编程助手本地部署llama3.1+deepseek-coder-v2
    领先的开源人工智能代码助手。您可以连接任何模型和任何上下文,以在IDE内构建自定义自动完成和聊天体验推荐以下开源模型:聊天:llama3.1-8B推理代码:deepseek-coder-v2:16b嵌入模型nomic-embed-text模型默认存储路径:C:\Users\你的用户名\.ollama\models\blobs模型离线下......
  • 使用一个io口同时兼容连接dht11和18b20温度传感器
    一个io口同时兼容dht11和18b20温度传感器,也就是说这个io口设计具有高度灵活性,可以兼容DHT11和18B20两种不同类型的温度传感器(一次只能连接一种温度传感器)。用户可以轻松地在同一个io口上连接不同的传感器,从而实现更广泛的应用。这种设计不仅简化了操作流程,也为未来连接其他传感......
  • SemanticKernel/C#:使用Ollama中的对话模型与嵌入模型用于本地离线场景
    前言上一篇文章介绍了使用SemanticKernel/C#的RAG简易实践,在上篇文章中我使用的是兼容OpenAI格式的在线API,但实际上会有很多本地离线的场景。今天跟大家介绍一下在SemanticKernel/C#中如何使用Ollama中的对话模型与嵌入模型用于本地离线场景。开始实践本文使用的对话模型是gemm......
  • ollama 简易使用教程
    ollama安装Install使用以下命令安装ollama:curl-fsSLhttps://ollama.com/install.sh|sh手动安装下载ollama二进制文件:sudocurl-Lhttps://ollama.com/download/ollama-linux-amd64-o/usr/bin/ollamasudochmod+x/usr/bin/ollama添加ollama作为启动服务(推......
  • 在 Python Langchain 应用程序的 Docker 文件中运行 Ollama
    背景信息我有一个使用langchain和Ollama的Python应用程序。在本地运行这个程序效果非常好,因为我的机器上运行着Ollama客户端。我想要做的是在无服务器平台(例如GCR)上托管这个应用程序,为了做到这一点,我需要容器化应用程序。这对于应用程序的python端来说很容......