forked from Mrinank-Bhowmick/python-beginner-projects
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchatbot.py
More file actions
51 lines (41 loc) · 1.33 KB
/
Copy pathchatbot.py
File metadata and controls
51 lines (41 loc) · 1.33 KB
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
import openai
import os
import argparse
from dotenv import load_dotenv
from langchain.llms import OpenAI
from langchain.chains import LLMChain
from langchain.prompts import PromptTemplate
from langchain.tools import YouTubeSearchTool
from langchain.tools import Tool
from langchain.agents import load_tools
from langchain.agents import initialize_agent
from langchain.utilities import SerpAPIWrapper
load_dotenv()
import ast
tool = YouTubeSearchTool()
openai.api_key = os.getenv("OPENAI_API_KEY")
os.environ["SERPAPI_API_KEY"] = os.getenv("SERPAPI_API_KEY")
tool_names = ["serpapi"]
tools = load_tools(tool_names)
youtube_url = ""
def get_message(message):
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
{"role": "user", "content": message},
],
)
response = response["choices"][0]["message"]["content"]
return response
def LLMPromptTemplate(Question, choice):
llm = OpenAI(temperature=0.8)
if choice == 2:
urls = tool.run(f"{Question}, 1")
list_ = ast.literal_eval(urls)
youtube_url = "".join(list_)
return f"www.youtube.com{youtube_url}"
else:
agent = initialize_agent(tools, llm)
return agent.run(Question)
if __name__ == "__main__":
LLMPromptTemplate