ollama安装与使用

1. ollama安装:

1.1 ollama下载地址:

https://ollama.com/download

1.2 安装Ollama(windows):

直接一键安装

若想进行个性化设置参见:

1.3 安装Ollama(linux):

  • 安装Ollama:

  • 调整模型下载目录:

    • 设置模型下载地址:
      vim ~/.bashrc

    配置 OLLAMA_MODELS 环境变量自定义路径

    ollama model dir 改为自定义的路径,默认路径 /usr/share/ollama/.ollama/models

    export OLLAMA_MODELS=/home/Ollama/ollama_cache

    复制/usr/share/ollama/.ollama/models目录中(blobs manifests)的文件夹到OLLAMA_MODELS环境变量目录

    cp -r /usr/share/ollama/.ollama/models /home/Ollama/ollama_cache

1.4 下载模型:

  1. 在ollama官网搜索所需模型:https://ollama.com/
  2. 复制模型下载命令即可,如下,获取qwen2:0.5b模型
  3. 在cmd或者shell终端执行第2步命令即可,比如:ollama run qwen2:0.5b

1.5 启动ollama:

  • windows版直接双击启动,其他可参考如下命令

  • 常见命令:

    启动服务

    ollama serve

    启动服务(挂后台)

    nohup ollama serve >/dev/null 2>&1 &

    查看已经安装的模型

    ollama list

    查看版本

    ollama v

2. ollama下模型如何使用?

2.1 LLM的使用:以qwen2:0.5b为例:

  • 终端交互:

    ollama run qwen2:0.5b

  • python版http请求:

    import os
    from openai import OpenAI

    os.environ['OPENAI_API_KEY'] = 'none'
    os.environ['OPENAI_BASE_URL'] = 'http://localhost:11434/v1'

    client = OpenAI()
    response = client.chat.completions.create(
    model="qwen",
    messages=[{"role": "user", "content": "你好,你能做什么?"}],
    )

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

返回示例:

复制代码
我很乐意为您效劳。我可以帮助您解答关于健康、旅游、教育或其他任何话题的问题。您需要帮助什么?我会尽力提供相应内容。欢迎随时提问!

2.2 表征模型的使用:以bge-large为例

  • python版http请求:

    #!/usr/bin/env python

    import requests

    if name == 'main':
    print('')

    复制代码
      url = "http://localhost:11434/api/embed"
      headers = {"Content-Type": "application/json"}
      data = {
          "model": "bge-large",
          "input": ["你好,bge 模型!"]
      }
      response = requests.post(url, json=data, headers=headers)
      print(response.json())

返回示例:

复制代码
{'model': 'bge-large', 'embeddings': [[-0.0070403893, 0.01906589, 0.002659078, 0.056569893, -0.023268774, 0.005505571, 0.056816433, 0.04278964, 0.00044504693, 0.023565972, 0.024955913, 0.019057797, 0.05871248, -0.03599396, -0.045997616, -0.030140555, -0.009543529, -0.053064633, -0.03361538, 0.02916276, 0.06290166, -0.019709377, -0.034709457, -0.011301448, 0.0117891235, 0.027437935, -3.430807e-07, 0.013488718, 0.076188676, 0.03509752, 0.00590025, -0.040265292, -0.027687589, -0.024458922, -0.014245673, -0.021977823, 0.029482568, 0.010672004, -0.008089688, -0.027499154, 0.0050347657, -0.019399296, 0.063457735, -0.020411367, -0.057074193, -0.034824282, 0.009907699, -0.015852498, 0.025248498, -0.045246854, 0.01432494, 0.0109622525, 0.037995335, -0.021219427, -0.027175924, -0.007347304, -0.024817608, 0.012287279, -0.034731314, 0.037794087, 0.037213646, -0.002320361, 0.030508645, -0.0465931, 0.048149984, 0.023971763, -0.027592681, -0.015870372, -0.021268606, 0.0076985643, -0.0006617156, -0.011590468, 0.01725008, -0.009122913, -0.016020289, 0.021580378, 0.02075024, -0.02218919, -0.02132194, 0.030158997, -0.04990588, 0.038913388, 0.023666574, -0.0072251437, -0.03669096, -0.02033102, 0.007982552, 0.030953584, -0.0127026625, 0.0060917297, -0.00430609, 0.03711033, -0.024787832, 0.019946046, 0.01957175, 0.021363134, -0.014233724, 0.0027091366, -0.0010168382, 0.0019552654, -0.003309192, 0.070714, -0.021763261, 0.051161986, -0.012890194, 0.012796871, 0.00059220876, 0.008461764, 0.022895597, -0.051393416, 0.001914221, -0.015363903, 0.020463891, -0.018298807, 0.016646013, 0.035598908, 0.010937788, 0.017291384, -0.057286683, 0.014260818, 0.015394249, -0.014542514, 0.025340704, -0.016369442, -0.019448617, -0.03153624, 0.018372204, 0.055603065, -0.027723052, -0.015020757, 0.002710605, -0.0019614245, 0.0067682737, 0.0110647585, 0.031332172, 0.018767634, -0.03062548, 0.03887965, 0.0022049733, -0.036204502, 0.051503938, 0.012743955, -0.015208852, 0.07831091, -0.010496072, 0.040942833, 0.020350454, -0.0060014976, 0.009145163, 0.04069311, -0.021685123, -0.011527088, -0.026825434, 0.04153383, -0.006385221, 0.036877394, -0.014902794, 0.016821373, 0.018585762, -0.009454982, 0.0019853725, 0.01334066, -0.021774137, 0.028166281, -0.047475036, 0.04230357, -0.013220999, 0.0033086804, -0.0053515285, 0.009780864, 0.009353123, -0.001663453, -0.030986562, 0.021455694, 0.04524756, 0.06669588, 0.027619319, 0.00290273, 0.058557734, 0.053362034, -0.017204573, -0.0111057395, -0.0056064418, 0.06425588, 0.018703718, 0.038351804, -0.009766951, -0.005928879, -0.0001467284, -0.023651257, 0.028751774, 0.01252139, -0.001539898, 0.039539866, -0.034142107, 0.05383606, -0.025278132, 0.009340684, -0.0037221434, -0.087359264, 0.0112593165, 0.04594102, -0.0006155078, 0.022432674, 0.014018834, -0.072135225, 0.013675576, 0.06880568, -0.04520597, 0.0052889143, 0.0040136566, 0.03396464, -0.013385941, -0.0029300766, 0.015143305, -0.017168017, -0.017260358, 0.05062348, 0.0428305, 0.05614264, 0.026061483, 0.009595507, 0.019631432, 0.025412323, 0.029536841, -0.0016593153, -0.0026602359, 0.07059497, 0.012257941, -0.043406468, -0.0073072603, 0.026898861, 0.003358133, 0.028841669, 0.026743665, -0.00840395, 0.043157034, 0.03650463, 0.01904319, 0.015189937, -0.00036257142, -0.021226443, 0.021171542, 0.009604236, 0.0053951317, 0.027112434, 0.022841005, -0.015011519, -0.010047954, 0.023563165, -0.0052388045, 0.02720629, 0.050796602, 0.07422631, -0.031874113, -5.72605e-05, 0.011858366, 0.053817872, -0.04693298, -0.026269851, -0.0010972716, 0.017700108, -0.050242335, -0.018399434, 0.017196946, 0.014187867, -0.037531275, 0.007089694, -0.024912696, -0.020629814, -0.015176327, -0.0058515877, -0.013573986, 0.0131033445, -0.047601238, -0.009737294, 0.065291345, 0.0038590103, 0.0025072414, 0.0044639413, -0.0067337677, -0.0026420099, -0.010315427, 0.02549983, 0.029839238, 0.023507776, -0.036168303, 0.009155077, -0.0073906025, 0.019673739, -0.050094742, 0.015362973, 0.017758433, 0.010960511, 0.0021826276, 0.030790022, -0.04717487, 0.024296198, 0.001125065, -0.056763783, 0.007048089, -0.0047614574, -0.017909031, -0.028350014, -0.015173812, 0.046852194, 0.00818632, -0.02434682, 0.029895946, 0.021330902, -0.03211086, 0.009632547, 0.019648362, 0.0039280932, -0.045631513, 0.00672944, 0.042310715, 0.003723977, -0.045502517, -0.022490233, -0.010750615, -0.03275634, 0.015078729, -0.044813063, -0.007980342, 0.028353306, 0.04611759, -0.056546412, 0.06193175, -0.02445804, -0.011335018, -0.063175425, -0.010993968, 0.038113285, 0.00875678, -0.015218607, -0.02709348, -0.008615219, 0.0594869, -0.005676508, 0.053490352, -0.0024553875, 0.012489176, 0.040417455, -0.007852411, -0.000744978, 0.027852757, 0.014134112, -0.022405768, -0.000464714, -0.011475244, -0.013227065, 0.023162592, 0.0424772, 0.0035211148, 0.01989717, -0.015941069, 0.05020719, -0.014955038, -0.0011783469, 0.044589713, 0.022643305, 0.024263838, -0.015206756, -0.028557576, -0.056986682, -0.03814067, 0.018890904, 0.0005248411, -0.03856115, 0.018961282, -0.0071108188, -0.023308976, 0.011264238, -0.03387144, 0.0156392, 0.044136915, -0.013936354, 0.02921954, -0.030549256, 0.01943521, -0.040158767, 0.037854236, 0.047375776, 0.02096697, 0.05385523, 0.012668689, 0.008472726, -0.013711658, -0.016134014, -0.026732491, -0.028708218, 0.036116485, -0.010307993, -0.06817803, -0.06015199, 0.03996574, 0.031118346, 0.045277625, 0.013415897, 0.010191913, 0.0074084187, 0.018649125, 0.015033783, -0.015746493, 0.006529237, -0.019605948, 0.042695966, 0.017905213, -0.0068788095, -0.03600669, 0.0065203253, -0.05678912, 0.00788002, -0.0060769315, 0.011572877, -0.017203568, 0.030282894, 0.009854192, 0.029095279, -0.028959468, -0.023280773, 0.00315682, 0.038356587, 0.054722648, -0.06227088, -0.030580536, -0.04799714, 0.058712058, 0.037994567, 0.025578184, -0.03761098, -0.038217913, 0.00649259, -0.04329216, 0.01472746, 0.04583287, -0.021681966, 0.012339355, -0.007184062, 0.04526136, -0.019612942, -0.00228237, 0.0014714554, -0.01380061, 0.012254029, 0.029728537, 0.0545876, -0.005607875, -0.025806531, 0.012823927, -0.030335505, 0.011734588, -0.009641436, -0.032856278, 0.0047602123, -0.03602563, 0.055535585, 0.022989685, 0.016154844, -0.048893888, 0.0009480896, 0.002739567, -0.016006595, -0.017131865, 0.059311, 0.0039769765, -0.0082349945, 0.006755224, 0.040497564, -0.010205873, 0.029403621, 0.0141168, -0.02416968, 0.039958585, -0.043204736, 0.024436941, -0.00037669606, -0.026583487, 0.021512257, -0.0024998996, 0.040400125, 0.014604914, -0.004248239, -0.02502539, -0.06756593, -0.016397944, 0.026882933, -0.033020154, 0.011576838, -0.011598247, 0.017744897, 0.012140011, -0.056696415, -0.032604817, -0.003792443, -0.010935416, -0.032546602, 0.00703559, -0.003630963, 0.033379536, -0.016389588, -0.04564086, -0.018783092, -0.017858133, -0.0043097083, -0.042435657, -0.01349656, -0.0048291185, 0.018763201, -0.03839084, -0.016486486, -0.0052825366, 0.0020295144, 0.034158576, 0.0072974777, -0.008529057, -0.014441216, -0.06551339, 0.021007057, 0.01922135, -0.056765694, -0.044160347, 0.04524463, 0.021202393, 0.02506909, -0.030560685, -0.005584031, -0.012294511, -0.10865492, -0.019071432, -0.03811353, -0.045279894, -0.047291975, -0.061994784, -0.049554866, 0.02011041, 0.03355916, -0.023247514, -0.01056736, -0.058101937, 0.005405596, 0.001882102, -0.029847803, -0.058218215, -0.056825172, -0.027234046, 0.05511729, -0.009983732, 0.0020296283, 0.018229945, 0.011483557, 0.007918112, 0.018996928, -0.0003343196, -0.03272991, -0.0059878444, 0.029216316, 0.003175229, -0.005475264, -0.048236713, 0.063257895, -0.03901231, 0.01738773, -0.04221106, 0.0082473345, 0.00120849, 0.0059951167, 0.0252575, -0.014470814, 0.023239605, -0.025079856, 0.0585418, 0.040912382, 0.027002893, -0.053181946, -0.03992778, -0.07480758, -0.06628144, 0.023957111, -0.04313811, -0.0025812224, -0.020075947, 0.004876303, 0.01693111, 0.023191255, 0.019019756, 0.06659408, -0.0006127229, -0.018039333, -0.031305127, 0.0033916165, 0.0055614356, -0.016497089, -0.02139959, 0.00028916888, -0.007821043, -0.0044675455, -0.026781842, -0.041178424, -0.038466938, -0.013517925, 0.019323459, -0.018820925, 0.057694726, -0.06000928, -0.055490676, -0.07068849, 0.031100508, 0.021655718, -0.0015028605, 0.061095078, 0.00082038034, 0.0103131095, 0.06623477, -0.008361736, 0.022882653, -0.04459498, 0.021046076, 0.02609461, -0.03401324, 0.025425026, 0.019058388, -0.073709324, -0.07573972, -0.012055938, -0.020797692, -0.00808806, -0.031378075, 0.0021154443, -0.032328963, 0.0018963816, -0.018422507, 0.047946475, 0.032200463, 0.013366403, 0.011669832, 0.009570461, -0.027379744, -0.0051984303, 0.06256587, -0.023468366, -0.007849275, -0.071204074, -0.0469633, -0.029246388, -0.013967516, 0.064554825, 0.01924814, -0.00014453426, 0.048427865, 0.0052879765, 0.026265174, 0.009010892, -0.0054303803, 0.009937031, -0.052449185, -0.07729043, -0.04593821, -0.049434617, 0.0024426489, 0.020747881, 0.0057712663, -0.013057568, 0.0002792154, 0.00648923, -0.028681457, -0.03681852, -0.0032926737, -0.08160643, -0.019366995, -0.05154472, -0.029506385, 0.018837303, -0.03116448, 0.046091314, -0.06302395, 0.01245183, 0.041979726, 0.018751252, 0.04339032, -0.024570035, -0.010310574, -0.043309942, -0.0809844, -0.031746972, 0.0047824346, -0.016300127, -0.028823081, -0.02021954, 0.012057317, -0.03499477, 0.040432245, 0.04752504, -0.011296172, -0.034992415, -0.044500027, -0.0037711635, 0.0011472511, 0.021947872, 0.021408243, 0.010713058, 0.0015879157, 0.00459016, -0.016229281, -0.010239487, -0.037076093, -0.033546336, 0.032470677, -0.02077174, -0.052966572, -0.020537175, 0.014860685, -0.017641691, 0.05024671, -0.036650296, -0.010280337, -0.018782679, 0.016514208, -0.019147204, 0.034859557, -0.0008312818, 0.004327462, 0.006941175, 0.0016733397, -0.0009555216, -0.022411846, 0.020836074, -0.033944603, 0.049242616, -0.025693765, 0.0040638493, 0.041403797, 0.004588412, 0.0056065, -0.03209177, -0.008504349, -0.03855394, -0.028733227, 0.019384496, 0.014475346, 0.016255, 0.0036393672, -0.006148987, -0.0007619093, -0.03376579, 0.0010282528, -0.054533295, -0.03971578, 0.034128048, -0.021811225, 0.017387718, 0.004186564, -0.04512461, 0.014225647, -0.032486048, 0.0070723053, -0.018503552, 0.027403668, 0.021878272, 0.04886967, -0.01913058, 0.008838069, 0.016880706, 0.032418747, -0.018118454, -0.039878085, 0.021717235, -0.021876583, 0.019476412, -0.023045834, 0.015805345, 0.0089367675, 0.014701033, -0.031975906, 0.00083135813, 0.011930838, -0.03604594, 0.02153676, -0.027527232, 0.010023248, -0.04767032, 0.041257042, -0.0125872465, -0.026804991, -0.019974552, 0.01649554, 0.06977112, 0.0012343794, 0.03824578, 0.0015352672, 0.02790019, -0.0014340117, 0.007105228, 0.005662698, -2.3596669e-05, 0.034551952, 0.019066937, -0.032828864, 0.009660383, 0.023890607, -0.019104857, -0.0033568407, 0.05448229, -0.010232222, -0.023445297, 0.02854046, 0.0014599522, 0.02502723, -0.011213519, -0.011628471, -0.0014890592, -0.04010781, -0.04247058, 0.01349673, -0.040459074, 0.0018228291, -0.03724213, -0.007911939, -0.025678987, -0.056632366, 0.030231247, 0.024136413, -0.010445779, -0.0009981233, 0.0068032523, 0.009657726, -0.02923514, 0.017277014, -0.0005935328, 0.027763328, 0.002965036, 0.006694811, 0.020482251, 0.00012587881, -0.021803936, -0.021546472, -0.050022062, 0.04072533, -0.012719364, -0.0032993613, -0.014552282, -0.011808402, 0.0075002383, -0.06435497, -0.0016929954, -0.037880596, -0.0077904407, 0.03439314, 0.006232501, 0.013079042, 0.022928517, -0.00074163656, 0.034630742, 0.066882245, 0.06948658, -0.03611347, 0.03468739, 0.017190145, -0.012596541, -0.002326759, -0.019623598, -0.0048387614, 0.008312497, -0.0032329937, -0.02732138, -0.010927489, 0.015252223, -0.021544315, 0.008864709, 0.0246544, -0.0050672265, 0.0043000747, -0.007930789, 0.025296085, -0.026734944, 0.013839042, 0.05451606, 0.038213946, -0.023635434, 0.0001035151, -0.03787938, 0.006273067, -0.001654922, -0.051417973, 0.01299924, -0.027492383, -0.05780047, -0.036766123, -0.018293768, -0.029786713, 0.0067153126, -0.034068834, -0.03472565, 0.012572684, 0.016737258, -0.022588473, 0.0167033, -0.030383442, -0.015435516, -0.018050583, 0.029136825, 0.011798588, 0.027731093, 0.008008394, 0.044055916, -0.015566233, -0.025969572, 0.002188756, 0.015084373, 0.0060450225, -0.017258225, -0.0053386586, -0.017889135, -0.049390856, 0.043644607, 0.052760225, -0.015971042, -0.011626393, -0.037941683, 0.013975054, -0.049510196, -0.009188764, 0.0058342605, 0.058040254, -0.014318325, -0.01182061, 0.01655925, -0.056711227, 0.22953044, 0.065997094, 0.032821953, 0.021836957, 0.026243776, -0.0037390916, -0.008494499, -0.04960849, 0.005399728, -0.0057244673, -0.0003645901, 0.03655987, 0.030705953, 0.034764085, 0.013580113, 0.07542869, -0.048138432, 0.0031213413, 0.021464214, -0.031239873, -0.05640091, -0.007403914, 0.032692682, 0.021625916, 0.00291546, 0.030211177, 0.010458836, -0.05320262, -0.041053165, -0.048457917, 0.021379316, -0.021033766, 0.0435075, -0.014468685, -0.055643108, 0.035139266, 0.0106867645, -0.044994894, 0.038692098, 0.0023467399, -0.0318589, 0.0018194969, 0.03438788, -0.006929983, 0.010699685, 0.037170444, -0.032113522, 0.040590253, 0.034197565, -0.052367035, 0.024414606, -0.00389446, 0.029397584, -0.04863344, -0.060736425, -0.0046046595, -0.0051328074, -0.041981533, -0.028272893, 0.03145401, 0.033963047, 0.00011752055, -0.016511729, 0.0077202828, -0.016373662, 0.026422322, 0.005688145, 0.013610299, -0.030170707, -0.016066613, 0.00013214747, -0.025308384, 0.028646383, -0.05272596, 0.036238644, 0.047462955, 0.010372873, 0.0048962752, -0.0011887142, 0.01294205, 0.012808615, -0.0532572, -0.015943907, -0.012670166, -0.0024075098, 0.032932773, -0.010881956, -0.025620753, -0.018004222, 0.07873536, 0.030353501, 0.024689674, -0.018145649, -0.0681936, -0.01708387]], 'total_duration': 1672800400, 'load_duration': 1405770200, 'prompt_eval_count': 8}
  • curl命令http请求:

    curl -X POST http://localhost:11434/api/embed
    -H "Content-Type: application/json"
    -d '{"model": "bge-large", "input": ["你好,bge 模型!"]}'

3. 参考文献:

参见大模型:百川网页版 ,o1,ds

下载模型:

https://ollama.com/library

openai-translator:

https://github.com/openai-translator/openai-translator?tab=readme-ov-file

open-webui

https://github.com/open-webui/open-webui

bge表征模型部署与使用:

https://www.53ai.com/news/LargeLanguageModel/2024081185429.html

安装教程:

https://blog.csdn.net/engchina/article/details/136125933

https://www.cnblogs.com/WilliamB/p/18069441

相关推荐
weixin_387545641 分钟前
探索 GitHub Copilot:当 AI 成为你的贴身编码助手
人工智能·github·copilot
ZTLJQ3 分钟前
基于机器学习的三国时期诸葛亮北伐失败因素量化分析
人工智能·算法·机器学习
赵钰老师34 分钟前
【Deepseek、ChatGPT】智能气候前沿:AI Agent结合机器学习与深度学习在全球气候变化驱动因素预测中的应用
人工智能·python·深度学习·机器学习·数据分析
AIGC-Lison34 分钟前
【CSDN首发】Stable Diffusion从零到精通学习路线分享
人工智能·ai·stable diffusion·aigc·sd
AI绘画咪酱35 分钟前
Stable Diffusion|Ai赋能电商 Inpaint Anything
人工智能·ai·ai作画·stable diffusion·sd·ai教程·sd教程
ruokkk36 分钟前
Spring AI MCP 客户端实战:轻松连接高德地图等工具
人工智能
_一条咸鱼_37 分钟前
AI Agent 工作原理深入剖析
人工智能
飞哥数智坊39 分钟前
AI编程实战:数据大屏生成初探
人工智能
蚝油菜花40 分钟前
Cua:Mac用户狂喜!这个开源框架让AI直接接管你的电脑,快速实现AI自动化办公
人工智能·开源
蚝油菜花41 分钟前
AutoAgent:无需编程!接入DeepSeek用自然语言创建和部署AI智能体!港大开源框架让AI智能体开发变成填空题
人工智能·开源