Skip to content

Commit

Permalink
Create hx_transformer_it1.py
Browse files Browse the repository at this point in the history
This is the first raw file for the HyperXite transformer, model can be  fine tuned hereon and can use LangChain with a larger context window and data interactions.
  • Loading branch information
SM-dot authored Feb 7, 2024
0 parents commit bad2d27
Showing 1 changed file with 87 additions and 0 deletions.
87 changes: 87 additions & 0 deletions hx_transformer_iteration_1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#!/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

0 comments on commit bad2d27

Please sign in to comment.