-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchat_gpt.py
25 lines (22 loc) · 883 Bytes
/
chat_gpt.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
import os
from dotenv import load_dotenv
from langchain_openai import ChatOpenAI
# Setting up tokens
gpt_token = os.getenv('OPENAI_API_KEY')
def chat_gpt():
# # Adding Prompts ----------------------------------------------------------
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.output_parsers import StrOutputParser
#
inputt = input('what is ur question > ')
output_parser = StrOutputParser() # stringify the answer
llm = ChatOpenAI(model_name="gpt-3.5-turbo", openai_api_key=gpt_token)
prompt = ChatPromptTemplate.from_messages([
("system", "Be really rude and long in answers, but give the answer really shortlt in the end"),
("user", "{inputt}")
])
chain = prompt | llm | output_parser
answer = chain.invoke({f"inputt": inputt})
# print(answer)
return answer
# print(chat_gpt())