File size: 1,060 Bytes
ab13803
 
 
 
 
 
 
1e333df
ab13803
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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"
query = "How do I trigger a function when clicking a button in Panel?"


def seek(contents, user, instance):
    messages = instance.serialize()[1:-1]
    rag_context = retrieve_context(query, 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, user="Fleet", message=message)


chat_interface = pn.chat.ChatInterface(callback=seek, callback_exception="verbose")
chat_interface.send("Ask me anything about Python libraries!", user="Fleet", respond=False)

template = pn.template.FastListTemplate(main=[chat_interface], title="Panel UI of Fleet Context")
template.servable()