Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -32,7 +32,7 @@ client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
|
|
| 32 |
api = HfApi(token=os.getenv("HF_TOKEN"))
|
| 33 |
repo_id = "manabb/nrl"
|
| 34 |
file_path_in_repo="LLMLogs.txt"
|
| 35 |
-
llm = ChatOpenAI(model="gpt-4o-mini", temperature=0)
|
| 36 |
#=====
|
| 37 |
#Payment type
|
| 38 |
manual_payment_type="""
|
|
@@ -74,13 +74,20 @@ PQC_rules="""
|
|
| 74 |
#===========================
|
| 75 |
#retriever = retrieve_chunks(repo_id)
|
| 76 |
#retriever=retrieve_chunks_GPC()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
def create_qa_chain(retriever):
|
| 78 |
prompt = ChatPromptTemplate.from_template(
|
| 79 |
"Use context to answer: {context}\n\nQ: {input}"
|
| 80 |
)
|
| 81 |
chain = (
|
| 82 |
-
{
|
| 83 |
-
|
|
|
|
|
|
|
|
|
|
| 84 |
| prompt
|
| 85 |
| llm
|
| 86 |
| StrOutputParser()
|
|
|
|
| 32 |
api = HfApi(token=os.getenv("HF_TOKEN"))
|
| 33 |
repo_id = "manabb/nrl"
|
| 34 |
file_path_in_repo="LLMLogs.txt"
|
| 35 |
+
llm = ChatOpenAI(model="gpt-4o-mini", temperature=0, max_tokens=500)
|
| 36 |
#=====
|
| 37 |
#Payment type
|
| 38 |
manual_payment_type="""
|
|
|
|
| 74 |
#===========================
|
| 75 |
#retriever = retrieve_chunks(repo_id)
|
| 76 |
#retriever=retrieve_chunks_GPC()
|
| 77 |
+
def limit_context(docs, max_chars=4000):
|
| 78 |
+
text = "\n\n".join(doc.page_content for doc in docs)
|
| 79 |
+
return text[:max_chars]
|
| 80 |
+
|
| 81 |
def create_qa_chain(retriever):
|
| 82 |
prompt = ChatPromptTemplate.from_template(
|
| 83 |
"Use context to answer: {context}\n\nQ: {input}"
|
| 84 |
)
|
| 85 |
chain = (
|
| 86 |
+
{
|
| 87 |
+
#"context": retriever | (lambda docs: "\n\n".join(doc.page_content for doc in docs)),
|
| 88 |
+
"context": retriever | (lambda docs: limit_context(docs)),
|
| 89 |
+
"input": RunnablePassthrough()
|
| 90 |
+
}
|
| 91 |
| prompt
|
| 92 |
| llm
|
| 93 |
| StrOutputParser()
|