Skip to content

Commit

Permalink
merge in main
Browse files Browse the repository at this point in the history
  • Loading branch information
walterbm-cohere committed Dec 4, 2023
2 parents 372eeea + 8ad466d commit ea4fdce
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 14 deletions.
1 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @cohere-ai/connectors
4 changes: 2 additions & 2 deletions confluence/.env-template
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
CONFLUENCE_USER=
CONFLUENCE_PASSWORD=
CONFLUENCE_API_TOKEN=
CONFLUENCE_PRODUCT_URL=https://sample.atlassian.net
CONFLUENCE_SPACE_NAME=
CONFLUENCE_SEARCH_LIMIT=10

# Connector Authorization
CONFLUENCE_CONNECTOR_API_KEY=
CONFLUENCE_CONNECTOR_API_KEY=
6 changes: 4 additions & 2 deletions confluence/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ This connector requires the following environment variables:

```
CONFLUENCE_USER
CONFLUENCE_PASSWORD
CONFLUENCE_API_TOKEN
CONFLUENCE_PRODUCT_URL
CONFLUENCE_SPACE_NAME
```

The user and password combination should be a user email address and an API token pair.
The user and api token combination should be a user email address and an API token pair.
The API token can be generated by logging into Confluence and going
to the API tokens [page](https://id.atlassian.com/manage-profile/security/api-tokens).
The product URL should be the URL for the Confluence wiki, including the https:// scheme.
The space name should be the name of a single space in your wiki.

Expand Down
4 changes: 2 additions & 2 deletions confluence/dev/load_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

confluence = Confluence(
url=os.environ.get("CONFLUENCE_PRODUCT_URL"),
username=os.environ.get("CONFLUENCE_CLIENT_USER"),
password=os.environ.get("CONFLUENCE_CLIENT_PASS"),
username=os.environ.get("CONFLUENCE_USER"),
password=os.environ.get("CONFLUENCE_API_TOKEN"),
)
space = os.environ.get("CONFLUENCE_SPACE_NAME")

Expand Down
12 changes: 7 additions & 5 deletions confluence/provider/client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import asyncio
import functools

import asyncio
from atlassian import Confluence
from flask import current_app as app

Expand All @@ -10,12 +10,12 @@


class ConfluenceClient:
def __init__(self, url, user, password, space, search_limit=10):
def __init__(self, url, user, api_token, space, search_limit=10):
try:
self.confluence = Confluence(
url=url,
username=user,
password=password,
password=api_token,
)
self.space = space
self.search_limit = search_limit
Expand Down Expand Up @@ -77,9 +77,11 @@ def get_client():

assert (url := app.config.get("PRODUCT_URL")), "CONFLUENCE_PRODUCT_URL must be set"
assert (user := app.config.get("USER")), "CONFLUENCE_USER must be set"
assert (password := app.config.get("PASSWORD")), "CONFLUENCE_PASSWORD must be set"
assert (
api_token := app.config.get("API_TOKEN")
), "CONFLUENCE_API_TOKEN must be set"
assert (space := app.config.get("SPACE_NAME")), "CONFLUENCE_SPACE_NAME must be set"
search_limit = app.config.get("SEARCH_LIMIT", 10)
client = ConfluenceClient(url, user, password, space, search_limit)
client = ConfluenceClient(url, user, api_token, space, search_limit)

return client
26 changes: 24 additions & 2 deletions gdrive/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,29 @@ The `GDRIVE_CONNECTOR_API_KEY` should contain an API key for the connector. This

When using OAuth for authentication, the connector does not require any additional environment variables. Instead, the OAuth flow should occur outside of the Connector and Cohere's API will forward the user's access token to this connector through the `Authorization` header.

To use OAuth, you must first create a Google OAuth client ID and secret. You can follow Google's [guide](https://developers.google.com/identity/protocols/oauth2/web-server#creatingcred) to get started. When creating your application use `https://api.cohere.com/v1/connectors/oauth/token` as the redirect URI.

Once your Google OAuth credentials are ready, you can register the connector in Cohere's API with the following configuration:

```bash
curl -X POST \
'https://api.cohere.ai/v1/connectors' \
--header 'Accept: */*' \
--header 'Authorization: Bearer {COHERE-API-KEY}' \
--header 'Content-Type: application/json' \
--data-raw '{
"name": "GDrive with OAuth",
"url": "{YOUR_CONNECTOR-URL}",
"oauth": {
"client_id": "{GOOGLE-OAUTH-CLIENT-ID}",
"client_secret": "{GOOGLE-OAUTH-CLIENT-SECRET}",
"authorize_url": "https://accounts.google.com/o/oauth2/auth",
"token_url": "https://oauth2.googleapis.com/token",
"scope": "https://www.googleapis.com/auth/drive.readonly"
}
}'
```

With OAuth the connector will be able to search any Google Drive folders that the user has access to.

## Optional Configuration
Expand All @@ -70,8 +93,7 @@ Create a virtual environment and install dependencies with poetry. We recommend
Next, start up the search connector server:

```bash
$ poetry shell
$ flask --app provider --debug run --port 5000
$ poetry flask --app provider --debug run --port 5000
```

and check with curl to see that everything works:
Expand Down
2 changes: 1 addition & 1 deletion gdrive/provider/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,4 @@ def search(query, access_token=None):
except HttpError as http_error:
raise UpstreamProviderError(message=str(http_error)) from http_error

return process_data_with_service(search_results, request_credentials)
return process_data_with_service(search_results, request_credentials(access_token))

0 comments on commit ea4fdce

Please sign in to comment.