Cogniswitch Toolkit
CogniSwitch is used to build production ready applications that can consume, organize and retrieve knowledge flawlessly. Using the framework of your choice, in this case Langchain, CogniSwitch helps alleviate the stress of decision making when it comes to, choosing the right storage and retrieval formats. It also eradicates reliability issues and hallucinations when it comes to responses that are generated.
Setupโ
Visit this page to register a Cogniswitch account.
-
Signup with your email and verify your registration
-
You will get a mail with a platform token and oauth token for using the services.
%pip install -qU langchain-community
Import necessary librariesโ
import warnings
warnings.filterwarnings("ignore")
import os
from langchain.agents.agent_toolkits import create_conversational_retrieval_agent
from langchain_community.agent_toolkits import CogniswitchToolkit
from langchain_openai import ChatOpenAI
Cogniswitch platform token, OAuth token and OpenAI API keyโ
cs_token = "Your CogniSwitch token"
OAI_token = "Your OpenAI API token"
oauth_token = "Your CogniSwitch authentication token"
os.environ["OPENAI_API_KEY"] = OAI_token
Instantiate the cogniswitch toolkit with the credentialsโ
cogniswitch_toolkit = CogniswitchToolkit(
cs_token=cs_token, OAI_token=OAI_token, apiKey=oauth_token
)
Get the list of cogniswitch toolsโ
tool_lst = cogniswitch_toolkit.get_tools()
Instantiate the LLMโ
llm = ChatOpenAI(
temperature=0,
openai_api_key=OAI_token,
max_tokens=1500,
model_name="gpt-3.5-turbo-0613",
)
Use the LLM with the Toolkitโ
Create an agent with the LLM and Toolkitโ
agent_executor = create_conversational_retrieval_agent(llm, tool_lst, verbose=False)
Invoke the agent to upload a URLโ
response = agent_executor.invoke("upload this url https://cogniswitch.ai/developer")
print(response["output"])
The URL https://cogniswitch.ai/developer has been uploaded successfully. The status of the document is currently being processed. You will receive an email notification once the processing is complete.
Invoke the agent to upload a Fileโ
response = agent_executor.invoke("upload this file example_file.txt")
print(response["output"])
The file example_file.txt has been uploaded successfully. The status of the document is currently being processed. You will receive an email notification once the processing is complete.
Invoke the agent to get the status of a documentโ
response = agent_executor.invoke("Tell me the status of this document example_file.txt")
print(response["output"])
The status of the document example_file.txt is as follows:
- Created On: 2024-01-22T19:07:42.000+00:00
- Modified On: 2024-01-22T19:07:42.000+00:00
- Document Entry ID: 153
- Status: 0 (Processing)
- Original File Name: example_file.txt
- Saved File Name: 1705950460069example_file29393011.txt
The document is currently being processed.