Feat: Promp engineering, front fixes
This commit is contained in:
Binary file not shown.
@@ -5,7 +5,6 @@ import json
|
||||
import yaml
|
||||
import st_auth
|
||||
import boto3
|
||||
|
||||
authenticator=st_auth.get_authenticator()
|
||||
from botocore.exceptions import ClientError
|
||||
|
||||
@@ -20,7 +19,7 @@ if "chat_answer_history" not in st.session_state:
|
||||
st.session_state["chat_answer_history"]=[]
|
||||
if "chat_history" not in st.session_state:
|
||||
st.session_state["chat_history"] = []
|
||||
prompt=st.text_input("Prompt",placeholder="Enter your prompt here..")
|
||||
prompt=st.chat_input(placeholder="Digite uma mensagem...",key="prompt")
|
||||
def create_sources_string(source_urls: Set[str])->str:
|
||||
if not source_urls:
|
||||
return ""
|
||||
@@ -32,17 +31,20 @@ def create_sources_string(source_urls: Set[str])->str:
|
||||
return sources_string
|
||||
if prompt:
|
||||
with st.spinner("Generating response.."):
|
||||
payload=st.session_state["chat_history"]+[{"role":"user","content":prompt}]
|
||||
content={"message":payload}
|
||||
payload=[{"role":"user","content":prompt}]
|
||||
content={"message":payload,"chat_history":st.session_state["chat_history"]}
|
||||
headers={"Content-type":"application/json","x-api-key":json.loads(st_auth.get_secret())['api-gateway-api-key']}
|
||||
generated_response=json.loads(requests.post(url,json=content,headers=headers).text)['json']
|
||||
generated_response=json.loads(requests.post(url,json=content,headers=headers).text)
|
||||
if 'json' in generated_response:
|
||||
generated_response=generated_response['json']
|
||||
#generated_response=[{"role":"user","content":prompt}]
|
||||
# sources= set([doc.metadata["source"] for doc in generated_response['context']])
|
||||
#formatted_response=f"{generated_response['answer']} \n\n {create_sources_string(sources)}"
|
||||
formatted_response=generated_response
|
||||
st.session_state["user_prompt_history"].append(prompt)
|
||||
st.session_state["chat_answer_history"].append(formatted_response)
|
||||
st.session_state["chat_history"]=st.session_state["chat_history"]+[{"role":"user","content":prompt}]
|
||||
st.session_state["chat_history"]=st.session_state["chat_history"]+[{"role":"user","content":prompt}]+[{"role":"assistant","content":formatted_response}]
|
||||
st.session_state.user_input=""
|
||||
if st.session_state["chat_answer_history"]:
|
||||
for generated_response, user_query in zip(st.session_state["chat_answer_history"],st.session_state["user_prompt_history"]):
|
||||
st.chat_message("user").write(user_query)
|
||||
|
||||
Reference in New Issue
Block a user