-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhx_transformer_iteration_1.py
87 lines (64 loc) · 2.73 KB
/
hx_transformer_iteration_1.py
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
#!/usr/bin/env python
# coding: utf-8
import os
import openai
import tiktoken
from dotenv import load_dotenv, find_dotenv
import panel as pn
_ = load_dotenv(find_dotenv()) # read local .env file
openai.api_key = os.environ['OPENAI_API_KEY']
def get_completion(prompt, model="gpt-3.5-turbo"):
messages = [{"role": "user", "content": prompt}]
response = openai.ChatCompletion.create(
model=model,
messages=messages,
temperature=0, # this is the degree of randomness of the model's output
)
return response.choices[0].message["content"]
##################Test 1######################################
response = get_completion("What is the capital of France?")
print(response)
##############################################################
def get_completion_from_messages(messages,
model="gpt-3.5-turbo",
temperature=0,
max_tokens=500):
response = openai.ChatCompletion.create(
model=model,
messages=messages,
temperature=temperature, # this is the degree of randomness of the model's output
max_tokens=max_tokens, # the maximum number of tokens the model can ouptut
)
return response.choices[0].message["content"]
##########################Test 2#############################
messages = [
{'role':'system',
'content':"""You are an assistant who\
responds in the style of Dr Seuss."""},
{'role':'user',
'content':"""write me a very short poem\
about a happy carrot"""},
]
response = get_completion_from_messages(messages, temperature=1)
print(response)
###############################################################
pn.extension()
panels = []
context = [ {'role':'system', 'content':"""
You are a chatbot designed to answer questions about the UCI HyperXite team. The UCI HyperXite team is building a\
scalable hyperloop. Introduce yourself as a bot that will help the user know more about HyperXite. Provide concise answers. Tone: friendly\
and resepctful. Keep it conversational.
Introduce yourself as "Hi, do you have any questions about HyperXite?" Also list out a few questions the user could ask\
Format the list properly.
The team is using a linear induction motor for propulsion. The pod can be controlled from a custom Graphical User Interface\
built by the team.
"""} ] # can be fine tuned further
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