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
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ name: CI
on:
push:
branches:
- main
- stainless
pull_request:
branches:
- main
- stainless

jobs:
lint:
Expand Down
8 changes: 5 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
# Changelog

## 0.4.0 (2024-02-14)
## 0.4.0 (2024-02-15)

Full Changelog: [v0.1.0...v0.4.0](https://github.com/groq/groq-python/compare/v0.1.0...v0.4.0)

### Features

* Add initial Stainless SDK ([d5a8512](https://github.com/groq/groq-python/commit/d5a851262e04e625dde130367ed91d8f95683599))
* Add initial Stainless SDK ([316de2c](https://github.com/groq/groq-python/commit/316de2ccfeb76e36fe34bb8656ea90a8d42a7d00))
* create default branch ([7e00266](https://github.com/groq/groq-python/commit/7e00266e3c691d92d508e753e2c14c03297c09f9))
* update via SDK Studio ([#3](https://github.com/groq/groq-python/issues/3)) ([2241036](https://github.com/groq/groq-python/commit/2241036e9dbee6629ad7ebce5e6f4f5e5f1028ce))
* update via SDK Studio ([#3](https://github.com/groq/groq-python/issues/3)) ([8d92c08](https://github.com/groq/groq-python/commit/8d92c086e320c2715e02bc79807ff872e84c0b0f))


### Chores

* go live ([#2](https://github.com/groq/groq-python/issues/2)) ([13665ad](https://github.com/groq/groq-python/commit/13665ad76705513d99cbaa497ccccc694932f2c3))
* go live ([#2](https://github.com/groq/groq-python/issues/2)) ([ba81c42](https://github.com/groq/groq-python/commit/ba81c42d6d0fd6d47819e0d58962235cb70ca4f1))
* go live ([#5](https://github.com/groq/groq-python/issues/5)) ([af9a838](https://github.com/groq/groq-python/commit/af9a838e240bb0f7385bc33fb18ce246427ca2f7))

## 0.1.0 (2024-02-10)

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,9 @@ completion = response.parse() # get the object that `chat.completions.create()`
print(completion.id)
```

These methods return an [`APIResponse`](https://github.com/groq/groq-python/tree/main/src/groq/_response.py) object.
These methods return an [`APIResponse`](https://github.com/groq/groq-python/tree/stainless/src/groq/_response.py) object.

The async client returns an [`AsyncAPIResponse`](https://github.com/groq/groq-python/tree/main/src/groq/_response.py) with the same structure, the only difference being `await`able methods for reading the response content.
The async client returns an [`AsyncAPIResponse`](https://github.com/groq/groq-python/tree/stainless/src/groq/_response.py) with the same structure, the only difference being `await`able methods for reading the response content.

#### `.with_streaming_response`

Expand Down
4 changes: 2 additions & 2 deletions bin/check-release-environment
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ if [ -z "${PYPI_TOKEN}" ]; then
errors+=("The GROQ_PYPI_TOKEN secret has not been set. Please set it in either this repository's secrets or your organization secrets.")
fi

len=${#errors[@]}
lenErrors=${#errors[@]}

if [[ len -gt 0 ]]; then
if [[ lenErrors -gt 0 ]]; then
echo -e "Found the following errors in the release environment:\n"

for error in "${errors[@]}"; do
Expand Down
2 changes: 1 addition & 1 deletion examples/chat_completion_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from groq import AsyncGroq


async def main():
async def main() -> None:
client = AsyncGroq()

chat_completion = await client.chat.completions.create(
Expand Down
2 changes: 1 addition & 1 deletion examples/chat_completion_async_streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from groq import AsyncGroq


async def main():
async def main() -> None:
client = AsyncGroq()

stream = await client.chat.completions.create(
Expand Down
26 changes: 15 additions & 11 deletions src/groq/lib/chat_completion_chunk.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
"ChoiceDeltaToolCall",
"ChoiceDeltaToolCallFunction",
]


class ChoiceDeltaFunctionCall(BaseModel):
arguments: Optional[str] = None
"""
Expand All @@ -28,6 +30,7 @@ class ChoiceDeltaFunctionCall(BaseModel):
name: Optional[str] = None
"""The name of the function to call."""


class ChoiceLogprobsContentTopLogprob(BaseModel):
token: Optional[str] = None

Expand Down Expand Up @@ -67,34 +70,35 @@ class ChoiceDeltaToolCall(BaseModel):


class ChoiceDelta(BaseModel):
content: Optional[str] = None
content: str

role: str

function_call: Optional[ChoiceDeltaFunctionCall] = None

role: Optional[str] = None

tool_calls: Optional[List[ChoiceDeltaToolCall]] = None


class Choice(BaseModel):
delta: ChoiceDelta

finish_reason: Optional[str] = None
finish_reason: str

index: Optional[int] = None
index: int

logprobs: Optional[ChoiceLogprobs] = None
logprobs: ChoiceLogprobs


class ChatCompletionChunk(BaseModel):
id: Optional[str] = None
id: str

choices: Optional[List[Choice]] = None
choices: List[Choice]

created: Optional[int] = None
created: int

model: Optional[str] = None
model: str

object: Optional[str] = None
object: str

system_fingerprint: Optional[str] = None
system_fingerprint: str
43 changes: 22 additions & 21 deletions src/groq/resources/chat/completions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

from __future__ import annotations

from typing import Dict, List, Union, Literal, Iterable, Optional, overload
from typing import Dict, List, Union, Iterable, Optional, overload
from typing_extensions import Literal

import httpx

Expand Down Expand Up @@ -39,12 +40,12 @@ def with_streaming_response(self) -> CompletionsWithStreamingResponse:
def create(
self,
*,
messages: Iterable[completion_create_params.Message],
model: str,
frequency_penalty: float | NotGiven = NOT_GIVEN,
logit_bias: Dict[str, int] | NotGiven = NOT_GIVEN,
logprobs: bool | NotGiven = NOT_GIVEN,
max_tokens: int | NotGiven = NOT_GIVEN,
messages: Iterable[completion_create_params.Message] | NotGiven = NOT_GIVEN,
model: str | NotGiven = NOT_GIVEN,
n: int | NotGiven = NOT_GIVEN,
presence_penalty: float | NotGiven = NOT_GIVEN,
response_format: completion_create_params.ResponseFormat | NotGiven = NOT_GIVEN,
Expand All @@ -70,12 +71,12 @@ def create(
def create(
self,
*,
messages: Iterable[completion_create_params.Message],
model: str,
frequency_penalty: float | NotGiven = NOT_GIVEN,
logit_bias: Dict[str, int] | NotGiven = NOT_GIVEN,
logprobs: bool | NotGiven = NOT_GIVEN,
max_tokens: int | NotGiven = NOT_GIVEN,
messages: Iterable[completion_create_params.Message] | NotGiven = NOT_GIVEN,
model: str | NotGiven = NOT_GIVEN,
n: int | NotGiven = NOT_GIVEN,
presence_penalty: float | NotGiven = NOT_GIVEN,
response_format: completion_create_params.ResponseFormat | NotGiven = NOT_GIVEN,
Expand All @@ -101,12 +102,12 @@ def create(
def create(
self,
*,
messages: Iterable[completion_create_params.Message],
model: str,
frequency_penalty: float | NotGiven = NOT_GIVEN,
logit_bias: Dict[str, int] | NotGiven = NOT_GIVEN,
logprobs: bool | NotGiven = NOT_GIVEN,
max_tokens: int | NotGiven = NOT_GIVEN,
messages: Iterable[completion_create_params.Message] | NotGiven = NOT_GIVEN,
model: str | NotGiven = NOT_GIVEN,
n: int | NotGiven = NOT_GIVEN,
presence_penalty: float | NotGiven = NOT_GIVEN,
response_format: completion_create_params.ResponseFormat | NotGiven = NOT_GIVEN,
Expand All @@ -131,12 +132,12 @@ def create(
def create(
self,
*,
messages: Iterable[completion_create_params.Message],
model: str,
frequency_penalty: float | NotGiven = NOT_GIVEN,
logit_bias: Dict[str, int] | NotGiven = NOT_GIVEN,
logprobs: bool | NotGiven = NOT_GIVEN,
max_tokens: int | NotGiven = NOT_GIVEN,
messages: Iterable[completion_create_params.Message] | NotGiven = NOT_GIVEN,
model: str | NotGiven = NOT_GIVEN,
n: int | NotGiven = NOT_GIVEN,
presence_penalty: float | NotGiven = NOT_GIVEN,
response_format: completion_create_params.ResponseFormat | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -175,12 +176,12 @@ def create(
"/openai/v1/chat/completions",
body=maybe_transform(
{
"messages": messages,
"model": model,
"frequency_penalty": frequency_penalty,
"logit_bias": logit_bias,
"logprobs": logprobs,
"max_tokens": max_tokens,
"messages": messages,
"model": model,
"n": n,
"presence_penalty": presence_penalty,
"response_format": response_format,
Expand Down Expand Up @@ -218,12 +219,12 @@ def with_streaming_response(self) -> AsyncCompletionsWithStreamingResponse:
async def create(
self,
*,
messages: Iterable[completion_create_params.Message],
model: str,
frequency_penalty: float | NotGiven = NOT_GIVEN,
logit_bias: Dict[str, int] | NotGiven = NOT_GIVEN,
logprobs: bool | NotGiven = NOT_GIVEN,
max_tokens: int | NotGiven = NOT_GIVEN,
messages: Iterable[completion_create_params.Message] | NotGiven = NOT_GIVEN,
model: str | NotGiven = NOT_GIVEN,
n: int | NotGiven = NOT_GIVEN,
presence_penalty: float | NotGiven = NOT_GIVEN,
response_format: completion_create_params.ResponseFormat | NotGiven = NOT_GIVEN,
Expand All @@ -249,12 +250,12 @@ async def create(
async def create(
self,
*,
messages: Iterable[completion_create_params.Message],
model: str,
frequency_penalty: float | NotGiven = NOT_GIVEN,
logit_bias: Dict[str, int] | NotGiven = NOT_GIVEN,
logprobs: bool | NotGiven = NOT_GIVEN,
max_tokens: int | NotGiven = NOT_GIVEN,
messages: Iterable[completion_create_params.Message] | NotGiven = NOT_GIVEN,
model: str | NotGiven = NOT_GIVEN,
n: int | NotGiven = NOT_GIVEN,
presence_penalty: float | NotGiven = NOT_GIVEN,
response_format: completion_create_params.ResponseFormat | NotGiven = NOT_GIVEN,
Expand All @@ -280,12 +281,12 @@ async def create(
async def create(
self,
*,
messages: Iterable[completion_create_params.Message],
model: str,
frequency_penalty: float | NotGiven = NOT_GIVEN,
logit_bias: Dict[str, int] | NotGiven = NOT_GIVEN,
logprobs: bool | NotGiven = NOT_GIVEN,
max_tokens: int | NotGiven = NOT_GIVEN,
messages: Iterable[completion_create_params.Message] | NotGiven = NOT_GIVEN,
model: str | NotGiven = NOT_GIVEN,
n: int | NotGiven = NOT_GIVEN,
presence_penalty: float | NotGiven = NOT_GIVEN,
response_format: completion_create_params.ResponseFormat | NotGiven = NOT_GIVEN,
Expand All @@ -310,12 +311,12 @@ async def create(
async def create(
self,
*,
messages: Iterable[completion_create_params.Message],
model: str,
frequency_penalty: float | NotGiven = NOT_GIVEN,
logit_bias: Dict[str, int] | NotGiven = NOT_GIVEN,
logprobs: bool | NotGiven = NOT_GIVEN,
max_tokens: int | NotGiven = NOT_GIVEN,
messages: Iterable[completion_create_params.Message] | NotGiven = NOT_GIVEN,
model: str | NotGiven = NOT_GIVEN,
n: int | NotGiven = NOT_GIVEN,
presence_penalty: float | NotGiven = NOT_GIVEN,
response_format: completion_create_params.ResponseFormat | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -354,12 +355,12 @@ async def create(
"/openai/v1/chat/completions",
body=maybe_transform(
{
"messages": messages,
"model": model,
"frequency_penalty": frequency_penalty,
"logit_bias": logit_bias,
"logprobs": logprobs,
"max_tokens": max_tokens,
"messages": messages,
"model": model,
"n": n,
"presence_penalty": presence_penalty,
"response_format": response_format,
Expand Down
16 changes: 8 additions & 8 deletions src/groq/types/chat/chat_completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,21 @@ class ChoiceMessageToolCall(BaseModel):


class ChoiceMessage(BaseModel):
content: Optional[str] = None
content: str

role: Optional[str] = None
role: str

tool_calls: Optional[List[ChoiceMessageToolCall]] = None


class Choice(BaseModel):
finish_reason: Optional[str] = None
finish_reason: str

index: Optional[int] = None
index: int

logprobs: Optional[ChoiceLogprobs] = None
logprobs: ChoiceLogprobs

message: Optional[ChoiceMessage] = None
message: ChoiceMessage


class Usage(BaseModel):
Expand All @@ -86,9 +86,9 @@ class Usage(BaseModel):


class ChatCompletion(BaseModel):
id: Optional[str] = None
choices: List[Choice]

choices: Optional[List[Choice]] = None
id: Optional[str] = None

created: Optional[int] = None

Expand Down
16 changes: 8 additions & 8 deletions src/groq/types/chat/completion_create_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from __future__ import annotations

from typing import Dict, List, Union, Iterable, Optional
from typing_extensions import Annotated, TypedDict
from typing_extensions import Required, Annotated, TypedDict

from ..._utils import PropertyInfo

Expand All @@ -22,6 +22,10 @@


class CompletionCreateParams(TypedDict, total=False):
messages: Required[Iterable[Message]]

model: Required[str]

frequency_penalty: float

logit_bias: Dict[str, int]
Expand All @@ -30,10 +34,6 @@ class CompletionCreateParams(TypedDict, total=False):

max_tokens: int

messages: Iterable[Message]

model: str

n: int

presence_penalty: float
Expand Down Expand Up @@ -78,11 +78,11 @@ class MessageToolCall(TypedDict, total=False):


class Message(TypedDict, total=False):
content: str
content: Required[str]

name: str
role: Required[str]

role: str
name: str

tool_call_id: str
"""ToolMessage Fields"""
Expand Down
Loading