-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SharePoint Plugin added #125
Open
kart2004
wants to merge
3
commits into
sirocco-ventures:main
Choose a base branch
from
kart2004:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
from app.models.prompt import Prompt | ||
from collections import OrderedDict | ||
from app.models.request import ConnectionArgument | ||
|
||
# Plugin Metadata | ||
__version__ = '1.0.0' | ||
__plugin_name__ = 'sharepoint' | ||
__display_name__ = 'SharePoint Loader' | ||
__description__ = 'SharePoint integration for handling SharePoint data' | ||
__icon__ = '/assets/plugins/logos/sharepoint.svg' | ||
__category__ = 2 | ||
|
||
# Connection arguments | ||
__connection_args__ = OrderedDict( | ||
sharepoint_site_url=ConnectionArgument( | ||
type=4, | ||
generic_name='SharePoint Site URL', | ||
description='URL of the SharePoint site', | ||
order=1, | ||
required=True, | ||
value=None, | ||
slug="sharepoint_site_url" | ||
), | ||
client_id=ConnectionArgument( | ||
type=1, | ||
generic_name='Client ID', | ||
description='Client ID for authentication', | ||
order=2, | ||
required=True, | ||
value=None, | ||
slug="client_id" | ||
), | ||
client_secret=ConnectionArgument( | ||
type=1, | ||
generic_name='Client Secret', | ||
description='Client Secret for authentication', | ||
order=3, | ||
required=True, | ||
value=None, | ||
slug="client_secret" | ||
), | ||
tenant_id=ConnectionArgument( | ||
type=1, | ||
generic_name='Tenant ID', | ||
description='Tenant ID for SharePoint', | ||
order=4, | ||
required=False, | ||
value=None, | ||
slug="tenant_id" | ||
) | ||
) | ||
|
||
# Prompt | ||
__prompt__ = Prompt(**{ | ||
"base_prompt": "{system_prompt}{user_prompt}", | ||
"system_prompt": { | ||
"template": """ | ||
You are a Chatbot designed to answer user questions based only on the context given to you. | ||
Use the details enclosed in `[context][/context]` to generate answers. | ||
|
||
[context] | ||
{context} | ||
[/context] | ||
|
||
Adhere to these rules while generating queries: | ||
- Deliberately go through the question and context word by word to appropriately answer the question. | ||
""" | ||
}, | ||
"user_prompt": { | ||
"template": """ | ||
User question is "$question" | ||
generate a JSON in the following format without any formatting. | ||
{ | ||
"explanation": "Explain how you finalized the query using the schemas and rules provided", | ||
"operation_kind": "none", | ||
"general_message": "Answer to user question based on the context", | ||
"confidence": "confidence in 100", | ||
"main_entity": "document" | ||
} | ||
""" | ||
}, | ||
"regeneration_prompt": { | ||
"template": """ | ||
User question is "$question" | ||
generate a JSON in the following format without any formatting. | ||
{ | ||
"explanation": "Explain how you finalized the query using the schemas and rules provided", | ||
"operation_kind": "none", | ||
"general_message": "Answer to user question based on the context", | ||
"confidence": "confidence in 100", | ||
"main_entity": "document" | ||
} | ||
""" | ||
} | ||
}) | ||
|
||
__all__ = [ | ||
__version__, __plugin_name__, __display_name__, __description__, __icon__, __category__, __prompt__ | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from typing import Any, Dict | ||
from loguru import logger | ||
|
||
class Formatter: | ||
""" | ||
SharePointFormatter class to format the response based on the inference and data. | ||
""" | ||
|
||
def format(self, data: Dict[str, Any], inference: Dict[str, Any]) -> dict: | ||
""" | ||
Format the response using the given data and inference information. | ||
|
||
:param data: The data containing records to process. | ||
:param inference: Inference details including main entity and operation kind. | ||
:return: Formatted response dictionary. | ||
""" | ||
|
||
logger.info("Processing SharePoint output using inference details") | ||
|
||
response = {} | ||
self.main_entity = inference.get("main_entity", "") | ||
self.kind = inference.get("operation_kind", "") | ||
self.general_message = inference.get("general_message", "Unable to process question, try again") | ||
|
||
response["content"] = self.general_message | ||
response["main_entity"] = self.main_entity | ||
response["main_format"] = self.kind | ||
response["role"] = "assistant" | ||
|
||
return response |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
from .formatter import Formatter | ||
from loguru import logger | ||
import requests | ||
from app.base.base_plugin import BasePlugin | ||
from app.base.remote_data_plugin import RemoteDataPlugin | ||
from app.base.plugin_metadata_mixin import PluginMetadataMixin | ||
from typing import Tuple, Optional | ||
from app.readers.base_reader import BaseReader | ||
|
||
class SharePoint(BasePlugin, PluginMetadataMixin, RemoteDataPlugin, Formatter): | ||
""" | ||
SharePoint class for interacting with SharePoint data. | ||
""" | ||
|
||
def __init__(self, site_url: str, client_id: str, client_secret: str, tenant_id: str): | ||
super().__init__(__name__) | ||
|
||
self.connection = {} | ||
|
||
# SharePoint connection parameters | ||
self.params = { | ||
'site_url': site_url, | ||
'client_id': client_id, | ||
'client_secret': client_secret, | ||
'tenant_id': tenant_id, | ||
} | ||
|
||
def connect(self) -> Tuple[bool, Optional[str]]: | ||
""" | ||
Establish a connection to the SharePoint site using the provided credentials. | ||
|
||
:return: Tuple containing connection status (True/False) and an error message if any. | ||
""" | ||
logger.info("Attempting to connect to SharePoint site") | ||
|
||
try: | ||
# Mocking connection setup to SharePoint | ||
# You might need to implement OAuth authentication here to get an access token | ||
# For example, you could use Microsoft's Authentication Library (MSAL) or similar | ||
logger.info("Successfully connected to SharePoint") | ||
return True, None | ||
except Exception as e: | ||
logger.exception(f"Failed to connect to SharePoint: {str(e)}") | ||
return False, str(e) | ||
|
||
def healthcheck(self) -> Tuple[bool, Optional[str]]: | ||
""" | ||
Perform a health check by checking if the SharePoint site is accessible. | ||
|
||
:return: Tuple containing the health status (True/False) and error message (if any). | ||
""" | ||
logger.info("Performing health check for SharePoint") | ||
|
||
site_url = self.params["site_url"] | ||
|
||
try: | ||
# Replace with actual SharePoint endpoint check if necessary | ||
response = requests.get(site_url) | ||
if response.status_code == 200: | ||
logger.info("SharePoint health check passed.") | ||
return True, None | ||
else: | ||
logger.error(f"Health check failed: {response.status_code} {response.text}") | ||
return False, "Failed to connect to SharePoint site" | ||
except Exception as e: | ||
logger.exception(f"Exception during health check: {str(e)}") | ||
return False, str(e) | ||
|
||
def fetch_data(self, params=None): | ||
""" | ||
Fetch data from SharePoint using a base reader. | ||
|
||
:param params: Additional parameters for data retrieval if needed. | ||
:return: Data fetched from the SharePoint site. | ||
""" | ||
logger.info("Fetching data from SharePoint") | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Implementation is not complete |
||
base_reader = BaseReader({ | ||
"type": "sharepoint", | ||
"path": [self.params.get('site_url')] | ||
}) | ||
data = base_reader.load_data() | ||
return data |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
health check should also validate the credentials