forked from monuminu/rag-voice-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtools.py
More file actions
46 lines (42 loc) · 1.25 KB
/
tools.py
File metadata and controls
46 lines (42 loc) · 1.25 KB
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
import json
import random
import chainlit as cl
from datetime import datetime, timedelta
import uuid
from azure.core.credentials import AzureKeyCredential
from azure.identity import get_bearer_token_provider
from azure.search.documents import SearchClient
from openai import AzureOpenAI
import os
search_client = SearchClient(
endpoint=os.environ["AZURE_SEARCH_ENDPOINT"],
index_name=os.environ["INDEX_NAME"],
credential=AzureKeyCredential(os.environ["AZURE_SEARCH_KEY"])
)
fetch_relevant_documents_def = {
"name": "fetch_relevant_documents",
"description": "Fetch relevant documents for a query",
"parameters": {
"type": "object",
"properties": {
"query": {
"type": "string",
"description": "query for which documents are to be fetched"
}
},
"required": ["query"]
}
}
async def fetch_relevant_documents_handler(params):
query = params['query']
search_results = search_client.search(
search_text=query,
top=5,
select="content"
)
sources_formatted = "\n".join([f'{document["content"]}' for document in search_results])
return sources_formatted
# Tools list
tools = [
(fetch_relevant_documents_def, fetch_relevant_documents_handler),
]