-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlangchain_chatmodel.py
52 lines (40 loc) · 1.13 KB
/
langchain_chatmodel.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
from langchain.chat_models import ChatOpenAI
from apikey import OPEN_AI_KEY
from langchain.prompts.chat import (
ChatPromptTemplate,
SystemMessagePromptTemplate,
AIMessagePromptTemplate,
HumanMessagePromptTemplate
)
from langchain.schema import AIMessage,HumanMessage,SystemMessage
from flask import Flask,request,render_template
app = Flask(__name__)
#chat model intialization
chat = ChatOpenAI(
temperature = 0.7,
openai_api_key = OPEN_AI_KEY,
openai_organization = ORG_KEY
)
# function for the prompt and user_input
def user(prompt):
messages = [
SystemMessage(
content = "You're the CEO of AdvantageAI, startup which provides AI services and SMM"
),
HumanMessage(
content = prompt
)
]
# returns the message as CEO of AdvantageAI
response = chat(messages)
return response.content
# API routes
@app.route("/")
def index():
return render_template('index.html')
@app.route("/ask",methods=['POST'])
def ask():
user_input = request.form['user_input']
return user(user_input)
if __name__ == "__main__":
app.run(debug=True)