API support for Chat to have citations (#569)

This commit is contained in:
Yuhong Sun
2023-10-13 17:38:25 -07:00
committed by GitHub
parent f0337d2eba
commit af510cc965
13 changed files with 127 additions and 63 deletions

View File

@@ -37,15 +37,24 @@ def send_chat_message(
"persona_id": persona_id,
}
docs: list[dict] | None = None
with requests.post(
LOCAL_CHAT_ENDPOINT + "send-message", json=data, stream=True
) as r:
for json_response in r.iter_lines():
response_text = json.loads(json_response.decode())
new_token = response_text.get("answer_piece")
print(new_token, end="", flush=True)
if docs is None:
docs = response_text.get("top_documents")
if new_token:
print(new_token, end="", flush=True)
print()
if docs:
print("\nReference Docs:")
for ind, doc in enumerate(docs, start=1):
print(f"\t - Doc {ind}: {doc.get('semantic_identifier')}")
def run_chat(contextual: bool) -> None:
try: