A Python SDK for interacting with an Cognitive API provided by Cognitive Solutions.
Project description
Cognitive SDK
A Python SDK for interacting with the Cognitive API from Cognitive Solutions. This SDK allows you to create and manage conversations with an already defined assistant, send messages, and retrieve conversation history. The package provides a user-friendly interface for integrating assistant chat functionalities into your applications.
Features
- Assistant Instantiation: Instantiate and interact with an assistant.
- Chat Creation: Create a chat with an initial message to start a conversation.
- Message Handling: Send messages to the assistant and receive responses.
- Chat History: Retrieve the full history of a conversation.
- References Management: Retrieve additional reference information associated with messages.
Installation
To install the SDK, you can clone the repository and install it locally:
pip install -e .
Usage
Import the SDK
from cogsol import Assistant
Create an Assistant Instance
assistant = Assistant(assistant_id=7, tenant="your_tenant_id", environment="develop")
Start a Chat with an Initial Message
chat, initial_response = assistant.create_chat(initial_message="Hello, who are you?")
print("Initial Assistant Response:", initial_response)
Send Messages to the Chat
response = chat.send_message("Can you tell me more?")
print("Assistant Response:", response)
Retrieve Chat History
history = chat.history
print("Chat History:", history)
References
The Message class contains an attribute called references, which provides additional information related to the message. A Reference object includes:
- reference_num: An integer indicating the reference number.
- source: A string representing the source of the reference (e.g., a document or URL).
- showed_num: An optional integer that represents the number displayed for the reference.
This attribute is particularly useful when the assistant provides responses that include citations or links to supporting information. You can access these references as follows:
for ref in initial_response.references:
print(f"Reference Number: {ref.reference_num}, Source: {ref.source}, Showed Number: {ref.showed_num}")
Configuration
The base URLs for the assistant API can be customized via environment variables. You can set the following environment variables to specify URLs for different environments:
COGSOL_PRODUCTION_URLCOGSOL_DEVELOP_URLCOGSOL_IMPLANTATION_URLCOGSOL_TEST_URL
If not set, the SDK defaults to http://localhost:8000/cognitive for all environments.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Feel free to contribute to this project by opening issues or submitting pull requests. Make sure to follow the standard coding guidelines and include tests for new features or bug fixes.
Requirements
- Python 3.6+
- Requests library (>=2.20.0)
Install requirements using:
pip install -r requirements.txt
Example
Below is a complete example showing how to use the SDK to create a chat, send a message, get the response, and get the history:
from cogsol import Assistant
# Initialize the assistant
assistant = Assistant(assistant_id=7, tenant="your_tenant_id", environment="develop")
# Start a new chat
chat, initial_response = assistant.create_chat(initial_message="Hello, who are you?")
print("Initial Assistant Response:", initial_response)
# Print references from the initial response
for ref in initial_response.references:
print(f"Reference Number: {ref.reference_num}, Source: {ref.source}, Showed Number: {ref.showed_num}")
# Send a message to the assistant
response = chat.send_message("Can you tell me more?")
print("Assistant Response:", response)
# Get the full chat history
history = chat.history
print("Chat History:", history)
Support
For any questions or support, please open an issue on GitHub.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cogsol-0.1.1.tar.gz.
File metadata
- Download URL: cogsol-0.1.1.tar.gz
- Upload date:
- Size: 5.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
085f0f727657fe4f5665437c5ade9f04f2a88f0396a6209b0adce216b673561b
|
|
| MD5 |
16d4918bb6b204f8c3c591cca8e60679
|
|
| BLAKE2b-256 |
8c2da704bed698bbcd7a80805aa6492e038bb6515ae0b6f53c61e4b36e982b69
|
File details
Details for the file cogsol-0.1.1-py3-none-any.whl.
File metadata
- Download URL: cogsol-0.1.1-py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
67318edbd897cf168a050615fef8e78c8d3d4b1c36daae7c21a0ec1ca8e4dc54
|
|
| MD5 |
b55147194d56bdbdaeb505b82038f58a
|
|
| BLAKE2b-256 |
a7899116302f030021e179f25252e2ae3c520fe9c76dcf0012c7d287bfa713fc
|