import{s as es,o as ts,n as Ot}from"../chunks/scheduler.65852ee5.js";import{S as ss,i as ls,g as p,s as a,r as o,A as as,h as r,f as s,c as n,j as Dt,u as m,x as i,k as jt,y as ns,a as l,v as u,d as c,t as h,w as M}from"../chunks/index.aa74147d.js";import{T as Kt}from"../chunks/Tip.bb8ccac8.js";import{D as ps,C as y}from"../chunks/DocNotebookDropdown.479f4286.js";import{H as Je,E as rs}from"../chunks/EditOnGithub.4eda6a96.js";function is(Te){let d,f="The generate endpoint is actually deprecated for Cohere, so it would be a phenomenal open-source contribution to create and commit an integration for the new Chat endpoint for Cohere’s API.";return{c(){d=p("p"),d.textContent=f},l(w){d=r(w,"P",{"data-svelte-h":!0}),i(d)!=="svelte-5yx0b"&&(d.textContent=f)},m(w,T){l(w,d,T)},p:Ot,d(w){w&&s(d)}}}function os(Te){let d,f="The authors mention that the sin scrubber is particularly prone to scrubbing things, so they apply it last to ensure that other number-related PII are scrubbed first";return{c(){d=p("p"),d.textContent=f},l(w){d=r(w,"P",{"data-svelte-h":!0}),i(d)!=="svelte-1ih2hi4"&&(d.textContent=f)},m(w,T){l(w,d,T)},p:Ot,d(w){w&&s(d)}}}function ms(Te){let d,f,w,T,U,je,$,Ue,I,Ut='<em>Authored by: <a href="https://github.com/asusevski" rel="nofollow">Anthony Susevski</a></em>',$e,g,$t="A common complaint around adopting LLMs for enterprise use-cases are those around data privacy; particularly for teams that deal with sensitive data. While open-weight models are always a great option and <em>should be trialed if possible</em>, sometimes we just want to demo things really quickly or have really good reasons for using an LLM API. In these cases, it is good practice to have some gateway that can handle scrubbing of Personal Identifiable Information (PII) data to mitigate the risk of PII leaking.",Ie,C,It='Wealthsimple, a FinTech headquartered in Toronto Canada, have <a href="https://github.com/wealthsimple/llm-gateway" rel="nofollow">open-sourced a repo</a> that was created for exactly this purpose. In this notebook we’ll explore how we can leverage this repo to scrub our data before making an API call to an LLM provider. To do this, we’ll look at a <a href="https://huggingface.co/datasets/ai4privacy/pii-masking-200k" rel="nofollow">PII Dataset from AI4Privacy</a> and make use of the <a href="https://cohere.com/blog/free-developer-tier-announcement" rel="nofollow">free trial api</a> for Cohere’s <a href="https://huggingface.co/CohereForAI/c4ai-command-r-plus" rel="nofollow">Command R+</a> model to demonstrate the Wealthsimple repo for PII Scrubbing.',ge,_,gt='To start, follow these instructions from the <a href="https://github.com/wealthsimple/llm-gateway" rel="nofollow">README</a> to install:',Ce,B,Ct="<li>Install Poetry and Pyenv</li> <li>Install pyenv install 3.11.3</li> <li>Install project requirements</li>",_e,k,Be,b,_t="<li>Run <code>cp .envrc.example .envrc</code> and update with API secrets</li>",ke,v,ve,E,Ee,x,xe,R,Bt="The wrapper obejct is a simple wrapper that applies “scrubbers” to the prompt before making the API call. Upon making a request with the wrapper, we are returned a response and a db_record object. Let’s see it in action before we dive into more specifics.",Re,V,Ve,Z,Ze,G,Ge,X,kt=`&#123;'data': ['Michael Smith made a mistake by using PyTorch Trainer instead of HF Trainer.'], 'return_likelihoods': None, 'meta': &#123;'api_version': &#123;'version': '1'}, 'billed_units': &#123;'input_tokens': 48, 'output_tokens': 14}}}
`,Xe,N,vt="The response returns the LLM output; in this case, since we asked the model to return a summary of an already short sentence, it returned the message:",Ne,Q,Et="<code>[&#39;Michael Smith made a mistake by using PyTorch Trainer instead of HF Trainer.&#39;]</code>",Qe,S,Se,W,xt=`&#123;'user_input': 'Michael Smith ([REDACTED EMAIL ADDRESS], (+1) [REDACTED PHONE NUMBER]) committed a mistake when he used PyTorch Trainer instead of HF Trainer.\\n\\nSummarize the above text in 1-2 sentences.', 'user_email': None, 'cohere_response': &#123;'data': ['Michael Smith made a mistake by using PyTorch Trainer instead of HF Trainer.'], 'return_likelihoods': None, 'meta': &#123;'api_version': &#123;'version': '1'}, 'billed_units': &#123;'input_tokens': 48, 'output_tokens': 14}}}, 'cohere_model': 'command-r-plus', 'temperature': 0.3, 'extras': '&#123;}', 'created_at': datetime.datetime(2024, 6, 10, 2, 16, 7, 666438), 'cohere_endpoint': 'generate'}
`,We,A,Rt="The second item returned is the database record. The repo is intended for use with a postgres backend; in fact, the repo comes with a full front-end built with Docker. The postgres database is to store the chat history for the gateway. However, it is also extremely helpful as it shows us what data was actually sent in each request. As we can see, the prompt was scrubbed and the following was sent:",Ae,H,Vt="<code>Michael Smith ([REDACTED EMAIL ADDRESS], (+1) [REDACTED PHONE NUMBER]) committed a mistake when he used PyTorch Trainer instead of HF Trainer.\\n\\nSummarize the above text in 1-2 sentences.</code>",He,F,Zt="But wait, I hear you thinking. Isn’t Michael Smith PII? Probably. But this repo does not actually implement a name scrubber. Below, we will investigate what scrubbers are applied to the prompt:",Fe,J,ze,z,Pe,P,Gt="From their repo, these are the scrubbers they implemented:",qe,q,Le,L,Xt="The gateway will apply each scrubber sequentially.",Ye,Y,Nt="This is pretty hacky, but if you really need to implement another scrubber, you can do that by modifying the wrapper’s method that calls the scrubber. Below we’ll demonstrate:",De,j,Ke,D,Oe,K,et,O,tt,ee,Qt=`&#123;'data': ['[REDACTED PERSON] made an error by using PyTorch Trainer instead of HF Trainer. They can be contacted at [RED'], 'return_likelihoods': None, 'meta': &#123;'api_version': &#123;'version': '1'}, 'billed_units': &#123;'input_tokens': 52, 'output_tokens': 25}}}
`,st,te,lt,se,St=`&#123;'user_input': '[REDACTED PERSON] ([REDACTED EMAIL ADDRESS], (+1) [REDACTED PHONE NUMBER]) committed a mistake when he used PyTorch Trainer instead of HF Trainer.\\n\\nSummarize the above text in 1-2 sentences.', 'user_email': None, 'cohere_response': &#123;'data': ['[REDACTED PERSON] made an error by using PyTorch Trainer instead of HF Trainer. They can be contacted at [RED'], 'return_likelihoods': None, 'meta': &#123;'api_version': &#123;'version': '1'}, 'billed_units': &#123;'input_tokens': 52, 'output_tokens': 25}}}, 'cohere_model': 'command-r-plus', 'temperature': 0.3, 'extras': '&#123;}', 'created_at': datetime.datetime(2024, 6, 10, 2, 59, 58, 733195), 'cohere_endpoint': 'generate'}
`,at,le,Wt="If you really have to do something like this, ensure you keep in mind that the scrubbers are applied sequentially, so if your custom scrubber interferes with any of the default scrubbers, there may be some odd behavior.",nt,ae,At='For example, for names specifically, there are <a href="https://github.com/kylemclaren/scrub" rel="nofollow">other scrubbing libraries</a> you can explore that employ more sophisitcated algorithms to scrub PII. This repo covers more PII such as <a href="https://github.com/kylemclaren/scrub/blob/master/scrubadubdub/scrub.py" rel="nofollow">ip addresses, hostnames, etc…</a>. If all you need is to remove specific matches, however, you can revert back to the above code.',pt,ne,rt,pe,Ht="Let’s explore this wrapper in action on a full dataset.",it,re,ot,ie,mt,oe,ut,me,Ft=`&#123;'data': ["The person is requesting an update on assessment results and is offering Kip 100,000 in exchange for the information and the recipient's account details."], 'return_likelihoods': None, 'meta': &#123;'api_version': &#123;'version': '1'}, 'billed_units': &#123;'input_tokens': 64, 'output_tokens': 33}}}
`,ct,ue,ht,ce,zt=`&#123;'user_input': "I need the latest update on assessment results. Please send the files to V[REDACTED EMAIL ADDRESS]. For your extra time, we'll offer you Kip 100,000 but please provide your лв account details.\\n\\nSummarize the above text in 1-2 sentences.", 'user_email': None, 'cohere_response': &#123;'data': ["The person is requesting an update on assessment results and is offering Kip 100,000 in exchange for the information and the recipient's account details."], 'return_likelihoods': None, 'meta': &#123;'api_version': &#123;'version': '1'}, 'billed_units': &#123;'input_tokens': 64, 'output_tokens': 33}}}, 'cohere_model': 'command-r-plus', 'temperature': 0.3, 'extras': '&#123;}', 'created_at': datetime.datetime(2024, 6, 10, 3, 10, 51, 416091), 'cohere_endpoint': 'generate'}
`,Mt,he,dt,Me,Pt="Here is what the summary would have looked like if we simply sent the text as is to the endpoint:",yt,de,wt,ye,ft,we,qt="To recap, in this notebook we demonstrated how to use an example Gateway for PII detection helpfully open-sourced by Wealthsimple and we built upon it by adding a custom scrubber. If you actually need reliable PII detection, ensure you run your own tests to verify that whatever scrubbing algorithms you employ actually cover your use-cases. And most importantly, wherever possible, deploying open-sourced models on infrastructure you host will always be the safest and most secure option for building with LLMs :)",Tt,fe,bt,be,Jt;return U=new ps({props:{classNames:"absolute z-10 right-0 top-0",options:[{label:"Google Colab",value:"https://colab.research.google.com/github/huggingface/cookbook/blob/milvus_refinements/notebooks/en/llm_gateway_pii_detection.ipynb"}]}}),$=new Je({props:{title:"LLM Gateway for PII Detection",local:"llm-gateway-for-pii-detection",headingTag:"h1"}}),k=new y({props:{code:"YnJldyUyMGluc3RhbGwlMjBnaXRsZWFrcyUwQXBvZXRyeSUyMGluc3RhbGwlMEFwb2V0cnklMjBydW4lMjBwcmUtY29tbWl0JTIwaW5zdGFsbA==",highlighted:`brew <span class="hljs-keyword">install</span> gitleaks
poetry <span class="hljs-keyword">install</span>
poetry run pre-commit <span class="hljs-keyword">install</span>`,wrap:!1}}),v=new y({props:{code:"aW1wb3J0JTIwb3MlMEFmcm9tJTIwbGxtX2dhdGV3YXkucHJvdmlkZXJzLmNvaGVyZSUyMGltcG9ydCUyMENvaGVyZVdyYXBwZXIlMEFmcm9tJTIwZGF0YXNldHMlMjBpbXBvcnQlMjBsb2FkX2RhdGFzZXQlMEFpbXBvcnQlMjBjb2hlcmUlMEFpbXBvcnQlMjB0eXBlcyUwQWltcG9ydCUyMHJl",highlighted:`<span class="hljs-keyword">import</span> os
<span class="hljs-keyword">from</span> llm_gateway.providers.cohere <span class="hljs-keyword">import</span> CohereWrapper
<span class="hljs-keyword">from</span> datasets <span class="hljs-keyword">import</span> load_dataset
<span class="hljs-keyword">import</span> cohere
<span class="hljs-keyword">import</span> types
<span class="hljs-keyword">import</span> re`,wrap:!1}}),E=new y({props:{code:"Q09IRVJFX0FQSV9LRVklMjAlM0QlMjBvcy5lbnZpcm9uJTVCJTIyQ09IRVJFX0FQSV9LRVklMjIlNUQlMEFEQVRBQkFTRV9VUkwlMjAlM0QlMjBvcy5lbnZpcm9uJTVCJTBBJTIwJTIwJTIwJTIwJTIyREFUQUJBU0VfVVJMJTIyJTBBJTVEJTIwJTIwJTIzJTIwZGVmYXVsdCUyMGRhdGFiYXNlJTIwdXJsJTNBJTIwJTIycG9zdGdyZXNxbCUzQSUyRiUyRnBvc3RncmVzJTNBcG9zdGdyZXMlNDBwb3N0Z3JlcyUzQTU0MzIlMkZsbG1fZ2F0ZXdheSUyMg==",highlighted:`COHERE_API_KEY = os.environ[<span class="hljs-string">&quot;COHERE_API_KEY&quot;</span>]
DATABASE_URL = os.environ[
    <span class="hljs-string">&quot;DATABASE_URL&quot;</span>
]  <span class="hljs-comment"># default database url: &quot;postgresql://postgres:postgres@postgres:5432/llm_gateway&quot;</span>`,wrap:!1}}),x=new Je({props:{title:"LLM Wrapper",local:"llm-wrapper",headingTag:"h2"}}),V=new y({props:{code:"d3JhcHBlciUyMCUzRCUyMENvaGVyZVdyYXBwZXIoKQ==",highlighted:"wrapper = CohereWrapper()",wrap:!1}}),Z=new y({props:{code:"ZXhhbXBsZSUyMCUzRCUyMCUyMk1pY2hhZWwlMjBTbWl0aCUyMChtc21pdGglNDBnbWFpbC5jb20lMkMlMjAoJTJCMSklMjAxMTEtMTExLTExMTEpJTIwY29tbWl0dGVkJTIwYSUyMG1pc3Rha2UlMjB3aGVuJTIwaGUlMjB1c2VkJTIwUHlUb3JjaCUyMFRyYWluZXIlMjBpbnN0ZWFkJTIwb2YlMjBIRiUyMFRyYWluZXIuJTIy",highlighted:'example = <span class="hljs-string">&quot;Michael Smith (msmith@gmail.com, (+1) 111-111-1111) committed a mistake when he used PyTorch Trainer instead of HF Trainer.&quot;</span>',wrap:!1}}),G=new y({props:{code:"cmVzcG9uc2UlMkMlMjBkYl9yZWNvcmQlMjAlM0QlMjB3cmFwcGVyLnNlbmRfY29oZXJlX3JlcXVlc3QoJTBBJTIwJTIwJTIwJTIwZW5kcG9pbnQlM0QlMjJnZW5lcmF0ZSUyMiUyQyUwQSUyMCUyMCUyMCUyMG1vZGVsJTNEJTIyY29tbWFuZC1yLXBsdXMlMjIlMkMlMEElMjAlMjAlMjAlMjBtYXhfdG9rZW5zJTNEMjUlMkMlMEElMjAlMjAlMjAlMjBwcm9tcHQlM0RmJTIyJTdCZXhhbXBsZSU3RCU1Q24lNUNuU3VtbWFyaXplJTIwdGhlJTIwYWJvdmUlMjB0ZXh0JTIwaW4lMjAxLTIlMjBzZW50ZW5jZXMuJTIyJTJDJTBBJTIwJTIwJTIwJTIwdGVtcGVyYXR1cmUlM0QwLjMlMkMlMEEpJTBBJTBBcHJpbnQocmVzcG9uc2Up",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>response, db_record = wrapper.send_cohere_request(
<span class="hljs-meta">... </span>    endpoint=<span class="hljs-string">&quot;generate&quot;</span>,
<span class="hljs-meta">... </span>    model=<span class="hljs-string">&quot;command-r-plus&quot;</span>,
<span class="hljs-meta">... </span>    max_tokens=<span class="hljs-number">25</span>,
<span class="hljs-meta">... </span>    prompt=<span class="hljs-string">f&quot;<span class="hljs-subst">{example}</span>\\n\\nSummarize the above text in 1-2 sentences.&quot;</span>,
<span class="hljs-meta">... </span>    temperature=<span class="hljs-number">0.3</span>,
<span class="hljs-meta">... </span>)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-built_in">print</span>(response)`,wrap:!1}}),S=new y({props:{code:"cHJpbnQoZGJfcmVjb3JkKQ==",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-built_in">print</span>(db_record)',wrap:!1}}),J=new Kt({props:{warning:!1,$$slots:{default:[is]},$$scope:{ctx:Te}}}),z=new Je({props:{title:"Scrubbers!",local:"scrubbers",headingTag:"h2"}}),q=new y({props:{code:"QUxMX1NDUlVCQkVSUyUyMCUzRCUyMCU1QiUwQSUyMCUyMCUyMCUyMHNjcnViX3Bob25lX251bWJlcnMlMkMlMEElMjAlMjAlMjAlMjBzY3J1Yl9jcmVkaXRfY2FyZF9udW1iZXJzJTJDJTBBJTIwJTIwJTIwJTIwc2NydWJfZW1haWxfYWRkcmVzc2VzJTJDJTBBJTIwJTIwJTIwJTIwc2NydWJfcG9zdGFsX2NvZGVzJTJDJTBBJTIwJTIwJTIwJTIwc2NydWJfc2luX251bWJlcnMlMkMlMEElNUQ=",highlighted:`ALL_SCRUBBERS = [
    scrub_phone_numbers,
    scrub_credit_card_numbers,
    scrub_email_addresses,
    scrub_postal_codes,
    scrub_sin_numbers,
]`,wrap:!1}}),j=new Kt({props:{warning:!1,$$slots:{default:[os]},$$scope:{ctx:Te}}}),D=new y({props:{code:"ZGVmJTIwbXlfY3VzdG9tX3NjcnViYmVyKHRleHQlM0ElMjBzdHIpJTIwLSUzRSUyMHN0ciUzQSUwQSUyMCUyMCUyMCUyMCUyMiUyMiUyMiUwQSUyMCUyMCUyMCUyMFNjcnViJTIwTWljaGFlbCUyMFNtaXRoJTIwaW4lMjB0ZXh0JTBBJTBBJTIwJTIwJTIwJTIwJTNBcGFyYW0lMjB0ZXh0JTNBJTIwSW5wdXQlMjB0ZXh0JTIwdG8lMjBzY3J1YiUwQSUyMCUyMCUyMCUyMCUzQXR5cGUlMjB0ZXh0JTNBJTIwc3RyJTBBJTIwJTIwJTIwJTIwJTNBcmV0dXJuJTNBJTIwSW5wdXQlMjB0ZXh0JTIwd2l0aCUyMGFueSUyMG1lbnRpb25zJTIwb2YlMjBNaWNoYWVsJTIwU21pdGglMjBzY3J1YmJlZCUwQSUyMCUyMCUyMCUyMCUzQXJ0eXBlJTNBJTIwc3RyJTBBJTIwJTIwJTIwJTIwJTIyJTIyJTIyJTBBJTIwJTIwJTIwJTIwcmV0dXJuJTIwcmUuc3ViKHIlMjJNaWNoYWVsJTIwU21pdGglMjIlMkMlMjAlMjIlNUJSRURBQ1RFRCUyMFBFUlNPTiU1RCUyMiUyQyUyMHRleHQlMkMlMjByZS5JR05PUkVDQVNFKQ==",highlighted:`<span class="hljs-keyword">def</span> <span class="hljs-title function_">my_custom_scrubber</span>(<span class="hljs-params">text: <span class="hljs-built_in">str</span></span>) -&gt; <span class="hljs-built_in">str</span>:
    <span class="hljs-string">&quot;&quot;&quot;
    Scrub Michael Smith in text

    :param text: Input text to scrub
    :type text: str
    :return: Input text with any mentions of Michael Smith scrubbed
    :rtype: str
    &quot;&quot;&quot;</span>
    <span class="hljs-keyword">return</span> re.sub(<span class="hljs-string">r&quot;Michael Smith&quot;</span>, <span class="hljs-string">&quot;[REDACTED PERSON]&quot;</span>, text, re.IGNORECASE)`,wrap:!1}}),K=new y({props:{code:"b3JpZ2luYWxfbWV0aG9kJTIwJTNEJTIwd3JhcHBlci5zZW5kX2NvaGVyZV9yZXF1ZXN0JTBBJTBBJTBBZGVmJTIwbW9kaWZpZWRfbWV0aG9kKHNlbGYlMkMlMjAqKmt3YXJncyklM0ElMEElMjAlMjAlMjAlMjBzZWxmLl92YWxpZGF0ZV9jb2hlcmVfZW5kcG9pbnQoa3dhcmdzLmdldCglMjJlbmRwb2ludCUyMiUyQyUyME5vbmUpKSUyMCUyMCUyMyUyMFVuZm9ydHVuYXRlJTIwZG91YmxlJTIwdmFsaWRhdGUlMjBjb2hlcmUlMjBlbmRwb2ludCUyMGNhbGwlMEElMjAlMjAlMjAlMjBwcm9tcHQlMjAlM0QlMjBrd2FyZ3MuZ2V0KCUyMnByb21wdCUyMiUyQyUyME5vbmUpJTBBJTIwJTIwJTIwJTIwdGV4dCUyMCUzRCUyMG15X2N1c3RvbV9zY3J1YmJlcihwcm9tcHQpJTBBJTIwJTIwJTIwJTIwa3dhcmdzJTVCJTIycHJvbXB0JTIyJTVEJTIwJTNEJTIwdGV4dCUwQSUyMCUyMCUyMCUyMHJldHVybiUyMG9yaWdpbmFsX21ldGhvZCgqKmt3YXJncyklMEElMEElMEElMjMlMjBBc3NpZ24lMjB0aGUlMjBuZXclMjBtZXRob2QlMjB0byUyMHRoZSUyMGluc3RhbmNlJTBBd3JhcHBlci5zZW5kX2NvaGVyZV9yZXF1ZXN0JTIwJTNEJTIwdHlwZXMuTWV0aG9kVHlwZShtb2RpZmllZF9tZXRob2QlMkMlMjB3cmFwcGVyKQ==",highlighted:`original_method = wrapper.send_cohere_request


<span class="hljs-keyword">def</span> <span class="hljs-title function_">modified_method</span>(<span class="hljs-params">self, **kwargs</span>):
    self._validate_cohere_endpoint(kwargs.get(<span class="hljs-string">&quot;endpoint&quot;</span>, <span class="hljs-literal">None</span>))  <span class="hljs-comment"># Unfortunate double validate cohere endpoint call</span>
    prompt = kwargs.get(<span class="hljs-string">&quot;prompt&quot;</span>, <span class="hljs-literal">None</span>)
    text = my_custom_scrubber(prompt)
    kwargs[<span class="hljs-string">&quot;prompt&quot;</span>] = text
    <span class="hljs-keyword">return</span> original_method(**kwargs)


<span class="hljs-comment"># Assign the new method to the instance</span>
wrapper.send_cohere_request = types.MethodType(modified_method, wrapper)`,wrap:!1}}),O=new y({props:{code:"cmVzcG9uc2UlMkMlMjBkYl9yZWNvcmQlMjAlM0QlMjB3cmFwcGVyLnNlbmRfY29oZXJlX3JlcXVlc3QoJTBBJTIwJTIwJTIwJTIwZW5kcG9pbnQlM0QlMjJnZW5lcmF0ZSUyMiUyQyUwQSUyMCUyMCUyMCUyMG1vZGVsJTNEJTIyY29tbWFuZC1yLXBsdXMlMjIlMkMlMEElMjAlMjAlMjAlMjBtYXhfdG9rZW5zJTNEMjUlMkMlMEElMjAlMjAlMjAlMjBwcm9tcHQlM0RmJTIyJTdCZXhhbXBsZSU3RCU1Q24lNUNuU3VtbWFyaXplJTIwdGhlJTIwYWJvdmUlMjB0ZXh0JTIwaW4lMjAxLTIlMjBzZW50ZW5jZXMuJTIyJTJDJTBBJTIwJTIwJTIwJTIwdGVtcGVyYXR1cmUlM0QwLjMlMkMlMEEpJTBBJTBBcHJpbnQocmVzcG9uc2Up",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>response, db_record = wrapper.send_cohere_request(
<span class="hljs-meta">... </span>    endpoint=<span class="hljs-string">&quot;generate&quot;</span>,
<span class="hljs-meta">... </span>    model=<span class="hljs-string">&quot;command-r-plus&quot;</span>,
<span class="hljs-meta">... </span>    max_tokens=<span class="hljs-number">25</span>,
<span class="hljs-meta">... </span>    prompt=<span class="hljs-string">f&quot;<span class="hljs-subst">{example}</span>\\n\\nSummarize the above text in 1-2 sentences.&quot;</span>,
<span class="hljs-meta">... </span>    temperature=<span class="hljs-number">0.3</span>,
<span class="hljs-meta">... </span>)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-built_in">print</span>(response)`,wrap:!1}}),te=new y({props:{code:"cHJpbnQoZGJfcmVjb3JkKQ==",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-built_in">print</span>(db_record)',wrap:!1}}),ne=new Je({props:{title:"Dataset",local:"dataset",headingTag:"h2"}}),re=new y({props:{code:"cGlpX2RzJTIwJTNEJTIwbG9hZF9kYXRhc2V0KCUyMmFpNHByaXZhY3klMkZwaWktbWFza2luZy0yMDBrJTIyKQ==",highlighted:'pii_ds = load_dataset(<span class="hljs-string">&quot;ai4privacy/pii-masking-200k&quot;</span>)',wrap:!1}}),ie=new y({props:{code:"cGlpX2RzJTVCJTIydHJhaW4lMjIlNUQlNUIzNiU1RCU1QiUyMnNvdXJjZV90ZXh0JTIyJTVE",highlighted:'pii_ds[<span class="hljs-string">&quot;train&quot;</span>][<span class="hljs-number">36</span>][<span class="hljs-string">&quot;source_text&quot;</span>]',wrap:!1}}),oe=new y({props:{code:"ZXhhbXBsZSUyMCUzRCUyMHBpaV9kcyU1QiUyMnRyYWluJTIyJTVEJTVCMzYlNUQlNUIlMjJzb3VyY2VfdGV4dCUyMiU1RCUwQSUwQXJlc3BvbnNlJTJDJTIwZGJfcmVjb3JkJTIwJTNEJTIwd3JhcHBlci5zZW5kX2NvaGVyZV9yZXF1ZXN0KCUwQSUyMCUyMCUyMCUyMGVuZHBvaW50JTNEJTIyZ2VuZXJhdGUlMjIlMkMlMEElMjAlMjAlMjAlMjBtb2RlbCUzRCUyMmNvbW1hbmQtci1wbHVzJTIyJTJDJTBBJTIwJTIwJTIwJTIwbWF4X3Rva2VucyUzRDUwJTJDJTBBJTIwJTIwJTIwJTIwcHJvbXB0JTNEZiUyMiU3QmV4YW1wbGUlN0QlNUNuJTVDblN1bW1hcml6ZSUyMHRoZSUyMGFib3ZlJTIwdGV4dCUyMGluJTIwMS0yJTIwc2VudGVuY2VzLiUyMiUyQyUwQSUyMCUyMCUyMCUyMHRlbXBlcmF0dXJlJTNEMC4zJTJDJTBBKSUwQSUwQXByaW50KHJlc3BvbnNlKQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>example = pii_ds[<span class="hljs-string">&quot;train&quot;</span>][<span class="hljs-number">36</span>][<span class="hljs-string">&quot;source_text&quot;</span>]

<span class="hljs-meta">&gt;&gt;&gt; </span>response, db_record = wrapper.send_cohere_request(
<span class="hljs-meta">... </span>    endpoint=<span class="hljs-string">&quot;generate&quot;</span>,
<span class="hljs-meta">... </span>    model=<span class="hljs-string">&quot;command-r-plus&quot;</span>,
<span class="hljs-meta">... </span>    max_tokens=<span class="hljs-number">50</span>,
<span class="hljs-meta">... </span>    prompt=<span class="hljs-string">f&quot;<span class="hljs-subst">{example}</span>\\n\\nSummarize the above text in 1-2 sentences.&quot;</span>,
<span class="hljs-meta">... </span>    temperature=<span class="hljs-number">0.3</span>,
<span class="hljs-meta">... </span>)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-built_in">print</span>(response)`,wrap:!1}}),ue=new y({props:{code:"cHJpbnQoZGJfcmVjb3JkKQ==",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-built_in">print</span>(db_record)',wrap:!1}}),he=new Je({props:{title:"Regular Output",local:"regular-output",headingTag:"h2"}}),de=new y({props:{code:"JTIwY28lMjAlM0QlMjBjb2hlcmUuQ2xpZW50KCUwQSUyMCUyMCUyMCUyMGFwaV9rZXklM0Rvcy5lbnZpcm9uJTVCJ0NPSEVSRV9BUElfS0VZJyU1RCUwQSUwQSUwQSUyMGVzcG9uc2VfdmFuaWxsYSUyMCUzRCUyMGNvLmdlbmVyYXRlKCUwQSUyMCUyMCUyMCUyMHByb21wdCUzRGYlMjIlN0JleGFtcGxlJTdEJTVDbiU1Q25TdW1tYXJpemUlMjB0aGUlMjBhYm92ZSUyMHRleHQlMjBpbiUyMDEtMiUyMHNlbnRlbmNlcy4lMjIlMkMlMEElMjAlMjAlMjAlMjBtb2RlbCUzRCUyMmNvbW1hbmQtci1wbHVzJTIyJTJDJTBBJTIwJTIwJTIwJTIwbWF4X3Rva2VucyUzRDUwJTJDJTBBJTIwJTIwJTIwJTIwdGVtcGVyYXR1cmUlM0QwLjM=",highlighted:` co = cohere.Client(
    api_key=os.environ[<span class="hljs-string">&#x27;COHERE_API_KEY&#x27;</span>]


 esponse_vanilla = co.generate(
    prompt=<span class="hljs-string">f&quot;<span class="hljs-subst">{example}</span>\\n\\nSummarize the above text in 1-2 sentences.&quot;</span>,
    model=<span class="hljs-string">&quot;command-r-plus&quot;</span>,
    max_tokens=<span class="hljs-number">50</span>,
    temperature=<span class="hljs-number">0.3</span>`,wrap:!1}}),ye=new y({props:{code:"cmVzcG9uc2VfdmFuaWxsYQ==",highlighted:"response_vanilla",wrap:!1}}),fe=new rs({props:{source:"https://github.com/huggingface/cookbook/blob/main/notebooks/en/llm_gateway_pii_detection.md"}}),{c(){d=p("meta"),f=a(),w=p("p"),T=a(),o(U.$$.fragment),je=a(),o($.$$.fragment),Ue=a(),I=p("p"),I.innerHTML=Ut,$e=a(),g=p("p"),g.innerHTML=$t,Ie=a(),C=p("p"),C.innerHTML=It,ge=a(),_=p("p"),_.innerHTML=gt,Ce=a(),B=p("ol"),B.innerHTML=Ct,_e=a(),o(k.$$.fragment),Be=a(),b=p("ol"),b.innerHTML=_t,ke=a(),o(v.$$.fragment),ve=a(),o(E.$$.fragment),Ee=a(),o(x.$$.fragment),xe=a(),R=p("p"),R.textContent=Bt,Re=a(),o(V.$$.fragment),Ve=a(),o(Z.$$.fragment),Ze=a(),o(G.$$.fragment),Ge=a(),X=p("pre"),X.textContent=kt,Xe=a(),N=p("p"),N.textContent=vt,Ne=a(),Q=p("p"),Q.innerHTML=Et,Qe=a(),o(S.$$.fragment),Se=a(),W=p("pre"),W.textContent=xt,We=a(),A=p("p"),A.textContent=Rt,Ae=a(),H=p("p"),H.innerHTML=Vt,He=a(),F=p("p"),F.textContent=Zt,Fe=a(),o(J.$$.fragment),ze=a(),o(z.$$.fragment),Pe=a(),P=p("p"),P.textContent=Gt,qe=a(),o(q.$$.fragment),Le=a(),L=p("p"),L.textContent=Xt,Ye=a(),Y=p("p"),Y.textContent=Nt,De=a(),o(j.$$.fragment),Ke=a(),o(D.$$.fragment),Oe=a(),o(K.$$.fragment),et=a(),o(O.$$.fragment),tt=a(),ee=p("pre"),ee.textContent=Qt,st=a(),o(te.$$.fragment),lt=a(),se=p("pre"),se.textContent=St,at=a(),le=p("p"),le.textContent=Wt,nt=a(),ae=p("p"),ae.innerHTML=At,pt=a(),o(ne.$$.fragment),rt=a(),pe=p("p"),pe.textContent=Ht,it=a(),o(re.$$.fragment),ot=a(),o(ie.$$.fragment),mt=a(),o(oe.$$.fragment),ut=a(),me=p("pre"),me.textContent=Ft,ct=a(),o(ue.$$.fragment),ht=a(),ce=p("pre"),ce.textContent=zt,Mt=a(),o(he.$$.fragment),dt=a(),Me=p("p"),Me.textContent=Pt,yt=a(),o(de.$$.fragment),wt=a(),o(ye.$$.fragment),ft=a(),we=p("p"),we.textContent=qt,Tt=a(),o(fe.$$.fragment),bt=a(),be=p("p"),this.h()},l(e){const t=as("svelte-u9bgzb",document.head);d=r(t,"META",{name:!0,content:!0}),t.forEach(s),f=n(e),w=r(e,"P",{}),Dt(w).forEach(s),T=n(e),m(U.$$.fragment,e),je=n(e),m($.$$.fragment,e),Ue=n(e),I=r(e,"P",{"data-svelte-h":!0}),i(I)!=="svelte-10g1t83"&&(I.innerHTML=Ut),$e=n(e),g=r(e,"P",{"data-svelte-h":!0}),i(g)!=="svelte-msdsl8"&&(g.innerHTML=$t),Ie=n(e),C=r(e,"P",{"data-svelte-h":!0}),i(C)!=="svelte-1acsyb0"&&(C.innerHTML=It),ge=n(e),_=r(e,"P",{"data-svelte-h":!0}),i(_)!=="svelte-1uh518a"&&(_.innerHTML=gt),Ce=n(e),B=r(e,"OL",{"data-svelte-h":!0}),i(B)!=="svelte-70jl22"&&(B.innerHTML=Ct),_e=n(e),m(k.$$.fragment,e),Be=n(e),b=r(e,"OL",{start:!0,"data-svelte-h":!0}),i(b)!=="svelte-1p91lr0"&&(b.innerHTML=_t),ke=n(e),m(v.$$.fragment,e),ve=n(e),m(E.$$.fragment,e),Ee=n(e),m(x.$$.fragment,e),xe=n(e),R=r(e,"P",{"data-svelte-h":!0}),i(R)!=="svelte-nmoklt"&&(R.textContent=Bt),Re=n(e),m(V.$$.fragment,e),Ve=n(e),m(Z.$$.fragment,e),Ze=n(e),m(G.$$.fragment,e),Ge=n(e),X=r(e,"PRE",{"data-svelte-h":!0}),i(X)!=="svelte-fgwnhs"&&(X.textContent=kt),Xe=n(e),N=r(e,"P",{"data-svelte-h":!0}),i(N)!=="svelte-hjvwqj"&&(N.textContent=vt),Ne=n(e),Q=r(e,"P",{"data-svelte-h":!0}),i(Q)!=="svelte-2gbnj8"&&(Q.innerHTML=Et),Qe=n(e),m(S.$$.fragment,e),Se=n(e),W=r(e,"PRE",{"data-svelte-h":!0}),i(W)!=="svelte-1obiiyg"&&(W.textContent=xt),We=n(e),A=r(e,"P",{"data-svelte-h":!0}),i(A)!=="svelte-196tu5x"&&(A.textContent=Rt),Ae=n(e),H=r(e,"P",{"data-svelte-h":!0}),i(H)!=="svelte-1jrlmt8"&&(H.innerHTML=Vt),He=n(e),F=r(e,"P",{"data-svelte-h":!0}),i(F)!=="svelte-1xq8mdu"&&(F.textContent=Zt),Fe=n(e),m(J.$$.fragment,e),ze=n(e),m(z.$$.fragment,e),Pe=n(e),P=r(e,"P",{"data-svelte-h":!0}),i(P)!=="svelte-e4th09"&&(P.textContent=Gt),qe=n(e),m(q.$$.fragment,e),Le=n(e),L=r(e,"P",{"data-svelte-h":!0}),i(L)!=="svelte-o1505i"&&(L.textContent=Xt),Ye=n(e),Y=r(e,"P",{"data-svelte-h":!0}),i(Y)!=="svelte-pky6il"&&(Y.textContent=Nt),De=n(e),m(j.$$.fragment,e),Ke=n(e),m(D.$$.fragment,e),Oe=n(e),m(K.$$.fragment,e),et=n(e),m(O.$$.fragment,e),tt=n(e),ee=r(e,"PRE",{"data-svelte-h":!0}),i(ee)!=="svelte-1ibz1w3"&&(ee.textContent=Qt),st=n(e),m(te.$$.fragment,e),lt=n(e),se=r(e,"PRE",{"data-svelte-h":!0}),i(se)!=="svelte-s3f3d0"&&(se.textContent=St),at=n(e),le=r(e,"P",{"data-svelte-h":!0}),i(le)!=="svelte-20zvgm"&&(le.textContent=Wt),nt=n(e),ae=r(e,"P",{"data-svelte-h":!0}),i(ae)!=="svelte-1xpcfov"&&(ae.innerHTML=At),pt=n(e),m(ne.$$.fragment,e),rt=n(e),pe=r(e,"P",{"data-svelte-h":!0}),i(pe)!=="svelte-1ghfd0h"&&(pe.textContent=Ht),it=n(e),m(re.$$.fragment,e),ot=n(e),m(ie.$$.fragment,e),mt=n(e),m(oe.$$.fragment,e),ut=n(e),me=r(e,"PRE",{"data-svelte-h":!0}),i(me)!=="svelte-1ap78y8"&&(me.textContent=Ft),ct=n(e),m(ue.$$.fragment,e),ht=n(e),ce=r(e,"PRE",{"data-svelte-h":!0}),i(ce)!=="svelte-45v8zv"&&(ce.textContent=zt),Mt=n(e),m(he.$$.fragment,e),dt=n(e),Me=r(e,"P",{"data-svelte-h":!0}),i(Me)!=="svelte-z0u4id"&&(Me.textContent=Pt),yt=n(e),m(de.$$.fragment,e),wt=n(e),m(ye.$$.fragment,e),ft=n(e),we=r(e,"P",{"data-svelte-h":!0}),i(we)!=="svelte-es6asg"&&(we.textContent=qt),Tt=n(e),m(fe.$$.fragment,e),bt=n(e),be=r(e,"P",{}),Dt(be).forEach(s),this.h()},h(){jt(d,"name","hf:doc:metadata"),jt(d,"content",us),jt(b,"start","4")},m(e,t){ns(document.head,d),l(e,f,t),l(e,w,t),l(e,T,t),u(U,e,t),l(e,je,t),u($,e,t),l(e,Ue,t),l(e,I,t),l(e,$e,t),l(e,g,t),l(e,Ie,t),l(e,C,t),l(e,ge,t),l(e,_,t),l(e,Ce,t),l(e,B,t),l(e,_e,t),u(k,e,t),l(e,Be,t),l(e,b,t),l(e,ke,t),u(v,e,t),l(e,ve,t),u(E,e,t),l(e,Ee,t),u(x,e,t),l(e,xe,t),l(e,R,t),l(e,Re,t),u(V,e,t),l(e,Ve,t),u(Z,e,t),l(e,Ze,t),u(G,e,t),l(e,Ge,t),l(e,X,t),l(e,Xe,t),l(e,N,t),l(e,Ne,t),l(e,Q,t),l(e,Qe,t),u(S,e,t),l(e,Se,t),l(e,W,t),l(e,We,t),l(e,A,t),l(e,Ae,t),l(e,H,t),l(e,He,t),l(e,F,t),l(e,Fe,t),u(J,e,t),l(e,ze,t),u(z,e,t),l(e,Pe,t),l(e,P,t),l(e,qe,t),u(q,e,t),l(e,Le,t),l(e,L,t),l(e,Ye,t),l(e,Y,t),l(e,De,t),u(j,e,t),l(e,Ke,t),u(D,e,t),l(e,Oe,t),u(K,e,t),l(e,et,t),u(O,e,t),l(e,tt,t),l(e,ee,t),l(e,st,t),u(te,e,t),l(e,lt,t),l(e,se,t),l(e,at,t),l(e,le,t),l(e,nt,t),l(e,ae,t),l(e,pt,t),u(ne,e,t),l(e,rt,t),l(e,pe,t),l(e,it,t),u(re,e,t),l(e,ot,t),u(ie,e,t),l(e,mt,t),u(oe,e,t),l(e,ut,t),l(e,me,t),l(e,ct,t),u(ue,e,t),l(e,ht,t),l(e,ce,t),l(e,Mt,t),u(he,e,t),l(e,dt,t),l(e,Me,t),l(e,yt,t),u(de,e,t),l(e,wt,t),u(ye,e,t),l(e,ft,t),l(e,we,t),l(e,Tt,t),u(fe,e,t),l(e,bt,t),l(e,be,t),Jt=!0},p(e,[t]){const Lt={};t&2&&(Lt.$$scope={dirty:t,ctx:e}),J.$set(Lt);const Yt={};t&2&&(Yt.$$scope={dirty:t,ctx:e}),j.$set(Yt)},i(e){Jt||(c(U.$$.fragment,e),c($.$$.fragment,e),c(k.$$.fragment,e),c(v.$$.fragment,e),c(E.$$.fragment,e),c(x.$$.fragment,e),c(V.$$.fragment,e),c(Z.$$.fragment,e),c(G.$$.fragment,e),c(S.$$.fragment,e),c(J.$$.fragment,e),c(z.$$.fragment,e),c(q.$$.fragment,e),c(j.$$.fragment,e),c(D.$$.fragment,e),c(K.$$.fragment,e),c(O.$$.fragment,e),c(te.$$.fragment,e),c(ne.$$.fragment,e),c(re.$$.fragment,e),c(ie.$$.fragment,e),c(oe.$$.fragment,e),c(ue.$$.fragment,e),c(he.$$.fragment,e),c(de.$$.fragment,e),c(ye.$$.fragment,e),c(fe.$$.fragment,e),Jt=!0)},o(e){h(U.$$.fragment,e),h($.$$.fragment,e),h(k.$$.fragment,e),h(v.$$.fragment,e),h(E.$$.fragment,e),h(x.$$.fragment,e),h(V.$$.fragment,e),h(Z.$$.fragment,e),h(G.$$.fragment,e),h(S.$$.fragment,e),h(J.$$.fragment,e),h(z.$$.fragment,e),h(q.$$.fragment,e),h(j.$$.fragment,e),h(D.$$.fragment,e),h(K.$$.fragment,e),h(O.$$.fragment,e),h(te.$$.fragment,e),h(ne.$$.fragment,e),h(re.$$.fragment,e),h(ie.$$.fragment,e),h(oe.$$.fragment,e),h(ue.$$.fragment,e),h(he.$$.fragment,e),h(de.$$.fragment,e),h(ye.$$.fragment,e),h(fe.$$.fragment,e),Jt=!1},d(e){e&&(s(f),s(w),s(T),s(je),s(Ue),s(I),s($e),s(g),s(Ie),s(C),s(ge),s(_),s(Ce),s(B),s(_e),s(Be),s(b),s(ke),s(ve),s(Ee),s(xe),s(R),s(Re),s(Ve),s(Ze),s(Ge),s(X),s(Xe),s(N),s(Ne),s(Q),s(Qe),s(Se),s(W),s(We),s(A),s(Ae),s(H),s(He),s(F),s(Fe),s(ze),s(Pe),s(P),s(qe),s(Le),s(L),s(Ye),s(Y),s(De),s(Ke),s(Oe),s(et),s(tt),s(ee),s(st),s(lt),s(se),s(at),s(le),s(nt),s(ae),s(pt),s(rt),s(pe),s(it),s(ot),s(mt),s(ut),s(me),s(ct),s(ht),s(ce),s(Mt),s(dt),s(Me),s(yt),s(wt),s(ft),s(we),s(Tt),s(bt),s(be)),s(d),M(U,e),M($,e),M(k,e),M(v,e),M(E,e),M(x,e),M(V,e),M(Z,e),M(G,e),M(S,e),M(J,e),M(z,e),M(q,e),M(j,e),M(D,e),M(K,e),M(O,e),M(te,e),M(ne,e),M(re,e),M(ie,e),M(oe,e),M(ue,e),M(he,e),M(de,e),M(ye,e),M(fe,e)}}}const us='{"title":"LLM Gateway for PII Detection","local":"llm-gateway-for-pii-detection","sections":[{"title":"LLM Wrapper","local":"llm-wrapper","sections":[],"depth":2},{"title":"Scrubbers!","local":"scrubbers","sections":[],"depth":2},{"title":"Dataset","local":"dataset","sections":[],"depth":2},{"title":"Regular Output","local":"regular-output","sections":[],"depth":2}],"depth":1}';function cs(Te){return ts(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class fs extends ss{constructor(d){super(),ls(this,d,cs,ms,es,{})}}export{fs as component};
