Skip to content
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

Format code snippets for text generation #244

Merged
merged 5 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,28 +34,29 @@ The code snippet below, for example, will produce a grounded answer to `"Where d

```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.",
}
}
}
]

# Add the user message
Expand All @@ -65,7 +66,8 @@ messages = [{"role": "user", "content": message}]
response = co.chat(
model="command-r-plus-08-2024",
messages=messages,
documents=documents)
documents=documents
)

print(response.message.content[0].text)

Expand Down Expand Up @@ -205,8 +207,9 @@ In the final step, we will be calling the Chat API again, but this time passing

**Request**

```py
```python
import cohere

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

documents = [
Expand Down
15 changes: 11 additions & 4 deletions fern/pages/v2/text-generation/structured-outputs-json.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,18 @@ When making an API request, you can specify the `response_format` parameter to i

```python
import cohere

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

res = co.chat(
model="command-r-plus-08-2024",
messages=[{"role": "user", "content": "Generate a JSON describing a person, with the fields 'name' and 'age'"}],
response_format={ "type": "json_object" }
model="command-r-plus-08-2024",
messages=[
{
"role": "user",
"content": "Generate a JSON describing a person, with the fields 'name' and 'age'",
}
],
response_format={"type": "json_object"}
)

print(res.message.content[0].text)
Expand Down Expand Up @@ -58,6 +64,7 @@ For example, let's say you want the LLM to generate a JSON object with specific

```python
import cohere

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

res = co.chat(
Expand All @@ -79,7 +86,7 @@ res = co.chat(
"publication_year": {"type": "integer"},
},
},
},
}
)

print(res.message.content[0].text)
Expand Down
Loading