Skip to content
Open
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
174 changes: 142 additions & 32 deletions tests/api_resources/chat/test_completions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import os
from typing import Any, cast

import httpx
import pytest
from respx import MockRouter

from tests.utils import assert_matches_type
from llama_api_client import LlamaAPIClient, AsyncLlamaAPIClient
Expand All @@ -17,9 +19,14 @@
class TestCompletions:
parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"])

@pytest.mark.skip(reason="Prism tests are disabled")
@pytest.mark.respx(base_url=base_url)
@parametrize
def test_method_create_overload_1(self, client: LlamaAPIClient) -> None:
def test_method_create_overload_1(self, client: LlamaAPIClient, respx_mock: MockRouter) -> None:
respx_mock.post("/chat/completions").mock(
return_value=httpx.Response(
200, json={"completion_message": {"role": "assistant", "content": "hello"}, "id": "chatcmpl-123"}
)
)
completion = client.chat.completions.create(
messages=[
{
Expand All @@ -31,9 +38,14 @@ def test_method_create_overload_1(self, client: LlamaAPIClient) -> None:
)
assert_matches_type(CreateChatCompletionResponse, completion, path=["response"])

@pytest.mark.skip(reason="Prism tests are disabled")
@pytest.mark.respx(base_url=base_url)
@parametrize
def test_method_create_with_all_params_overload_1(self, client: LlamaAPIClient) -> None:
def test_method_create_with_all_params_overload_1(self, client: LlamaAPIClient, respx_mock: MockRouter) -> None:
respx_mock.post("/chat/completions").mock(
return_value=httpx.Response(
200, json={"completion_message": {"role": "assistant", "content": "hello"}, "id": "chatcmpl-123"}
)
)
completion = client.chat.completions.create(
messages=[
{
Expand Down Expand Up @@ -71,9 +83,14 @@ def test_method_create_with_all_params_overload_1(self, client: LlamaAPIClient)
)
assert_matches_type(CreateChatCompletionResponse, completion, path=["response"])

@pytest.mark.skip(reason="Prism tests are disabled")
@pytest.mark.respx(base_url=base_url)
@parametrize
def test_raw_response_create_overload_1(self, client: LlamaAPIClient) -> None:
def test_raw_response_create_overload_1(self, client: LlamaAPIClient, respx_mock: MockRouter) -> None:
respx_mock.post("/chat/completions").mock(
return_value=httpx.Response(
200, json={"completion_message": {"role": "assistant", "content": "hello"}, "id": "chatcmpl-123"}
)
)
response = client.chat.completions.with_raw_response.create(
messages=[
{
Expand All @@ -89,9 +106,14 @@ def test_raw_response_create_overload_1(self, client: LlamaAPIClient) -> None:
completion = response.parse()
assert_matches_type(CreateChatCompletionResponse, completion, path=["response"])

@pytest.mark.skip(reason="Prism tests are disabled")
@pytest.mark.respx(base_url=base_url)
@parametrize
def test_streaming_response_create_overload_1(self, client: LlamaAPIClient) -> None:
def test_streaming_response_create_overload_1(self, client: LlamaAPIClient, respx_mock: MockRouter) -> None:
respx_mock.post("/chat/completions").mock(
return_value=httpx.Response(
200, json={"completion_message": {"role": "assistant", "content": "hello"}, "id": "chatcmpl-123"}
)
)
with client.chat.completions.with_streaming_response.create(
messages=[
{
Expand All @@ -109,9 +131,16 @@ def test_streaming_response_create_overload_1(self, client: LlamaAPIClient) -> N

assert cast(Any, response.is_closed) is True

@pytest.mark.skip(reason="Prism tests are disabled")
@pytest.mark.respx(base_url=base_url)
@parametrize
def test_method_create_overload_2(self, client: LlamaAPIClient) -> None:
def test_method_create_overload_2(self, client: LlamaAPIClient, respx_mock: MockRouter) -> None:
respx_mock.post("/chat/completions").mock(
return_value=httpx.Response(
200,
headers={"content-type": "text/event-stream"},
content=b'data: {"event":{"event_type":"start","delta":{"type":"text","text":"hi"}}}\n\n',
)
)
completion_stream = client.chat.completions.create(
messages=[
{
Expand All @@ -124,9 +153,16 @@ def test_method_create_overload_2(self, client: LlamaAPIClient) -> None:
)
completion_stream.response.close()

@pytest.mark.skip(reason="Prism tests are disabled")
@pytest.mark.respx(base_url=base_url)
@parametrize
def test_method_create_with_all_params_overload_2(self, client: LlamaAPIClient) -> None:
def test_method_create_with_all_params_overload_2(self, client: LlamaAPIClient, respx_mock: MockRouter) -> None:
respx_mock.post("/chat/completions").mock(
return_value=httpx.Response(
200,
headers={"content-type": "text/event-stream"},
content=b'data: {"event":{"event_type":"start","delta":{"type":"text","text":"hi"}}}\n\n',
)
)
completion_stream = client.chat.completions.create(
messages=[
{
Expand Down Expand Up @@ -164,9 +200,16 @@ def test_method_create_with_all_params_overload_2(self, client: LlamaAPIClient)
)
completion_stream.response.close()

@pytest.mark.skip(reason="Prism tests are disabled")
@pytest.mark.respx(base_url=base_url)
@parametrize
def test_raw_response_create_overload_2(self, client: LlamaAPIClient) -> None:
def test_raw_response_create_overload_2(self, client: LlamaAPIClient, respx_mock: MockRouter) -> None:
respx_mock.post("/chat/completions").mock(
return_value=httpx.Response(
200,
headers={"content-type": "text/event-stream"},
content=b'data: {"event":{"event_type":"start","delta":{"type":"text","text":"hi"}}}\n\n',
)
)
response = client.chat.completions.with_raw_response.create(
messages=[
{
Expand All @@ -182,9 +225,16 @@ def test_raw_response_create_overload_2(self, client: LlamaAPIClient) -> None:
stream = response.parse()
stream.close()

@pytest.mark.skip(reason="Prism tests are disabled")
@pytest.mark.respx(base_url=base_url)
@parametrize
def test_streaming_response_create_overload_2(self, client: LlamaAPIClient) -> None:
def test_streaming_response_create_overload_2(self, client: LlamaAPIClient, respx_mock: MockRouter) -> None:
respx_mock.post("/chat/completions").mock(
return_value=httpx.Response(
200,
headers={"content-type": "text/event-stream"},
content=b'data: {"event":{"event_type":"start","delta":{"type":"text","text":"hi"}}}\n\n',
)
)
with client.chat.completions.with_streaming_response.create(
messages=[
{
Expand All @@ -209,9 +259,14 @@ class TestAsyncCompletions:
"async_client", [False, True, {"http_client": "aiohttp"}], indirect=True, ids=["loose", "strict", "aiohttp"]
)

@pytest.mark.skip(reason="Prism tests are disabled")
@pytest.mark.respx(base_url=base_url)
@parametrize
async def test_method_create_overload_1(self, async_client: AsyncLlamaAPIClient) -> None:
async def test_method_create_overload_1(self, async_client: AsyncLlamaAPIClient, respx_mock: MockRouter) -> None:
respx_mock.post("/chat/completions").mock(
return_value=httpx.Response(
200, json={"completion_message": {"role": "assistant", "content": "hello"}, "id": "chatcmpl-123"}
)
)
completion = await async_client.chat.completions.create(
messages=[
{
Expand All @@ -223,9 +278,16 @@ async def test_method_create_overload_1(self, async_client: AsyncLlamaAPIClient)
)
assert_matches_type(CreateChatCompletionResponse, completion, path=["response"])

@pytest.mark.skip(reason="Prism tests are disabled")
@pytest.mark.respx(base_url=base_url)
@parametrize
async def test_method_create_with_all_params_overload_1(self, async_client: AsyncLlamaAPIClient) -> None:
async def test_method_create_with_all_params_overload_1(
self, async_client: AsyncLlamaAPIClient, respx_mock: MockRouter
) -> None:
respx_mock.post("/chat/completions").mock(
return_value=httpx.Response(
200, json={"completion_message": {"role": "assistant", "content": "hello"}, "id": "chatcmpl-123"}
)
)
completion = await async_client.chat.completions.create(
messages=[
{
Expand Down Expand Up @@ -263,9 +325,16 @@ async def test_method_create_with_all_params_overload_1(self, async_client: Asyn
)
assert_matches_type(CreateChatCompletionResponse, completion, path=["response"])

@pytest.mark.skip(reason="Prism tests are disabled")
@pytest.mark.respx(base_url=base_url)
@parametrize
async def test_raw_response_create_overload_1(self, async_client: AsyncLlamaAPIClient) -> None:
async def test_raw_response_create_overload_1(
self, async_client: AsyncLlamaAPIClient, respx_mock: MockRouter
) -> None:
respx_mock.post("/chat/completions").mock(
return_value=httpx.Response(
200, json={"completion_message": {"role": "assistant", "content": "hello"}, "id": "chatcmpl-123"}
)
)
response = await async_client.chat.completions.with_raw_response.create(
messages=[
{
Expand All @@ -281,9 +350,16 @@ async def test_raw_response_create_overload_1(self, async_client: AsyncLlamaAPIC
completion = await response.parse()
assert_matches_type(CreateChatCompletionResponse, completion, path=["response"])

@pytest.mark.skip(reason="Prism tests are disabled")
@pytest.mark.respx(base_url=base_url)
@parametrize
async def test_streaming_response_create_overload_1(self, async_client: AsyncLlamaAPIClient) -> None:
async def test_streaming_response_create_overload_1(
self, async_client: AsyncLlamaAPIClient, respx_mock: MockRouter
) -> None:
respx_mock.post("/chat/completions").mock(
return_value=httpx.Response(
200, json={"completion_message": {"role": "assistant", "content": "hello"}, "id": "chatcmpl-123"}
)
)
async with async_client.chat.completions.with_streaming_response.create(
messages=[
{
Expand All @@ -301,9 +377,16 @@ async def test_streaming_response_create_overload_1(self, async_client: AsyncLla

assert cast(Any, response.is_closed) is True

@pytest.mark.skip(reason="Prism tests are disabled")
@pytest.mark.respx(base_url=base_url)
@parametrize
async def test_method_create_overload_2(self, async_client: AsyncLlamaAPIClient) -> None:
async def test_method_create_overload_2(self, async_client: AsyncLlamaAPIClient, respx_mock: MockRouter) -> None:
respx_mock.post("/chat/completions").mock(
return_value=httpx.Response(
200,
headers={"content-type": "text/event-stream"},
content=b'data: {"event":{"event_type":"start","delta":{"type":"text","text":"hi"}}}\n\n',
)
)
completion_stream = await async_client.chat.completions.create(
messages=[
{
Expand All @@ -316,9 +399,18 @@ async def test_method_create_overload_2(self, async_client: AsyncLlamaAPIClient)
)
await completion_stream.response.aclose()

@pytest.mark.skip(reason="Prism tests are disabled")
@pytest.mark.respx(base_url=base_url)
@parametrize
async def test_method_create_with_all_params_overload_2(self, async_client: AsyncLlamaAPIClient) -> None:
async def test_method_create_with_all_params_overload_2(
self, async_client: AsyncLlamaAPIClient, respx_mock: MockRouter
) -> None:
respx_mock.post("/chat/completions").mock(
return_value=httpx.Response(
200,
headers={"content-type": "text/event-stream"},
content=b'data: {"event":{"event_type":"start","delta":{"type":"text","text":"hi"}}}\n\n',
)
)
completion_stream = await async_client.chat.completions.create(
messages=[
{
Expand Down Expand Up @@ -356,9 +448,18 @@ async def test_method_create_with_all_params_overload_2(self, async_client: Asyn
)
await completion_stream.response.aclose()

@pytest.mark.skip(reason="Prism tests are disabled")
@pytest.mark.respx(base_url=base_url)
@parametrize
async def test_raw_response_create_overload_2(self, async_client: AsyncLlamaAPIClient) -> None:
async def test_raw_response_create_overload_2(
self, async_client: AsyncLlamaAPIClient, respx_mock: MockRouter
) -> None:
respx_mock.post("/chat/completions").mock(
return_value=httpx.Response(
200,
headers={"content-type": "text/event-stream"},
content=b'data: {"event":{"event_type":"start","delta":{"type":"text","text":"hi"}}}\n\n',
)
)
response = await async_client.chat.completions.with_raw_response.create(
messages=[
{
Expand All @@ -374,9 +475,18 @@ async def test_raw_response_create_overload_2(self, async_client: AsyncLlamaAPIC
stream = await response.parse()
await stream.close()

@pytest.mark.skip(reason="Prism tests are disabled")
@pytest.mark.respx(base_url=base_url)
@parametrize
async def test_streaming_response_create_overload_2(self, async_client: AsyncLlamaAPIClient) -> None:
async def test_streaming_response_create_overload_2(
self, async_client: AsyncLlamaAPIClient, respx_mock: MockRouter
) -> None:
respx_mock.post("/chat/completions").mock(
return_value=httpx.Response(
200,
headers={"content-type": "text/event-stream"},
content=b'data: {"event":{"event_type":"start","delta":{"type":"text","text":"hi"}}}\n\n',
)
)
async with async_client.chat.completions.with_streaming_response.create(
messages=[
{
Expand Down
Loading