Skip to content

Commit

Permalink
Fixing issue with format code snippets pipeline (#412)
Browse files Browse the repository at this point in the history
* testing workflow trigger

* testing workflow trigger

* testing workflow trigger

* testing workflow trigger

* testing workflow trigger

* testing workflow trigger

* reformat python code examples

---------

Co-authored-by: Max Shkutnyk <[email protected]>
  • Loading branch information
invader89 and Max Shkutnyk authored Feb 18, 2025
1 parent 8374c65 commit 05b391d
Show file tree
Hide file tree
Showing 14 changed files with 304 additions and 370 deletions.
9 changes: 3 additions & 6 deletions .github/workflows/check-python-code-snippets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,8 @@ jobs:
run: |
git diff --exit-code || echo "::set-output name=changes::true"
- name: Commit and Push Changes
- name: Fail if changes are detected
if: steps.diff.outputs.changes == 'true'
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git add -u
git commit -m "Format Python snippets in MDX files"
git push
echo "Changes in python code snippets are detected. Please run check-python-code-snippets locally and commit the changes."
exit 1
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ The only difference between using Cohere's models on private deployments and the
import cohere

co = cohere.Client(
api_key="", # Leave this blank
base_url="<YOUR_DEPLOYMENT_URL>"
api_key="", base_url="<YOUR_DEPLOYMENT_URL>" # Leave this blank
)
```

Expand Down
24 changes: 9 additions & 15 deletions fern/pages/get-started/quickstart/rag-quickstart.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ Next, import the library and create a client.
```python PYTHON
import cohere

co = cohere.Client("COHERE_API_KEY") # Get your free API key here: https://dashboard.cohere.com/api-keys
co = cohere.Client(
"COHERE_API_KEY"
) # Get your free API key here: https://dashboard.cohere.com/api-keys
```

</Tab>
Expand All @@ -39,8 +41,7 @@ co = cohere.Client("COHERE_API_KEY") # Get your free API key here: https://dashb
import cohere

co = cohere.Client(
api_key="", # Leave this blank
base_url="<YOUR_DEPLOYMENT_URL>"
api_key="", base_url="<YOUR_DEPLOYMENT_URL>" # Leave this blank
)
```

Expand Down Expand Up @@ -118,7 +119,7 @@ message = "Are there fitness-related benefits?"
response = co.chat(
model="command-r-plus-08-2024",
message=message,
documents=documents
documents=documents,
)

print(response.text)
Expand All @@ -132,7 +133,7 @@ message = "Are there fitness-related benefits?"
response = co.chat(
model="command-r-plus-08-2024",
message=message,
documents=documents
documents=documents,
)

print(response.text)
Expand All @@ -144,9 +145,7 @@ print(response.text)
message = "Are there fitness-related benefits?"

response = co.chat(
model="YOUR_MODEL_NAME",
message=message,
documents=documents
model="YOUR_MODEL_NAME", message=message, documents=documents
)

print(response.text)
Expand All @@ -158,9 +157,7 @@ print(response.text)
message = "Are there fitness-related benefits?"

response = co.chat(
model="YOUR_ENDPOINT_NAME",
message=message,
documents=documents
model="YOUR_ENDPOINT_NAME", message=message, documents=documents
)

print(response.text)
Expand All @@ -171,10 +168,7 @@ print(response.text)
```python PYTHON
message = "Are there fitness-related benefits?"

response = co.chat(
message=message,
documents=documents
)
response = co.chat(message=message, documents=documents)

print(response.text)
```
Expand Down
30 changes: 9 additions & 21 deletions fern/pages/get-started/quickstart/reranking-quickstart.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ Next, import the library and create a client.
```python PYTHON
import cohere

co = cohere.Client("COHERE_API_KEY") # Get your free API key here: https://dashboard.cohere.com/api-keys
co = cohere.Client(
"COHERE_API_KEY"
) # Get your free API key here: https://dashboard.cohere.com/api-keys
```

</Tab>
Expand All @@ -36,8 +38,7 @@ co = cohere.Client("COHERE_API_KEY") # Get your free API key here: https://dashb
import cohere

co = cohere.Client(
api_key="", # Leave this blank
base_url="<YOUR_DEPLOYMENT_URL>"
api_key="", base_url="<YOUR_DEPLOYMENT_URL>" # Leave this blank
)
```

Expand All @@ -62,10 +63,7 @@ co = cohere.SagemakerClient(
```python PYTHON
import cohere

co = cohere.Client(
api_key="AZURE_API_KEY",
base_url="AZURE_ENDPOINT"
)
co = cohere.Client(api_key="AZURE_API_KEY", base_url="AZURE_ENDPOINT")
```
</Tab>

Expand Down Expand Up @@ -96,10 +94,7 @@ query = "Are there fitness-related perks?"

# Rerank the documents
results = co.rerank(
model="rerank-v3.5",
query=query,
documents=documents,
top_n=2
model="rerank-v3.5", query=query, documents=documents, top_n=2
)

for result in results.results:
Expand All @@ -114,10 +109,7 @@ query = "Are there fitness-related perks?"

# Rerank the documents
results = co.rerank(
model="rerank-v3.5",
query=query,
documents=documents,
top_n=2
model="rerank-v3.5", query=query, documents=documents, top_n=2
)

for result in results.results:
Expand All @@ -135,7 +127,7 @@ results = co.rerank(
model="YOUR_ENDPOINT_NAME",
query=query,
documents=documents,
top_n=2
top_n=2,
)

for result in results.results:
Expand All @@ -149,11 +141,7 @@ for result in results.results:
query = "Are there fitness-related perks?"

# Rerank the documents
results = co.rerank(
query=query,
documents=documents,
top_n=2
)
results = co.rerank(query=query, documents=documents, top_n=2)

for result in results.results:
print(result)
Expand Down
38 changes: 20 additions & 18 deletions fern/pages/get-started/quickstart/sem-search-quickstart.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ Next, import the library and create a client.
```python PYTHON
import cohere

co = cohere.Client("COHERE_API_KEY") # Get your free API key here: https://dashboard.cohere.com/api-keys
co = cohere.Client(
"COHERE_API_KEY"
) # Get your free API key here: https://dashboard.cohere.com/api-keys
```

</Tab>
Expand All @@ -38,8 +40,7 @@ co = cohere.Client("COHERE_API_KEY") # Get your free API key here: https://dashb
import cohere

co = cohere.Client(
api_key="", # Leave this blank
base_url="<YOUR_DEPLOYMENT_URL>"
api_key="", base_url="<YOUR_DEPLOYMENT_URL>" # Leave this blank
)
```

Expand Down Expand Up @@ -81,8 +82,7 @@ co = cohere.SagemakerClient(
import cohere

co = cohere.Client(
api_key="AZURE_API_KEY_COMMAND",
base_url="AZURE_ENDPOINT_COMMAND"
api_key="AZURE_API_KEY_COMMAND", base_url="AZURE_ENDPOINT_COMMAND"
)
```
</Tab>
Expand All @@ -107,7 +107,7 @@ doc_emb = co.embed(
model="embed-english-v3.0",
input_type="search_document",
texts=documents,
embedding_types=["float"]
embedding_types=["float"],
).embeddings.float
```
</Tab>
Expand All @@ -126,7 +126,7 @@ doc_emb = co.embed(
model="embed-english-v3.0",
input_type="search_document",
texts=documents,
embedding_types=["float"]
embedding_types=["float"],
).embeddings.float
```
</Tab>
Expand All @@ -145,7 +145,7 @@ doc_emb = co.embed(
model="YOUR_MODEL_NAME",
input_type="search_document",
texts=documents,
embedding_types=["float"]
embedding_types=["float"],
).embeddings.float
```
</Tab>
Expand All @@ -164,7 +164,7 @@ doc_emb = co.embed(
model="YOUR_ENDPOINT_NAME",
input_type="search_document",
texts=documents,
embedding_types=["float"]
embedding_types=["float"],
).embeddings.float
```
</Tab>
Expand All @@ -182,7 +182,7 @@ documents = [
doc_emb = co.embed(
input_type="search_document",
texts=documents,
embedding_types=["float"]
embedding_types=["float"],
).embeddings.float
```
</Tab>
Expand All @@ -202,7 +202,7 @@ query_emb = co.embed(
model="embed-english-v3.0",
input_type="search_query",
texts=[query],
embedding_types=["float"]
embedding_types=["float"],
).embeddings.float
```
</Tab>
Expand All @@ -217,7 +217,7 @@ query_emb = co.embed(
model="embed-english-v3.0",
input_type="search_query",
texts=[query],
embedding_types=["float"]
embedding_types=["float"],
).embeddings.float
```
</Tab>
Expand All @@ -232,7 +232,7 @@ query_emb = co.embed(
model="YOUR_MODEL_NAME",
input_type="search_query",
texts=[query],
embedding_types=["float"]
embedding_types=["float"],
).embeddings.float
```
</Tab>
Expand All @@ -247,7 +247,7 @@ query_emb = co.embed(
model="YOUR_ENDPOINT_NAME",
input_type="search_query",
texts=[query],
embedding_types=["float"]
embedding_types=["float"],
).embeddings.float
```
</Tab>
Expand All @@ -261,7 +261,7 @@ query = "Ways to connect with my teammates"
query_emb = co.embed(
input_type="search_query",
texts=[query],
embedding_types=["float"]
embedding_types=["float"],
).embeddings.float
```
</Tab>
Expand All @@ -274,17 +274,19 @@ Then, perform semantic search by computing the similarity between the query embe
```python PYTHON
import numpy as np


# Compute dot product similarity and display results
def return_results(query_emb, doc_emb, documents):
n = 2 # customize your top N results
n = 2 # customize your top N results
scores = np.dot(query_emb, np.transpose(doc_emb))[0]
max_idx = np.argsort(-scores)[:n]

for rank, idx in enumerate(max_idx):
print(f"Rank: {rank+1}")
print(f"Score: {scores[idx]}")
print(f"Document: {documents[idx]}\n")



return_results(query_emb, doc_emb, documents)
```
```mdx wordWrap
Expand Down
Loading

0 comments on commit 05b391d

Please sign in to comment.