-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
62 lines (47 loc) · 1.46 KB
/
main.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
53
54
55
56
57
58
59
60
61
62
import streamlit as st
import os
from langchain.llms import OpenAI
from langchain.agents import AgentExecutor, AgentType, initialize_agent, load_tools # type: ignore
from langchain.tools import BaseTool
from typing import List
def main():
st.title("Fraud Sheild")
search = st.text_input("Identify Financial Faudulent News")
if st.button("Search"):
res = fraud(search)
if res == "Scam":
st.error(res)
else:
st.success(res)
def fraud(search):
# Create a new instance of the OpenAI class
llm = OpenAI(
openai_api_key=st.secrets["OPENAI_API_KEY"],
max_tokens=200,
temperature=0,
client=None,
model="text-davinci-003",
frequency_penalty=1,
presence_penalty=0,
top_p=1,
)
# Load the tools
tools: List[BaseTool] = load_tools(["google-serper"], llm=llm)
# Create a new instance of the AgentExecutor class
agent: AgentExecutor = initialize_agent(
tools=tools,
llm=llm,
agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
verbose=False,
)
# Create the template
# Give your own prompt with variable as template
# Generate the response
response: str = agent.run(template.format(topic=search))
# Print the response
print(response)
# # Convert the response to a dictionary
# result = json.loads(response)
return response
if __name__ == "__main__":
main()