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
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ anthropic = Anthropic(
completion = anthropic.completions.create(
model="claude-2",
max_tokens_to_sample=300,
prompt=f"{HUMAN_PROMPT} how does a court case get to the Supreme Court? {AI_PROMPT}",
prompt=f"{HUMAN_PROMPT} how does a court case get to the Supreme Court?{AI_PROMPT}",
)
print(completion.completion)
```
Expand All @@ -118,7 +118,7 @@ async def main():
completion = await anthropic.completions.create(
model="claude-2",
max_tokens_to_sample=300,
prompt=f"{HUMAN_PROMPT} how does a court case get to the Supreme Court? {AI_PROMPT}",
prompt=f"{HUMAN_PROMPT} how does a court case get to the Supreme Court?{AI_PROMPT}",
)
print(completion.completion)

Expand All @@ -138,7 +138,7 @@ from anthropic import Anthropic, HUMAN_PROMPT, AI_PROMPT
anthropic = Anthropic()

stream = anthropic.completions.create(
prompt=f"{HUMAN_PROMPT} Your prompt here {AI_PROMPT}",
prompt=f"{HUMAN_PROMPT} Your prompt here{AI_PROMPT}",
max_tokens_to_sample=300,
model="claude-2",
stream=True,
Expand All @@ -155,7 +155,7 @@ from anthropic import AsyncAnthropic, HUMAN_PROMPT, AI_PROMPT
anthropic = AsyncAnthropic()

stream = await anthropic.completions.create(
prompt=f"{HUMAN_PROMPT} Your prompt here {AI_PROMPT}",
prompt=f"{HUMAN_PROMPT} Your prompt here{AI_PROMPT}",
max_tokens_to_sample=300,
model="claude-2",
stream=True,
Expand Down Expand Up @@ -195,7 +195,7 @@ client = anthropic.Anthropic()

try:
client.completions.create(
prompt=f"{anthropic.HUMAN_PROMPT} Your prompt here {anthropic.AI_PROMPT}",
prompt=f"{anthropic.HUMAN_PROMPT} Your prompt here{anthropic.AI_PROMPT}",
max_tokens_to_sample=300,
model="claude-2",
)
Expand Down Expand Up @@ -242,7 +242,7 @@ anthropic = Anthropic(

# Or, configure per-request:
anthropic.with_options(max_retries=5).completions.create(
prompt=f"{HUMAN_PROMPT} Can you help me effectively ask for a raise at work? {AI_PROMPT}",
prompt=f"{HUMAN_PROMPT} Can you help me effectively ask for a raise at work?{AI_PROMPT}",
max_tokens_to_sample=300,
model="claude-2",
)
Expand All @@ -269,7 +269,7 @@ anthropic = Anthropic(

# Override per-request:
anthropic.with_options(timeout=5 * 1000).completions.create(
prompt=f"{HUMAN_PROMPT} Where can I get a good coffee in my neighbourhood? {AI_PROMPT}",
prompt=f"{HUMAN_PROMPT} Where can I get a good coffee in my neighbourhood?{AI_PROMPT}",
max_tokens_to_sample=300,
model="claude-2",
)
Expand Down
2 changes: 1 addition & 1 deletion examples/streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ async def async_stream() -> None:
def stream_error() -> None:
try:
client.completions.create(
prompt=f"{HUMAN_PROMPT}{question}{AI_PROMPT}",
prompt=f"{HUMAN_PROMPT} {question}{AI_PROMPT}",
model="claude-unknown-model",
stream=True,
max_tokens_to_sample=300,
Expand Down
97 changes: 42 additions & 55 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ packages = [
python = "^3.7"
httpx = ">= 0.23.0, < 1"
pydantic = "^1.9.0"
typing-extensions = ">= 4.1.1, < 5"
typing-extensions = ">= 4.5, < 5"
anyio = ">= 3.5.0, < 4"
distro = ">= 1.7.0, < 2"
tokenizers = ">= 0.13.0"

[tool.poetry.group.dev.dependencies]
pyright = "1.1.318"
mypy = "1.4.1"
black = "22.10.0"
black = "23.3.0"
respx = "0.19.2"
pytest = "7.1.1"
pytest-asyncio = "0.18.3"
pytest-asyncio = "0.21.1"
ruff = "0.0.282"
isort = "5.10.1"
time-machine = "^2.9.0"
Expand Down
8 changes: 2 additions & 6 deletions src/anthropic/resources/completions.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,7 @@ def create(
max_tokens_to_sample: int,
model: Union[str, Literal["claude-2", "claude-instant-1"]],
prompt: str,
metadata: completion_create_params.CompletionRequestNonStreamingMetadata
| completion_create_params.CompletionRequestStreamingMetadata
| NotGiven = NOT_GIVEN,
metadata: completion_create_params.CompletionRequestNonStreamingMetadata | NotGiven = NOT_GIVEN,
stop_sequences: List[str] | NotGiven = NOT_GIVEN,
stream: Literal[False] | Literal[True] | NotGiven = NOT_GIVEN,
temperature: float | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -439,9 +437,7 @@ async def create(
max_tokens_to_sample: int,
model: Union[str, Literal["claude-2", "claude-instant-1"]],
prompt: str,
metadata: completion_create_params.CompletionRequestNonStreamingMetadata
| completion_create_params.CompletionRequestStreamingMetadata
| NotGiven = NOT_GIVEN,
metadata: completion_create_params.CompletionRequestNonStreamingMetadata | NotGiven = NOT_GIVEN,
stop_sequences: List[str] | NotGiven = NOT_GIVEN,
stream: Literal[False] | Literal[True] | NotGiven = NOT_GIVEN,
temperature: float | NotGiven = NOT_GIVEN,
Expand Down
7 changes: 5 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import asyncio
from typing import Iterator

import pytest

pytest.register_assert_rewrite("tests.utils")


@pytest.fixture(scope="session")
def event_loop() -> asyncio.AbstractEventLoop:
return asyncio.new_event_loop()
def event_loop() -> Iterator[asyncio.AbstractEventLoop]:
loop = asyncio.new_event_loop()
yield loop
loop.close()