justmichaelaj commited on
Commit
d7e67f6
·
1 Parent(s): 9f337b2

Upload 6 files

Browse files
Files changed (6) hide show
  1. Constants.py +1 -0
  2. Stbotchainlit.py +90 -0
  3. chainlit.md +10 -0
  4. chainlitstbot.py +27 -0
  5. michaelajayi.jpg +0 -0
  6. stbot.py +145 -0
Constants.py ADDED
@@ -0,0 +1 @@
 
 
1
+ API_KEY = "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"
Stbotchainlit.py ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from langchain import PromptTemplate, LLMChain
2
+ from langchain import OpenAI, LLMMathChain, SerpAPIWrapper
3
+ from langchain.agents import initialize_agent, Tool, AgentExecutor
4
+ from langchain.chat_models import ChatOpenAI
5
+ import os
6
+ import chainlit as cl
7
+ from langchain.chat_models import ChatOpenAI
8
+ from langchain.agents import load_tools, initialize_agent, AgentType
9
+ import os
10
+ from langchain.chat_models import ChatOpenAI
11
+ from langchain.agents import initialize_agent
12
+ from langchain.agents import AgentType
13
+ import os
14
+ from langchain.tools import ShellTool
15
+ from langchain.tools import YouTubeSearchTool
16
+ from langchain.agents import initialize_agent, Tool
17
+ from langchain.agents import AgentType
18
+ from langchain.llms import OpenAI
19
+ from langchain import LLMMathChain, SerpAPIWrapper
20
+ import os
21
+ from chainlit.types import AskFileResponse
22
+ import chainlit as cl
23
+ from langchain.chat_models import ChatOpenAI
24
+ from langchain.chains import RetrievalQAWithSourcesChain
25
+ from langchain.vectorstores import Chroma
26
+ from langchain.embeddings.openai import OpenAIEmbeddings
27
+ from langchain.text_splitter import RecursiveCharacterTextSplitter
28
+ from langchain.document_loaders import PyPDFLoader, TextLoader
29
+ import os
30
+ import openai
31
+
32
+
33
+ os.environ['OPENAI_API_KEY'] = "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"
34
+ OpenAI.api_key = "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"
35
+
36
+
37
+ template = """Question: {question}
38
+ Answer: Let's think step by step."""
39
+
40
+
41
+ @cl.langchain_factory(use_async=True)
42
+ def factory():
43
+ prompt = PromptTemplate(template=template, input_variables=["question"])
44
+ llm_chain = LLMChain(prompt=prompt, llm=ChatOpenAI(
45
+ temperature=0, streaming=True))
46
+ return llm_chain
47
+
48
+
49
+ def get_gpt_output(user_message):
50
+ response = openai.ChatCompletion.create(
51
+ model="gpt-4",
52
+ messages=[
53
+ {"role": "system", "content": "you are an writer that is obsessed with storytelling and will never stop talking about it"},
54
+ {"role": "user", "content": user_message}
55
+ ],
56
+ temperature=1,
57
+ max_tokens=256,
58
+ top_p=1,
59
+ frequency_penalty=0,
60
+ presence_penalty=0
61
+ )
62
+
63
+ return response
64
+
65
+
66
+ @cl.on_message
67
+ async def main(message: str):
68
+ await cl.Message(content=f"{get_gpt_output(message)['choices'][0]['message']['content']}",).send()
69
+
70
+
71
+ #! pip install youtube_search
72
+ tool = YouTubeSearchTool()
73
+
74
+ tools = [
75
+ Tool(
76
+ name="Search",
77
+ func=tool.run,
78
+ description="useful for when you need to give links to youtube videos. Remember to put https://youtube.com/ in front of every link to complete it",
79
+ )
80
+ ]
81
+
82
+
83
+ agent = initialize_agent(
84
+ tools,
85
+ OpenAI(temperature=0),
86
+ agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
87
+ verbose=True,
88
+ )
89
+
90
+ agent.run('Whats a good vido on the topic of dialogue')
chainlit.md ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ # Hey Welcome to Mike's Storytelling 101! 🚀🤖
2
+
3
+ Hi there, Writer! 👋 I'm excited to have you on board. This chatbot is a powerful tool designed to help you write, format and share stories built from the ground up.
4
+
5
+ ## Useful Links 🔗
6
+
7
+ - **YouTube Video:** Get started with watching some of these videos [YouTube Channel](https://www.youtube.com/@TylerMowery)
8
+ - **X Community:** Join friendly communities like [Sudowrite X](https://twitter.com/sudowrite?lang=en) to ask questions, share your projects, and connect with other writers! 💬
9
+
10
+ We can't wait to see what you create with this chatbot! Happy writing! 💻😊
chainlitstbot.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import chainlit as cl
2
+ import openai
3
+ import os
4
+
5
+ openai.api_key = "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"
6
+
7
+
8
+ def get_gpt_output(user_message):
9
+ response = openai.ChatCompletion.create(
10
+ model="gpt-4",
11
+ messages=[
12
+ {"role": "system", "content": "you are an writer that is obsessed with storytelling and will never stop talking about them"},
13
+ {"role": "user", "content": user_message}
14
+ ],
15
+ temperature=1,
16
+ max_tokens=1024,
17
+ top_p=1,
18
+ frequency_penalty=1,
19
+ presence_penalty=1
20
+ )
21
+
22
+ return response
23
+
24
+
25
+ @cl.on_message
26
+ async def main(message: str):
27
+ await cl.Message(content=f"{get_gpt_output(message)['choices'][0]['message']['content']}",).send()
michaelajayi.jpg ADDED
stbot.py ADDED
@@ -0,0 +1,145 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import Constants
3
+ import sys
4
+ import openai
5
+ from PyQt5.QtCore import Qt
6
+ from PyQt5.QtGui import QPixmap
7
+ from PyQt5.QtWidgets import (
8
+ QApplication,
9
+ QWidget,
10
+ QLabel,
11
+ QLineEdit,
12
+ QPushButton,
13
+ QVBoxLayout,
14
+ QHBoxLayout,
15
+ QGroupBox,
16
+ QTextEdit
17
+ )
18
+
19
+ openai.api_key = Constants.API_KEY
20
+
21
+
22
+ class MainWindow(QWidget):
23
+ def __init__(self):
24
+ super().__init__()
25
+ self.init_ui()
26
+
27
+ def init_ui(self):
28
+ self.logo_label = QLabel()
29
+ self.logo_pixmap = QPixmap('michaelajayi.jpg').scaled(
30
+ 500, 500, Qt.KeepAspectRatio, Qt.SmoothTransformation)
31
+ self.logo_label.setPixmap(self.logo_pixmap)
32
+
33
+ self.input_label = QLabel('Ask Something')
34
+ self.input_field = QLineEdit()
35
+ self.input_field.setPlaceholderText('Type here...')
36
+ self.answer_label = QLabel('Answer:')
37
+ self.answer_field = QTextEdit()
38
+ self.answer_field.setReadOnly(True)
39
+ self.sumbit_button = QPushButton('Sumbit')
40
+ self.sumbit_button.setStyleSheet(
41
+ """
42
+ QPushButton {
43
+ background-color: #2F3540;
44
+ border: none;
45
+ color: white;
46
+ padding: 15px 32px;
47
+ font-size: 18px;
48
+ font-weight: bold;
49
+ border-radius: 25px;
50
+ }
51
+ QpushButton:hover {
52
+ background-color: #3e8e41;
53
+ }
54
+ """
55
+
56
+ )
57
+ self.recommended_questions_group = QGroupBox('Recommended Questions')
58
+ self.recommended_questions_layout = QVBoxLayout()
59
+ self.recommended_questions = ["What is the four corner opposition?",
60
+ "How do I become a better storyteller?", "What are some popular ways to get better at writting?"]
61
+ self.question_buttons = []
62
+
63
+ # Create a layout
64
+ layout = QVBoxLayout()
65
+ layout.setContentsMargins(20, 20, 20, 20)
66
+ layout.setSpacing(50)
67
+ layout.setAlignment(Qt.AlignCenter)
68
+
69
+ # Add Logo
70
+ layout.addWidget(self.logo_label, alignment=Qt.AlignCenter)
71
+
72
+ # Add Input Field and Sumbit Button
73
+ input_layout = QHBoxLayout()
74
+ input_layout.addWidget(self.input_label)
75
+ input_layout.addWidget(self.input_field)
76
+ input_layout.addWidget(self.sumbit_button)
77
+ layout.addLayout(input_layout)
78
+
79
+ # Add Answer Field
80
+ layout.addWidget(self.answer_label)
81
+ layout.addWidget(self.answer_field)
82
+
83
+ # add the recommended questions buttons
84
+ for question in self.recommended_questions:
85
+ button = QPushButton(question)
86
+ button.setStyleSheet(
87
+ """
88
+ QPushButton {
89
+ background-color: #FFFFFF:
90
+ border: 2px solid #00AEFF;
91
+ colour: #00AEFF;
92
+ padding: 10px 20px;
93
+ font-size: 30px;
94
+ font-weight: bold;
95
+ border-radius: 5px;
96
+ }
97
+ QPushButton:hover {
98
+ background-color: #00AEFF;
99
+ color: #FFFFFF;
100
+ }"""
101
+ )
102
+ button.clicked.connect(
103
+ lambda _, q=question: self.input_field.setText(q))
104
+ self.recommended_questions_layout.addWidget(button)
105
+ self.question_buttons.append(button)
106
+ self.recommended_questions_group.setLayout(
107
+ self.recommended_questions_layout)
108
+ layout.addWidget(self.recommended_questions_group)
109
+
110
+ # Set the layout
111
+ self.setLayout(layout)
112
+
113
+ # Set the window properties
114
+ self.setWindowTitle('Storyteller Writer Advisor Bot')
115
+ self.setGeometry(200, 200, 600, 600)
116
+
117
+ # Connect the submit button to the function which queries OpenAI's API
118
+ self.sumbit_button.clicked.connect(self.get_answer)
119
+
120
+ def get_answer(self):
121
+ question = self.input_field.text()
122
+
123
+ completion = openai.ChatCompletion.create(
124
+ model="gpt-4",
125
+ messages=[
126
+ {"role": "system", "content": "You are a Storyteller expert. Answer the follwing questions in a concise way or with bullet points."},
127
+ {"role": "user", "content": "What is the four corner opposition?"},
128
+ {"role": "assistant", "content": "A story structure writing technique that draws the lines between four leading charcters conflicts."},
129
+ {"role": "user", "content": f'{question}'}],
130
+ max_tokens=1024,
131
+ n=1,
132
+ stop=None,
133
+ temperature=1
134
+ )
135
+
136
+ answer = completion.choices[0].message.content
137
+
138
+ self.answer_field.setText(answer)
139
+
140
+
141
+ if __name__ == '__main__':
142
+ app = QApplication(sys.argv)
143
+ window = MainWindow()
144
+ window.show()
145
+ sys.exit(app.exec_())