Spaces:
Runtime error
Runtime error
from os import environ | |
from utils.ai import ( | |
retrieve_context, | |
construct_prompt, | |
get_remote_chat_response, | |
) | |
import panel as pn | |
pn.extension() | |
MODEL = "gpt-3.5-turbo" | |
def seek(contents, user, instance): | |
messages = instance.serialize()[1:-1] | |
rag_context = retrieve_context(contents, k=1, openai_api_key=environ["OPENAI_API_KEY"]) | |
prompts = construct_prompt( | |
messages, | |
rag_context, | |
model=MODEL, | |
cite_sources=True, | |
context_window=4097, | |
) | |
message = None | |
for response in get_remote_chat_response(prompts, model=MODEL): | |
if response: | |
message = instance.stream(response, avatar="🛩️", user="Fleet Context", message=message) | |
chat_interface = pn.chat.ChatInterface(callback=seek, callback_exception="verbose") | |
chat_interface.send("Ask me anything about Python libraries!", avatar="🛩️", user="Fleet Context", respond=False) | |
template = pn.template.FastListTemplate(main=[chat_interface], title="Panel UI of Fleet Context") | |
template.servable() |