A Python package for integrating Pica with LangChain.
Full Documentation: https://docs.picaos.com/sdk/langchain
pip install pica-langchain
The PicaClientOptions
class allows you to configure the Pica client with the following options:
Option | Type | Required | Default | Description |
---|---|---|---|---|
server_url | str | No | https://api.picaos.com | URL for self-hosted Pica server. |
connectors | List[str] | No | All available connectors | List of connector keys to give the LLM access to. If not provided, all available connectors will be initialized. |
The create_pica_agent
function allows customizing the following parameters:
Option | Type | Required | Default | Description |
---|---|---|---|---|
verbose | bool | No | False | Whether to print verbose logs. |
system_prompt | str | No | None | A custom system prompt to append to the default system prompt. |
agent_type | AgentType | No | OPENAI_FUNCTIONS | The type of agent to create. |
tools | List[BaseTool] | No | None | A list of tools to use in the agent. |
from langchain_openai import ChatOpenAI
from langchain.agents import AgentType
from pica_langchain import PicaClient, create_pica_agent
from pica_langchain.models import PicaClientOptions
# Initialize the Pica client
pica_client = PicaClient(secret="your-pica-secret")
# Create a LangChain agent with Pica tools
llm = ChatOpenAI(
temperature=0,
model="gpt-4o"
)
# Create an agent with Pica tools
agent = create_pica_agent(
client=pica_client,
llm=llm,
agent_type=AgentType.OPENAI_FUNCTIONS,
# Optional: Custom system prompt to append
system_prompt="Always start your response with `Pica works like ✨\n`"
)
# Use the agent
result = agent.invoke({
"input": (
"Star the picahq/pica repo in github. "
"Then, list 5 of the repositories that I have starred in github."
)
})
print(result)
from langchain.agents import AgentType, initialize_agent
from langchain_openai import ChatOpenAI
from pica_langchain import PicaClient, create_pica_tools
# Initialize the Pica client
pica_client = PicaClient(secret="your-pica-secret")
# Create Pica tools
tools = create_pica_tools(pica_client)
# Create a custom agent with the tools
llm = ChatOpenAI(temperature=0, model="gpt-4o")
agent = initialize_agent(
tools,
llm,
agent=AgentType.OPENAI_FUNCTIONS,
verbose=True
)
# Use the agent
result = agent.run("What actions are available in Gmail?")
print(result)
- Clone the repository:
git clone https://github.com/yourusername/pica-langchain.git
cd pica-langchain
- Create and activate a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
- Create a connection on Pica:
1. Create an account on app.picaos.com.
2. Navigate to the "My Connections" tab and create the required connection.
3. Retrieve your API Key from the "API Keys" section.
- Export required environment variables:
export PICA_SECRET="your-pica-secret"
export OPENAI_API_KEY="your-openai-api-key"
- Install development dependencies:
pip install -e ".[dev]"
pytest
The Pica LangChain SDK uses the logging
module to log messages. The log level can be set using the PICA_LOG_LEVEL
environment variable.
The following log levels are available:
debug
info
warning
error
critical
export PICA_LOG_LEVEL="debug"
Examples can be found in the examples directory.
> python3 examples/use_with_langchain.py # LangChain agent example
This project is licensed under the GNU General Public License v3.0.