Skip to content
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
71 changes: 9 additions & 62 deletions tests/test_async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,28 @@ async def test_context_manager(self) -> None:

async def test_chat(self) -> None:
chat = await self.co.chat(
model="command-a-03-2025",
chat_history=[
UserMessage(
message="Who discovered gravity?"),
ChatbotMessage(message="The man who is widely credited with discovering "
"gravity is Sir Isaac Newton")
],
message="What year was he born?",
connectors=[ChatConnector(id="web-search")]
)

print(chat)

async def test_chat_stream(self) -> None:
stream = self.co.chat_stream(
model="command-a-03-2025",
chat_history=[
UserMessage(
message="Who discovered gravity?"),
ChatbotMessage(message="The man who is widely credited with discovering "
"gravity is Sir Isaac Newton")
],
message="What year was he born?",
connectors=[ChatConnector(id="web-search")]
)

events = set()
Expand Down Expand Up @@ -218,75 +218,22 @@ async def test_save_load(self) -> None:

await self.co.datasets.delete(my_dataset.id or "")

async def test_summarize(self) -> None:
text = (
"Ice cream is a sweetened frozen food typically eaten as a snack or dessert. "
"It may be made from milk or cream and is flavoured with a sweetener, "
"either sugar or an alternative, and a spice, such as cocoa or vanilla, "
"or with fruit such as strawberries or peaches. "
"It can also be made by whisking a flavored cream base and liquid nitrogen together. "
"Food coloring is sometimes added, in addition to stabilizers. "
"The mixture is cooled below the freezing point of water and stirred to incorporate air spaces "
"and to prevent detectable ice crystals from forming. The result is a smooth, "
"semi-solid foam that is solid at very low temperatures (below 2 °C or 35 °F). "
"It becomes more malleable as its temperature increases.\n\n"
"The meaning of the name \"ice cream\" varies from one country to another. "
"In some countries, such as the United States, \"ice cream\" applies only to a specific variety, "
"and most governments regulate the commercial use of the various terms according to the "
"relative quantities of the main ingredients, notably the amount of cream. "
"Products that do not meet the criteria to be called ice cream are sometimes labelled "
"\"frozen dairy dessert\" instead. In other countries, such as Italy and Argentina, "
"one word is used fo\r all variants. Analogues made from dairy alternatives, "
"such as goat's or sheep's milk, or milk substitutes "
"(e.g., soy, cashew, coconut, almond milk or tofu), are available for those who are "
"lactose intolerant, allergic to dairy protein or vegan."
)

response = await self.co.summarize(
text=text,
)

print(response)

async def test_tokenize(self) -> None:
response = await self.co.tokenize(
text='tokenize me! :D',
model='command',
model="command-a-03-2025",
offline=False,
)
print(response)

async def test_detokenize(self) -> None:
response = await self.co.detokenize(
tokens=[10104, 12221, 1315, 34, 1420, 69],
model="command",
model="command-a-03-2025",
offline=False,
)
print(response)

@unittest.skipIf(os.getenv("CO_API_URL") is not None, "Doesn't work in staging.")
async def test_connectors_crud(self) -> None:
created_connector = await self.co.connectors.create(
name="Example connector",
url="https://dummy-connector-o5btz7ucgq-uc.a.run.app/search",
service_auth=CreateConnectorServiceAuth(
token="dummy-connector-token",
type="bearer",
)
)
print(created_connector)

connector = await self.co.connectors.get(created_connector.connector.id)

print(connector)

updated_connector = await self.co.connectors.update(
id=connector.connector.id, name="new name")

print(updated_connector)

await self.co.connectors.delete(created_connector.connector.id)

@unittest.skipIf(os.getenv("CO_API_URL") is not None, "Doesn't work in staging.")
async def test_tool_use(self) -> None:
tools = [
Expand Down Expand Up @@ -347,7 +294,7 @@ async def test_tool_use(self) -> None:
tools=tools,
tool_results=tool_results,
force_single_step=True,
model="command-nightly",
model="command-a-03-2025",
)

self.assertEqual(cited_response.documents, [
Expand All @@ -362,21 +309,21 @@ async def test_tool_use(self) -> None:

async def test_local_tokenize(self) -> None:
response = await self.co.tokenize(
model="command",
model="command-a-03-2025",
text="tokenize me! :D"
)
print(response)

async def test_local_detokenize(self) -> None:
response = await self.co.detokenize(
model="command",
model="command-a-03-2025",
tokens=[10104, 12221, 1315, 34, 1420, 69]
)
print(response)

async def test_tokenize_async_context_with_sync_client(self) -> None:
# Test that the sync client can be used in an async context.
co = cohere.Client(timeout=10000)
print(co.tokenize(model="command", text="tokenize me! :D"))
print(co.detokenize(model="command", tokens=[
print(co.tokenize(model="command-a-03-2025", text="tokenize me! :D"))
print(co.detokenize(model="command-a-03-2025", tokens=[
10104, 12221, 1315, 34, 1420, 69]))
62 changes: 4 additions & 58 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ def test_chat(self) -> None:
"gravity is Sir Isaac Newton")
],
message="What year was he born?",
connectors=[ChatConnector(id="web-search")]
)

print(chat)
Expand All @@ -45,7 +44,6 @@ def test_chat_stream(self) -> None:
"gravity is Sir Isaac Newton")
],
message="What year was he born?",
connectors=[ChatConnector(id="web-search")]
)

events = set()
Expand Down Expand Up @@ -257,74 +255,22 @@ def test_save_load(self) -> None:

co.datasets.delete(my_dataset.id or "")

def test_summarize(self) -> None:
text = (
"Ice cream is a sweetened frozen food typically eaten as a snack or dessert. "
"It may be made from milk or cream and is flavoured with a sweetener, "
"either sugar or an alternative, and a spice, such as cocoa or vanilla, "
"or with fruit such as strawberries or peaches. "
"It can also be made by whisking a flavored cream base and liquid nitrogen together. "
"Food coloring is sometimes added, in addition to stabilizers. "
"The mixture is cooled below the freezing point of water and stirred to incorporate air spaces "
"and to prevent detectable ice crystals from forming. The result is a smooth, "
"semi-solid foam that is solid at very low temperatures (below 2 °C or 35 °F). "
"It becomes more malleable as its temperature increases.\n\n"
"The meaning of the name \"ice cream\" varies from one country to another. "
"In some countries, such as the United States, \"ice cream\" applies only to a specific variety, "
"and most governments regulate the commercial use of the various terms according to the "
"relative quantities of the main ingredients, notably the amount of cream. "
"Products that do not meet the criteria to be called ice cream are sometimes labelled "
"\"frozen dairy dessert\" instead. In other countries, such as Italy and Argentina, "
"one word is used fo\r all variants. Analogues made from dairy alternatives, "
"such as goat's or sheep's milk, or milk substitutes "
"(e.g., soy, cashew, coconut, almond milk or tofu), are available for those who are "
"lactose intolerant, allergic to dairy protein or vegan."
)

response = co.summarize(
text=text,
)

print(response)

def test_tokenize(self) -> None:
response = co.tokenize(
text='tokenize me! :D',
model='command',
model='command-a-03-2025',
offline=False,
)
print(response)

def test_detokenize(self) -> None:
response = co.detokenize(
tokens=[10104, 12221, 1315, 34, 1420, 69],
model="command",
model="command-a-03-2025",
offline=False,
)
print(response)

@unittest.skipIf(os.getenv("CO_API_URL") is not None, "Doesn't work in staging.")
def test_connectors_crud(self) -> None:
created_connector = co.connectors.create(
name="Example connector",
url="https://dummy-connector-o5btz7ucgq-uc.a.run.app/search",
service_auth=CreateConnectorServiceAuth(
token="dummy-connector-token",
type="bearer",
)
)
print(created_connector)

connector = co.connectors.get(created_connector.connector.id)

print(connector)

updated_connector = co.connectors.update(
id=connector.connector.id, name="new name")

print(updated_connector)

co.connectors.delete(created_connector.connector.id)

@unittest.skipIf(os.getenv("CO_API_URL") is not None, "Doesn't work in staging.")
def test_tool_use(self) -> None:
Expand Down Expand Up @@ -401,14 +347,14 @@ def test_tool_use(self) -> None:

def test_local_tokenize(self) -> None:
response = co.tokenize(
model="command",
model="command-a-03-2025",
text="tokenize me! :D"
)
print(response)

def test_local_detokenize(self) -> None:
response = co.detokenize(
model="command",
model="command-a-03-2025",
tokens=[10104, 12221, 1315, 34, 1420, 69]
)
print(response)
10 changes: 5 additions & 5 deletions tests/test_client_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ class TestClientV2(unittest.TestCase):

def test_chat(self) -> None:
response = co.chat(
model="command-r-plus", messages=[cohere.UserChatMessageV2(content="hello world!")])
model="command-a-03-2025", messages=[cohere.UserChatMessageV2(content="hello world!")])

print(response.message)

def test_chat_stream(self) -> None:
stream = co.chat_stream(
model="command-r-plus", messages=[cohere.UserChatMessageV2(content="hello world!")])
model="command-a-03-2025", messages=[cohere.UserChatMessageV2(content="hello world!")])

events = set()

Expand Down Expand Up @@ -49,7 +49,7 @@ def test_chat_documents(self) -> None:
messages=[cohere.UserChatMessageV2(
content=[cohere.TextContent(text="how many widges were sold in 2020?")],
)],
model="command-r-plus",
model="command-a-03-2025",
documents=documents,
)

Expand All @@ -76,7 +76,7 @@ def test_chat_tools(self) -> None:
messages: cohere.ChatMessages = [
cohere.UserChatMessageV2(content="what is the weather in Toronto?")
]
res = co.chat(model="command-r-plus", tools=tools, messages=messages)
res = co.chat(model="command-a-03-2025", tools=tools, messages=messages)

# call the get_weather tool
tool_result = {"temperature": "30C"}
Expand All @@ -88,5 +88,5 @@ def test_chat_tools(self) -> None:
messages.append(cohere.ToolChatMessageV2(
tool_call_id=res.message.tool_calls[0].id, content=list(tool_content)))

res = co.chat(tools=tools, messages=messages, model="command-r-plus")
res = co.chat(tools=tools, messages=messages, model="command-a-03-2025")
print(res.message)