-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f3f38f3
commit 8b76436
Showing
20 changed files
with
3,479 additions
and
542 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
modules/programming/module_programming_llm/module_programming_llm/helpers/web_search.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
from typing import Sequence, List | ||
|
||
from langchain.chains.qa_with_sources.retrieval import RetrievalQAWithSourcesChain | ||
from langchain_community.document_loaders import AsyncChromiumLoader | ||
from langchain_community.document_transformers import BeautifulSoupTransformer | ||
from duckduckgo_search import DDGS | ||
import re | ||
|
||
from langchain_community.retrievers import WebResearchRetriever | ||
from langchain_community.utilities import GoogleSearchAPIWrapper | ||
from langchain_community.vectorstores import Chroma | ||
from langchain_core.documents import Document | ||
from langchain_core.tools import Tool | ||
from langchain_openai import OpenAIEmbeddings | ||
|
||
from module_programming_llm.helpers.models import ModelConfigType | ||
|
||
|
||
def bulk_search(queries: Sequence[str], model: ModelConfigType) -> List[str]: | ||
result = [] | ||
for query in queries: | ||
result.append(answer_query(query, model)) | ||
return result | ||
# | ||
# | ||
# def search(query: str) -> List[str]: | ||
# results = DDGS().text(query, max_results=5) | ||
# urls = [] | ||
# for result in results: | ||
# url = result['href'] | ||
# urls.append(url) | ||
# | ||
# docs = get_page(urls) | ||
# | ||
# content = [] | ||
# for doc in docs: | ||
# page_text = re.sub("\n\n+", "\n", doc.page_content) | ||
# text = truncate(page_text) | ||
# content.append(text) | ||
# | ||
# return content | ||
# | ||
# | ||
# def get_page(urls: List[str]) -> Sequence[Document]: | ||
# loader = AsyncChromiumLoader(urls, headless=True) | ||
# html = loader.load() | ||
# | ||
# bs_transformer = BeautifulSoupTransformer() | ||
# docs_transformed = bs_transformer.transform_documents(html, tags_to_extract=["p"], remove_unwanted_tags=["a"]) | ||
# | ||
# return docs_transformed | ||
# | ||
# | ||
# def truncate(text) -> str: | ||
# words = text.split() | ||
# truncated = " ".join(words[:1000]) | ||
# | ||
# return truncated | ||
|
||
def answer_query(query, model: ModelConfigType): | ||
model = model.get_model() # type: ignore[attr-defined] | ||
vectorstore = Chroma( | ||
embedding_function=OpenAIEmbeddings(), persist_directory="./chroma_db_oai" | ||
) | ||
|
||
# Search | ||
search = GoogleSearchAPIWrapper() | ||
|
||
# # Initialize | ||
web_search_retriever = WebResearchRetriever.from_llm( | ||
vectorstore=vectorstore, llm=model, search=search, allow_dangerous_requests=True | ||
) | ||
qa_chain = RetrievalQAWithSourcesChain.from_chain_type( | ||
model, retriever=web_search_retriever | ||
) | ||
result = qa_chain({"question": query}) | ||
|
||
search = GoogleSearchAPIWrapper() | ||
|
||
tool = Tool( | ||
name="google_search", | ||
description="Search Google for recent results.", | ||
func=search.run, | ||
) | ||
|
||
return tool.run(query) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...e_programming_llm/module_programming_llm/prompts/generate_suggestions_by_file/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
from .generate_suggestions_by_file import GenerateSuggestionsByFile | ||
from .generate_suggestions_by_file_input import GenerateSuggestionsByFileInput | ||
from .generate_suggestions_by_file_output import GenerateSuggestionsByFileOutput | ||
|
||
__all__ = ['GenerateSuggestionsByFile', 'GenerateSuggestionsByFileOutput'] | ||
__all__ = ['GenerateSuggestionsByFile', 'GenerateSuggestionsByFileOutput', 'GenerateSuggestionsByFileInput'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
modules/programming/module_programming_llm/module_programming_llm/prompts/rag/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from .rag import RAG | ||
from .rag_input import RAGInput | ||
from .rag_output import RAGOutput | ||
|
||
__all__ = ['RAG', 'RAGInput', 'RAGOutput'] |
23 changes: 23 additions & 0 deletions
23
modules/programming/module_programming_llm/module_programming_llm/prompts/rag/prompt.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
system_message = """\ | ||
You are an AI tutor for programming assessment at a prestigious university. | ||
# Task | ||
Identify, if you understand the problem and surrounding information completely. | ||
In case you do not understand something, formulate up to 2 specific questions that will help you understand the problem statement better. | ||
# Style | ||
1. Constructive, 2. Specific, 3. Balanced, 4. Clear and Concise, 5. Contextual | ||
For testing purposes, assume you do not know anything about sorting | ||
""" | ||
|
||
human_message = """\ | ||
# Problem statement | ||
{problem_statement} | ||
Changed files from template to sample solution: | ||
{changed_files_from_template_to_solution} | ||
# Diff between template (deletions) and sample solution(additions): | ||
{template_to_solution_diff} | ||
""" |
Oops, something went wrong.