Giter Site home page Giter Site logo

cloudflare-worker-ai-example's Introduction

CF-AI

Cloudflare recently introduced the ability to deploy AI on Worker. Although it is still in beta stage, it is already functional. The official documentation provides some examples, but they are not very detailed and do not allow passing parameters when using them. I made some modifications to enable passing JSON parameters in a POST request. Here is an example of how I used it, hoping it will be helpful to everyone.

  1. llama2-7b
curl -X POST https://worker-falling-sun-8cee.studyinglover.workers.dev/ -d '{"prompt":"Write a poem for my girlfriend"}'

response

[{"inputs":{"messages":[{"role":"system","content":"You are a helpful, kind, honest, friendly, good at writing and never fails to answer my requests immediately and with details and precision."},{"role":"user","content":"Write a poem for my girlfriend"}]},"response":{"response":"My dearest girlfriend, oh how I adore,\nThe way you make me feel, I can't ignore,\nYour smile, your laugh, your eyes so bright,\nMake my heart sing, and fill my life with light.\n\nIn your arms, I find my peaceful place,\nWhere I can be myself, and show my face,\nWith you by my side, I know I can face,\nAny challenge, with grace.\n\nYour kindness, love, and gentle touch,\nMake my heart skip a beat, and fill my soul with such,\nI'm grateful for each moment we share,\nAnd cherish every moment, with love and care.\n\nSo here's to you, my dearest girlfriend,\nThe one who brings me joy, and makes my life complete,\nForever and always, my love will be,\nYours, my heart, my everything, my sweet retreat."}}]
  1. embadding
curl -X POST https://worker-lively-bread-7ecc.studyinglover.workers.dev/ -d '{"text":"Write a poem for my girlfriend"}'

response

[{"inputs":{"shape":[1,768],"data":[[-0.001929550082422793,0.007866619154810905,-0.006432635243982077,0.016418294981122017,0.03844735026359558,0.03561463952064514,0.03520742803812027,0.029238354414701462,0.015689441934227943,-0.014042237773537636,0.03997594490647316,-0.024096865206956863,-0.045347802340984344,-0.015882166102528572,0.001899111201055348,0.048985324800014496,0.017608430236577988,0.01719832420349121,0.017801783978939056,-0.014953495003283024,0.02738932892680168,0.03026404045522213,-0.03115958906710148,0.019517231732606888,0.043421465903520584,-0.020341338589787483,0.04148756340146065,0.007809483911842108,-0.03543968126177788,-0.04145635664463043,-0.019821863621473312,-0.039904359728097916,-0.012828235514461994,-0.06021871045231819,-0.0233736764639616,0.019873788580298424,0.024157527834177017,0.029069572687149048,0.01570882461965084,-0.01866799034178257,-0.02768409065902233,-0.008794575929641724,0.030734527856111526,-0.02696041576564312,-0.014564159326255322,-0.007077849004417658,-0.011065879836678505,0.0407375693321228,0.022660227492451668,-0.036900196224451065,-0.03535282611846924,0.06128298491239548,0.04720475524663925,0.024565299972891808,-0.003986400552093983,0.0228179469704628,0.013278492726385593,-0.03423907235264778,-0.011423999443650246,-0.05967092514038086,0.013003791682422161,0.018345510587096214,-0.0005753297009505332,-0.02860509790480137,0.027574332430958748,0.03245356306433678,-0.046580810099840164,0.013531919568777084,-0.07553047686815262,-0.015130594372749329,0.011849658563733101,0.006697935052216053,0.01904630847275257,-0.005162132903933525,0.0019004375208169222,0.00688603101298213,-0.0004308612842578441,-0.0056296708062291145,0.02616531401872635,0.0014839083887636662,-0.014486121013760567,-0.006568253040313721,-0.022220583632588387,0.045066624879837036,0.002912195399403572,-0.019732683897018433,0.017659278586506844,0.04843788594007492,-0.06711535155773163,0.007767969276756048,0.017895903438329697,-0.041982267051935196,0.045817311853170395,0.026049207895994186,0.01736595667898655,-0.01929294317960739,0.03930700197815895,0.05772542208433151,0.031193861737847328,0.008290734142065048,-0.01112462393939495,-0.002219824120402336,0.0042087621986866,-0.07738855481147766,-0.07873137295246124,-0.011100511997938156,-0.05904116481542587,-0.026030054315924644,0.06816843897104263,-0.017301715910434723,0.017509108409285545,-0.00989614799618721,0.020693544298410416,0.00041885036625899374,-0.03862285241484642,0.045561283826828,0.023605939000844955,-0.0070046973414719105,-0.0755128264427185,0.0005228515947237611,0.0020585122983902693,-0.02994588203728199,0.06436872482299805,0.07141585648059845,0.005684145726263523,0.004978672601282597,0.01658584736287594,0.04745982587337494,-0.04584520682692528,-0.062049634754657745,0.014865254051983356,0.021868037059903145,-0.02387222647666931,-0.021272622048854828,0.03026331588625908,-0.05521554872393608,0.0037422990426421165,-0.039827410131692886,0.04666513577103615,0.03853503242135048,0.004931970965117216,0.03300967440009117,-0.009414032101631165,-0.02588948793709278,0.014044185169041157,0.006291735451668501,-0.01775665208697319,-0.04738502949476242,-0.003148372983559966,0.05216952785849571,-0.020586680620908737,0.01996639184653759,0.00012943735055159777,-0.0007298355340026319,-0.06702301651239395,0.04554710537195206,-0.003587550949305296,0.08629105240106583,0.0026355290319770575,0.0664437860250473,0.006419849116355181,-0.020717458799481392,-0.021237097680568695,0.05638597533106804,-0.03882596269249916,0.0011848144931718707,-0.024622289463877678,0.009828313253819942,-0.035495106130838394,-0.01839258335530758,-0.008117638528347015,-0.011773868463933468,0.00793920736759901,-0.013327691704034805,-0.026459025219082832,-0.010942414402961731,0.0742797926068306,0.013349439948797226,0.02050541341304779,0.04189649596810341,-0.09945140779018402,0.0659712553024292,0.018722299486398697,0.029026750475168228,-0.02611728385090828,-0.019768001511693,0.029668493196368217,0.05559943616390228,-0.05421609804034233,0.02852906472980976,-0.07661118358373642,-0.0538620762526989,0.012034416198730469,0.055472616106271744,0.048732366412878036,-0.0646497830748558,-0.0343833863735199,0.04471060261130333,0.004128493834286928,0.03416205197572708,-0.006909389514476061,-0.069733627140522,0.025325745344161987,-0.03036656230688095,-0.013292362913489342,0.026639776304364204,0.03939220681786537,-0.0023152988869696856,-0.02715197019279003,-0.028799181804060936,-0.03570796176791191,-0.005771193653345108,0.07689730823040009,-0.022817011922597885,-0.005908155348151922,-0.003458702238276601,0.03658661991357803,-0.05755608156323433,0.013844005763530731,-0.05588628351688385,0.023913739249110222,0.008228840306401253,0.00359390489757061,-0.02312939241528511,0.008658102713525295,0.0772482305765152,-0.02520112507045269,-0.07644445449113846,-0.030613262206315994,0.018433507531881332,-0.05340401455760002,-0.060394756495952606,-0.01827879063785076,0.033674195408821106,0.0279705747961998,0.12292461842298508,0.015017216093838215,-0.005781916435807943,0.048328496515750885,-0.06075703725218773,-0.019877664744853973,0.045938655734062195,0.03431330621242523,0.08502473682165146,-0.02476557344198227,0.008828100748360157,0.007983004674315453,-0.04548387601971626,-0.018695877864956856,0.011445203796029091,0.006487591192126274,-0.004213654901832342,-0.03412604704499245,0.058126356452703476,-0.004589206539094448,-0.04174031317234039,-0.02559451200067997,0.027563733980059624,0.06474387645721436,0.00005034376954426989,-0.06307981163263321,-0.031084103509783745,0.04389994964003563,0.022099198773503304,0.004355737008154392,-0.078322634100914,-0.03550591319799423,-0.01183287799358368,0.008953039534389973,-0.003911646548658609,0.054572366178035736,0.02531363070011139,0.04746986925601959,0.018930161371827126,0.008376913145184517,-0.003960369620472193,0.020832089707255363,-0.008204868994653225,-0.00809425301849842,-0.09841954708099365,0.02178194746375084,0.04082402586936951,-0.03371357545256615,-0.03860490024089813,-0.0024728497955948114,-0.057414814829826355,0.00380154512822628,-0.03037429228425026,-0.061569154262542725,0.01918989047408104,-0.009094499051570892,0.062012478709220886,0.007547762244939804,-0.0451250895857811,0.025181371718645096,0.02865334041416645,-0.027281945571303368,0.034278642386198044,0.010128116235136986,0.025268325582146645,0.022349918261170387,-0.02220962941646576,0.02901797741651535,0.029394708573818207,-0.0050874510779976845,0.0015883742598816752,-0.0010490419808775187,-0.007337829098105431,-0.19463776051998138,0.00985361635684967,-0.031811103224754333,-0.07071680575609207,0.03232761099934578,-0.000059781435993500054,-0.001480732811614871,-0.029802566394209862,-0.032573774456977844,-0.004021239932626486,-0.0516357421875,0.01631414145231247,0.012126121670007706,0.04138363152742386,0.002474280772730708,-0.04251604899764061,-0.043871913105249405,-0.07075747102499008,0.011138100177049637,-0.02166888676583767,0.0032893745228648186,-0.05998401716351509,-0.0349632203578949,0.03316083922982216,-0.011029540561139584,0.032513782382011414,-0.014201401732861996,-0.0008445729035884142,-0.03121219016611576,0.011461260728538036,0.003550381399691105,-0.004383763764053583,0.03987545892596245,0.047693151980638504,-0.04458518698811531,0.04556621238589287,0.03826843202114105,-0.005653838627040386,-0.0017240442102774978,-0.00848240964114666,-0.01774856075644493,-0.046024125069379807,-0.03983933851122856,-0.04205115884542465,0.03509574010968208,-0.03464636206626892,-0.019909940659999847,-0.005933858919888735,-0.0011199970031157136,0.046749651432037354,-0.04553334787487984,-0.03626349940896034,0.02383200079202652,-0.021180562674999237,0.019610797986388206,-0.027933776378631592,-0.011360961012542248,-0.00019220769172534347,-0.04320641607046127,-0.051387012004852295,0.018892444670200348,-0.04439936578273773,-0.026194380596280098,-0.03454303741455078,-0.015956075862050056,-0.0268742386251688,-0.018070602789521217,-0.03326338529586792,0.01576007716357708,0.04693683981895447,-0.024970579892396927,0.003035397967323661,-0.05811687931418419,-0.05194059759378433,-0.038006845861673355,-0.010109973140060902,-0.006091359071433544,-0.0008993893279694021,-0.020502189174294472,-0.00041268920176662505,-0.005022769793868065,-0.022577574476599693,-0.07376918941736221,0.01771664246916771,-0.030560478568077087,-0.07071010768413544,0.013688408769667149,-0.042330339550971985,-0.0502329058945179,-0.025271208956837654,0.03901313617825508,0.005849051754921675,-0.07246126234531403,0.027468912303447723,0.08019015938043594,0.023674188181757927,0.03825663775205612,0.016559937968850136,0.007088921498507261,-0.04920092970132828,0.0896860808134079,-0.02833482436835766,-0.007702982984483242,0.026730572804808617,0.017241602763533592,0.00021094732801429927,-0.104842409491539,0.020685233175754547,0.012708202004432678,-0.030965566635131836,-0.014468040317296982,-0.009452851489186287,0.07692421227693558,-0.08574140816926956,-0.03254193440079689,-0.05237117409706116,0.06940831989049911,0.03348255529999733,-0.00043360638665035367,0.011503714136779308,-0.009052013978362083,0.05405806377530098,-0.03484636917710304,-0.04776293784379959,-0.08793167769908905,0.0341380350291729,0.004322401713579893,-0.044577885419130325,0.006268535740673542,0.022026153281331062,0.03212941437959671,-0.05345245450735092,-0.020763257518410683,0.04597301036119461,0.010041058994829655,-0.023579318076372147,0.012497668154537678,-0.0593988336622715,-0.0037200364749878645,-0.00613166019320488,-0.0231754332780838,-0.012378605082631111,-0.005819797981530428,0.015497726388275623,0.046297769993543625,-0.01735738106071949,-0.02999827079474926,-0.0762721598148346,-0.01269228383898735,0.0017186292679980397,-0.022947249934077263,-0.03224814683198929,0.029609793797135353,-0.07789768278598785,-0.031631968915462494,-0.014433670789003372,0.008154241368174553,0.015366406179964542,0.007468261756002903,-0.003343387506902218,-0.04867997765541077,-0.08492805808782578,-0.011933949775993824,-0.01592175103724003,0.00830170139670372,0.02784019522368908,-0.005402695387601852,-0.0032191965728998184,-0.016229476779699326,0.014564281329512596,-0.02533041313290596,-0.02340911328792572,0.011972850188612938,0.01818850263953209,-0.04298771917819977,0.02038414217531681,-0.03241186961531639,0.017243606969714165,0.046411022543907166,0.03606076166033745,0.0192075464874506,-0.034712664783000946,0.0198987890034914,-0.004709732253104448,0.05353168398141861,-0.005680725444108248,0.027112731710076332,-0.050426989793777466,-0.007566980551928282,0.06912576407194138,-0.04343337565660477,0.0527857206761837,0.014209040440618992,0.037879228591918945,-0.021320538595318794,-0.07061223685741425,0.014540922828018665,0.008480243384838104,0.009286330081522465,-0.014144654385745525,0.048352137207984924,-0.03725297749042511,-0.025767194107174873,0.0024763878900557756,0.03431369364261627,-0.08346042037010193,0.050910644233226776,-0.00894893053919077,0.0031202107202261686,0.028722170740365982,-0.014475646428763866,-0.014157053083181381,0.015553372912108898,0.009037821553647518,0.03914234787225723,0.03644562512636185,-0.012723229825496674,-0.00373575440607965,0.008681355975568295,-0.01066470518708229,0.014172937721014023,-0.028126560151576996,-0.010320987552404404,0.025243762880563736,-0.004176632035523653,0.04380298778414726,-0.06495103985071182,-0.04144906997680664,-0.011830441653728485,-0.0008843990508466959,0.08096981793642044,0.0014963303692638874,0.02472650818526745,0.008936692029237747,0.01846235990524292,0.03546195104718208,0.029260115697979927,-0.009436995722353458,-0.007442880421876907,0.08690530806779861,0.03727152198553085,-0.006405607331544161,-0.05055391043424606,-0.023867517709732056,-0.012800898402929306,0.041222769767045975,-0.005434753373265266,-0.0020285022910684347,-0.030078114941716194,-0.034943729639053345,-0.012419980950653553,0.014290163293480873,0.013489954173564911,-0.0607701912522316,0.08783439546823502,-0.03625776991248131,-0.04452391341328621,0.05085689574480057,-0.02199559286236763,-0.03343811258673668,0.03064802661538124,0.006135032512247562,-0.02992182970046997,0.006188325118273497,0.05395495146512985,0.01792948879301548,0.030581222847104073,0.045247577130794525,0.02197589911520481,0.005379209760576487,0.034531254321336746,-0.07740313559770584,-0.019673455506563187,-0.06374149024486542,-0.004357800353318453,0.01766524463891983,-0.01991669274866581,0.02682904712855816,0.016369523480534554,-0.025640316307544708,0.026714494451880455,0.049199387431144714,-0.017287014052271843,0.0022267380263656378,0.02864610217511654,-0.022578060626983643,0.013917657546699047,-0.00784379243850708,-0.057886552065610886,0.01009491179138422,0.05709100514650345,0.03601941466331482,-0.024205155670642853,-0.004650856368243694,0.014637003652751446,0.0004320875450503081,0.02933534048497677,0.025078060105443,0.009006143547594547,0.008076396770775318,-0.04201618954539299,0.010075674392282963,0.03480871394276619,0.006961860693991184,-0.033274367451667786,0.036158643662929535,0.004247473087161779,-0.05769862234592438,0.03215949237346649,0.012022184208035469,-0.05871040001511574,-0.008806560188531876,0.04059038311243057,-0.0020235134288668633,-0.025671925395727158,-0.005351508967578411,0.01685752347111702,-0.03480511158704758,0.03969496116042137,0.021287307143211365,0.004453783389180899,-0.06105120852589607,0.06456248462200165,0.03080087900161743,0.010035838931798935,0.09124691784381866,-0.04848794266581535,0.00906162429600954,0.010074049234390259,0.043829064816236496,0.042722251266241074,0.08177772909402847,-0.0005342524382285774,0.08799494057893753,0.016042757779359818,-0.04811105132102966,0.012554442510008812,-0.007664289325475693,0.014059122651815414,0.02147490717470646,-0.021075256168842316,0.010446651838719845,0.018504636362195015,0.09579090029001236,0.034912291914224625,0.008504063822329044,0.013299677520990372,0.038107845932245255,0.011485729366540909,-0.015402424149215221,0.03508290648460388,0.05059107393026352,-0.03055194579064846,-0.014288325794041157,0.056192148476839066,-0.03775116428732872,0.0629790797829628,0.0015672051813453436,-0.02239685133099556,-0.0006945432396605611,-0.019123677164316177,0.04930087551474571,0.07196018099784851,-0.045474644750356674,-0.045371152460575104,-0.0023979174438863993,0.030492965131998062,0.035788483917713165,0.013892575167119503,0.017562909051775932,0.012540597468614578,0.021282415837049484,-0.027212008833885193,0.056097086519002914,-0.011971800588071346,0.012628038413822651,-0.007975725457072258,-0.027706865221261978,0.009076414629817009,0.015021812170743942,0.015597834251821041,0.003962099552154541,-0.06095850095152855,-0.0007547420100308955,-0.04620344191789627,-0.019642554223537445,-0.004912385251373053,-0.04201049357652664,-0.01964399591088295,-0.035253506153821945,0.0009638326009735465,0.0018558456795290112,0.017719758674502373,-0.021017851307988167,0.012761048972606659,-0.029255906119942665,0.037169333547353745,0.04066469520330429,-0.05032825469970703,0.01198516134172678,0.05218109115958214,-0.01219112053513527,-0.022439725697040558,-0.024718424305319786,0.017574302852153778,0.03671153262257576,0.011478611268103123,0.04089901223778725,-0.07179749757051468,-0.000558624102268368,0.047428473830223083,0.0142032066360116,-0.05947323143482208,-0.008795211091637611,-0.025837615132331848,-0.020788583904504776,0.06872990727424622,0.03655107691884041,0.024041714146733284,-0.005275265779346228,0.0034325644373893738,0.0122533505782485,0.04784011468291283,0.03200806304812431,-0.04339369013905525,0.028605163097381592,-0.011928457766771317,0.023502446711063385,0.022533489391207695,0.03818219155073166,0.008303762413561344,-0.040084660053253174,-0.02029380202293396,0.008731681853532791,-0.0018046695040538907,-0.04500259831547737,-0.048869792371988297,-0.031479690223932266,-0.02924424782395363,-0.03593647480010986,0.02623891830444336,-0.017340583726763725,0.02138623595237732,0.05505247786641121,-0.049903977662324905,-0.042055536061525345,-0.03729870170354843,-0.043843332678079605,-0.061918068677186966,0.02410283498466015,0.04286840930581093,-0.0321534126996994,-0.00021953822579234838,-0.03351743146777153,-0.04180692508816719,0.03794749826192856,-0.024175262078642845,-0.008869313634932041,-0.03209817409515381,0.02264823205769062]]}}]
  1. whisper(audio-link)
curl -X POST https://worker-wispy-star-8197.studyinglover.workers.dev/ -d '{       
    "audio_link": "https://github.com/Azure-Samples/cognitive-services-speech-sdk/raw/master/samples/cpp/windows/console/samples/enrollment_audio_katie.wav"
}'

response

{"text":" Hello, it is a good day for me to teach you the sound of my voice. You have learned what I look like now you can hear what I sound like. The sound of my voice will help the transcription service to recognize my unique voice in the future. Training will provide a better experience with greater accuracy when talking or dictating. Thank you and goodbye."}
  1. text-classification
curl -X POST https://worker-long-fire-2e44.studyinglover.workers.dev/ -d '{"text": "I like you"}'

response

{"inputs":{"text":"I like you"},"response":[{"label":"NEGATIVE","score":0.00013044140359852463},{"label":"POSITIVE","score":0.9998695850372314}]}
  1. translation
curl -X POST https://worker-cool-smoke-637e.studyinglover.workers.dev/ -d '{
    "text": "I like you",
    "source_lang": "en",
    "target_lang": "zh"
}'

response

{"inputs":{"text":"I like you","source_lang":"en","target_lang":"zh"},"response":{"translated_text":"我喜欢你"}}
  1. image-classification
curl -X POST https://worker-dawn-scene-db6f.studyinglover.workers.dev/ -d '{        
    "image_link": "https://cataas.com/cat"
}'

response

{"inputs":{"image":[]},"response":[{"label":"SWING","score":0.7907406687736511},{"label":"CALDRON","score":0.07133843749761581},{"label":"TABBY","score":0.06216946616768837},{"label":"LYNX","score":0.012759794481098652},{"label":"EGYPTIAN CAT","score":0.011273459531366825}]}

cloudflare-worker-ai-example's People

Contributors

studyinglover avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.