Back to Llama Index

Cogniswitch

llama-index-integrations/tools/llama-index-tools-cogniswitch/examples/cogniswitch.ipynb

0.14.213.3 KB
Original Source

Cogniswitch ToolSpec

Use CogniSwitch to build production ready applications that can consume, organize and retrieve knowledge flawlessly. Using the framework of your choice, in this case LlamaIndex, 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. Get started by interacting with your knowledge in a few simple steps

visit https://www.cogniswitch.ai/developer.

Registration:

  • Signup with your email and verify your registration
  • You will get a mail with a platform token and oauth token for using the services.

Step 1: Instantiate the Cogniswitch ToolSpec:

  • Use your cogniswitch token, openAI API key, oauth token to instantiate the toolspec.

Step 2: Instantiate the Agent:

  • Instantiate the agent with the list of tools from the toolspec.

Step 3: Cogniswitch Store data:

  • Make the call to the agent by giving the file path or url to the agent input.

  • The agent will pick the tool and use the file/url and it will be processed and stored in your knowledge store.

  • You can check the status of document processing with a call to the agent. Alternatively you can also check in [cogniswitch console](- You can check the status of document processing with a call to the agent. Alternatively you can also check in cogniswitch console.

Step 4: Cogniswitch Answer:

  • Make the call to the agent by giving query as agent input.

  • You will get the answer from your knowledge as the response.

Import Required Libraries

python
import warnings

warnings.filterwarnings("ignore")

import os
python
from llama_index.tools.cogniswitch import CogniswitchToolSpec
from llama_index.agent import ReActAgent

Cogniswitch Credentials and OpenAI token

python
# cs_token = <your cogniswitch platform token>
# oauth_token = <your cogniswitch apikey>
# os.environ["OPENAI_API_KEY"] = <your OpenAI token>

Instantiate the Tool Spec

python
toolspec = CogniswitchToolSpec(cs_token=cs_token, apiKey=oauth_token)

Get the list of tools in the toolspec

python
tool_lst = toolspec.to_tool_list()

Instantiate the agent

python
agent = ReActAgent.from_tools(tool_lst)

Use the agent for storing data in cogniswitch with a single call

python
store_response = agent.chat("Upload this URL- https://cogniswitch.ai/developer")
python
print(store_response)

Use the agent for storing data from a file

python
store_response = agent.chat("Upload this file- sample_file.txt")
python
print(store_response)

Use the agent to know the document status with a single call

python
response = agent.chat("Tell me the status of Cogniswitch Developer Website")
python
print(response)
python
print(response.sources[0])

Use agent for answering with a single call

python
answer_response = agent.chat("How does cogniswitch help developers")
python
print(answer_response)