import{s as wt,n as rt,o as mt}from"../chunks/scheduler.d586627e.js";import{S as Ct,i as It,g as M,s as n,r as y,A as bt,h as p,f as s,c as a,j as ut,u as i,x as U,k as ct,y as dt,a as e,v as J,d as o,t as T,w as j}from"../chunks/index.9053ba3c.js";import{C as u}from"../chunks/CodeBlock.ebc837c6.js";import{D as ht}from"../chunks/DocNotebookDropdown.7672ca8b.js";import{H as Fl,E as Qt}from"../chunks/getInferenceSnippets.715d1ea1.js";function Vt(Xl){let c,el,tl,nl,w,al,r,Ml,m,Yl="이 튜토리얼에서는 <code>smolagents</code>를 사용해 SQL을 다루는 에이전트를 구현해보겠습니다.",pl,C,Hl="<p>먼저 중요한 질문 하나로 시작하겠습니다. 그냥 간단하게 일반적인 text-to-SQL 파이프라인을 쓰면 안 될까요?</p>",Ul,I,zl="표준 text-to-SQL 파이프라인은 안정성이 떨어지는 경우가 많습니다. 쿼리가 잘못 생성될 수 있고, 심지어는 오류 없이 틀리거나 쓸모없는 결과를 반환할 수도 있습니다.",yl,b,Ll="👉 반면, 에이전트 시스템은 출력 결과를 비판적으로 점검할 수 있고 쿼리를 수정할 필요가 있는지 스스로 결정할 수 있이 성능이 크게 향상됩니다.",il,d,Dl="이제 이 에이전트를 직접 만들어봅시다! 💪",Jl,h,Ol="아래 명령어를 실행해 필요한 의존성을 설치하세요:",ol,Q,Tl,V,Pl=`추론 프로바이더를 호출하려면 환경 변수 <code>HF_TOKEN</code>에 유효한 토큰이 설정되어 있어야 합니다.
python-dotenv를 이용해 환경 변수를 불러오겠습니다.`,jl,g,ul,B,Kl="다음으로, SQL 환경을 구성하겠습니다:",cl,f,wl,q,rl,k,lt="이제 도구를 활용해 SQL 테이블을 조회할 수 있도록 만들어봅시다.",ml,N,tt="툴의 설명 속성은 에이전트 시스템에 의해 LLM 프롬프트에 포함되는 부분으로, LLM이 해당 도구를 어떻게 사용할 수 있는지에 대한 정보를 제공합니다. 바로 이 부분에 우리가 정의한 SQL 테이블의 설명을 작성하면 됩니다.",Cl,A,Il,E,bl,R,st='이제 우리만의 툴을 만들어봅시다. 도구은 아래와 같은 요소를 필요로 합니다. (자세한 내용은 <a href="../tutorials/tools">도구 문서</a>를 참고하세요)',dl,_,et="<li>인자(<code>Args:</code>) 목록이 포함된 docstring</li> <li>입력과 출력에 대한 타입 힌트</li>",hl,Z,Ql,S,nt="이제 이 도구를 사용하는 에이전트를 만들어보겠습니다.",Vl,W,at="여기서는 smolagent의 메인 에이전트 클래스인 <code>CodeAgent</code>를 사용합니다. <code>CodeAgent</code>는 코드로 액션을 작성하고 ReAct 프레임워크에 따라 이전 출력 결과를 반복적으로 개선할 수 있습니다.",gl,G,Mt="모델은 에이전트 시스템을 구동하는 LLM을 의미합니다. <code>InferenceClientModel</code>을 사용하면 허깅페이스의 Inference API를 통해 서버리스 또는 Dedicated 엔드포인트 방식으로 LLM을 호출할 수 있으며, 필요에 따라 다른 사설 API를 사용할 수도 있습니다.",Bl,v,fl,x,ql,$,pt="이제 좀 더 어려운 과제를 해결해 볼까요? 에이전트가 여러 테이블에 걸친 조인을 처리하도록 만들어 보겠습니다.",kl,F,Ut="이를 위해 각 <code>receipt_id</code>에 해당하는 웨이터의 이름을 기록하는 두 번째 테이블을 만들어 보겠습니다.",Nl,X,Al,Y,yt="테이블이 변경되었기 때문에 LLM이 테이블 정보를 올바르게 활용할 수 있도록 <code>sql_engine</code>의 설명을 업데이트하겠습니다.",El,H,Rl,z,it='이번 요청은 이전보다 조금 더 어려우므로, 더 강력한 <a href="https://huggingface.co/Qwen/Qwen2.5-Coder-32B-Instruct" rel="nofollow">Qwen/Qwen2.5-Coder-32B-Instruct</a> 모델을 사용하도록 LLM 엔진을 바꾸겠습니다!',_l,L,Zl,D,Jt="바로 성공입니다! 놀라울 만큼 간단하게 설정되지 않았나요?",Sl,O,ot="이번 예제는 여기까지입니다! 지금까지 다음과 같은 개념들을 살펴보았습니다.",Wl,P,Tt="<li>새로운 도구 만들기</li> <li>도구 설명 업데이트하기</li> <li>더 강력한 LLM으로 에이전트 추론 능력 향상시키기</li>",Gl,K,jt="✅ 이제 여러분이 꿈꿔왔던 text-to-SQL 시스템을 직접 만들어 보세요! ✨",vl,ll,xl,sl,$l;return w=new Fl({props:{title:"Text-to-SQL",local:"text-to-sql",headingTag:"h1"}}),r=new ht({props:{classNames:"absolute z-10 right-0 top-0",options:[{label:"Mixed",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/smolagents_doc/ko/text_to_sql.ipynb"},{label:"PyTorch",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/smolagents_doc/ko/pytorch/text_to_sql.ipynb"},{label:"TensorFlow",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/smolagents_doc/ko/tensorflow/text_to_sql.ipynb"},{label:"Mixed",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/smolagents_doc/ko/text_to_sql.ipynb"},{label:"PyTorch",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/smolagents_doc/ko/pytorch/text_to_sql.ipynb"},{label:"TensorFlow",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/smolagents_doc/ko/tensorflow/text_to_sql.ipynb"}]}}),Q=new u({props:{code:"IXBpcCUyMGluc3RhbGwlMjBzbW9sYWdlbnRzJTIwcHl0aG9uLWRvdGVudiUyMHNxbGFsY2hlbXklMjAtLXVwZ3JhZGUlMjAtcQ==",highlighted:"!pip install smolagents python-dotenv sqlalchemy --upgrade -q",wrap:!1}}),g=new u({props:{code:"ZnJvbSUyMGRvdGVudiUyMGltcG9ydCUyMGxvYWRfZG90ZW52JTBBbG9hZF9kb3RlbnYoKQ==",highlighted:`<span class="hljs-keyword">from</span> dotenv <span class="hljs-keyword">import</span> load_dotenv
load_dotenv()`,wrap:!1}}),f=new u({props:{code:"ZnJvbSUyMHNxbGFsY2hlbXklMjBpbXBvcnQlMjAoJTBBJTIwJTIwJTIwJTIwY3JlYXRlX2VuZ2luZSUyQyUwQSUyMCUyMC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X25hbWUlMjIlM0ElMjAlMjJNYXJnYXJldCUyMEphbWVzJTIyJTJDJTIwJTIycHJpY2UlMjIlM0ElMjAyMS4xMSUyQyUyMCUyMnRpcCUyMiUzQSUyMDEuMDAlN0QlMkMlMEElNUQlMEFpbnNlcnRfcm93c19pbnRvX3RhYmxlKHJvd3MlMkMlMjByZWNlaXB0cyk=",highlighted:`<span class="hljs-keyword">from</span> sqlalchemy <span class="hljs-keyword">import</span> (
    create_engine,
    MetaData,
    Table,
    Column,
    String,
    Integer,
    Float,
    insert,
    inspect,
    text,
)

engine = create_engine(<span class="hljs-string">&quot;sqlite:///:memory:&quot;</span>)
metadata_obj = MetaData()

<span class="hljs-keyword">def</span> <span class="hljs-title function_">insert_rows_into_table</span>(<span class="hljs-params">rows, table, engine=engine</span>):
    <span class="hljs-keyword">for</span> row <span class="hljs-keyword">in</span> rows:
        stmt = insert(table).values(**row)
        <span class="hljs-keyword">with</span> engine.begin() <span class="hljs-keyword">as</span> connection:
            connection.execute(stmt)

table_name = <span class="hljs-string">&quot;receipts&quot;</span>
receipts = Table(
    table_name,
    metadata_obj,
    Column(<span class="hljs-string">&quot;receipt_id&quot;</span>, Integer, primary_key=<span class="hljs-literal">True</span>),
    Column(<span class="hljs-string">&quot;customer_name&quot;</span>, String(<span class="hljs-number">16</span>), primary_key=<span class="hljs-literal">True</span>),
    Column(<span class="hljs-string">&quot;price&quot;</span>, Float),
    Column(<span class="hljs-string">&quot;tip&quot;</span>, Float),
)
metadata_obj.create_all(engine)

rows = [
    {<span class="hljs-string">&quot;receipt_id&quot;</span>: <span class="hljs-number">1</span>, <span class="hljs-string">&quot;customer_name&quot;</span>: <span class="hljs-string">&quot;Alan Payne&quot;</span>, <span class="hljs-string">&quot;price&quot;</span>: <span class="hljs-number">12.06</span>, <span class="hljs-string">&quot;tip&quot;</span>: <span class="hljs-number">1.20</span>},
    {<span class="hljs-string">&quot;receipt_id&quot;</span>: <span class="hljs-number">2</span>, <span class="hljs-string">&quot;customer_name&quot;</span>: <span class="hljs-string">&quot;Alex Mason&quot;</span>, <span class="hljs-string">&quot;price&quot;</span>: <span class="hljs-number">23.86</span>, <span class="hljs-string">&quot;tip&quot;</span>: <span class="hljs-number">0.24</span>},
    {<span class="hljs-string">&quot;receipt_id&quot;</span>: <span class="hljs-number">3</span>, <span class="hljs-string">&quot;customer_name&quot;</span>: <span class="hljs-string">&quot;Woodrow Wilson&quot;</span>, <span class="hljs-string">&quot;price&quot;</span>: <span class="hljs-number">53.43</span>, <span class="hljs-string">&quot;tip&quot;</span>: <span class="hljs-number">5.43</span>},
    {<span class="hljs-string">&quot;receipt_id&quot;</span>: <span class="hljs-number">4</span>, <span class="hljs-string">&quot;customer_name&quot;</span>: <span class="hljs-string">&quot;Margaret James&quot;</span>, <span class="hljs-string">&quot;price&quot;</span>: <span class="hljs-number">21.11</span>, <span class="hljs-string">&quot;tip&quot;</span>: <span class="hljs-number">1.00</span>},
]
insert_rows_into_table(rows, receipts)`,wrap:!1}}),q=new Fl({props:{title:"에이전트 만들기",local:"build-our-agent",headingTag:"h3"}}),A=new u({props:{code:"aW5zcGVjdG9yJTIwJTNEJTIwaW5zcGVjdChlbmdpbmUpJTBBY29sdW1uc19pbmZvJTIwJTNEJTIwJTVCKGNvbCU1QiUyMm5hbWUlMjIlNUQlMkMlMjBjb2wlNUIlMjJ0eXBlJTIyJTVEKSUyMGZvciUyMGNvbCUyMGluJTIwaW5zcGVjdG9yLmdldF9jb2x1bW5zKCUyMnJlY2VpcHRzJTIyKSU1RCUwQSUwQXRhYmxlX2Rlc2NyaXB0aW9uJTIwJTNEJTIwJTIyQ29sdW1ucyUzQSU1Q24lMjIlMjAlMkIlMjAlMjIlNUNuJTIyLmpvaW4oJTVCZiUyMiUyMCUyMC0lMjAlN0JuYW1lJTdEJTNBJTIwJTdCY29sX3R5cGUlN0QlMjIlMjBmb3IlMjBuYW1lJTJDJTIwY29sX3R5cGUlMjBpbiUyMGNvbHVtbnNfaW5mbyU1RCklMEFwcmludCh0YWJsZV9kZXNjcmlwdGlvbik=",highlighted:`inspector = inspect(engine)
columns_info = [(col[<span class="hljs-string">&quot;name&quot;</span>], col[<span class="hljs-string">&quot;type&quot;</span>]) <span class="hljs-keyword">for</span> col <span class="hljs-keyword">in</span> inspector.get_columns(<span class="hljs-string">&quot;receipts&quot;</span>)]

table_description = <span class="hljs-string">&quot;Columns:\\n&quot;</span> + <span class="hljs-string">&quot;\\n&quot;</span>.join([<span class="hljs-string">f&quot;  - <span class="hljs-subst">{name}</span>: <span class="hljs-subst">{col_type}</span>&quot;</span> <span class="hljs-keyword">for</span> name, col_type <span class="hljs-keyword">in</span> columns_info])
<span class="hljs-built_in">print</span>(table_description)`,wrap:!1}}),E=new u({props:{code:"Q29sdW1ucyUzQSUwQSUyMCUyMC0lMjByZWNlaXB0X2lkJTNBJTIwSU5URUdFUiUwQSUyMCUyMC0lMjBjdXN0b21lcl9uYW1lJTNBJTIwVkFSQ0hBUigxNiklMEElMjAlMjAtJTIwcHJpY2UlM0ElMjBGTE9BVCUwQSUyMCUyMC0lMjB0aXAlM0ElMjBGTE9BVA==",highlighted:`Columns:
  - receipt_id: INTEGER
  - customer_name: VARCHAR(16)
  - price: FLOAT
  - tip: FLOAT`,wrap:!1}}),Z=new u({props:{code:"ZnJvbSUyMHNtb2xhZ2VudHMlMjBpbXBvcnQlMjB0b29sJTBBJTBBJTQwdG9vbCUwQWRlZiUyMHNxbF9lbmdpbmUocXVlcnklM0ElMjBzdHIpJTIwLSUzRSUyMHN0ciUzQSUwQSUyMCUyMCUyMCUyMCUyMiUyMiUyMiUwQSUyMCUyMCUyMCUyMCVFRCU4NSU4QyVFQyU5RCVCNCVFQiVCOCU5NCVFQyU5NyU5MCUyMFNRTCUyMCVFQyVCRiVCQyVFQiVBNiVBQyVFQiVBNSVCQyUyMCVFQyU4OCU5OCVFRCU5NiU4OSVFRCU5NSVBMCUyMCVFQyU4OCU5OCUyMCVFQyU5RSU4OCVFQyU4QSVCNSVFQiU4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JUVEJTk1JUE5JUVCJThCJTg4JUVCJThCJUE0LiUwQSUyMCUyMCUyMCUyMCUyMiUyMiUyMiUwQSUyMCUyMCUyMCUyMG91dHB1dCUyMCUzRCUyMCUyMiUyMiUwQSUyMCUyMCUyMCUyMHdpdGglMjBlbmdpbmUuY29ubmVjdCgpJTIwYXMlMjBjb24lM0ElMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjByb3dzJTIwJTNEJTIwY29uLmV4ZWN1dGUodGV4dChxdWVyeSkpJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwZm9yJTIwcm93JTIwaW4lMjByb3dzJTNBJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwb3V0cHV0JTIwJTJCJTNEJTIwJTIyJTVDbiUyMiUyMCUyQiUyMHN0cihyb3cpJTBBJTIwJTIwJTIwJTIwcmV0dXJuJTIwb3V0cHV0",highlighted:`<span class="hljs-keyword">from</span> smolagents <span class="hljs-keyword">import</span> tool

<span class="hljs-meta">@tool</span>
<span class="hljs-keyword">def</span> <span class="hljs-title function_">sql_engine</span>(<span class="hljs-params">query: <span class="hljs-built_in">str</span></span>) -&gt; <span class="hljs-built_in">str</span>:
    <span class="hljs-string">&quot;&quot;&quot;
    테이블에 SQL 쿼리를 수행할 수 있습니다. 결과를 문자열로 반환합니다.
    테이블 이름은 &#x27;receipts&#x27;이며, 설명은 다음과 같습니다:
        Columns:
        - receipt_id: INTEGER
        - customer_name: VARCHAR(16)
        - price: FLOAT
        - tip: FLOAT

    Args:
        query: 수행할 쿼리입니다. 올바른 SQL이어야 합니다.
    &quot;&quot;&quot;</span>
    output = <span class="hljs-string">&quot;&quot;</span>
    <span class="hljs-keyword">with</span> engine.connect() <span class="hljs-keyword">as</span> con:
        rows = con.execute(text(query))
        <span class="hljs-keyword">for</span> row <span class="hljs-keyword">in</span> rows:
            output += <span class="hljs-string">&quot;\\n&quot;</span> + <span class="hljs-built_in">str</span>(row)
    <span class="hljs-keyword">return</span> output`,wrap:!1}}),v=new u({props:{code:"ZnJvbSUyMHNtb2xhZ2VudHMlMjBpbXBvcnQlMjBDb2RlQWdlbnQlMkMlMjBJbmZlcmVuY2VDbGllbnRNb2RlbCUwQSUwQWFnZW50JTIwJTNEJTIwQ29kZUFnZW50KCUwQSUyMCUyMCUyMCUyMHRvb2xzJTNEJTVCc3FsX2VuZ2luZSU1RCUyQyUwQSUyMCUyMCUyMCUyMG1vZGVsJTNESW5mZXJlbmNlQ2xpZW50TW9kZWwobW9kZWxfaWQlM0QlMjJtZXRhLWxsYW1hJTJGTGxhbWEtMy4xLThCLUluc3RydWN0JTIyKSUyQyUwQSklMEFhZ2VudC5ydW4oJTIyQ2FuJTIweW91JTIwZ2l2ZSUyMG1lJTIwdGhlJTIwbmFtZSUyMG9mJTIwdGhlJTIwY2xpZW50JTIwd2hvJTIwZ290JTIwdGhlJTIwbW9zdCUyMGV4cGVuc2l2ZSUyMHJlY2VpcHQlM0YlMjIp",highlighted:`<span class="hljs-keyword">from</span> smolagents <span class="hljs-keyword">import</span> CodeAgent, InferenceClientModel

agent = CodeAgent(
    tools=[sql_engine],
    model=InferenceClientModel(model_id=<span class="hljs-string">&quot;meta-llama/Llama-3.1-8B-Instruct&quot;</span>),
)
agent.run(<span class="hljs-string">&quot;Can you give me the name of the client who got the most expensive receipt?&quot;</span>)`,wrap:!1}}),x=new Fl({props:{title:"레벨 업: 테이블 조인",local:"level-2-table-joins",headingTag:"h3"}}),X=new u({props:{code:"dGFibGVfbmFtZSUyMCUzRCUyMCUyMndhaXRlcnMlMjIlMEF3YWl0ZXJzJTIwJTNEJTIwVGFibGUoJTBBJTIwJTIwJTIwJTIwdGFibGVfbmFtZSUyQyUwQSUyMCUyMCUyMCUyMG1ldGFkYXRhX29iaiUyQyUwQSUyMCUyMCUyMCUyMENvbHVtbiglMjJyZWNlaXB0X2lkJTIyJTJDJTIwSW50ZWdlciUyQyUyMHByaW1hcnlfa2V5JTNEVHJ1ZSklMkMlMEElMjAlMjAlMjAlMjBDb2x1bW4oJTIyd2FpdGVyX25hbWUlMjIlMkMlMjBTdHJpbmcoMTYpJTJDJTIwcHJpbWFyeV9rZXklM0RUcnVlKSUyQyUwQSklMEFtZXRhZGF0YV9vYmouY3JlYXRlX2FsbChlbmdpbmUpJTBBJTBBcm93cyUyMCUzRCUyMCU1QiUwQSUyMCUyMCUyMCUyMCU3QiUyMnJlY2VpcHRfaWQlMjIlM0ElMjAxJTJDJTIwJTIyd2FpdGVyX25hbWUlMjIlM0ElMjAlMjJDb3JleSUyMEpvaG5zb24lMjIlN0QlMkMlMEElMjAlMjAlMjAlMjAlN0IlMjJyZWNlaXB0X2lkJTIyJTNBJTIwMiUyQyUyMCUyMndhaXRlcl9uYW1lJTIyJTNBJTIwJTIyTWljaGFlbCUyMFdhdHRzJTIyJTdEJTJDJTBBJTIwJTIwJTIwJTIwJTdCJTIycmVjZWlwdF9pZCUyMiUzQSUyMDMlMkMlMjAlMjJ3YWl0ZXJfbmFtZSUyMiUzQSUyMCUyMk1pY2hhZWwlMjBXYXR0cyUyMiU3RCUyQyUwQSUyMCUyMCUyMCUyMCU3QiUyMnJlY2VpcHRfaWQlMjIlM0ElMjA0JTJDJTIwJTIyd2FpdGVyX25hbWUlMjIlM0ElMjAlMjJNYXJnYXJldCUyMEphbWVzJTIyJTdEJTJDJTBBJTVEJTBBaW5zZXJ0X3Jvd3NfaW50b190YWJsZShyb3dzJTJDJTIwd2FpdGVycyk=",highlighted:`table_name = <span class="hljs-string">&quot;waiters&quot;</span>
waiters = Table(
    table_name,
    metadata_obj,
    Column(<span class="hljs-string">&quot;receipt_id&quot;</span>, Integer, primary_key=<span class="hljs-literal">True</span>),
    Column(<span class="hljs-string">&quot;waiter_name&quot;</span>, String(<span class="hljs-number">16</span>), primary_key=<span class="hljs-literal">True</span>),
)
metadata_obj.create_all(engine)

rows = [
    {<span class="hljs-string">&quot;receipt_id&quot;</span>: <span class="hljs-number">1</span>, <span class="hljs-string">&quot;waiter_name&quot;</span>: <span class="hljs-string">&quot;Corey Johnson&quot;</span>},
    {<span class="hljs-string">&quot;receipt_id&quot;</span>: <span class="hljs-number">2</span>, <span class="hljs-string">&quot;waiter_name&quot;</span>: <span class="hljs-string">&quot;Michael Watts&quot;</span>},
    {<span class="hljs-string">&quot;receipt_id&quot;</span>: <span class="hljs-number">3</span>, <span class="hljs-string">&quot;waiter_name&quot;</span>: <span class="hljs-string">&quot;Michael Watts&quot;</span>},
    {<span class="hljs-string">&quot;receipt_id&quot;</span>: <span class="hljs-number">4</span>, <span class="hljs-string">&quot;waiter_name&quot;</span>: <span class="hljs-string">&quot;Margaret James&quot;</span>},
]
insert_rows_into_table(rows, waiters)`,wrap:!1}}),H=new u({props:{code:"dXBkYXRlZF9kZXNjcmlwdGlvbiUyMCUzRCUyMCUyMiUyMiUyMkFsbG93cyUyMHlvdSUyMHRvJTIwcGVyZm9ybSUyMFNRTCUyMHF1ZXJpZXMlMjBvbiUyMHRoZSUyMHRhYmxlLiUyMEJld2FyZSUyMHRoYXQlMjB0aGlzJTIwdG9vbCdzJTIwb3V0cHV0JTIwaXMlMjBhJTIwc3RyaW5nJTIwcmVwcmVzZW50YXRpb24lMjBvZiUyMHRoZSUyMGV4ZWN1dGlvbiUyMG91dHB1dC4lMEFJdCUyMGNhbiUyMHVzZSUyMHRoZSUyMGZvbGxvd2luZyUyMHRhYmxlcyUzQSUyMiUyMiUyMiUwQSUwQWluc3BlY3RvciUyMCUzRCUyMGluc3BlY3QoZW5naW5lKSUwQWZvciUyMHRhYmxlJTIwaW4lMjAlNUIlMjJyZWNlaXB0cyUyMiUyQyUyMCUyMndhaXRlcnMlMjIlNUQlM0ElMEElMjAlMjAlMjAlMjBjb2x1bW5zX2luZm8lMjAlM0QlMjAlNUIoY29sJTVCJTIybmFtZSUyMiU1RCUyQyUyMGNvbCU1QiUyMnR5cGUlMjIlNUQpJTIwZm9yJTIwY29sJTIwaW4lMjBpbnNwZWN0b3IuZ2V0X2NvbHVtbnModGFibGUpJTVEJTBBJTBBJTIwJTIwJTIwJTIwdGFibGVfZGVzY3JpcHRpb24lMjAlM0QlMjBmJTIyVGFibGUlMjAnJTdCdGFibGUlN0QnJTNBJTVDbiUyMiUwQSUwQSUyMCUyMCUyMCUyMHRhYmxlX2Rlc2NyaXB0aW9uJTIwJTJCJTNEJTIwJTIyQ29sdW1ucyUzQSU1Q24lMjIlMjAlMkIlMjAlMjIlNUNuJTIyLmpvaW4oJTVCZiUyMiUyMCUyMC0lMjAlN0JuYW1lJTdEJTNBJTIwJTdCY29sX3R5cGUlN0QlMjIlMjBmb3IlMjBuYW1lJTJDJTIwY29sX3R5cGUlMjBpbiUyMGNvbHVtbnNfaW5mbyU1RCklMEElMjAlMjAlMjAlMjB1cGRhdGVkX2Rlc2NyaXB0aW9uJTIwJTJCJTNEJTIwJTIyJTVDbiU1Q24lMjIlMjAlMkIlMjB0YWJsZV9kZXNjcmlwdGlvbiUwQSUwQXByaW50KHVwZGF0ZWRfZGVzY3JpcHRpb24p",highlighted:`updated_description = <span class="hljs-string">&quot;&quot;&quot;Allows you to perform SQL queries on the table. Beware that this tool&#x27;s output is a string representation of the execution output.
It can use the following tables:&quot;&quot;&quot;</span>

inspector = inspect(engine)
<span class="hljs-keyword">for</span> table <span class="hljs-keyword">in</span> [<span class="hljs-string">&quot;receipts&quot;</span>, <span class="hljs-string">&quot;waiters&quot;</span>]:
    columns_info = [(col[<span class="hljs-string">&quot;name&quot;</span>], col[<span class="hljs-string">&quot;type&quot;</span>]) <span class="hljs-keyword">for</span> col <span class="hljs-keyword">in</span> inspector.get_columns(table)]

    table_description = <span class="hljs-string">f&quot;Table &#x27;<span class="hljs-subst">{table}</span>&#x27;:\\n&quot;</span>

    table_description += <span class="hljs-string">&quot;Columns:\\n&quot;</span> + <span class="hljs-string">&quot;\\n&quot;</span>.join([<span class="hljs-string">f&quot;  - <span class="hljs-subst">{name}</span>: <span class="hljs-subst">{col_type}</span>&quot;</span> <span class="hljs-keyword">for</span> name, col_type <span class="hljs-keyword">in</span> columns_info])
    updated_description += <span class="hljs-string">&quot;\\n\\n&quot;</span> + table_description

<span class="hljs-built_in">print</span>(updated_description)`,wrap:!1}}),L=new u({props:{code:"c3FsX2VuZ2luZS5kZXNjcmlwdGlvbiUyMCUzRCUyMHVwZGF0ZWRfZGVzY3JpcHRpb24lMEElMEFhZ2VudCUyMCUzRCUyMENvZGVBZ2VudCglMEElMjAlMjAlMjAlMjB0b29scyUzRCU1QnNxbF9lbmdpbmUlNUQlMkMlMEElMjAlMjAlMjAlMjBtb2RlbCUzREluZmVyZW5jZUNsaWVudE1vZGVsKG1vZGVsX2lkJTNEJTIyUXdlbiUyRlF3ZW4yLjUtQ29kZXItMzJCLUluc3RydWN0JTIyKSUyQyUwQSklMEElMEFhZ2VudC5ydW4oJTIyV2hpY2glMjB3YWl0ZXIlMjBnb3QlMjBtb3JlJTIwdG90YWwlMjBtb25leSUyMGZyb20lMjB0aXBzJTNGJTIyKQ==",highlighted:`sql_engine.description = updated_description

agent = CodeAgent(
    tools=[sql_engine],
    model=InferenceClientModel(model_id=<span class="hljs-string">&quot;Qwen/Qwen2.5-Coder-32B-Instruct&quot;</span>),
)

agent.run(<span class="hljs-string">&quot;Which waiter got more total money from tips?&quot;</span>)`,wrap:!1}}),ll=new Qt({props:{source:"https://github.com/huggingface/smolagents/blob/main/docs/source/ko/examples/text_to_sql.md"}}),{c(){c=M("meta"),el=n(),tl=M("p"),nl=n(),y(w.$$.fragment),al=n(),y(r.$$.fragment),Ml=n(),m=M("p"),m.innerHTML=Yl,pl=n(),C=M("blockquote"),C.innerHTML=Hl,Ul=n(),I=M("p"),I.textContent=zl,yl=n(),b=M("p"),b.textContent=Ll,il=n(),d=M("p"),d.textContent=Dl,Jl=n(),h=M("p"),h.textContent=Ol,ol=n(),y(Q.$$.fragment),Tl=n(),V=M("p"),V.innerHTML=Pl,jl=n(),y(g.$$.fragment),ul=n(),B=M("p"),B.textContent=Kl,cl=n(),y(f.$$.fragment),wl=n(),y(q.$$.fragment),rl=n(),k=M("p"),k.textContent=lt,ml=n(),N=M("p"),N.textContent=tt,Cl=n(),y(A.$$.fragment),Il=n(),y(E.$$.fragment),bl=n(),R=M("p"),R.innerHTML=st,dl=n(),_=M("ul"),_.innerHTML=et,hl=n(),y(Z.$$.fragment),Ql=n(),S=M("p"),S.textContent=nt,Vl=n(),W=M("p"),W.innerHTML=at,gl=n(),G=M("p"),G.innerHTML=Mt,Bl=n(),y(v.$$.fragment),fl=n(),y(x.$$.fragment),ql=n(),$=M("p"),$.textContent=pt,kl=n(),F=M("p"),F.innerHTML=Ut,Nl=n(),y(X.$$.fragment),Al=n(),Y=M("p"),Y.innerHTML=yt,El=n(),y(H.$$.fragment),Rl=n(),z=M("p"),z.innerHTML=it,_l=n(),y(L.$$.fragment),Zl=n(),D=M("p"),D.textContent=Jt,Sl=n(),O=M("p"),O.textContent=ot,Wl=n(),P=M("ul"),P.innerHTML=Tt,Gl=n(),K=M("p"),K.textContent=jt,vl=n(),y(ll.$$.fragment),xl=n(),sl=M("p"),this.h()},l(l){const t=bt("svelte-u9bgzb",document.head);c=p(t,"META",{name:!0,content:!0}),t.forEach(s),el=a(l),tl=p(l,"P",{}),ut(tl).forEach(s),nl=a(l),i(w.$$.fragment,l),al=a(l),i(r.$$.fragment,l),Ml=a(l),m=p(l,"P",{"data-svelte-h":!0}),U(m)!=="svelte-13dstk6"&&(m.innerHTML=Yl),pl=a(l),C=p(l,"BLOCKQUOTE",{"data-svelte-h":!0}),U(C)!=="svelte-1ikljlx"&&(C.innerHTML=Hl),Ul=a(l),I=p(l,"P",{"data-svelte-h":!0}),U(I)!=="svelte-g5lnky"&&(I.textContent=zl),yl=a(l),b=p(l,"P",{"data-svelte-h":!0}),U(b)!=="svelte-1v5lrwx"&&(b.textContent=Ll),il=a(l),d=p(l,"P",{"data-svelte-h":!0}),U(d)!=="svelte-cbvetl"&&(d.textContent=Dl),Jl=a(l),h=p(l,"P",{"data-svelte-h":!0}),U(h)!=="svelte-1fbovla"&&(h.textContent=Ol),ol=a(l),i(Q.$$.fragment,l),Tl=a(l),V=p(l,"P",{"data-svelte-h":!0}),U(V)!=="svelte-118l2e"&&(V.innerHTML=Pl),jl=a(l),i(g.$$.fragment,l),ul=a(l),B=p(l,"P",{"data-svelte-h":!0}),U(B)!=="svelte-16ss1rh"&&(B.textContent=Kl),cl=a(l),i(f.$$.fragment,l),wl=a(l),i(q.$$.fragment,l),rl=a(l),k=p(l,"P",{"data-svelte-h":!0}),U(k)!=="svelte-1nrlsq7"&&(k.textContent=lt),ml=a(l),N=p(l,"P",{"data-svelte-h":!0}),U(N)!=="svelte-3e74wm"&&(N.textContent=tt),Cl=a(l),i(A.$$.fragment,l),Il=a(l),i(E.$$.fragment,l),bl=a(l),R=p(l,"P",{"data-svelte-h":!0}),U(R)!=="svelte-10vsy3u"&&(R.innerHTML=st),dl=a(l),_=p(l,"UL",{"data-svelte-h":!0}),U(_)!=="svelte-1b2eezm"&&(_.innerHTML=et),hl=a(l),i(Z.$$.fragment,l),Ql=a(l),S=p(l,"P",{"data-svelte-h":!0}),U(S)!=="svelte-1yzitq4"&&(S.textContent=nt),Vl=a(l),W=p(l,"P",{"data-svelte-h":!0}),U(W)!=="svelte-1uki3as"&&(W.innerHTML=at),gl=a(l),G=p(l,"P",{"data-svelte-h":!0}),U(G)!=="svelte-u38hz5"&&(G.innerHTML=Mt),Bl=a(l),i(v.$$.fragment,l),fl=a(l),i(x.$$.fragment,l),ql=a(l),$=p(l,"P",{"data-svelte-h":!0}),U($)!=="svelte-hibzfv"&&($.textContent=pt),kl=a(l),F=p(l,"P",{"data-svelte-h":!0}),U(F)!=="svelte-r9y53z"&&(F.innerHTML=Ut),Nl=a(l),i(X.$$.fragment,l),Al=a(l),Y=p(l,"P",{"data-svelte-h":!0}),U(Y)!=="svelte-c6lwa0"&&(Y.innerHTML=yt),El=a(l),i(H.$$.fragment,l),Rl=a(l),z=p(l,"P",{"data-svelte-h":!0}),U(z)!=="svelte-lzjvgj"&&(z.innerHTML=it),_l=a(l),i(L.$$.fragment,l),Zl=a(l),D=p(l,"P",{"data-svelte-h":!0}),U(D)!=="svelte-dg1nco"&&(D.textContent=Jt),Sl=a(l),O=p(l,"P",{"data-svelte-h":!0}),U(O)!=="svelte-1vks9f4"&&(O.textContent=ot),Wl=a(l),P=p(l,"UL",{"data-svelte-h":!0}),U(P)!=="svelte-wxkiue"&&(P.innerHTML=Tt),Gl=a(l),K=p(l,"P",{"data-svelte-h":!0}),U(K)!=="svelte-b3m8r8"&&(K.textContent=jt),vl=a(l),i(ll.$$.fragment,l),xl=a(l),sl=p(l,"P",{}),ut(sl).forEach(s),this.h()},h(){ct(c,"name","hf:doc:metadata"),ct(c,"content",gt)},m(l,t){dt(document.head,c),e(l,el,t),e(l,tl,t),e(l,nl,t),J(w,l,t),e(l,al,t),J(r,l,t),e(l,Ml,t),e(l,m,t),e(l,pl,t),e(l,C,t),e(l,Ul,t),e(l,I,t),e(l,yl,t),e(l,b,t),e(l,il,t),e(l,d,t),e(l,Jl,t),e(l,h,t),e(l,ol,t),J(Q,l,t),e(l,Tl,t),e(l,V,t),e(l,jl,t),J(g,l,t),e(l,ul,t),e(l,B,t),e(l,cl,t),J(f,l,t),e(l,wl,t),J(q,l,t),e(l,rl,t),e(l,k,t),e(l,ml,t),e(l,N,t),e(l,Cl,t),J(A,l,t),e(l,Il,t),J(E,l,t),e(l,bl,t),e(l,R,t),e(l,dl,t),e(l,_,t),e(l,hl,t),J(Z,l,t),e(l,Ql,t),e(l,S,t),e(l,Vl,t),e(l,W,t),e(l,gl,t),e(l,G,t),e(l,Bl,t),J(v,l,t),e(l,fl,t),J(x,l,t),e(l,ql,t),e(l,$,t),e(l,kl,t),e(l,F,t),e(l,Nl,t),J(X,l,t),e(l,Al,t),e(l,Y,t),e(l,El,t),J(H,l,t),e(l,Rl,t),e(l,z,t),e(l,_l,t),J(L,l,t),e(l,Zl,t),e(l,D,t),e(l,Sl,t),e(l,O,t),e(l,Wl,t),e(l,P,t),e(l,Gl,t),e(l,K,t),e(l,vl,t),J(ll,l,t),e(l,xl,t),e(l,sl,t),$l=!0},p:rt,i(l){$l||(o(w.$$.fragment,l),o(r.$$.fragment,l),o(Q.$$.fragment,l),o(g.$$.fragment,l),o(f.$$.fragment,l),o(q.$$.fragment,l),o(A.$$.fragment,l),o(E.$$.fragment,l),o(Z.$$.fragment,l),o(v.$$.fragment,l),o(x.$$.fragment,l),o(X.$$.fragment,l),o(H.$$.fragment,l),o(L.$$.fragment,l),o(ll.$$.fragment,l),$l=!0)},o(l){T(w.$$.fragment,l),T(r.$$.fragment,l),T(Q.$$.fragment,l),T(g.$$.fragment,l),T(f.$$.fragment,l),T(q.$$.fragment,l),T(A.$$.fragment,l),T(E.$$.fragment,l),T(Z.$$.fragment,l),T(v.$$.fragment,l),T(x.$$.fragment,l),T(X.$$.fragment,l),T(H.$$.fragment,l),T(L.$$.fragment,l),T(ll.$$.fragment,l),$l=!1},d(l){l&&(s(el),s(tl),s(nl),s(al),s(Ml),s(m),s(pl),s(C),s(Ul),s(I),s(yl),s(b),s(il),s(d),s(Jl),s(h),s(ol),s(Tl),s(V),s(jl),s(ul),s(B),s(cl),s(wl),s(rl),s(k),s(ml),s(N),s(Cl),s(Il),s(bl),s(R),s(dl),s(_),s(hl),s(Ql),s(S),s(Vl),s(W),s(gl),s(G),s(Bl),s(fl),s(ql),s($),s(kl),s(F),s(Nl),s(Al),s(Y),s(El),s(Rl),s(z),s(_l),s(Zl),s(D),s(Sl),s(O),s(Wl),s(P),s(Gl),s(K),s(vl),s(xl),s(sl)),s(c),j(w,l),j(r,l),j(Q,l),j(g,l),j(f,l),j(q,l),j(A,l),j(E,l),j(Z,l),j(v,l),j(x,l),j(X,l),j(H,l),j(L,l),j(ll,l)}}}const gt='{"title":"Text-to-SQL","local":"text-to-sql","sections":[{"title":"에이전트 만들기","local":"build-our-agent","sections":[],"depth":3},{"title":"레벨 업: 테이블 조인","local":"level-2-table-joins","sections":[],"depth":3}],"depth":1}';function Bt(Xl){return mt(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Et extends Ct{constructor(c){super(),It(this,c,Bt,Vt,wt,{})}}export{Et as component};
