Update rag_chain.py
This commit is contained in:
parent
18f0237de0
commit
f60c7ccacb
121
app/rag_chain.py
121
app/rag_chain.py
@ -5,6 +5,7 @@ from weaviate import Client
|
|||||||
from weaviate import WeaviateClient
|
from weaviate import WeaviateClient
|
||||||
from weaviate.connect import ConnectionParams
|
from weaviate.connect import ConnectionParams
|
||||||
from weaviate.auth import AuthApiKey
|
from weaviate.auth import AuthApiKey
|
||||||
|
from weaviate.auth import AuthCredentials
|
||||||
from weaviate.classes.init import Auth
|
from weaviate.classes.init import Auth
|
||||||
from langchain.vectorstores import Weaviate
|
from langchain.vectorstores import Weaviate
|
||||||
from langchain.chains import RetrievalQA
|
from langchain.chains import RetrievalQA
|
||||||
@ -15,97 +16,58 @@ def build_rag_chain():
|
|||||||
# 1. Weaviate 클라이언트
|
# 1. Weaviate 클라이언트
|
||||||
auth = weaviate.AuthApiKey(api_key="01js3q6y7twaxccm5dbh3se9bt")
|
auth = weaviate.AuthApiKey(api_key="01js3q6y7twaxccm5dbh3se9bt")
|
||||||
|
|
||||||
# client = weaviate.connect_to_weaviate_cloud(cluster_url="http://183.111.96.67:32668",
|
|
||||||
# auth_credentials=Auth.api_key("01js3q6y7twaxccm5dbh3se9bt"),
|
|
||||||
# headers={
|
|
||||||
# "X-OpenAI-Api-Key": "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" # 필요할 경우
|
|
||||||
# })
|
|
||||||
OPENAI_API_KEY="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"
|
OPENAI_API_KEY="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"
|
||||||
|
|
||||||
# client = Client(
|
# http_config = {
|
||||||
# connection_params=ConnectionParams.from_http(
|
# "host": "183.111.96.67",
|
||||||
# host="183.111.96.67", # 도메인 or IP
|
# "port": 32668,
|
||||||
# port=32668, # 포트
|
# "secure": False
|
||||||
# secure=False, # HTTP면 False, HTTPS면 True
|
# }
|
||||||
# auth_credentials=auth
|
# grpc_config = {
|
||||||
# )
|
# "host": "183.111.96.67",
|
||||||
# )
|
# "port": 32619,
|
||||||
|
# "secure": False
|
||||||
# connection_params = {
|
|
||||||
# "http": {
|
|
||||||
# "host": "183.111.96.67",
|
|
||||||
# "port": 32668,
|
|
||||||
# "secure": False
|
|
||||||
# },
|
|
||||||
# "grpc": {
|
|
||||||
# "host": "183.111.96.67",
|
|
||||||
# "port": 32619,
|
|
||||||
# "secure": False
|
|
||||||
# },
|
|
||||||
# "auth_credentials": auth
|
|
||||||
# }
|
# }
|
||||||
http_config = {
|
|
||||||
"host": "183.111.96.67",
|
|
||||||
"port": 32668,
|
|
||||||
"secure": False
|
|
||||||
}
|
|
||||||
grpc_config = {
|
|
||||||
"host": "183.111.96.67",
|
|
||||||
"port": 32619,
|
|
||||||
"secure": False
|
|
||||||
}
|
|
||||||
|
|
||||||
# connection_params = ConnectionParams(
|
# connection_params = ConnectionParams(
|
||||||
# http=HttpConfig(
|
# http=http_config,
|
||||||
# host="183.111.96.67",
|
# grpc=grpc_config,
|
||||||
# port=32668,
|
# auth_credentials=auth
|
||||||
# secure=False),
|
|
||||||
# grpc=GrpcConfig(
|
|
||||||
# host="183.111.96.67",
|
|
||||||
# port=32619,
|
|
||||||
# secure=False),
|
|
||||||
# auth_credentials=auth_config
|
|
||||||
# )
|
# )
|
||||||
|
|
||||||
connection_params = ConnectionParams(
|
# client = WeaviateClient(connection_params=connection_params)
|
||||||
http=http_config,
|
|
||||||
grpc=grpc_config,
|
|
||||||
auth_credentials=auth
|
|
||||||
)
|
|
||||||
|
|
||||||
client = WeaviateClient(connection_params=connection_params)
|
# client2 = weaviate.connect_to_custom(
|
||||||
|
# http_host="183.111.96.67",
|
||||||
|
# http_port=32668,
|
||||||
|
# grpc_host="183.111.96.67",
|
||||||
|
# http_secure=False,
|
||||||
|
# grpc_port=32619,
|
||||||
|
# grpc_secure=False,
|
||||||
|
# auth_credentials=auth, # 인증이 필요 없으면 생략 가능
|
||||||
|
# headers={"X-OpenAI-Api-Key": OPENAI_API_KEY} # 필요시
|
||||||
|
# )
|
||||||
|
|
||||||
client2 = weaviate.connect_to_custom(
|
# if client.is_ready():
|
||||||
http_host="183.111.96.67",
|
# print("Weaviate 연결 성공!")
|
||||||
http_port=32668,
|
# else:
|
||||||
grpc_host="183.111.96.67",
|
# print("연결 실패. 서버 상태를 확인하세요.")
|
||||||
http_secure=False,
|
|
||||||
grpc_port=32619,
|
|
||||||
grpc_secure=False,
|
|
||||||
auth_credentials=auth, # 인증이 필요 없으면 생략 가능
|
|
||||||
headers={"X-OpenAI-Api-Key": OPENAI_API_KEY} # 필요시
|
|
||||||
)
|
|
||||||
|
|
||||||
if client.is_ready():
|
# if client2.is_ready():
|
||||||
print("Weaviate 연결 성공!")
|
# print("Weaviate 2 연결 성공!")
|
||||||
else:
|
# else:
|
||||||
print("연결 실패. 서버 상태를 확인하세요.")
|
# print("연결 실패 2. 서버 상태를 확인하세요.")
|
||||||
|
|
||||||
if client2.is_ready():
|
|
||||||
print("Weaviate 2 연결 성공!")
|
|
||||||
else:
|
|
||||||
print("연결 실패 2. 서버 상태를 확인하세요.")
|
|
||||||
|
|
||||||
|
|
||||||
client3 = weaviate.connect_to_weaviate_cloud(
|
# client3 = weaviate.connect_to_weaviate_cloud(
|
||||||
cluster_url="s4x71b3lt32z3md1ya0yw.c0.asia-southeast1.gcp.weaviate.cloud", # 예: "http://183.111.96.67:32668"
|
# cluster_url="s4x71b3lt32z3md1ya0yw.c0.asia-southeast1.gcp.weaviate.cloud", # 예: "http://183.111.96.67:32668"
|
||||||
auth_credentials=Auth.api_key("0ojxypfXy2Y1rKw3KQdBUtwcWSrYPWitE7Qu")
|
# auth_credentials=Auth.api_key("0ojxypfXy2Y1rKw3KQdBUtwcWSrYPWitE7Qu")
|
||||||
)
|
# )
|
||||||
|
|
||||||
if client3.is_ready():
|
# if client3.is_ready():
|
||||||
print("Weaviate 3 연결 성공!")
|
# print("Weaviate 3 연결 성공!")
|
||||||
else:
|
# else:
|
||||||
print("연결 실패 3. 서버 상태를 확인하세요.")
|
# print("연결 실패 3. 서버 상태를 확인하세요.")
|
||||||
|
|
||||||
|
|
||||||
# auth_key = AuthCredentials.api_key("01js3q6y7twaxccm5dbh3se9bt") # 없으면 None
|
# auth_key = AuthCredentials.api_key("01js3q6y7twaxccm5dbh3se9bt") # 없으면 None
|
||||||
@ -128,7 +90,8 @@ def build_rag_chain():
|
|||||||
else:
|
else:
|
||||||
print("연결 실패 4. 서버 상태를 확인하세요.")
|
print("연결 실패 4. 서버 상태를 확인하세요.")
|
||||||
|
|
||||||
legacy_client = weaviate.Client(connection_params=client4.connection_params) # langchain용
|
import weaviate as legacy_weaviate
|
||||||
|
legacy_client = legacy_weaviate.Client(connection_params=client4.connection_params) # langchain용
|
||||||
|
|
||||||
|
|
||||||
# 2. 벡터스토어
|
# 2. 벡터스토어
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user