Upload app.py with huggingface_hub
Browse files214 unmodified lines21521621721821922022122222322422522625 unmodified lines25225325425525625725825926026126266 unmodified lines329330331332333334335214 unmodified lines("user", "Query: {query}\nContext: {context}\n\nfeedback: {feedback}")])chain = response_prompt | llmresponse = chain.invoke({"query": state['query'],"context": "\n".join([doc["content"] for doc in state['context']]),"feedback": state['feedback'] # add feedback to the prompt})state['response'] = response.contentprint("intermediate response: ", response)25 unmodified lines("user", "Context: {context}\nResponse: {response}\n\nGroundedness score:")])chain = groundedness_prompt | llm | StrOutputParser()groundedness_score = float(chain.invoke({"context": "\n".join([doc["content"] for doc in state['context']]),"response": state['response'] # Complete the code to define the response}))print("groundedness_score: ", groundedness_score)state['groundedness_loop_count'] += 1print("#########Groundedness Incremented###########")66 unmodified lineschain = refine_response_prompt | llm| StrOutputParser()# Store response suggestions in a structured formatfeedback = f"Previous Response: {state['response']}\nSuggestions: {chain.invoke({'query': state['query'], 'context': "\n".join([doc["content"] for doc in state['context']]), 'response': state['response']})}"print("feedback: ", feedback)print(f"State: {state}")state['feedback'] = feedback214 unmodified lines21521621721821922022122222322422522622722822923023123223323423523623723823924024124224324425 unmodified lines27027127227327427527627727827928028128228328428528628728828929029129229329429566 unmodified lines362363364365366367368369370371372373374375376377214 unmodified lines("user", "Query: {query}\nContext: {context}\n\nfeedback: {feedback}")])# chain = response_prompt | llm# response = chain.invoke({# "query": state['query'],# "context": "\n".join([doc["content"] for doc in state['context']]),# "feedback": state['feedback'] # add feedback to the prompt# })# Build the context string separately for claritycontext_str = "\n".join(doc["content"] for doc in state["context"])# Optionally, make sure feedback is always a stringfeedback_str = state.get("feedback", "")# Build the input payload for the chainchain_input = {"query": state["query"],"context": context_str,"feedback": feedback_str, # add feedback to the prompt}# Run the chainchain = response_prompt | llmresponse = chain.invoke(chain_input)state['response'] = response.contentprint("intermediate response: ", response)25 unmodified lines("user", "Context: {context}\nResponse: {response}\n\nGroundedness score:")])# chain = groundedness_prompt | llm | StrOutputParser()# groundedness_score = float(chain.invoke({# "context": "\n".join([doc["content"] for doc in state['context']]),# "response": state['response'] # Complete the code to define the response# }))# Build the context string separatelycontext_str = "\n".join(doc["content"] for doc in state["context"])# Build the input payload for the groundedness chaingroundedness_input = {"context": context_str,"response": state["response"], # Complete the code to define the response}# Run the chain and parse the groundedness scorechain = groundedness_prompt | llm | StrOutputParser()groundedness_score = float(chain.invoke(groundedness_input))print("groundedness_score: ", groundedness_score)state['groundedness_loop_count'] += 1print("#########Groundedness Incremented###########")66 unmodified lineschain = refine_response_prompt | llm| StrOutputParser()# Store response suggestions in a structured format# feedback = f"Previous Response: {state['response']}\nSuggestions: {chain.invoke({'query': state['query'], 'context': "\n".join([doc["content"] for doc in state['context']]), 'response': state['response']})}"context_str = "\n".join(doc["content"] for doc in state["context"])suggestions = chain.invoke({"query": state["query"],"context": context_str,"response": state["response"],})feedback = f"Previous Response: {state['response']}\nSuggestions: {suggestions}"print("feedback: ", feedback)print(f"State: {state}")state['feedback'] = feedback
app.py+52-10