-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquestions.py
35 lines (30 loc) · 1.41 KB
/
questions.py
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
# questions.py
from utils import format_documents
from file_processing import search_documents
class QuestionContext:
def __init__(self, index, documents, llm_chain, model_name, repo_name, github_url, conversation_history, file_type_counts, filenames):
self.index = index
self.documents = documents
self.llm_chain = llm_chain
self.model_name = model_name
self.hub_name = hub_name
self.github_url = github_url
self.conversation_history = conversation_history
self.file_type_counts = file_type_counts
self.filenames = filenames
def ask_question(question, context: QuestionContext):
relevant_docs = search_documents(question, context.index, context.documents, n_results=5)
numbered_documents = format_documents(relevant_docs)
question_context = f"This question is about the GitHub repository '{context.repo_name}' available at {context.github_url}. The most relevant documents are:\n\n{numbered_documents}"
answer_with_sources = context.llm_chain.run(
model=context.model_name,
question=question,
context=question_context,
hub_name=context.repo_name,
github_url=context.github_url,
conversation_history=context.conversation_history,
numbered_documents=numbered_documents,
file_type_counts=context.file_type_counts,
filenames=context.filenames
)
return answer_with_sources