Skip to content

Commit

Permalink
reformat code examples from text-generation section (#342)
Browse files Browse the repository at this point in the history
Co-authored-by: Max Shkutnyk <max@lightsonsoftware.com>
  • Loading branch information
invader89 and Max Shkutnyk authored Jan 9, 2025
1 parent b6700cc commit 31d3d07
Show file tree
Hide file tree
Showing 10 changed files with 324 additions and 233 deletions.
15 changes: 12 additions & 3 deletions fern/pages/v2/text-generation/chat-api.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Every message comes with a `content` field and an associated `role`, which indic
<CodeBlocks>
```python PYTHON
import cohere

co = cohere.ClientV2(api_key="<YOUR API KEY>")

res = co.chat(
Expand All @@ -30,7 +31,8 @@ res = co.chat(
],
)

print(res.message.content[0].text) # "The Ultimate Guide to API Design: Best Practices for Building Robust and Scalable APIs"
print(res.message.content[0].text)
# "The Ultimate Guide to API Design: Best Practices for Building Robust and Scalable APIs"
```
```java JAVA
package chatv2post;
Expand Down Expand Up @@ -135,6 +137,7 @@ It is recommended to send the system message as the first element in the message

```python PYTHON
import cohere

co = cohere.ClientV2(api_key="<YOUR API KEY>")

system_message = "You respond concisely, in about 5 words or less"
Expand All @@ -160,6 +163,7 @@ A single Chat request can encapsulate multiple turns of a conversation, where ea

```python PYTHON
import cohere

co = cohere.ClientV2(api_key="<YOUR API KEY>")

system_message = "You respond concisely, in about 5 words or less"
Expand All @@ -173,10 +177,15 @@ res = co.chat(
"content": "Write a title for a blog post about API design. Only output the title text.",
},
{"role": "assistant", "content": "Designing Perfect APIs"},
{"role": "user", "content": "Another one about generative AI."},
{
"role": "user",
"content": "Another one about generative AI.",
},
],
)

print(res.message.content[0].text) # "AI: The Generative Age"
# "AI: The Generative Age"
print(res.message.content[0].text)

```

44 changes: 24 additions & 20 deletions fern/pages/v2/text-generation/documents-and-citations.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -19,36 +19,40 @@ Here's an example of using RAG with the Chat endpoint. We're asking the `co.chat

```python PYTHON
import cohere

co = cohere.ClientV2(api_key="<YOUR API KEY>")

# Retrieve the documents
documents = [
{
"data": {
"title": "Tall penguins",
"snippet": "Emperor penguins are the tallest."
}
},
{
"data": {
"title": "Penguin habitats",
"snippet": "Emperor penguins only live in Antarctica."
}
},
{
"data": {
"title": "What are animals?",
"snippet": "Animals are different from plants."
}
}
{
"data": {
"title": "Tall penguins",
"snippet": "Emperor penguins are the tallest.",
}
},
{
"data": {
"title": "Penguin habitats",
"snippet": "Emperor penguins only live in Antarctica.",
}
},
{
"data": {
"title": "What are animals?",
"snippet": "Animals are different from plants.",
}
},
]

messages = [{'role': 'user', 'content': "Where do the tallest penguins live?"}]
messages = [
{"role": "user", "content": "Where do the tallest penguins live?"}
]

response = co.chat(
model="command-r-plus-08-2024",
documents=documents,
messages=messages)
messages=messages,
)
```

Here's an example reply:
Expand Down
Loading

0 comments on commit 31d3d07

Please sign in to comment.