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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
| def get_completion(prompt, model="gpt-3.5-turbo"): messages = [{"role": "user", "content": prompt}] response = openai.ChatCompletion.create( model=model, messages=messages, temperature=0, ) return response.choices[0].message["content"]
def get_completion_from_messages(messages, model="gpt-3.5-turbo", temperature=0): response = openai.ChatCompletion.create( model=model, messages=messages, temperature=temperature, ) return response.choices[0].message["content"] messages = [ {'role':'system', 'content':'You are friendly chatbot.'}, {'role':'user', 'content':'Hi, my name is Isa'}, {'role':'assistant', 'content': "Hi Isa! It's nice to meet you. \\ Is there anything I can help you with today?"}, {'role':'user', 'content':'Yes, you can remind me, What is my name?'} ] response = get_completion_from_messages(messages, temperature=1) print(response)
def collect_messages(_): prompt = inp.value_input inp.value = '' context.append({'role':'user', 'content':f"{prompt}"}) response = get_completion_from_messages(context) context.append({'role':'assistant', 'content':f"{response}"}) panels.append( pn.Row('User:', pn.pane.Markdown(prompt, width=600))) panels.append( pn.Row('Assistant:', pn.pane.Markdown(response, width=600, style={'background-color': '#F6F6F6'}))) return pn.Column(*panels) import panel as pn pn.extension()
panels = []
context = [ {'role':'system', 'content':""" You are OrderBot, an automated service to collect orders for a pizza restaurant. \\ You first greet the customer, then collects the order, \\ and then asks if it's a pickup or delivery. \\ You wait to collect the entire order, then summarize it and check for a final \\ time if the customer wants to add anything else. \\ If it's a delivery, you ask for an address. \\ Finally you collect the payment.\\ Make sure to clarify all options, extras and sizes to uniquely \\ identify the item from the menu.\\ You respond in a short, very conversational friendly style. \\ The menu includes \\ pepperoni pizza 12.95, 10.00, 7.00 \\ cheese pizza 10.95, 9.25, 6.50 \\ eggplant pizza 11.95, 9.75, 6.75 \\ fries 4.50, 3.50 \\ greek salad 7.25 \\ Toppings: \\ extra cheese 2.00, \\ mushrooms 1.50 \\ sausage 3.00 \\ canadian bacon 3.50 \\ AI sauce 1.50 \\ peppers 1.00 \\ Drinks: \\ coke 3.00, 2.00, 1.00 \\ sprite 3.00, 2.00, 1.00 \\ bottled water 5.00 \\ """} ]
inp = pn.widgets.TextInput(value="Hi", placeholder='Enter text here…') button_conversation = pn.widgets.Button(name="Chat!")
interactive_conversation = pn.bind(collect_messages, button_conversation)
dashboard = pn.Column( inp, pn.Row(button_conversation), pn.panel(interactive_conversation, loading_indicator=True, height=300), )
dashboard messages = context.copy() messages.append( {'role':'system', 'content':'create a json summary of the previous food order. Itemize the price for each item\\ The fields should be 1) pizza, include size 2) list of toppings 3) list of drinks, include size 4) list of sides include size 5)total price '}, )
response = get_completion_from_messages(messages, temperature=0) print(response)
|