Stéphane G commited on
Commit ·
ef46e30
1
Parent(s): 81bba60
tidy up
Browse files- code_qa_app.py +14 -14
code_qa_app.py
CHANGED
|
@@ -1,6 +1,10 @@
|
|
| 1 |
#!pip install langchain openai chromadb tiktoken panel gitpython
|
| 2 |
|
| 3 |
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
from langchain.chains import RetrievalQA
|
| 5 |
from langchain.llms import OpenAI
|
| 6 |
from langchain.document_loaders import GitLoader
|
|
@@ -9,12 +13,9 @@ from langchain.text_splitter import RecursiveCharacterTextSplitter
|
|
| 9 |
from langchain.embeddings import OpenAIEmbeddings
|
| 10 |
from langchain.vectorstores import Chroma
|
| 11 |
from langchain.chat_models import ChatOpenAI
|
| 12 |
-
from typing import List
|
| 13 |
from langchain.vectorstores import Chroma
|
| 14 |
-
from urllib.parse import urlparse
|
| 15 |
from langchain.docstore.document import Document
|
| 16 |
from langchain.schema import BaseRetriever
|
| 17 |
-
import panel as pn
|
| 18 |
|
| 19 |
# UI configuration
|
| 20 |
pn.extension(
|
|
@@ -49,7 +50,6 @@ openaikey = pn.widgets.PasswordInput(
|
|
| 49 |
width=300
|
| 50 |
)
|
| 51 |
|
| 52 |
-
|
| 53 |
context_texteditor = pn.widgets.TextEditor(
|
| 54 |
value="",
|
| 55 |
placeholder="(Optional) Enter your index query here...",
|
|
@@ -80,10 +80,10 @@ select_chain_type = pn.widgets.RadioButtonGroup(
|
|
| 80 |
)
|
| 81 |
|
| 82 |
class FixedRetriever(BaseRetriever):
|
| 83 |
-
def __init__(self, documents: [Document]):
|
| 84 |
self.documents = documents
|
| 85 |
|
| 86 |
-
def get_relevant_documents(self, query: str)
|
| 87 |
# Ignoring query
|
| 88 |
return self.documents
|
| 89 |
|
|
@@ -121,9 +121,7 @@ def qa_fetching_repo(url_repo, branch, context_query, prompt_query, chain_type,
|
|
| 121 |
file_filter=lambda file_path: file_path.endswith(".swift") or file_path.endswith(".h") or file_path.endswith(".m")
|
| 122 |
)
|
| 123 |
|
| 124 |
-
|
| 125 |
documents = loader.load()
|
| 126 |
-
|
| 127 |
|
| 128 |
# split documents into chunks
|
| 129 |
text_splitter = RecursiveCharacterTextSplitter(chunk_size=3000, chunk_overlap=0)
|
|
@@ -238,7 +236,7 @@ def toggle_github_inputs(event):
|
|
| 238 |
|
| 239 |
use_cached_repo.param.watch(toggle_github_inputs, 'value')
|
| 240 |
|
| 241 |
-
setup = pn.
|
| 242 |
pn.Column(github_inputs, openaikey),
|
| 243 |
pn.Card(
|
| 244 |
"Chain type:",
|
|
@@ -246,7 +244,9 @@ setup = pn.Row(
|
|
| 246 |
select_chain_type,
|
| 247 |
select_k
|
| 248 |
),
|
| 249 |
-
title="Advanced settings",
|
|
|
|
|
|
|
| 250 |
)
|
| 251 |
)
|
| 252 |
|
|
@@ -258,11 +258,11 @@ queries = pn.Column(
|
|
| 258 |
|
| 259 |
pn.Column(
|
| 260 |
pn.pane.Markdown("""
|
| 261 |
-
## \U0001F60A
|
| 262 |
|
| 263 |
-
1
|
| 264 |
-
2
|
| 265 |
-
3
|
| 266 |
|
| 267 |
"""),
|
| 268 |
setup,
|
|
|
|
| 1 |
#!pip install langchain openai chromadb tiktoken panel gitpython
|
| 2 |
|
| 3 |
import os
|
| 4 |
+
import panel as pn
|
| 5 |
+
from typing import List
|
| 6 |
+
from urllib.parse import urlparse
|
| 7 |
+
|
| 8 |
from langchain.chains import RetrievalQA
|
| 9 |
from langchain.llms import OpenAI
|
| 10 |
from langchain.document_loaders import GitLoader
|
|
|
|
| 13 |
from langchain.embeddings import OpenAIEmbeddings
|
| 14 |
from langchain.vectorstores import Chroma
|
| 15 |
from langchain.chat_models import ChatOpenAI
|
|
|
|
| 16 |
from langchain.vectorstores import Chroma
|
|
|
|
| 17 |
from langchain.docstore.document import Document
|
| 18 |
from langchain.schema import BaseRetriever
|
|
|
|
| 19 |
|
| 20 |
# UI configuration
|
| 21 |
pn.extension(
|
|
|
|
| 50 |
width=300
|
| 51 |
)
|
| 52 |
|
|
|
|
| 53 |
context_texteditor = pn.widgets.TextEditor(
|
| 54 |
value="",
|
| 55 |
placeholder="(Optional) Enter your index query here...",
|
|
|
|
| 80 |
)
|
| 81 |
|
| 82 |
class FixedRetriever(BaseRetriever):
|
| 83 |
+
def __init__(self, documents: List[Document]):
|
| 84 |
self.documents = documents
|
| 85 |
|
| 86 |
+
def get_relevant_documents(self, query: str):
|
| 87 |
# Ignoring query
|
| 88 |
return self.documents
|
| 89 |
|
|
|
|
| 121 |
file_filter=lambda file_path: file_path.endswith(".swift") or file_path.endswith(".h") or file_path.endswith(".m")
|
| 122 |
)
|
| 123 |
|
|
|
|
| 124 |
documents = loader.load()
|
|
|
|
| 125 |
|
| 126 |
# split documents into chunks
|
| 127 |
text_splitter = RecursiveCharacterTextSplitter(chunk_size=3000, chunk_overlap=0)
|
|
|
|
| 236 |
|
| 237 |
use_cached_repo.param.watch(toggle_github_inputs, 'value')
|
| 238 |
|
| 239 |
+
setup = pn.Column(
|
| 240 |
pn.Column(github_inputs, openaikey),
|
| 241 |
pn.Card(
|
| 242 |
"Chain type:",
|
|
|
|
| 244 |
select_chain_type,
|
| 245 |
select_k
|
| 246 |
),
|
| 247 |
+
title="Advanced settings",
|
| 248 |
+
margin=10,
|
| 249 |
+
collapsed=True
|
| 250 |
)
|
| 251 |
)
|
| 252 |
|
|
|
|
| 258 |
|
| 259 |
pn.Column(
|
| 260 |
pn.pane.Markdown("""
|
| 261 |
+
### \U0001F60A Ask Squirrel a question about your codebase
|
| 262 |
|
| 263 |
+
1. Enter the url of a github repo and a branch (swift / objc)
|
| 264 |
+
2. Enter OpenAI API key. This costs $. Set up billing at [OpenAI](https://platform.openai.com/account).
|
| 265 |
+
3. Type a question and click "Run".
|
| 266 |
|
| 267 |
"""),
|
| 268 |
setup,
|