Skip to content

Instantly share code, notes, and snippets.

@rajivmehtaflex
Created July 10, 2024 13:27
Show Gist options
  • Save rajivmehtaflex/4a0bb1db0a75faf4d4bd70da9fc416f4 to your computer and use it in GitHub Desktop.
Save rajivmehtaflex/4a0bb1db0a75faf4d4bd70da9fc416f4 to your computer and use it in GitHub Desktop.
Apply Live information to Agent

Here's the converted text block organized into task-wise categories in Markdown format:

Installing and Configuring Conda

- conda config --set auto_activate_base false
- conda create --name gptexp python=3.10 -y
- conda activate gptexp

Git Operations

- git clone https://github.com/searxng/searxng
- cd searxng/

Docker Operations

- make docker.build
- docker run --rm -d -p 32768:8080 -v "${PWD}/searxng:/etc/searxng" -e "BASE_URL=http://localhost:$PORT/" -e "INSTANCE_NAME=my-instance" searxng/searxng
- docker ps --all

Package Installation

- pip install -U langchain langchain-community langchain-core langchain-experimental langchain-openai langchain-text-splitters langchainhub duckdb pandas e2b_code_interpreter

File and Directory Operations

- cd langchain_with_search/
- touch server.py
- code server.py

Running Python Scripts

- /home/gitpod/miniconda3/envs/gptexp/bin/python /workspace/PythonBlankRepo/langchain_with_search/server.py
- python server.py
from langchain.prompts.chat import ChatPromptTemplate
from langchain_openai import ChatOpenAI
from langchain_community.agent_toolkits.load_tools import load_tools
from langchain.agents import AgentExecutor, create_tool_calling_agent
from langchain import hub
model=ChatOpenAI(base_url='https://llm.mdb.ai/',model='claude-3-haiku',api_key='<KEY>',temperature=0.35,max_tokens=2000)
instructions = """You are an assistant."""
base_prompt = hub.pull("langchain-ai/openai-functions-template")
prompt = base_prompt.partial(instructions=instructions)
tools = load_tools(["searx-search"],searx_host="http://localhost:32768")
agent = create_tool_calling_agent(model, tools, prompt)
agent_executor = AgentExecutor(
agent=agent,
tools=tools,
verbose=False,
)
if __name__ == "__main__":
while True:
user_input = input("Your question: ")
if user_input == "exit":
break
response=agent_executor.invoke({"input": user_input})
print(response['output'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment