Skip to content

Commit 251011f

Browse files
committed
simple chatgpt by using python and node.js
1 parent 87000e9 commit 251011f

27 files changed

+4821
-0
lines changed

Streamlit-AI-chatbot/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
myvenv
2+
.env

Streamlit-AI-chatbot/.sample.env

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
OPENAI_API_KEY=""
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"[python]": {
3+
"editor.defaultFormatter": "ms-python.autopep8"
4+
},
5+
"python.formatting.provider": "none"
6+
}

Streamlit-AI-chatbot/Readme.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Build Your Own Chatbot 🤖 with openAI GPT-3 and Streamlit 🎈
2+
3+
<img src = "https://miro.medium.com/v2/resize:fit:720/1*XOoI8eWNTRAPyrFHCiXPNg.gif" width = "100%"/>
4+

Streamlit-AI-chatbot/app.py

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import openai
2+
import streamlit as st
3+
4+
from decouple import config
5+
from streamlit_chat import message
6+
7+
OPENAI_API_KEY = config('OPENAI_API_KEY')
8+
9+
10+
openai.api_key = st.secrets[OPENAI_API_KEY]
11+
12+
13+
def generate_response(prompt):
14+
completions = openai.Completion.create(
15+
engine="text-davinci-003",
16+
prompt=prompt,
17+
max_tokens=1024,
18+
n=1,
19+
stop=None,
20+
temperature=0.5
21+
)
22+
message = completions.choice[0].text
23+
return message
24+
25+
26+
st.title("chatBot : Streamlit + openAI")
27+
28+
if 'generated' not in st.session_state:
29+
st.session_state['generated'] = []
30+
31+
if 'past' not in st.session_state:
32+
st.session_state['past'] = []
33+
34+
35+
def get_text():
36+
input_text = st.text_input("You: ", "Hello, how are you?", key="input")
37+
return input_text
38+
39+
40+
user_input = get_text()
41+
42+
43+
if user_input:
44+
output = generate_response(user_input)
45+
46+
st.session_state.past.append(user_input)
47+
st.session_state.generated.append(output)
48+
49+
if st.session_state['generated']:
50+
51+
for i in range(len(st.session_state['generated'])-1, -1, -1):
52+
message(st.session_state["generated"][i], key=str(i))
53+
message(st.session_state['past'][i],
54+
is_user=True, key=str(i) + '_user')

nodejs-chatgpt-tutorial/Readme.md

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/node_modules
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { Configuration, OpenAIApi } from "openai";
2+
import express from "express";
3+
import bodyParser from "body-parser";
4+
import cors from "cors";
5+
6+
const app = express();
7+
const port = 8000;
8+
app.use(bodyParser.json());
9+
app.use(cors());
10+
11+
const configuration = new Configuration({
12+
organization: "org-kjnKvGjJOhuoqiN9NjAL7PyD",
13+
apiKey: "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",
14+
});
15+
const openai = new OpenAIApi(configuration);
16+
17+
app.post("/", async (request, response) => {
18+
const { chats } = request.body;
19+
20+
const result = await openai.createChatCompletion({
21+
model: "gpt-3.5-turbo",
22+
messages: [
23+
{
24+
role: "system",
25+
content: "You are a EbereGPT. You can help with graphic design tasks",
26+
},
27+
...chats,
28+
],
29+
});
30+
31+
response.json({
32+
output: result.data.choices[0].message,
33+
});
34+
});
35+
36+
app.listen(port, () => {
37+
console.log(`listening on port ${port}`);
38+
});

0 commit comments

Comments
 (0)