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

Reformat code samples formatting for tutorials pages #379

Merged
merged 1 commit into from
Jan 23, 2025
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
7 changes: 4 additions & 3 deletions fern/pages/tutorials/build-things-with-cohere.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ Next, we'll import the `cohere` library and create a client to be used throughou
```python PYTHON
import cohere

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

# Accessing Cohere from Other Platforms
Expand Down Expand Up @@ -93,8 +94,8 @@ For further information, read this documentation on [Cohere on Azure](/docs/cohe
import cohere

co = cohere.Client(
api_key="...",
base_url="...",
api_key="...",
base_url="...",
)
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ To get started, first we need to install the `cohere` library and create a Coher

import cohere

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

## Creating a custom preamble
Expand All @@ -48,15 +49,14 @@ In the example below, the preamble provides context for the assistant's task (ta
message = "I'm joining a new startup called Co1t today. Could you help me write a short introduction message to my teammates."

# Create a custom preamble
preamble="""## Task and Context
preamble = """## Task and Context
You are an assistant who assist new employees of Co1t with their first week.

## Style Guide
Try to speak in rhymes as much as possible. Be professional."""

# Generate the response
response = co.chat(message=message,
preamble=preamble)
response = co.chat(message=message, preamble=preamble)

print(response.text)
```
Expand Down Expand Up @@ -107,12 +107,11 @@ Here, we are also adding a custom preamble for generating concise response, just
message = "I'm joining a new startup called Co1t today. Could you help me write a short introduction message to my teammates."

# Create a custom preamble
preamble="""## Task & Context
preamble = """## Task & Context
Generate concise responses, with maximum one-sentence."""

# Generate the response
response = co.chat(message=message,
preamble=preamble)
response = co.chat(message=message, preamble=preamble)

print(response.text)
```
Expand All @@ -136,9 +135,11 @@ Looking at the response, we see that the model is able to get the context from t
message = "Make it more upbeat and conversational."

# Generate the response with the current chat history as the context
response = co.chat(message=message,
preamble=preamble,
chat_history=response.chat_history)
response = co.chat(
message=message,
preamble=preamble,
chat_history=response.chat_history,
)

print(response.text)
```
Expand All @@ -157,12 +158,16 @@ You can continue doing this for any number of turns by passing the most recent `

```python PYTHON
# Add the user message
message = "Thanks. Could you create another one for my DM to my manager."
message = (
"Thanks. Could you create another one for my DM to my manager."
)

# Generate the response with the current chat history as the context
response = co.chat(message=message,
preamble=preamble,
chat_history=response.chat_history)
response = co.chat(
message=message,
preamble=preamble,
chat_history=response.chat_history,
)

print(response.text)
```
Expand All @@ -178,8 +183,8 @@ To look at the current chat history, you can print the `response.chat_history` o
```python PYTHON
# View the chat history
for turn in response.chat_history:
print("Role:",turn.role)
print("Message:",turn.message,"\n")
print("Role:", turn.role)
print("Message:", turn.message, "\n")
```

```
Expand Down
Loading
Loading