Skip to content

Commit

Permalink
Auto-format code snippets in text-generation connectors (#310)
Browse files Browse the repository at this point in the history
Co-authored-by: Max Shkutnyk <[email protected]>
  • Loading branch information
invader89 and Max Shkutnyk authored Dec 18, 2024
1 parent e06004b commit 373b29b
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 73 deletions.
121 changes: 74 additions & 47 deletions fern/pages/text-generation/connectors/connector-authentication.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ First, start by generating a secure token. Here’s a snippet of what generating

```python PYTHON
# Generate a token
import secrets
import secrets

secrets.token_urlsafe(32)
```

Expand All @@ -55,7 +56,11 @@ curl --request POST
```
```python PYTHON
import requests
r = requests.post('{base_connector_url}/search', {'query': 'How do I expense a meal?'})

r = requests.post(
"{base_connector_url}/search",
{"query": "How do I expense a meal?"},
)
```
```typescript TYPESCRIPT
const response = await fetch('{base_connector_url}/search'{
Expand All @@ -82,9 +87,12 @@ curl --request POST
```
```python PYTHON
import requests
r = requests.post('{base_connector_url}/search',
data={'query': 'How do I expense a meal?'},
headers={"Authorization":"Bearer {Connector API key}"})

r = requests.post(
"{base_connector_url}/search",
data={"query": "How do I expense a meal?"},
headers={"Authorization": "Bearer {Connector API key}"},
)
```
```typescript TYPESCRIPT
const response = await fetch('{base_connector_url}/search'{
Expand Down Expand Up @@ -116,16 +124,17 @@ curl --request POST
}'
```
```python PYTHON
import cohere
co = cohere.Client('Your API key')
import cohere

co = cohere.Client("Your API key")
created_connector = co.create_connector(
name="test-connector",
url="http://connector-example.com/search",
service_auth={
"type": "bearer",
"token": "{Connector API Key}",
},
)
name="test-connector",
url="http://connector-example.com/search",
service_auth={
"type": "bearer",
"token": "{Connector API Key}",
},
)
```
```typescript TYPESCRIPT
const { CohereClient } = require("cohere-ai");
Expand Down Expand Up @@ -164,12 +173,16 @@ curl --request PATCH
```
```python PYTHON
import cohere

# initialize the Cohere Client with an API Key
co = cohere.Client('YOUR_API_KEY')
connectors = co.update_connector(connector_id, service_auth={
"type": "bearer",
"token": "{Connector API Key}",
})
co = cohere.Client("YOUR_API_KEY")
connectors = co.update_connector(
connector_id,
service_auth={
"type": "bearer",
"token": "{Connector API Key}",
},
)
```
```typescript TYPESCRIPT
const { CohereClient } = require("cohere-ai");
Expand Down Expand Up @@ -215,9 +228,12 @@ curl --request POST
```
```python PYTHON
import requests
r = requests.post('http://connector-example.com/search',
data={'query': 'How do I expense a meal?'},
headers={"Authorization":"Bearer {Personal/Service API key}"})

r = requests.post(
"http://connector-example.com/search",
data={"query": "How do I expense a meal?"},
headers={"Authorization": "Bearer {Personal/Service API key}"},
)
```
```typescript TYPESCRIPT
const response = await fetch('http://connector-example.com/search'{
Expand Down Expand Up @@ -265,19 +281,20 @@ curl --request POST
}'
```
```python PYTHON
import cohere
co = cohere.Client('Your API key')
import cohere

co = cohere.Client("Your API key")
created_connector = co.create_connector(
name="test-connector",
url="http://connector-example.com/search",
oauth={
"client_id": "xxx-yyy.apps.googleusercontent.com",
"client_secret": "zzz-vvv",
"authorize_url": "https://accounts.google.com/o/oauth2/auth",
"token_url": "https://oauth2.googleapis.com/token",
"scope": "https://www.googleapis.com/auth/drive.readonly"
},
)
name="test-connector",
url="http://connector-example.com/search",
oauth={
"client_id": "xxx-yyy.apps.googleusercontent.com",
"client_secret": "zzz-vvv",
"authorize_url": "https://accounts.google.com/o/oauth2/auth",
"token_url": "https://oauth2.googleapis.com/token",
"scope": "https://www.googleapis.com/auth/drive.readonly",
},
)
```
```typescript TYPESCRIPT
const { CohereClient } = require("cohere-ai");
Expand Down Expand Up @@ -322,15 +339,19 @@ curl --request PATCH
```
```python PYTHON
import cohere

# initialize the Cohere Client with an API Key
co = cohere.Client('YOUR_API_KEY')
connectors = co.update_connector(connector_id, oauth={
"client_id": "xxx-yyy.apps.googleusercontent.com",
"client_secret": "zzz-vvv",
"authorize_url": "https://accounts.google.com/o/oauth2/auth",
"token_url": "https://oauth2.googleapis.com/token",
"scope": "https://www.googleapis.com/auth/drive.readonly"
})
co = cohere.Client("YOUR_API_KEY")
connectors = co.update_connector(
connector_id,
oauth={
"client_id": "xxx-yyy.apps.googleusercontent.com",
"client_secret": "zzz-vvv",
"authorize_url": "https://accounts.google.com/o/oauth2/auth",
"token_url": "https://oauth2.googleapis.com/token",
"scope": "https://www.googleapis.com/auth/drive.readonly",
},
)
```
```typescript TYPESCRIPT
const { CohereClient } = require("cohere-ai");
Expand Down Expand Up @@ -365,11 +386,17 @@ To use pass through authentication/authorization specify the access token in the

<CodeBlocks>
```python PYTHON
import cohere
co = cohere.Client('Your API key')
response = co.chat(
message="What is the chemical formula for glucose?",
connectors=[{"id": "web-search", "user_access_token": "{Personal/Service API key}" }]
import cohere

co = cohere.Client("Your API key")
response = co.chat(
message="What is the chemical formula for glucose?",
connectors=[
{
"id": "web-search",
"user_access_token": "{Personal/Service API key}",
}
],
)
```
```curl CURL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ curl --request POST
```
```python PYTHON
import requests
r = requests.post('{base_connector_url}/search', {'query': 'How do I expense a meal?'})

r = requests.post(
"{base_connector_url}/search",
{"query": "How do I expense a meal?"},
)
```
```typescript TYPESCRIPT
const response = await fetch('{base_connector_url}/search'{
Expand Down Expand Up @@ -117,12 +121,12 @@ After you’ve deployed the connector and verified it can respond to requests, i
import cohere

# initialize the Cohere Client with an API Key
co = cohere.Client('YOUR_API_KEY')
co = cohere.Client("YOUR_API_KEY")

created_connector = co.create_connector(
name="Example connector",
url="https://connector-example.com/search",
)
name="Example connector",
url="https://connector-example.com/search",
)
```
```curl CURL
curl --request POST
Expand Down Expand Up @@ -179,7 +183,11 @@ curl --request POST
```
```python PYTHON
import requests
r = requests.post('{base_connector_url}/search', {'query': 'How do I expense a meal?'})

r = requests.post(
"{base_connector_url}/search",
{"query": "How do I expense a meal?"},
)
```
```typescript TYPESCRIPT
const response = await fetch('https://connector.example.com/search'{
Expand All @@ -198,11 +206,14 @@ In order to produce grounded generations, include your connector id in the `conn

<CodeBlocks>
```python PYTHON
import cohere
co = cohere.Client('Your API key')
response = co.chat(
message="What is the chemical formula for glucose?",
connectors=[{"id": "example_connector_id"}] # this is from the create step
import cohere

co = cohere.Client("Your API key")
response = co.chat(
message="What is the chemical formula for glucose?",
connectors=[
{"id": "example_connector_id"}
], # this is from the create step
)
```
```curl CURL
Expand Down
25 changes: 16 additions & 9 deletions fern/pages/text-generation/connectors/managing-your-connector.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ const cohere = new CohereClient({
```
```python PYTHON
import cohere

# initialize the Cohere Client with an API Key
co = cohere.Client('YOUR_API_KEY')
co = cohere.Client("YOUR_API_KEY")
connectors = co.list_connectors()
```
</CodeBlocks>
Expand Down Expand Up @@ -88,9 +89,12 @@ curl --request PATCH
```
```python PYTHON
import cohere

# initialize the Cohere Client with an API Key
co = cohere.Client('YOUR_API_KEY')
connectors = co.update_connector(connector_id, name="new name", url="new_url")
co = cohere.Client("YOUR_API_KEY")
connectors = co.update_connector(
connector_id, name="new name", url="new_url"
)
```
```typescript TYPESCRIPT
const { CohereClient } = require("cohere-ai");
Expand All @@ -115,12 +119,15 @@ Step 1: Make a streaming request to the connector using the Chat API and check t

<CodeBlocks>
```python PYTHON
import cohere
co = cohere.Client('Your API key')
response = co.chat(
message="What is the chemical formula for glucose?",
stream: True,
connectors=[{"id": "example_connector_id"}] # this is from the create step
import cohere

co = cohere.Client("Your API key")
response = co.chat(
message="What is the chemical formula for glucose?",
stream=True,
connectors=[
{"id": "example_connector_id"}
], # this is from the create step
)
```
```curl CURL
Expand Down
13 changes: 7 additions & 6 deletions fern/pages/text-generation/connectors/overview-1.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ Connectors are specified when calling the Chat endpoint, which you can read more

<CodeBlocks>
```python PYTHON
import cohere
co = cohere.Client(api_key='Your API key')
import cohere

co = cohere.Client(api_key="Your API key")

response = co.chat(
model="command-r-plus-08-2024",
message="What is the chemical formula for glucose?",
connectors=[{"id": "web-search"}]
model="command-r-plus-08-2024",
message="What is the chemical formula for glucose?",
connectors=[{"id": "web-search"}],
)
```
```curl CURL
Expand Down Expand Up @@ -76,7 +77,7 @@ response, err := client.Chat(
If you or an administrator at your organization has created a new connector, you can add this connector id to the list. Here’s an example:
```python PYTHON
connectors=[{"id": "web-search"}, {"id": "customer-connector-id"}].
connectors = [{"id": "web-search"}, {"id": "customer-connector-id"}]
```
The response will then contain the generated text with citation elements that link to the documents returned from the connector. For example, the formula `C6H12O6` below has a citation element that links to three websites.
Expand Down

0 comments on commit 373b29b

Please sign in to comment.