3:本地部署大模型
·
1. 安装相关环境
1.1. 安装命令
docker run -d --name ollama -p 11434:11434 ollama/ollama
docker exec -it ollama ollama run llama3
docker exec -it ollama ollama run mxbai-embed-large
1.2. 安装过程
C:\Users\caimingyang>docker run -d --name ollama -p 11434:11434 ollama/ollama
Unable to find image 'ollama/ollama:latest' locally
latest: Pulling from ollama/ollama
20043066d3d5: Pull complete
f11123a9d5d2: Pull complete
079ea04de26f: Pull complete
6e77e15ec01d: Pull complete
Digest: sha256:4d1c3ff8badca57327c1eb35e1842f7a28f3578ef40c8488a58854e083f53a1b
Status: Downloaded newer image for ollama/ollama:latest
63cf1c2d403a72162cd16531b7ea675ef050a058919dd4ccca05a457e901aa39
C:\Users\caimingyang>docker exec -it ollama ollama run llama3
pulling manifest
pulling 6a0746a1ec1a: 100% ▕██████████████████████████████████████████████████████████▏ 4.7 GB
pulling 4fa551d4f938: 100% ▕██████████████████████████████████████████████████████████▏ 12 KB
pulling 8ab4849b038c: 100% ▕██████████████████████████████████████████████████████████▏ 254 B
pulling 577073ffcc6c: 100% ▕██████████████████████████████████████████████████████████▏ 110 B
pulling 3f8eb4da87fa: 100% ▕██████████████████████████████████████████████████████████▏ 485 B
verifying sha256 digest
writing manifest
success
C:\Users\caimingyang>docker exec -it ollama ollama run mxbai-embed-large
C:\Users\caimingyang>docker exec -it ollama ollama run mxbai-embed-large
pulling manifest
pulling 819c2adf5ce6: 49% ▕███████████████████████████████████████████████████████████████████████ ▏ 325 MB/669 MB 20 MB/s 16s
2. 使用这两个模型
2.1. llama3
C:\Users\caimingyang>docker exec -it ollama ollama run llama3
>>> 你是谁?
I'm just an AI, a computer program designed to simulate conversation and answer questions to the best of my ability. I'm not a human being, but rather a collection of algorithms and data structures that
process and generate text.
I was created by Meta AI, a company that specializes in natural language processing (NLP) and machine learning. My training is based on a massive corpus of text data, which allows me to understand and
respond to questions in a way that's similar to how humans communicate.
My primary function is to assist users with information and tasks, such as answering questions, providing definitions, summarizing texts, and even generating creative content like stories or poems. I'm
constantly learning and improving my abilities through user interactions and algorithmic updates.
So, while I'm not a human, I'm here to help you in any way I can!
>>> 使用中文回答这个问题
😊
我是一個 AI,計算機程序,用於模擬對話和回答問題。不是人類,但是一個算法和資料結構的集合,可以處理和生成文本。
我是 Meta AI 的一份子,這家公司專門研究自然語言處理(NLP)和機器學習。我的訓練基於龐大量的文字資料集,使得我能夠理解和回應問題,類似於人類交流。
我的主要任務是幫助使用者獲得信息和完成任務,如回答問題、提供定義、總結文本、甚至生成創作內容,如故事或詩歌。我經常學習和改進能力靠著用戶互動和算法更新。
因此,儘管我不是人類,但我仍然願意幫助你! 🤖
>>> 可以使用中文简体回答吗?
可以! 😊
我是一个 AI,计算机程序,用于模拟对话和回答问题。不是人類,但是是一個算法和数据结构的集合,可以处理和生成文本。
我是 Meta AI 的一员,这家公司专门研究自然语言处理(NLP)和机器学习。我们的训练基于大量文字数据集,使得我们能夠理解和回应问题,类似于人类交流。
我的主要任务是帮助使用者获取信息和完成任务,如回答问题、提供定义、总结文本、甚至生成创作内容,如故事或诗歌。我们经常学习和改进能力靠着用户互动和算法更新。
因此,虽然我不是人類,但是仍然愿意帮助你! 🤖
>>> 你认为百度和谷歌之间的区别是什么?我们之间所有的对话都采用中文简体回答
🤔
百度和谷歌这两个搜索引擎之间主要的差异有以下几点:
1. **语言**:百度主要聚焦于中国市场,而谷歌则可在全球多种语言中使用。
2. **搜索算法**:虽然两者都使用复杂的算法来排名搜索结果,但百度的算法更适合中国市场和其特有特征(例如,基于汉字输入)。
3. **内容偏好**:百度强调本地内容和来自中国网站,而谷歌则倾向于全球和国际来源。
4. **广告**:百度主要靠广告收入,强调显示广告和付费搜索结果,而谷歌则更关注付费点击(PPC)和搜索广告。
总的来说,百度和谷歌都是搜索引擎,但它们对搜索结果排名、内容偏好和广告模型等方面有所不同。
>>> 那你怎么看Youtube和哔哩哔哩呢
📹
YouTube 和哔哩哔哩(Bilibili)这两个视频分享平台之间的差异主要体现在以下几个方面:
1. **内容**: YouTube 主要聚焦于娱乐、音乐、电影等广泛的视频内容,而哔哩哔哩则更偏向于游戏、动画、科普等类型的内容。
2. **用户基础**:YouTube 的用户基础广泛,涵盖全球多个国家和地区,而哔哩哔哩则主要聚焦于中国市场和亚洲地区。
3. **视频风格**: YouTube 上的视频风格较为多样化,有各种类型的视频,如音乐演唱、电影剪辑等;而哔哩哔哩上的视频则更趋向于有创意和娱乐性,例如游戏直播、动画片段等。
4. **评论系统**:YouTube 的评论系统较为自由开放,而哔哩哔哩的评论系统则更加受限制,旨在维护平台的良好环境。
总的来说,YouTube 和哔哩哔哩都是视频分享平台,但它们的内容、用户基础和视频风格等方面有所不同。
2.2. mxbai-embed-large
C:\Users\caimingyang>docker exec -it ollama ollama run mxbai-embed-large "PostgreSQL 是一个非常强大的数据库"
[-0.000077419856,0.016234817,0.034392472,0.028154552,-0.02513302,-0.021789156,0.030146835,0.037717216,0.044279296,0.048613977,0.057834603,-0.016429499,-0.013210537,-0.0059083966,-0.046943847,-0.01800065,-0.024154166,-0.009959285,-0.066013336,0.03250951,0.0018954849,0.020894878,-0.08843847,-0.0042996486,-0.022839705,0.04201827,-0.023089424,-0.0043636183,0.097655185,0.07599349,-0.021704355,0.0051418412,0.00092891615,0.023249192,-0.00063465536,-0.0050292406,0.031939674,0.025482403,-0.0008640676,-0.030258518,0.025276527,0.01241161,0.033469748,-0.04319248,-0.09126506,-0.01417582,0.003860027,-0.0013782507,0.022473974,-0.025217589,-0.018053083,0.004629674,0.04201865,0.015765203,0.011293246,-0.0134825725,-0.008387658,0.0019002693,-0.039815444,0.041084692,0.009550697,-0.014234711,0.011571991,-0.04975869,0.0128262155,0.005773443,0.0073531484,-0.0438336,0.0167183,0.010125708,-0.028709259,0.0012389035,-0.01345525,0.005073531,-0.025976479,0.031024208,0.047115788,-0.011138135,-0.045537364,0.018250726,-0.029328333,0.01682984,0.041152917,0.014698725,-0.016869074,-0.025738766,-0.024201425,0.032106947,-0.01231239,-0.017560735,-0.014784631,0.020639138,0.053156015,0.005014816,-0.015815005,0.049589455,-0.0032702389,-0.0060774013,0.02725788,0.0011210158,0.0074037123,0.016677193,-0.010896493,0.022587424,0.024807164,0.021132395,0.0040039606,0.04010505,-0.03326825,-0.01693323,-0.03526918,-0.023480844,0.0044795913,0.005586533,0.0070232567,0.011502507,-0.02282442,0.02762058,-0.02812252,-0.037884098,0.027022064,-0.014051869,0.03551795,0.016790902,-0.0032512245,-0.051209543,0.0037107882,0.0154656265,-0.021766996,-0.011638902,-0.0016817524,-0.022216186,0.0047369017,-0.024923045,0.036045298,0.013298583,-0.04398766,0.0067602172,0.026092708,-0.049644813,0.01921509,-0.016953941,-0.021153653,0.053706415,-0.0077076955,0.060199432,0.03689823,-0.009787424,-0.023264326,0.060267817,-0.018756036,-0.021227617,-0.04229644,0.0020725331,0.01692657,0.004447983,0.00040375174,-0.020433346,0.00947573,0.04095674,-0.013373845,-0.029009031,-0.011067979,0.0036063727,0.011013013,0.08560403,-0.030809741,0.0348184,-0.037022524,-0.017539833,0.01504084,0.006326884,-0.006064883,0.025402557,0.027834063,0.04875838,0.0067866184,-0.003379269,0.040341876,0.027072277,0.013624593,-0.003115548,0.018970396,0.022942333,0.053479314,0.02973707,-0.021743989,-0.008722491,-0.010404301,-0.021928921,0.0009993665,0.012308202,-0.014794759,0.03848825,-0.03385405,-0.012079653,-0.03263598,-0.02070515,-0.016415836,-0.028630413,-0.041490983,0.027003583,-0.001628579,0.029699914,0.021536706,-0.050245352,0.012744161,0.025848148,-0.046413913,-0.03374428,0.029056514,-0.008316605,-0.0067618354,-0.0231698,-0.034592297,-0.01591624,-0.059944417,0.044626947,-0.0050724084,0.02203072,0.009299475,0.057926297,0.02366766,0.0230301,0.011706863,-0.027604587,0.013367996,0.027909702,-0.005954926,0.05793615,0.0072637964,0.03669599,0.013623404,0.0218989,0.025504652,-0.019275652,0.031198813,0.058708873,0.014560489,0.06270031,-0.0023503006,-0.004855693,0.004791575,-0.033763733,-0.0071045747,0.023318626,0.019223982,-0.004808253,-0.00633376,0.05001895,0.006235637,0.064353265,-0.0033917138,0.017182019,0.00526664,-0.006765956,0.051052373,-0.0013715391,-0.048450686,0.004084473,0.0087437285,0.018044809,-0.03375237,0.014226058,0.000019622934,-0.015061573,0.018865995,0.008776818,-0.010023702,0.002240745,0.022689603,-0.0061610816,0.019181043,-0.02395942,-0.059274495,-0.03266353,-0.0009827367,0.012129412,-0.003153049,0.027978864,0.023412056,-0.025750613,-0.012506912,0.047935925,0.030200835,-0.0010968458,-0.050037816,-0.017051714,0.027443605,0.05072592,-0.020126607,0.024902018,0.016049834,0.015380193,-0.011048825,-0.01140101,-0.03002942,0.0026096653,0.014241395,-0.058541268,-0.024048602,-0.0006476495,-0.03279008,-0.0052773403,-0.023920016,0.03872726,0.01448508,0.007254704,0.017419752,0.02753651,-0.026417026,-0.021864714,0.015508997,0.031390548,-0.059617985,0.026849639,0.022241052,-0.0037186297,-0.041428115,-0.064052284,-0.017821679,-0.033880252,0.011575335,-0.03896295,-0.01739114,0.007198522,-0.009538944,-0.049407803,0.034366783,-0.017642563,-0.01586564,-0.041979313,-0.045139425,0.022096766,-0.01037223,-0.01844266,-0.010378171,0.0011244707,0.0385129,0.022368174,0.027290924,-0.02992405,-0.023715788,0.066352315,-0.011195445,-0.014723773,0.022853011,-0.014859158,-0.018539263,0.002929726,-0.028012633,-0.00010785435,0.03935246,0.03650594,-0.0004601117,0.03736745,0.020628793,0.03314059,0.0060978686,0.038101867,0.07542235,0.021602558,0.012805188,-0.005108094,-0.006940205,-0.06445095,-0.024542661,-0.010298213,0.008988364,-0.055157684,0.040944703,0.026649686,0.018957894,0.02131485,-0.037141223,-0.036404766,0.036428362,-0.0030598063,0.029166318,0.006051555,0.02224921,-0.0071851313,0.0012691778,0.059070397,0.0075408956,0.048856407,0.015391666,0.005686595,-0.03737954,-0.038408242,-0.010271086,-0.008244045,-0.0043256753,-0.040174734,-0.045404907,-0.040103834,0.021713026,0.03431962,-0.0047375937,0.00012204773,0.019164024,0.008099569,0.015769837,0.050179504,0.0003611284,-0.00046301837,-0.005347683,0.030751245,0.046041824,0.007834992,0.005185879,-0.0017396234,-0.050435502,0.011473616,-0.001229303,-0.009607563,-0.036357366,0.035046622,0.03499373,0.0066049676,0.002410423,-0.00932482,-0.030936651,0.0013379848,0.012141235,-0.027960263,-0.035469912,-0.060114067,0.027870823,0.053949684,0.00084097096,-0.059230752,-0.018142931,-0.0011566271,-0.041534714,0.036072154,0.06170442,-0.010430619,0.027081147,-0.05910171,0.0073451176,-0.031182332,0.033769153,-0.00014804205,0.0041659116,0.01293391,-0.013804271,0.015334591,0.02159502,-0.045061167,0.0047443537,-0.022034388,0.06658404,-0.009593882,-0.035643373,0.010574033,-0.020456104,0.023221819,0.019668754,0.0196805,0.0026647015,-0.01569261,0.008549105,0.0012035856,-0.019257095,0.042673588,-0.01156693,-0.010339918,-0.0059270095,0.0074639306,-0.03672329,0.054774065,0.027071394,-0.0045463564,0.012269752,-0.030619511,0.06519069,0.0036154133,-0.0028026223,-0.00820984,-0.0141104655,0.03198705,-0.004448593,0.010366824,-0.036154427,-0.111507654,-0.0047377707,0.00015312446,-0.023038913,0.022221357,-0.02837113,-0.026116949,0.034468517,-0.021593265,-0.015277682,0.008066045,-0.007519536,-0.03323831,0.016794914,0.0007763322,0.016152384,-0.028923139,-0.0674295,0.013001724,-0.004021268,0.0007369927,-0.05372834,0.007933374,0.025790693,0.0069051096,-0.05817133,-0.020137759,-0.03861514,-0.011942527,0.027828706,-0.0025038244,0.016328348,-0.02640644,-0.079231575,0.02512285,0.046265677,-0.02629912,-0.046145517,0.043298382,-0.039265305,0.046251286,0.0009978962,0.023596637,-0.03541267,-0.07459535,0.024663923,-0.037748568,-0.017817738,-0.046146818,-0.058591496,-0.01693364,-0.006316709,0.07981316,-0.032561887,-0.00043191164,-0.07223372,0.051371787,-0.04142477,0.014705712,-0.016491383,-0.009708594,-0.0127632385,0.055669613,-0.0026924764,0.026193447,0.0115062855,-0.012218227,0.03407691,0.048728727,-0.028425789,-0.021677164,0.019521408,-0.0054518534,0.0028656456,-0.040359072,-0.07459689,0.03591246,-0.04250577,-0.015354309,-0.02661131,0.027763871,-0.054279674,-0.0154901305,0.032096654,-0.016870638,0.006352841,0.003436287,0.06435447,0.020299558,0.006712817,-0.022613598,-0.029164035,-0.048197135,-0.055530217,0.028182944,-0.026602222,-0.0046324595,0.0050860583,0.010805924,0.022014743,-0.006200167,0.075793475,0.0943865,0.009934296,0.017183745,0.0036436203,0.015452549,0.049739733,-0.046355594,0.006452477,0.006037829,-0.012320325,-0.01685119,-0.040247954,-0.075354874,-0.022431292,-0.054109503,0.027618093,-0.01736396,0.021897314,-0.04656069,-0.004650133,-0.058129538,0.026433412,0.038944047,0.04875614,0.08363647,-0.027604861,-0.025324415,0.032215323,-0.0143621005,0.0065048384,-0.04768699,0.016798934,0.024508424,-0.05599682,0.04988365,0.0365839,-0.06628047,-0.0866433,0.0033958782,-0.054357197,0.014204628,-0.029474799,0.0063762576,-0.015212404,-0.01517328,-0.012385936,0.026276821,-0.016828394,0.025245419,0.02633047,-0.010897064,-0.028618168,-0.024031498,0.039001398,0.02562128,0.030499274,-0.07306257,-0.03715771,-0.028133847,0.031126343,0.041341245,0.024292957,0.012755737,0.02639908,0.043422747,0.0428388,-0.03407564,-0.019133149,-0.014181326,-0.023346093,-0.04685568,0.0011451812,-0.03658391,0.010514297,0.02839374,0.007977514,0.025637664,0.044391636,0.041191705,-0.012028109,-0.04290645,0.0025404196,-0.08571853,-0.035092615,-0.005370487,-0.017059317,-0.0004942231,0.012973643,0.015718607,-0.04959641,0.010563058,0.00868496,-0.06263304,0.03711913,-0.0114961695,0.009578719,-0.059095886,-0.050400242,-0.01278402,0.0116802845,-0.010096541,0.0207559,0.017709348,0.042252395,-0.007957317,-0.03305534,0.012763339,-0.0036754226,-0.022963353,-0.045160376,0.01577747,-0.006076434,-0.039119724,-0.006356984,-0.0008566007,0.019748509,0.0089687845,-0.010849749,-0.028410343,-0.07418476,-0.0048461314,-0.012807064,-0.019208698,-0.034630336,-0.049226645,0.01136548,-0.017219014,0.023673685,-0.039733775,-0.026391033,-0.023967272,-0.012632748,0.006049856,0.021291643,0.014578288,0.006642048,0.0019507383,0.000012746658,-0.0092053395,-0.011788972,0.02701246,0.00064410735,0.0017136766,0.028013535,0.0075547644,0.010702744,0.031644136,-0.0024968237,-0.04007313,-0.0077695367,-0.00824959,-0.023697201,0.012061454,0.038413692,-0.012358036,0.037786633,0.014805105,-0.035473395,-0.013152795,-0.03835731,-0.05697706,-0.023873568,0.032886863,-0.018061975,0.00064973405,-0.008871298,-0.055538237,0.012650158,0.040756736,0.006518479,-0.01617515,0.026993044,0.01780159,0.018155247,0.006322537,-0.01797336,0.03030085,0.019610455,-0.025634028,-0.043124884,0.023616312,-0.04956563,0.025437547,0.016653787,0.011724209,-0.012130457,-0.013458492,-0.033523098,0.012365386,0.026232991,-0.04160504,0.00093664415,-0.04172881,-0.00072300737,-0.08142243,0.017214967,0.032013293,-0.003865223,-0.036816742,0.023615608,0.031945277,0.008274957,0.027789919,0.05722977,-0.008868096,-0.013255751,-0.01966454,0.017364757,0.023235306,0.050056398,0.011123608,-0.04886339,-0.01724387,-0.0092663225,0.044368282,-0.0089546675,0.0067923483,0.024762366,0.018909646,0.05526569,0.026841884,-0.049065173,-0.022912607,-0.048925925,0.040617567,-0.008898072,-0.03345786,-0.002941291,-0.031515785,0.0023296324,-0.0012637755,-0.011333242,-0.036233842,-0.052241296,-0.011417476,0.036532424,-0.0241642,-0.0481709,0.01567393,-0.0067275474,0.006169525,0.007995855,0.005713992,0.04518113,-0.028672416,-0.010891659,-0.040158395,0.028374901,-0.043046813,-0.039965257,-0.014919637,0.0006029366,0.0105872145,0.030320756,0.017111752,-0.015119327,-0.024258573,-0.004527485,-0.011405021,0.004219146,0.021388898,0.017350357,0.02186466,0.032932516,0.024647797,-0.032521468,0.017389908,0.014574749,0.0867025,-0.022371119,0.020174142,0.06609116,-0.018454408,0.008292202,0.012675374,0.008805059,-0.040135346,-0.015699668,0.0093499785,-0.002520092,0.018298244,-0.04286272,0.024417982,0.016597122,0.011805299,-0.035969608,-0.00067424955,-0.0030675507,-0.04792215,0.047303297,0.071587905,0.0026867623,-0.009355939,0.013512888,-0.03766808,-0.007214305,0.05148401,-0.0150026595,0.03779449,0.007564829,-0.05943352,-0.0038295456,0.0067920084,-0.019014876,0.007038285,-0.009005821,-0.03634677,0.020926181,0.054293957,0.025108706,0.02876002,-0.04867454,0.02221968,-0.016167376,0.039949685,-0.0022530702,0.045805234,0.005501892,0.022263626,-0.01270224,0.012542406,0.007831191,0.0017988138,0.002553516,0.0082576675,-0.024923202,-0.01676697,-0.031715553,0.035080556,0.07363072,-0.0072122323,-0.0021062752,-0.035607487,-0.032705147,-0.039401002,-0.0283424,-0.04545564,0.00034055384,-0.020920726,-0.020229384,0.006495205,-0.043814596,0.19930919,0.06194025,0.039846808,-0.024627075,-0.009346872,0.018670728,-0.0115830535,-0.048984636,0.043816593,-0.051651392,0.027792579,0.006585775,-0.0042261,0.030137118,-0.015886594,0.04764536,-0.061149973,0.017189229,0.019733215,-0.07331147,-0.036580034,0.0071310694,0.019759458,0.036411263,-0.012281456,0.008948613,0.0155986445,-0.03959009,-0.0041164025,0.0003279704,0.018250205,-0.0020539071,-0.008753851,0.023425978,-0.009265654,0.010238815,-0.029081786,-0.019133164,0.026649749,0.03338813,0.04499197,-0.0021694521,-0.023926236,-0.018961396,0.024419686,0.024061963,-0.019685727,0.043797363,0.028729348,-0.0063831317,0.01648007,-0.0034957724,0.040852882,-0.06305535,-0.05022138,-0.01237162,-0.016203722,-0.015119301,0.0047725947,0.09377045,0.0060203937,0.014682639,-0.005635808,0.0006276164,0.037981894,0.052322496,-0.011696041,0.016946744,0.002433995,0.009740752,0.039496407,-0.053902566,0.025860958,-0.031119486,-0.0031137029,0.028049832,-0.05584918,0.00942494,-0.044749115,0.006227939,0.030494347,-0.017097164,-0.008336114,-0.0075001135,-0.010787451,0.017683957,-0.020058468,-0.009652502,-0.018375397,0.025325691,0.022271495,0.058663607,-0.05589523,-0.03746168,0.010563908]
C:\Users\caimingyang>docker exec -it ollama ollama run mxbai-embed-large "MySQL 是一个非常强大的数据库"
[-0.021849979,-0.013969537,0.009450908,0.03287568,-0.002826986,-0.0062305816,0.02434385,0.021741688,0.015115986,0.070190705,0.06447581,0.034228228,-0.0052713337,0.0023661698,-0.08712944,-0.011688458,-0.007648668,-0.012566442,-0.073292844,0.055066835,0.027002526,0.019666456,-0.08315262,0.0010420788,-0.03621679,0.027438985,-0.010081028,-0.026041312,0.059649877,0.09789327,-0.051401313,-0.016771708,0.0035688027,0.018617716,-0.00086835417,0.0022887078,0.015453723,0.031766564,-0.0063867024,-0.03855901,-0.0042594345,0.01857888,0.031072589,-0.035101872,-0.083814785,0.013077309,-0.0068225297,0.005389085,0.031295452,-0.020063559,-0.026228098,-0.012585626,0.027067093,0.03816093,0.007054769,-0.029618965,0.00094835093,-0.0040175524,-0.04801028,0.052597936,0.014362916,-0.018153086,0.024334133,-0.050052986,0.010161814,-0.002909825,0.0037099724,-0.03545962,0.032859996,-0.008800086,-0.015767932,0.008902343,-0.01679539,-0.012299409,-0.04340711,0.03794043,0.037991147,-0.02267108,-0.045133807,0.016650932,-0.045669135,0.038380552,0.047733005,-0.0027251309,-0.028197385,-0.003800271,-0.046635717,0.027650425,-0.028850753,-0.00044417003,-0.01359683,0.017591808,0.030049298,0.007478574,0.0134425415,0.043067344,-0.0031059887,0.02663241,0.0033174108,-0.006228433,0.018961163,0.008387798,-0.0022534423,0.011275109,0.015657574,0.014838284,-0.013849109,0.05231084,-0.013839952,-0.021877272,-0.009459537,-0.037780683,0.003195746,0.023857035,-0.02001952,0.0048449985,-0.00854609,0.04371371,-0.04076716,-0.02780631,0.033516504,0.0021409153,-0.007936018,0.0064717485,-0.02033789,-0.04221901,-0.0055674147,0.024144052,-0.019338928,-0.01707101,-0.0098366905,-0.022256166,0.02753863,0.0032622295,0.014867336,0.0013271533,-0.025793213,0.020307712,0.045699794,-0.023463022,0.031599358,-0.017280374,-0.009533444,0.04318225,-0.019988105,0.07772677,-0.0004464572,0.010568322,-0.024361547,0.039117448,-0.031508017,-0.025376575,-0.011194124,-0.0140323015,0.03220344,-0.005100097,0.0133020235,-0.01653007,0.019083988,0.023733148,-0.01603677,-0.0026097842,-0.0070568104,-0.0069603687,0.0143179335,0.051291775,-0.047785826,0.0241365,-0.02919206,-0.015437113,0.016128406,-0.0220755,0.0027776163,0.024299676,0.013913216,0.0653033,-0.0122260135,-0.0023891742,0.03736022,0.011561193,-0.02053917,0.008706495,-0.00007271623,0.01672549,0.04498988,-0.0030802386,0.0045046397,0.004170429,-0.0352302,0.005704109,0.023550732,0.023279382,-0.034501005,0.019823547,-0.044286054,-0.024307502,-0.030176485,0.0035098132,0.004624069,-0.020113377,-0.041814264,-0.00096449186,0.005055689,-0.0012584821,0.021034995,-0.06182639,0.017670482,0.04446126,-0.0449246,-0.009778018,0.0057928446,-0.012136988,0.008109055,-0.026811475,-0.019323574,-0.00088727614,-0.036969773,0.02214501,-0.031805594,0.033270232,0.011152557,0.06940574,0.04006893,0.0063343723,-0.00071040523,-0.010314928,-0.004547482,0.03744578,-0.008850321,0.03641371,0.01674815,0.0059343493,0.015840631,0.0061711203,0.026077334,-0.01367481,0.03736596,0.08643452,0.032392774,0.06363376,0.012119104,0.017020758,0.022459377,-0.020236023,-0.012085942,0.011115183,0.062038172,0.009332303,0.0070963744,0.02737706,0.023082824,0.07724644,0.015402948,0.010720641,-0.00006303485,0.013124958,0.014956273,0.004975737,-0.0547302,-0.018409038,-0.00674783,0.001846917,0.004337217,0.0069665466,0.008750604,-0.040624943,0.026736053,-0.004950427,-0.0019887444,-0.02262494,0.003529494,-0.022936657,-0.0033021434,-0.019126967,-0.02632939,-0.03058675,-0.0023193322,0.03853473,-0.0023573653,0.03350787,0.031063892,-0.031549893,-0.028276527,0.03841787,0.010910185,-0.00009271963,-0.041810706,-0.026817624,0.0190865,0.05824815,-0.012377607,0.009052435,0.018501779,0.015329575,-0.039291,-0.0072232066,-0.017435828,0.020649014,0.0045376676,-0.067648046,-0.0022175475,-0.007900814,-0.033149514,-0.006686154,-0.017586982,0.011539263,-0.00030394067,0.011643823,0.018816838,0.02842182,-0.021809831,-0.021871865,0.017993951,0.013533864,-0.055869702,0.008184601,0.012322642,0.016152754,-0.04044841,-0.06469906,-0.02066804,-0.017432265,0.011028364,-0.038474727,-0.0048441687,0.008504261,-0.0084290635,-0.0659759,0.0032287093,-0.03236602,-0.012202122,-0.0290579,-0.032169525,0.021073192,-0.013142208,0.00055582816,-0.005247212,-0.0101003945,0.04568627,0.009457,0.04724367,-0.012607378,-0.025054134,0.056891646,-0.00745806,-0.02267372,0.007931762,-0.01447007,-0.032110553,0.0026748537,-0.03856557,-0.011396075,0.033302356,0.020758895,-0.011691516,0.053283256,0.0135263335,0.039909523,0.035277884,0.04929626,0.08140513,-0.0045068427,-0.0019700334,-0.014444558,0.019520367,-0.06536667,0.0012590697,0.010918317,0.019879997,-0.049918864,0.05836817,0.027743971,0.026636008,0.020962108,-0.02030221,-0.034502394,0.028228424,0.0017648016,0.029877832,-0.021929223,0.014610064,0.0070423903,0.02514335,0.06872847,0.029374039,0.055193845,-0.011327979,-0.044654083,-0.028845705,-0.023339214,-0.018120527,0.018387929,-0.023073403,-0.02365747,-0.044474754,-0.07994432,-0.0020100523,0.023482611,0.019232439,-0.017379249,0.009331861,0.0050401282,0.0217653,0.055285588,0.00039401697,0.005821429,0.020518504,0.03396738,0.055168144,0.006498977,-0.00801188,-0.0009173869,-0.026941447,0.001714875,-0.007043845,-0.020864101,-0.02961164,0.021593617,0.0039453106,0.009448376,0.003918831,-0.034399863,-0.020293951,-0.026527427,0.016362952,-0.057247408,-0.013718948,-0.047991928,0.04122579,0.03296147,0.021272259,-0.06128209,-0.037925985,-0.010955061,-0.038509093,0.016891211,0.063987575,-0.029372055,0.015402388,-0.02223356,-0.0024464875,-0.04058773,0.02700006,0.020902263,0.006568936,-0.0038823881,-0.0206827,0.021157835,-0.0027543292,-0.047774356,-0.022842579,-0.01842324,0.04737805,-0.007819155,-0.009362846,0.016932176,-0.049216498,0.019166468,0.0359308,0.022566156,0.0048087905,-0.022795971,-0.0135141285,0.015285053,-0.035998046,0.059684575,-0.01913854,-0.0027729487,-0.0068623335,0.013934928,-0.008816351,0.041360956,0.04835773,0.015294646,0.020354649,-0.02630949,0.045579497,0.005840893,0.009886366,-0.00010932021,-0.000027876706,0.034593005,-0.00015622743,0.02470935,-0.029804617,-0.08942817,-0.0025309913,0.019971713,-0.01090045,0.0052059786,-0.027876982,-0.028937355,-0.0007106216,0.0030658066,-0.027829234,0.008302438,-0.00728281,-0.023588812,-0.0072484086,0.005647247,0.04047161,-0.024795834,-0.05238972,0.016035818,0.0013919608,0.011423933,-0.04227529,-0.0110092005,0.06517301,-0.0023068422,-0.062196255,-0.015218073,-0.0543559,-0.022613712,0.03257867,0.0031122537,-0.025054183,-0.00085104967,-0.06835085,-0.014246664,0.06180037,-0.028728373,-0.03749413,0.033188127,-0.05506759,0.038356792,0.0013244352,0.013378314,-0.06577732,-0.06833939,0.035470344,-0.028009333,-0.030193929,-0.052667398,-0.04108061,-0.046120245,0.004956016,0.06907576,-0.023408547,0.011685076,-0.07769791,0.043912854,-0.017276255,0.000964587,-0.007582011,-0.042726934,-0.007151615,0.03276637,-0.011761844,0.04723664,-0.00009004274,-0.009380263,0.030348383,0.039725624,-0.033926487,-0.008403287,0.025529006,-0.0058236406,-0.022388251,-0.024832135,-0.07260358,0.010077752,-0.042962622,-0.023752237,-0.0018793538,0.01773128,-0.049875066,0.0009490346,0.021710625,-0.024078537,-0.0068413215,0.0006002123,0.08042732,-0.0033676762,-0.0020558762,-0.05681638,-0.03892085,-0.029927494,-0.027465468,0.04040014,-0.03223925,0.019562088,-0.014154282,0.008937749,0.009992813,0.0072801732,0.04550996,0.10099219,-0.010854562,0.029393308,-0.022631673,0.026455209,0.05720673,-0.05157581,0.037116263,0.043700796,-0.034145307,-0.016427616,-0.032159165,-0.06673587,-0.03941809,-0.045238446,0.011756032,-0.0052625267,0.030042803,-0.06218138,-0.036959037,-0.061297923,0.05600238,0.03558046,0.023238273,0.08833645,-0.015047274,-0.010126265,0.044043783,-0.008399442,0.012722105,-0.032893416,0.029640663,0.029091503,-0.03701053,0.059510473,0.043884315,-0.03787962,-0.09921563,-0.0032565338,-0.061516907,0.0069127544,-0.026947938,-0.011382671,-0.012369536,-0.011909421,-0.013604435,0.018153472,-0.011860572,0.00843858,-0.004232869,0.011829301,-0.023575393,-0.034749653,0.05482454,0.008501975,0.025166454,-0.05900701,-0.0191705,-0.017341143,0.036171515,0.040083695,0.026904946,0.03889733,0.043640748,0.027033275,0.04198476,-0.030335788,0.02504822,-0.006491642,-0.02282803,-0.033299502,-0.0036027187,-0.013895029,0.01444267,0.037994754,-0.015472144,0.026914693,-0.00069865386,0.014373755,-0.01929307,-0.036025647,0.015865255,-0.10102129,-0.025482869,-0.0017394692,0.014942174,-0.02083822,0.015919266,0.027020684,-0.06803944,-0.006656512,0.030064505,-0.019656572,0.0061490913,-0.014232986,0.0032213817,-0.05369691,-0.050088633,-0.014247606,0.036484204,-0.0068195187,-0.0016019264,0.022231432,0.023632467,0.0008019469,0.0013985491,-0.019159792,-0.010130842,-0.014524483,-0.0454523,0.04570333,0.015303776,-0.012183812,0.028660048,0.005470159,0.008079628,0.019627512,-0.021040164,-0.008556084,-0.05104407,0.0021414415,0.013352521,-0.02560721,-0.035440564,-0.049733583,0.006178521,-0.028895404,0.014293154,-0.01716329,-0.021735165,-0.017881993,-0.027956998,0.0029471,0.026178693,-0.0068849586,0.01363321,-0.004406243,-0.011134671,0.01617538,-0.002142722,0.02038359,0.022682788,0.013286923,0.016350754,-0.016369613,0.005949125,0.005295114,0.009435404,-0.01612152,-0.023809655,-0.038962424,-0.021067727,0.03611548,0.021880098,0.008695249,0.026396506,-0.020208996,-0.02860184,-0.013249673,-0.033562157,-0.059041947,-0.015477706,0.04292582,-0.038543604,-0.016518658,-0.013788144,-0.052437413,-0.0021226457,0.01507711,0.008290609,-0.016923822,0.02481212,0.011968863,0.008227337,0.0221276,-0.007962873,0.031454828,0.028249541,-0.014726791,-0.04937569,0.015915025,-0.021697963,0.015465507,-0.0013077246,0.011827319,-0.0044980706,0.0052497042,0.00027330744,0.017204797,0.031491093,-0.013250332,-0.009910232,-0.013031174,0.026598478,-0.09001251,0.01387551,0.021299139,0.011657393,-0.018561779,-0.01303944,0.03861145,0.009025032,0.04191739,0.047404163,-0.002190731,0.013630558,-0.0035771795,-0.006512618,0.019075058,0.042911988,0.013494235,-0.035903417,-0.021321896,0.027764084,0.05239387,-0.0035947592,0.05377002,-0.002099977,-0.0063789035,0.061793856,0.027335517,-0.037272096,-0.018842248,-0.035002742,0.0177794,0.003541232,-0.025168031,-0.00026474195,-0.031770766,0.01424518,-0.022069892,-0.0040525845,-0.038870204,-0.046838805,-0.00846216,0.01631765,-0.028950572,-0.06761895,0.023957528,-0.009412435,0.030444056,0.022501905,0.0067484346,0.0579694,-0.044414394,-0.002768252,-0.022715334,0.024207786,-0.02964415,-0.04208327,-0.0071958257,-0.023589479,0.0047428343,0.035046756,0.024733879,-0.00565569,-0.030744558,-0.017924007,0.007456994,0.010858305,0.011205618,0.032763753,0.024356745,0.024878338,0.023470774,-0.02578556,0.017996272,-0.017941188,0.06393932,-0.004609902,0.0069162413,0.044509087,-0.030179784,-0.014137578,0.01685077,0.020773591,-0.058411527,0.0043210494,0.001368524,0.0033443735,0.026530959,-0.04807667,0.037553668,0.0016417328,-0.01408896,-0.045214355,-0.015521429,-0.0017067675,-0.030139163,0.03517759,0.040396877,0.015554358,0.021559795,0.011154166,-0.021525305,0.018156666,0.067870595,-0.011493211,0.011299451,-0.01858037,-0.0522468,-0.010566827,0.01821484,-0.035806503,0.023393314,-0.016877057,-0.043685276,0.02260328,0.07232558,0.05236405,0.013699101,-0.041615218,0.0071084085,-0.017873118,0.024596944,-0.020625552,0.069424994,0.014384958,0.017111782,-0.025037048,0.03998269,0.008289277,0.023130331,-0.026408559,0.0040086987,-0.024671692,-0.022582352,-0.023437375,0.037263557,0.060003497,0.0128142545,-0.0068656974,-0.02596989,-0.0586652,-0.04386201,-0.009809424,-0.055661555,0.035613514,-0.034422554,-0.042643,0.013003067,-0.03042967,0.19670637,0.027993478,0.03892097,-0.05294669,-0.010931201,0.015759937,-0.022061273,-0.016504133,0.014397192,-0.0429053,0.05475848,-0.013868307,0.008280652,0.026903497,-0.0015673697,0.020757753,-0.039967977,0.024415566,0.032864213,-0.06836836,-0.027098637,0.0075701936,0.018151745,0.03421849,-0.011651517,-0.014435046,0.053117886,-0.050689183,0.006624736,-0.02775484,0.029822461,-0.011106165,0.023035323,0.022830691,-0.038686495,0.0100583965,-0.015992515,-0.012530534,0.0071336553,0.040040895,0.023681998,-0.0032928614,-0.00045044278,-0.0199224,0.021747187,0.029393913,-0.01941109,0.046673007,0.0037679614,-0.00959635,0.029413665,0.0053230575,0.04681836,-0.08180264,-0.061233845,0.0058097523,-0.012228732,-0.016646655,-0.009847249,0.0814307,-0.010211455,0.047537453,-0.035079382,0.003499372,0.011469143,0.026496042,-0.018728936,0.020333083,0.0009871172,0.0025839217,0.04134713,-0.038938217,0.0076174554,-0.045143962,-0.023066789,0.033880703,-0.047538705,0.03320174,-0.031195544,0.006774797,0.028724685,-0.024886727,-0.025343813,-0.04829715,-0.022021804,0.032309655,-0.023703497,-0.003529664,-0.018242678,0.018027404,0.03773523,0.05314418,-0.039733663,-0.0047858665,0.021997198]
2.2.1. 计算两个值的相似度
import json
import math
import urllib.request
OLLAMA_URL = "http://localhost:11434/api/embeddings"
MODEL = "mxbai-embed-large"
def get_embedding(text: str) -> list[float]:
"""
调用 Ollama embedding 接口,返回向量数组
"""
data = json.dumps({
"model": MODEL,
"prompt": text
}).encode("utf-8")
req = urllib.request.Request(
OLLAMA_URL,
data=data,
headers={"Content-Type": "application/json"}
)
with urllib.request.urlopen(req) as resp:
result = json.loads(resp.read().decode("utf-8"))
return result["embedding"]
def cosine_similarity(v1: list[float], v2: list[float]) -> float:
"""
计算余弦相似度
"""
dot_product = sum(a * b for a, b in zip(v1, v2))
norm_v1 = math.sqrt(sum(a * a for a in v1))
norm_v2 = math.sqrt(sum(b * b for b in v2))
return dot_product / (norm_v1 * norm_v2)
if __name__ == "__main__":
text1 = "MySQL 是一个非常强大的数据库"
text2 = "PostgreSQL 是一个非常强大的数据库"
v1 = get_embedding(text1)
v2 = get_embedding(text2)
print(f"向量维度: {len(v1)}")
similarity = cosine_similarity(v1, v2)
print(f"余弦相似度: {similarity:.4f}")
文本1: MySQL 是一个非常强大的数据库
文本2: PostgreSQL 是一个非常强大的数据库
向量维度: 1024
余弦相似度: 0.8656
文本1: 小菜是优秀的程序员
文本2: PostgreSQL 是一个非常强大的数据库
向量维度: 1024
余弦相似度: 0.5369
3. 调用模型
3.1. 代码使用llama3本地模型
3.1.1. 调用核心代码
// 配置本地llama3大模型参数
const string platformName = "本地llama3大模型";
const string apiKey = ""; // 替换为您的API密钥
const string baseUrl = "http://127.0.0.1:11434/v1";
const string model = "llama3";
3.1.2. 调用效果
正在调用本地llama3大模型平台...
AI回复:
What a great sentence! ?? As an experienced teacher, I'd be happy to help you identify any Chinese-specific vocabulary that may not have been covered in your junior high school English textbooks.
After analyzing the sentence, I found a few words that might fit the bill:
1. uncharted (not commonly used in junior high school texts)
2. backwaters (not typically taught in junior high school)
3. Western Spiral arm of the Galaxy (this phrase is quite advanced and may not have been covered in junior high school English lessons)
I'll keep these words in mind, but if you'd like me to extract more, please let me know! ??
使用统计:
提示词令牌数: 129
完成令牌数: 135
总令牌数: 264
3.2. 再介绍要给智谱大模型
3.2.1. 调用核心代码
// 配置智谱大模型参数
const string platformName = "智谱大模型";
const string apiKey = "78db6cf7d01c4bfc90834fca11b3f216.7C0XwO3yXa9olUkV"; // 替换为您的API密钥
const string baseUrl = "https://open.bigmodel.cn/api/paas/v4";
const string model = "glm-4.5";
3.2.2. 调用效果
正在调用智谱大模型平台...
AI回复:
在这个句子中,超出中国初中英语教材范围的单词有:
- uncharted (原型: uncharted)
- backwater (原型: backwater,句中是复数形式backwaters)
- unfashionable (原型: unfashionable)
- spiral (原型: spiral,句中是大写开头的Spiral)
- galaxy (原型: galaxy,句中是大写开头的Galaxy)
- unregarded (原型: unregard)
使用统计:
提示词令牌数: 100
完成令牌数: 668
总令牌数: 768
D:\Code\CSharp\AI\LearnAIWithZack\LiveCode\FirstAICallWithHttpClient\bin\Debug\net9.0\FirstAICallWithHttpClient.exe (进程 62192)已退出,代码为 0 (0x0)。
要在调试停止时自动关闭控制台,请启用“工具”->“选项”->“调试”->“调试停止时自动关闭控制台”。
按任意键关闭此窗口. . .
更多推荐
所有评论(0)