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

Fix quickstart slug path #417

Closed
wants to merge 3 commits into from
Closed
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
4 changes: 2 additions & 2 deletions fern/pages/v2/get-started/quickstart/rag-quickstart.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Retrieval Augmented Generation (RAG)
slug: /docs/v2/rag-quickstart
title: Retrieval augmented generation (RAG) - quickstart
slug: v2/docs/rag-quickstart

description: "A quickstart guide for performing retrieval augmented generation (RAG) with Cohere's Command models (v2 API)."
image: "../../../../assets/images/f1cc130-cohere_meta_image.jpg"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Reranking
slug: /docs/v2/reranking-quickstart
title: Reranking - quickstart
slug: v2/docs/reranking-quickstart

description: "A quickstart guide for performing reranking with Cohere's Reranking models (v2 API)."
image: "../../../../assets/images/f1cc130-cohere_meta_image.jpg"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Semantic Search
slug: /docs/v2/sem-search-quickstart
title: Semantic search - quickstart
slug: v2/docs/sem-search-quickstart

description: "A quickstart guide for performing text semantic search with Cohere's Embed models (v2 API)."
image: "../../../../assets/images/f1cc130-cohere_meta_image.jpg"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Text Generation
slug: /docs/v2/text-gen-quickstart
title: Text generation - quickstart
slug: v2/docs/text-gen-quickstart

description: "A quickstart guide for performing text generation with Cohere's Command models (v2 API)."
image: "../../../../assets/images/f1cc130-cohere_meta_image.jpg"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Tool Use & Agents
slug: /docs/v2/tool-use-quickstart
title: Tool use & agents - quickstart
slug: v2/docs/tool-use-quickstart

description: "A quickstart guide for using tool use and building agents with Cohere's Command models (v2 API)."
image: "../../../../assets/images/f1cc130-cohere_meta_image.jpg"
Expand Down
90 changes: 53 additions & 37 deletions fern/pages/v2/tool-use/tool-use-citations.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ First, define the tool and its associated schema.
import cohere
import json

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

Expand All @@ -41,8 +43,7 @@ import cohere
import json

co = cohere.ClientV2(
api_key="", # Leave this blank
base_url="<YOUR_DEPLOYMENT_URL>"
api_key="", base_url="<YOUR_DEPLOYMENT_URL>" # Leave this blank
)
```
</Tab>
Expand All @@ -53,13 +54,14 @@ def get_weather(location):
temperature = {
"bern": "22°C",
"madrid": "24°C",
"brasilia": "28°C"
"brasilia": "28°C",
}
loc = location.lower()
if loc in temperature:
return [{"temperature": {loc: temperature[loc]}}]
return [{"temperature": {loc: "Unknown"}}]


functions_map = {"get_weather": get_weather}

tools = [
Expand All @@ -86,12 +88,15 @@ tools = [
Next, run the tool calling and execution steps.

```python PYTHON
messages = [{"role": "user", "content": "What's the weather in Madrid and Brasilia?"}]
messages = [
{
"role": "user",
"content": "What's the weather in Madrid and Brasilia?",
}
]

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

if response.message.tool_calls:
Expand All @@ -102,16 +107,25 @@ if response.message.tool_calls:
"tool_calls": response.message.tool_calls,
}
)

for tc in response.message.tool_calls:
tool_result = functions_map[tc.function.name](
**json.loads(tc.function.arguments)
)
tool_content = []
for data in tool_result:
tool_content.append({"type": "document", "document": {"data": json.dumps(data)}})
tool_content.append(
{
"type": "document",
"document": {"data": json.dumps(data)},
}
)
messages.append(
{"role": "tool", "tool_call_id": tc.id, "content": tool_content}
{
"role": "tool",
"tool_call_id": tc.id,
"content": tool_content,
}
)
```

Expand All @@ -124,9 +138,7 @@ Each citation object contains:

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

messages.append(
Expand Down Expand Up @@ -154,24 +166,20 @@ Each citation object contains the same fields as the [non-streaming scenario](#n

```python PYTHON
response = co.chat_stream(
model="command-r-plus-08-2024",
messages=messages,
tools=tools
model="command-r-plus-08-2024", messages=messages, tools=tools
)

response_text = ""
citations = []
citations = []
for chunk in response:
if chunk:
if chunk.type == "content-delta":
response_text += chunk.delta.message.content.text
print(chunk.delta.message.content.text, end="")
if chunk.type == "citation-start":
citations.append(chunk.delta.message.citations)

messages.append(
{"role": "assistant", "content": response_text}
)

messages.append({"role": "assistant", "content": response_text})

for citation in citations:
print(citation, "\n")
Expand All @@ -198,10 +206,15 @@ Here is an example of using custom IDs. To keep it concise, let's start with a p
import cohere
import json

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

messages = [
{"role": "user", "content": "What's the weather in Madrid and Brasilia?"},
{
"role": "user",
"content": "What's the weather in Madrid and Brasilia?",
},
{
"role": "assistant",
"tool_plan": "I will search for the weather in Madrid and Brasilia.",
Expand All @@ -211,15 +224,15 @@ messages = [
"type": "function",
"function": {
"name": "get_weather",
"arguments": '{"location":"Madrid"}'
"arguments": '{"location":"Madrid"}',
},
},
{
"id": "get_weather_gh65bt2tcdy1",
"type": "function",
"function": {
"name": "get_weather",
"arguments": '{"location":"Brasilia"}'
"arguments": '{"location":"Brasilia"}',
},
},
],
Expand All @@ -232,7 +245,7 @@ messages = [
"type": "document",
"document": {
"data": '{"temperature": {"madrid": "24°C"}}',
"id" : "1"
"id": "1",
},
}
],
Expand All @@ -245,7 +258,7 @@ messages = [
"type": "document",
"document": {
"data": '{"temperature": {"brasilia": "28°C"}}',
"id" : "2"
"id": "2",
},
}
],
Expand All @@ -257,9 +270,7 @@ When document IDs are provided, the citation will refer to the documents using t

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

print(response.message.content[0].text)
Expand Down Expand Up @@ -307,17 +318,19 @@ With the `citation_options` mode set to `accurate`, we get the citations after t
import cohere
import json

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

response = co.chat_stream(
model="command-r-plus-08-2024",
messages=messages,
tools=tools,
citation_options={"mode": "accurate"}
citation_options={"mode": "accurate"},
)

response_text = ""
citations = []
citations = []
for chunk in response:
if chunk:
if chunk.type == "content-delta":
Expand All @@ -326,7 +339,7 @@ for chunk in response:
if chunk.type == "citation-start":
citations.append(chunk.delta.message.citations)

print("\n")
print("\n")
for citation in citations:
print(citation, "\n")
```
Expand All @@ -351,7 +364,7 @@ response = co.chat_stream(
model="command-r-plus-08-2024",
messages=messages,
tools=tools,
citation_options={"mode": "fast"}
citation_options={"mode": "fast"},
)

response_text = ""
Expand All @@ -361,7 +374,10 @@ for chunk in response:
response_text += chunk.delta.message.content.text
print(chunk.delta.message.content.text, end="")
if chunk.type == "citation-start":
print(f" [{chunk.delta.message.citations.sources[0].id}]", end="")
print(
f" [{chunk.delta.message.citations.sources[0].id}]",
end="",
)
```
Example response:
```mdx wordWrap
Expand Down
Loading