|
import openai |
|
import langchain |
|
|
|
from langchain.agents import Tool, ConversationalAgent, AgentExecutor, load_tools, tool |
|
from langchain import OpenAI, LLMChain, LLMMathChain |
|
from langchain.chains.conversation.memory import ConversationBufferMemory, ConversationBufferWindowMemory |
|
|
|
from duckduckgo_search import ddg, ddg_answers |
|
|
|
|
|
@tool ("Current Search") |
|
def ddgsearch_api(query: str) -> str: |
|
"""Searches the API for the query.""" |
|
|
|
keywords=query |
|
region = 'wt-wt' |
|
safesearch = 'off' |
|
max_results = 5 |
|
results = ddg(keywords, region=region, safesearch=safesearch, max_results=max_results) |
|
|
|
|
|
keywords=query+ ' site:hukumonline.com' |
|
region = 'wt-wt' |
|
safesearch = 'off' |
|
max_results = 5 |
|
results_ho = ddg(keywords, region=region, safesearch=safesearch, max_results=max_results) |
|
|
|
results = results_ho + results |
|
|
|
tempstr = '' |
|
for i in range(len(results)): |
|
tempstr+=("; " + results[i]['body'][:200]) |
|
return tempstr |
|
|
|
ddgsearch_api.description = "useful for when you need to answer questions about current events or the current state of the world" |
|
|
|
|
|
llm_math_chain = LLMMathChain(llm=llm, verbose=True) |
|
|
|
|
|
|
|
|
|
tools = [ |
|
ddgsearch_api, |
|
|
|
Tool( |
|
name = "Calculator", |
|
func=llm_math_chain.run, |
|
description="useful for when you need to answer questions about math" |
|
) |
|
] |
|
|
|
|
|
|
|
allowed_tools = [tool.name for tool in tools] |