Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -67,51 +67,34 @@ for name in retriever_names:
|
|
67 |
|
68 |
def format_docs_with_id(docs: List[Document]) -> str:
|
69 |
"""
|
70 |
-
Formatte les documents fournis avec des informations pertinentes sur chaque source.
|
71 |
-
Inclut XINumber, Book Number, Raw Material Cost RMC, Fragrance Formula Name et Fragrance Formula Descriptors.
|
72 |
-
Args:
|
73 |
-
docs (List[Document]): Liste des documents ou articles à formater.
|
74 |
-
Returns:
|
75 |
-
str: Représentation formatée des documents.
|
76 |
"""
|
77 |
formatted = [
|
78 |
(
|
79 |
-
f"
|
80 |
-
f"
|
81 |
-
|
82 |
-
f"Fragrance Formula Name: {doc.metadata.get('Formula Name', 'Missing')}\n"
|
83 |
-
f"Date Evaluated: {doc.metadata.get('Date Evaluated', 'Missing')}\n"
|
84 |
-
f"Application Product: {doc.metadata.get('Application', 'Missing')}\n"
|
85 |
-
f"Fragrance Type: {doc.metadata.get('Fragrance Type', 'Missing')}\n"
|
86 |
-
f"Fragrance Formula Notes: {doc.page_content}\n"
|
87 |
)
|
88 |
for doc in docs
|
89 |
]
|
90 |
return "\n\n" + "\n\n".join(formatted)
|
91 |
|
92 |
|
93 |
-
def prompt_fn(
|
94 |
|
95 |
return (
|
96 |
-
"You are
|
97 |
-
"Return formulas with all their details: XINumber, Book Number, Raw Material Cost RMC, Application Product, Fragrance Formula Name, Fragrance Formula and Descriptors"
|
98 |
-
"Return 15 formulas at least that fits. Reorder the returned formulas according to the matching criterias."
|
99 |
-
"Return only the Formulas with all their details without any additional comments."
|
100 |
-
|
101 |
-
f"Here are additional criterias to respect and to filter for from context: {criteria}"
|
102 |
"\n\nHere is the context: "
|
103 |
"{context}"
|
104 |
)
|
105 |
|
106 |
llm = ChatOpenAI(temperature=0, model="gpt-4o")
|
107 |
-
structured_llm = llm.with_structured_output(CitedAnswer_fr)
|
108 |
|
109 |
retrieve_docs = {name: (lambda x: x["input"]) | retrievers[name] for name in retriever_names}
|
110 |
|
111 |
-
def legal(question
|
112 |
|
113 |
prompt = ChatPromptTemplate.from_messages([
|
114 |
-
("system", prompt_fn(
|
115 |
("human", "{input}"),
|
116 |
])
|
117 |
|
@@ -159,6 +142,6 @@ with gr.Blocks() as demo:
|
|
159 |
#output3 = gr.Text(label="Documents IDs")
|
160 |
|
161 |
btn = gr.Button("Submit")
|
162 |
-
btn.click(legal, inputs=[input1
|
163 |
|
164 |
demo.launch(debug=True)
|
|
|
67 |
|
68 |
def format_docs_with_id(docs: List[Document]) -> str:
|
69 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
"""
|
71 |
formatted = [
|
72 |
(
|
73 |
+
f"Metadata: {doc.metadata}\n"
|
74 |
+
f"Content: {doc.page_content}\n"
|
75 |
+
|
|
|
|
|
|
|
|
|
|
|
76 |
)
|
77 |
for doc in docs
|
78 |
]
|
79 |
return "\n\n" + "\n\n".join(formatted)
|
80 |
|
81 |
|
82 |
+
def prompt_fn():
|
83 |
|
84 |
return (
|
85 |
+
"You are an expert pharmachemist, answer the question based on the context."
|
|
|
|
|
|
|
|
|
|
|
86 |
"\n\nHere is the context: "
|
87 |
"{context}"
|
88 |
)
|
89 |
|
90 |
llm = ChatOpenAI(temperature=0, model="gpt-4o")
|
|
|
91 |
|
92 |
retrieve_docs = {name: (lambda x: x["input"]) | retrievers[name] for name in retriever_names}
|
93 |
|
94 |
+
def legal(question):
|
95 |
|
96 |
prompt = ChatPromptTemplate.from_messages([
|
97 |
+
("system", prompt_fn()),
|
98 |
("human", "{input}"),
|
99 |
])
|
100 |
|
|
|
142 |
#output3 = gr.Text(label="Documents IDs")
|
143 |
|
144 |
btn = gr.Button("Submit")
|
145 |
+
btn.click(legal, inputs=[input1], outputs=[output1])
|
146 |
|
147 |
demo.launch(debug=True)
|