Skip to content

Commit 3427bcc

Browse files
authored
test: simplify cohere tests (#563)
1 parent bb46c02 commit 3427bcc

File tree

1 file changed

+16
-24
lines changed

1 file changed

+16
-24
lines changed

projects/extension/tests/test_cohere.py

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import os
2-
from time import sleep
32

43
import psycopg
54
import pytest
@@ -364,26 +363,19 @@ def test_cohere_rerank_simple(cur_with_api_key):
364363

365364

366365
def test_cohere_chat_complete(cur_with_api_key):
367-
actual = None
368-
expected = """According to a tongue-twister that originated in the United States, a woodchuck would chuck "as much wood as a woodchuck would, if a woodchuck could chuck wood."\n\nThis phrase is meant to be difficult to say quickly and can be fun to practice with family and friends!"""
369-
# apparently cohere doesn't always use the seed that we tell it to, so give it a few chances
370-
for _ in range(5):
371-
cur_with_api_key.execute("""
372-
select ai.cohere_chat_complete
373-
( 'command-r'
374-
, jsonb_build_array
375-
( jsonb_build_object
376-
( 'role', 'user'
377-
, 'content', 'How much wood would a woodchuck chuck if a woodchuck could chuck wood?'
378-
)
379-
)
380-
, seed=>42
381-
, temperature=>0.0
382-
)->'message'->'content'->0->>'text'
383-
""")
384-
actual = cur_with_api_key.fetchone()[0]
385-
if actual == expected:
386-
return
387-
else:
388-
sleep(0.1)
389-
assert actual == expected
366+
# even with temperature 0.0 and seed 42, the response can vary, so we only check if it's not empty
367+
cur_with_api_key.execute("""
368+
select ai.cohere_chat_complete
369+
( 'command-r'
370+
, jsonb_build_array
371+
( jsonb_build_object
372+
( 'role', 'user'
373+
, 'content', 'How much wood would a woodchuck chuck if a woodchuck could chuck wood?'
374+
)
375+
)
376+
, seed=>42
377+
, temperature=>0.0
378+
)->'message'->'content'->0->>'text'
379+
""")
380+
result = cur_with_api_key.fetchone()[0]
381+
assert result

0 commit comments

Comments
 (0)