๐Ÿ“—
smiley book
  • Smiley Books
  • AI
    • Readme
    • openai-whisper
      • ์ƒ˜ํ”Œ ์‹คํ–‰ํ•ด๋ณด๊ธฐ
      • GPU ์„œ๋ฒ„ ์ค€๋น„ํ•˜๊ธฐ
      • API๋กœ whisper๋ฅผ ์™ธ๋ถ€์— ์˜คํ”ˆํ•˜๊ธฐ
      • ํ”„๋กฌํ”„ํŠธ ์ง€์›
      • ์‹ค์‹œ๊ฐ„ message chat
      • ํ™”๋ฉด ์ด์˜๊ฒŒ ๋งŒ๋“ค๊ธฐ์™€ ๋กœ๊ทธ์ธ
      • ํŒŒ์ด์ฌ ๊ฐ€์ƒํ™˜๊ฒฝ
      • ์‹ค์‹œ๊ฐ„ voice chat
      • fine tunning(๋ฏธ์„ธ ์กฐ์ •) ์œผ๋กœ ์„ฑ๋Šฅ ์˜ฌ๋ฆฌ๊ธฐ
      • app์—์„œ api๋ฅผ ํ˜ธ์ถœํ•˜์—ฌ ์‹ค์‹œ๊ฐ„์œผ๋กœ ํ…์ŠคํŠธ๋กœ ๋ฐ”๊ฟ”๋ณด๊ธฐ
    • ollama - llm์„ ์‰ฝ๊ฒŒ ๋‚ด์ปด์—์„œ ์‹คํ–‰
      • ollama webui
      • ollama docker
    • stable diffusion
      • SDXL - text to image
      • SD-webui
    • ChatGPT
      • ๋‹ต๋ณ€์ด ๋Š๊ธธ๋•Œ
      • ์—ญํ• ์„ ์ •ํ•˜์ž
      • ๊ตฌ์ฒด์ ์ธ ์งˆ๋ฌธ
      • ๊ฒฐ๊ณผํ˜•ํƒœ๋ฅผ ์ง€์ •
      • ํ”„๋กฌํ”„ํŠธ๋ฅผ ์—ฌ๋Ÿฌ์ค„๋กœ ์‚ฌ์šฉํ•˜์ž.
      • ๋งˆํ‹ด ํŒŒ์šธ๋Ÿฌ ๊ธ€ ๋ฒˆ์—ญ๋ณธ
    • Prompt Engineering
    • Auto-GPT
    • Gemini
      • google ai studio
      • gemini-api
      • embedding guide
    • Huggingface
      • huggingface ์‚ฌ์šฉ๋ฒ•
      • huggingface nlp ๊ณต๋ถ€์ค‘
    • kaggle
      • download dataset
    • langchain
      • langchain์„ ๊ณต๋ถ€ํ•˜๋ฉฐ ์ •๋ฆฌ
      • basic
      • slackbot
      • rag
      • document-loader
      • website-loader
      • confluence
      • memory
      • function-call
      • langsmith
      • agent-toolkit
  • Ansible
    • templates vs files and jinja2
    • dynamic inventory
    • limit ์˜ต์…˜ ๊ฐ•์ œํ•˜๊ธฐ
    • limit ์‚ฌ์šฉํ›„ gather_fact ๋ฌธ์ œ
  • AWS
    • AWS CLI
    • EKS
      • cluster manage
      • ALB Controller
      • external-dns
      • fargate
    • ECR
    • S3
    • Certificate Manager
  • Azure
    • Azure AD OAuth Client Flow
  • Container
    • Registry
    • ๋นŒ๋“œ์‹œ์— env๊ฐ’ ์„ค์ •ํ•˜๊ธฐ
  • DB
    • PXC
      • Operator
      • PMM
      • ์‚ญ์ œ
      • GTID
      • Cross Site Replication
    • Mssql
    • Mysql
  • dotnet
    • Thread Pool
    • Connection Pool
    • Thread Pool2
  • Devops
    • Recommendation
  • GIT
    • Basic
    • Submodule
  • GitHub
    • Repository
    • GitHub Action
    • GitHub PR
    • Self Hosted Runner
    • GitHub Webhook
  • GitLab
    • CI/CD
    • CI/CD Advance
    • Ssl renew
    • CI/CD Pass env to other job
  • Go Lang
    • ๊ฐœ๋ฐœ ํ™˜๊ฒฝ ๊ตฌ์ถ•
    • multi os binary build
    • kubectl๊ฐ™์€ cli๋งŒ๋“ค๊ธฐ
    • azure ad cli
    • embed static file
    • go study
      • pointer
      • module and package
      • string
      • struct
      • goroutine
  • Kubernetes
    • Kubernetes๋Š” ๋ฌด์—‡์ธ๊ฐ€
    • Tools
    • Install with kubespray
    • Kubernetes hardening guidance
    • 11 ways not to get hacked
    • ArgoCD
      • Install
      • CLI
      • Repository
      • Apps
      • AWS ALB ์‚ฌ์šฉ
      • Notification slack
      • Backup / DR
      • Ingress
      • 2021-11-16 Github error
      • Server Config
      • auth0 ์ธ์ฆ ์ถ”๊ฐ€(oauth,OIDC)
    • Extension
      • Longhorn pvc
      • External dns
      • Ingress nginx
      • Cert Manager
      • Kube prometheus
    • Helm
      • Subchart
      • Tip
    • Loki
    • Persistent Volume
    • TIP
      • Job
      • Pod
      • Log
  • KAFKA
    • raft
  • KVM
    • kvm cpu model
  • Linux
    • DNS Bind9
      • Cert-Manager
      • Certbot
      • Dynamic Update
      • Log
    • Export and variable
    • Grep ์‚ฌ์šฉ๋ฒ•
  • Modeling
    • C4 model introduce
    • Mermaid
    • reference
  • Monitoring
    • Readme
    • 0. What is Monitoring
    • 1. install prometheus and grafana
    • 2. grafana provisioning
    • 3. grafana dashboard
    • 4. grafana portable dashboard
    • 5. prometheus ui
    • 6. prometheus oauth2
    • Prometheus
      • Metric type
      • basic
      • rate vs irate
      • k8s-prometheus
    • Grafana
      • Expolorer
    • Node Exporter
      • advance
      • textfile collector
  • Motivation
    • 3 Simple Rule
  • OPENNEBULA
    • Install(ansible)
    • Install
    • Tip
    • Windows vm
  • Reading
    • comfort zone
    • ๋ฐฐ๋ ค
    • elon musk 6 rule for insane productivity
    • Feynman Technique
    • how to interview - elon musk
    • ๊ฒฝ์ฒญ
    • Readme
  • Redis
    • Install
    • Master-slave Architecture
    • Sentinel
    • Redis Cluster
    • Client programming c#
  • SEO
    • Readme
  • Security
    • criminalip.io
      • criminalip.io
  • Stock
    • robinhood-python
  • Terraform
    • moved block
    • output
  • vault
    • Readme
  • VS Code
    • dev container
    • dev container on remote server
  • Old fashione trend
    • curity
    • MAAS
      • Install maas
      • Manage maas
      • Tip
Powered by GitBook
On this page
  • tool
  • toolkit
  • Python REPL
  • ์ฃผ์‹ ํ‹ฐ์ปค ์ฐพ๊ธฐ agent
  • sql agent
  • langgraph
  • Agent

Was this helpful?

  1. AI
  2. langchain

agent-toolkit

tool

https://python.langchain.com/v0.2/docs/integrations/tools/

toolkit

https://python.langchain.com/v0.2/docs/integrations/toolkits/

agent executor๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ agent๋ฅผ ๊ตฌ์ถ•ํ•˜๋Š”๋ฐ ๋‹ค์Œ ๋ฌธ์„œ๋ฅผ ๋ณด์ž.

https://python.langchain.com/v0.2/docs/how_to/agent_executor/#jupyter-notebook

์ด ์„น์…˜์—์„œ๋Š” ๋ ˆ๊ฑฐ์‹œ LangChain AgentExecutor๋ฅผ ์‚ฌ์šฉํ•œ ๊ตฌ์ถ•์„ ๋‹ค๋ฃน๋‹ˆ๋‹ค. ์‹œ์ž‘ํ•˜๋Š” ๋ฐ๋Š” ๊ดœ์ฐฎ์ง€๋งŒ ํŠน์ • ์ง€์ ์ด ์ง€๋‚˜๋ฉด ์ด ๊ธฐ๋Šฅ์ด ์ œ๊ณตํ•˜์ง€ ์•Š๋Š” ์œ ์—ฐ์„ฑ๊ณผ ์ œ์–ด ๊ธฐ๋Šฅ์ด ํ•„์š”ํ•  ๊ฒƒ์ž…๋‹ˆ๋‹ค. ๊ณ ๊ธ‰ ์—์ด์ „ํŠธ๋ฅผ ์‚ฌ์šฉํ•˜๋ ค๋ฉด LangGraph ์—์ด์ „ํŠธ ๋˜๋Š” ๋งˆ์ด๊ทธ๋ ˆ์ด์…˜ ๊ฐ€์ด๋“œ๋ฅผ ํ™•์ธํ•˜๋Š” ๊ฒƒ์ด ์ข‹์Šต๋‹ˆ๋‹ค.

๋ ˆ๊ฑฐ์‹œ๋กœ ์ฒ˜๋ฆฌ๋˜๊ณ  ์ž‡๋‹ค. langgraph agent๋ฅผ ์‚ฌ์šฉํ•˜๋Š”๊ฒŒ ๋งž๋Š”๊ฑฐ๊ฐ™์€๋ฐ ๊ทธ๋ž˜์„œ ๊ทธ๋Ÿฐ์ง€ ์ด๊ฑด ๋Œ€์ถฉ ๋ด๋‘๊ณ  ๋ฐ”๋กœ langgraph๋กœ ๊ฐ€์ž.

Python REPL

%pip install langchain_experimental
from langchain_core.tools import Tool
from langchain_experimental.utilities import PythonREPL
python_repl = PythonREPL()
python_repl.run("print(1+1)")
# You can create the tool to pass to an agent
repl_tool = Tool(
    name="python_repl",
    description="ํŒŒ์ด์ฌ ์…ธ์ž…๋‹ˆ๋‹ค. ํŒŒ์ด์ฌ ๋ช…๋ น์„ ์‹คํ–‰ํ•  ๋•Œ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ์ž…๋ ฅ์€ ์œ ํšจํ•œ ํŒŒ์ด์ฌ ๋ช…๋ น์ด์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ๊ฐ’์˜ ์ถœ๋ ฅ์„ ํ™•์ธํ•˜๋ ค๋ฉด `print(...)`๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ถœ๋ ฅํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.",
    func=python_repl.run,
)

repl_tool.invoke("print(5+5)")

์ฃผ์‹ ํ‹ฐ์ปค ์ฐพ๊ธฐ agent

from dotenv import load_dotenv
load_dotenv()
from typing import Any, Type
from langchain_openai import ChatOpenAI
from langchain.tools import BaseTool
from pydantic import BaseModel, Field
from langchain.agents import initialize_agent, AgentType

llm = ChatOpenAI(temperature=0.1)

from langchain.utilities import DuckDuckGoSearchAPIWrapper

# schema
class StockMarketSymbolSearchToolArgsSchema(BaseModel):
    query: str = Field(description="๊ฒ€์ƒ‰ํ•  ์ฟผ๋ฆฌ์ž…๋‹ˆ๋‹ค. ์ฟผ๋ฆฌ ์˜ˆ์‹œ: Apple ํšŒ์‚ฌ์˜ ์ฃผ์‹ ์‹œ์žฅ ์‹ฌ๋ณผ")

from langchain.utilities import DuckDuckGoSearchAPIWrapper
class StockMarketSymbolSearchTool(BaseTool):
    name = "StockMarketSymbolSearchTool"
    description = """
    ์ด ๋„๊ตฌ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํšŒ์‚ฌ์˜ ์ฃผ์‹ ์‹œ์žฅ ์‹ฌ๋ณผ์„ ์ฐพ์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
    ์ฟผ๋ฆฌ๋ฅผ ์ธ์ˆ˜๋กœ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค.
    """
    args_schema: Type[
        StockMarketSymbolSearchToolArgsSchema
    ] = StockMarketSymbolSearchToolArgsSchema

    def _run(self, query):
        ddg = DuckDuckGoSearchAPIWrapper()
        return ddg.run(query)
agent = initialize_agent(
    llm=llm,
    verbose=True,
    agent=AgentType.OPENAI_FUNCTIONS,
    handle_parsing_errors=True,
    tools=[
        StockMarketSymbolSearchTool(),
    ],
)

prompt = "Cloudflare์˜ ํ‹ฐ์ปค๊ฐ€ ๋ฌด์—‡์ธ์ง€ ์•Œ๋ ค์ฃผ์„ธ์š”. ํ•œ๊ตญ์–ด๋กœ ๋‹ต๋ณ€ํ•ด์ค˜"

agent.invoke(prompt)

sql agent

https://github.com/lerocha/chinook-database/blob/master/ChinookDatabase/DataSources/Chinook_Sqlite.sqlite

chinook_sqlite๋ฅผ ์‚ฌ์šฉํ•จ

!wget 'https://github.com/lerocha/chinook-database/releases/download/v1.4.2/Chinook_Sqlite.sql'

from langchain_openai import ChatOpenAI
llm = ChatOpenAI(
    temperature=0.1,
)
from langchain_community.utilities.sql_database import SQLDatabase

db = SQLDatabase.from_uri("sqlite:///db/Chinook.sqlite")
print(db.dialect) #sqlite

print(db.get_usable_table_names())
result = db.run("select * from artist limit 5;")
# db.run("select * from artists limit 5;")
print(type(result))
result
from langchain_community.agent_toolkits import SQLDatabaseToolkit
toolkit = SQLDatabaseToolkit(db=db, llm=llm)
from langchain.agents import create_sql_agent, AgentType

agent_executor = create_sql_agent(
    llm=llm,
    toolkit=toolkit,
    agent_type="openai-tools",
    verbose=False,
)

agent_executor.invoke(
    "employees๋Š” ๋ช‡๋ช…์ด์•ผ?"
)
agent_executor.invoke(
    "artist ๋ช‡๋ช…์ด์•ผ?"
)
agent_executor.invoke(
    "Alanis Morissette ๋…ธ๋ž˜๋งŒ ๋ฝ‘์•„์ค˜?"
)
agent_executor.invoke({"input": "Describe the schema of the playlist table"})
agent_executor.invoke(
    {
        "input": "๊ตญ๊ฐ€๋ณ„ ์ด ๋งค์ถœ์„ ๋‚˜์—ดํ•ฉ๋‹ˆ๋‹ค. ๊ฐ€์žฅ ๋งŽ์ด ์ง€์ถœํ•œ ๊ตญ๊ฐ€?"
    }
)

langgraph

์š”์ฆ˜์€ langchain agent๋ณด๋‹ค langgraph๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ์ข‹์€๊ฑฐ๊ฐ™์€ ๊ฐœ์ธ์  ๋А๋‚Œ์ด๋ผ. agent์ชฝ์€ ๋งŽ์ด ๋ณด์ง€๋Š” ์•Š๊ณ  langgraph๋กœ ๋ฐ”๋กœ ๋„˜์–ด๊ฐ€๋ฒ„๋ฆด๊นŒ ํ•ฉ๋‹ˆ๋‹ค.

Agent

์ธ๊ณต์ง€๋Šฅ Agent๋Š” ์‚ฌ์šฉ์ž์˜ ์š”์ฒญ์„ ๋ฐ›์€ ํ›„ ์–ด๋–ค ๊ธฐ๋Šฅ์„ ์–ด๋–ค ์ˆœ์„œ๋กœ ์‹คํ–‰ํ• ์ง€ ๊ฒฐ์ •ํ•˜๋Š” ์—ญํ• ์„ ํ•ฉ๋‹ˆ๋‹ค. Agent์˜ ์ฃผ์š” ํŠน์ง•๋“ค์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

  • ๋ชฉํ‘œ(์ •์ฑ…) ๊ธฐ๋ฐ˜ ํ–‰๋™: ์ฃผ์–ด์ง„ ๋ชฉํ‘œ๋ฅผ ๋‹ฌ์„ฑํ•˜๊ธฐ ์œ„ํ•ด ํ–‰๋™ํ•ฉ๋‹ˆ๋‹ค.

  • ์ž์œจ์„ฑ: ๋ชฉํ‘œ๊ฐ€ ์ฃผ์–ด์ง€๋ฉด ์ž๋™์œผ๋กœ ์ž‘๋™ํ•ฉ๋‹ˆ๋‹ค.

  • ๊ฐ์ง€: ์ฃผ๋ณ€ ํ™˜๊ฒฝ์—์„œ ์ •๋ณด๋ฅผ ์ˆ˜์ง‘ํ•ฉ๋‹ˆ๋‹ค.

Tools๋Š” Agent๊ฐ€ ํ•  ์ˆ˜ ์žˆ๋Š” ์ผ

  1. Input: ์‚ฌ์šฉ์ž๊ฐ€ Agent์—๊ฒŒ ์ž‘์—…์„ ํ• ๋‹นํ•ฉ๋‹ˆ๋‹ค.

  2. Thought: Agent๊ฐ€ ์ž‘์—…์„ ์™„์ˆ˜ํ•˜๊ธฐ ์œ„ํ•ด ๋ฌด์—‡์„ ํ• ์ง€ ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค.

  3. Action/Action Input: ์‚ฌ์šฉํ•  ๋„๊ตฌ๋ฅผ ๊ฒฐ์ •ํ•˜๊ณ , ๋„๊ตฌ์˜ ์ž…๋ ฅ(ํ•จ์ˆ˜์˜ ์ž…๋ ฅ๊ฐ’)์„ ๊ฒฐ์ •ํ•ฉ๋‹ˆ๋‹ค.

  4. Observation: ๋„๊ตฌ์˜ ์ถœ๋ ฅ ๊ฒฐ๊ณผ๋ฅผ ๊ด€์ฐฐํ•ฉ๋‹ˆ๋‹ค.

  5. ๊ด€์ฐฐ ๊ฒฐ๊ณผ ์ž‘์—…์„ ์™„๋ฃŒ(Finish)ํ–ˆ๋‹ค๋Š” ํŒ๋‹จ์— ๋„๋‹ฌํ•  ๋•Œ๊นŒ์ง€ 2~4๋ฒˆ ๊ณผ์ •์„ ๋ฐ˜๋ณตํ•ฉ๋‹ˆ๋‹ค.

PreviouslangsmithNexttemplates vs files and jinja2

Last updated 11 months ago

Was this helpful?

alt text