Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] langgraph tools (websearch, vectorstore search) 생성 #6

Merged
merged 4 commits into from
Dec 8, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added app/__init__.py
Empty file.
51 changes: 51 additions & 0 deletions app/langgraph/tools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import getpass
import os
import sys
f-lab-owen marked this conversation as resolved.
Show resolved Hide resolved

from langchain_community.tools import DuckDuckGoSearchRun
from langchain_core.tools import tool
from app.vectorstore.opensearch_hybrid import OpenSearchHybridSearch

# tool에 필요한 class 초기화
duckduckgo_search = DuckDuckGoSearchRun()

opensearch_password = getpass.getpass("Enter your Opensearch password: ")
opensearch = OpenSearchHybridSearch(user="admin", pw=opensearch_password)

@tool(parse_docstring=True)
def web_search(query: str):
"""A tool to use when websearch is needed. Use this tool when there isn't enough information in OpenSearch vector store Database

Args:
query : a query to websearch

Returns:
list[str]: websearch result in list of strings
"""
res = duckduckgo_search.invoke({"query": query})
return [res]


@tool(parse_docstring=True)
def vectorstore_search(query: str, search_type: str = "hybrid"):
"""search OpenSearch vector databsee for documents that are relevant to a given query
f-lab-owen marked this conversation as resolved.
Show resolved Hide resolved

Args:
query: a query to search vector database
search_type (str, optional): one of three similarity search method: hybrid, BM25, and Cosine similarity search Defaults to "hybrid".

Returns:
list[pd.DataFrmae]: list of langchain document
"""
if search_type == "hybrid":
result = opensearch.hybrid_search(query)
elif search_type == "bm25":
result = opensearch.bm25_search(query)
elif search_type == "cosine":
result = opensearch.cosine_similarity_search(query)

result["text"].tolist()

return result


42 changes: 41 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ version = "0.0.0"
description = "ML/DL 관련 지식과 최신 정보관련 대화할 수 있는 챗봇"
authors = ["tmdqja75 <[email protected]>"]
readme = "README.md"
packages = [{ include = "app" }]

[tool.poetry.dependencies]
python = "^3.10"
Expand All @@ -24,6 +25,7 @@ langchain-huggingface = "^0.1.0"
faiss-cpu = "^1.9.0"
langchain-ollama = "^0.2.0"
tavily-python = "^0.5.0"
duckduckgo-search = "^6.3.7"


[tool.poetry.group.dev.dependencies]
Expand Down
Loading