Skip to content

Instantly share code, notes, and snippets.

View Jensssen's full-sized avatar
🧐

Sören Erichsen Jensssen

🧐
View GitHub Profile
@Jensssen
Jensssen / format_instruction.py
Created May 19, 2023 13:31
LangChain Agent Format Instructions
agent_chain = initialize_agent(tools,
llm,
agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
verbose=True,
agent_kwargs={"format_instructions": "Use the following format: \n\n"
"Question: the input question you must answer \n"
"Thought: you should always think about what to do \n"
"Action: the action to take, should be one of [{tool_names}] "
"Action Input: the input to the action \n"
"Observation: the result of the action\n... "
@Jensssen
Jensssen / agent_execution.py
Created May 19, 2023 11:38
Run LangChain Agent
agent.run("Play the song Adieu of the Album Zeit from the band Rammstein!")
@Jensssen
Jensssen / agent_initialization
Created May 19, 2023 11:34
How to initialize agent in LangChain.
from langchain.agents import AgentType, initialize_agent
from langchain.llms import OpenAI
llm = OpenAI(temperature=0)
agent = initialize_agent(tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True)
@Jensssen
Jensssen / langchain_tool_definition.py
Created May 19, 2023 11:26
How to define tools in LangChain.
from langchain.agents import Tool
tools = [
Tool(
name="play_action",
func=play_a_song,
description="Useful when you want to play one song via the spotify api. "
"Try to find a single song that fits best to the prompt of the user! "
"This song should be the input to this tool in form of a comma "