-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add experimental co.summarize API (#145)
- Loading branch information
Showing
5 changed files
with
105 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from typing import NamedTuple | ||
|
||
SummarizeResponse = NamedTuple("SummarizeResponse", [("id", str), ("summary", float)]) | ||
SummarizeResponse.__doc__ = """ | ||
Returned by co.summarize, which generates a summary of the specified length for the provided text. | ||
Example: | ||
``` | ||
res = co.summarize(text="Stock market report for today...") | ||
print(res.summary) | ||
``` | ||
Example: | ||
``` | ||
res = co.summarize( | ||
text="Stock market report for today...", | ||
model="summarize-xlarge", | ||
length="long", | ||
format="bullets", | ||
temperature=0.3, | ||
additional_instruction="focusing on the highest performing stocks") | ||
print(res.summary) | ||
``` | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import unittest | ||
|
||
from utils import get_api_key | ||
|
||
import cohere | ||
from cohere.summarize import SummarizeResponse | ||
from cohere.error import CohereError | ||
|
||
API_KEY = get_api_key() | ||
co = cohere.Client(API_KEY) | ||
|
||
text = """Leah LaBelle Vladowski was born on September 8, 1986, in Toronto, \ | ||
Ontario, and raised in Seattle, Washington. Her parents, Anastasia and Troshan Vladowski, \ | ||
are Bulgarian singers and her uncle made rock music in Bulgaria. Anastasia recorded pop music \ | ||
and was in a group with Troshan, who was a founding member of Bulgaria's first rock band, \ | ||
Srebyrnite grivni.[3] After defecting from Bulgaria during a 1979 tour,[1][3] LaBelle's parents \ | ||
emigrated to Canada and later the United States, becoming naturalized citizens in both countries. \ | ||
LaBelle grew up listening to music, including jazz and the Beatles, but felt the most connected to R&B""" | ||
|
||
|
||
class TestFeedback(unittest.TestCase): | ||
|
||
def test_success(self): | ||
res = co.summarize(text) | ||
self.assertIsInstance(res, SummarizeResponse) | ||
|
||
def error(self): | ||
res = co.summarize(text, length="potato") | ||
self.assertIsInstance(res, CohereError) |