Spaces:
Sleeping
Sleeping
File size: 2,790 Bytes
de6fb09 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | from datetime import datetime, date, timedelta
from typing import Optional as _Optional
import json
import httpx
from urllib.parse import urljoin
from llama_index.llms.groq import Groq
import asyncio
import random
import os
from dotenv import load_dotenv
load_dotenv(dotenv_path="./.env.local")
from agents import function_tool , RunContextWrapper
from .VectorDBManagers import VectorDBManager
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
CHROMA_DB_PATH = os.path.join(BASE_DIR, "chromafast_db")
WEBSITE_PATH = os.path.join(BASE_DIR, "website")
manager = VectorDBManager(db_path=CHROMA_DB_PATH, collection_name="DB_collection")
if not os.path.exists(CHROMA_DB_PATH) or manager.is_collection_empty():
print("π No existing embeddings found. Building new Chroma DB...")
manager.build_index_from_documents(WEBSITE_PATH)
else:
print("π Existing Chroma DB found. Loading it...")
manager.load_existing_index()
@function_tool(
name_override="suggestion_ragtool",
description_override="""
Name: suggestion_ragtool
Query the company's knowledge base for information.
Description:
all Question except any meeting , call , invitation like schedule
Searches the company's internal knowledge base to provide informative, paragraph-style answers
related to services, policies, technologies, or any general information embedded in the vector store.
Parameters:
context (RunContextWrapper): The openai session context used for communicating with the user.
query (str): The question or query asked by the user about the company.
Returns:
str:
""",
)
async def suggestion_ragtool(ctx: RunContextWrapper, query: str) :
"""
π Tool Name: suggestion_ragtool
Description:
all Question except any meeting , call , invitation like schedule
Searches the company's internal knowledge base to provide informative, paragraph-style answers
related to services, policies, technologies, or any general information embedded in the vector store.
Parameters:
context (RunContext): The Openai session context used for communicating with the user.
query (str): The question or query asked by the user about the company.
Returns:
str:
"""
try:
print(f"Answering from knowledgebase: {query}")
res = await manager.aquery(query)
print("Query result:", res)
result=str(res)
return result
except Exception as e:
print(f"Error: {e}")
return f"β Failed: Unable to answer the question. {str(e)}"
|