From e46d3ed8591ef543a6f50c4443825fd547b74ab4 Mon Sep 17 00:00:00 2001 From: Stainless Bot Date: Tue, 21 May 2024 22:49:18 +0000 Subject: [PATCH] feat(api): Improve types * Mark required fields as required * Define enums values for various strings * fix tool call choice support --- .stats.yml | 2 +- README.md | 4 +- src/groq/resources/audio/transcriptions.py | 12 +- src/groq/resources/audio/translations.py | 12 +- src/groq/resources/chat/completions.py | 443 +++++++++--------- src/groq/resources/embeddings.py | 12 +- .../audio/transcription_create_params.py | 6 +- .../types/audio/translation_create_params.py | 6 +- .../types/chat/completion_create_params.py | 385 ++++++++++++--- src/groq/types/embedding_create_params.py | 5 +- .../api_resources/audio/test_translations.py | 4 +- tests/api_resources/chat/test_completions.py | 280 +++-------- tests/api_resources/test_embeddings.py | 18 +- 13 files changed, 652 insertions(+), 537 deletions(-) diff --git a/.stats.yml b/.stats.yml index cd8b6b7..1de8464 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,2 +1,2 @@ configured_endpoints: 7 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/groqcloud%2Fgroqcloud-4643bbeed7059f8301560a9fa93e4196393cf65a0ce9b243f5bc071efadd2748.yml +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/groqcloud%2Fgroqcloud-45aff5d28bf67a962a928a38a6cf90ae3034bc824d2e65036d8784643e4995db.yml diff --git a/README.md b/README.md index 8ed555c..82c11cd 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ chat_completion = client.chat.completions.create( ], model="mixtral-8x7b-32768", ) -print(chat_completion.choices[0].message.content) +print(chat_completion.choices_0.message.content) ``` While you can provide an `api_key` keyword argument, @@ -66,7 +66,7 @@ async def main() -> None: ], model="mixtral-8x7b-32768", ) - print(chat_completion.choices[0].message.content) + print(chat_completion.choices_0.message.content) asyncio.run(main()) diff --git a/src/groq/resources/audio/transcriptions.py b/src/groq/resources/audio/transcriptions.py index 6855273..3c1759f 100644 --- a/src/groq/resources/audio/transcriptions.py +++ b/src/groq/resources/audio/transcriptions.py @@ -47,7 +47,7 @@ def create( model: Union[str, Literal["whisper-large-v3"]], language: str | NotGiven = NOT_GIVEN, prompt: str | NotGiven = NOT_GIVEN, - response_format: Literal["json", "text", "srt", "verbose_json", "vtt"] | NotGiven = NOT_GIVEN, + response_format: Literal["json", "text", "verbose_json"] | NotGiven = NOT_GIVEN, temperature: float | NotGiven = NOT_GIVEN, timestamp_granularities: List[Literal["word", "segment"]] | NotGiven = NOT_GIVEN, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. @@ -75,8 +75,8 @@ def create( segment. The [prompt](/docs/guides/speech-to-text/prompting) should match the audio language. - response_format: The format of the transcript output, in one of these options: `json`, `text`, - `srt`, `verbose_json`, or `vtt`. + response_format: The format of the transcript output, in one of these options: `json`, `text`, or + `verbose_json`. temperature: The sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and @@ -147,7 +147,7 @@ async def create( model: Union[str, Literal["whisper-large-v3"]], language: str | NotGiven = NOT_GIVEN, prompt: str | NotGiven = NOT_GIVEN, - response_format: Literal["json", "text", "srt", "verbose_json", "vtt"] | NotGiven = NOT_GIVEN, + response_format: Literal["json", "text", "verbose_json"] | NotGiven = NOT_GIVEN, temperature: float | NotGiven = NOT_GIVEN, timestamp_granularities: List[Literal["word", "segment"]] | NotGiven = NOT_GIVEN, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. @@ -175,8 +175,8 @@ async def create( segment. The [prompt](/docs/guides/speech-to-text/prompting) should match the audio language. - response_format: The format of the transcript output, in one of these options: `json`, `text`, - `srt`, `verbose_json`, or `vtt`. + response_format: The format of the transcript output, in one of these options: `json`, `text`, or + `verbose_json`. temperature: The sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and diff --git a/src/groq/resources/audio/translations.py b/src/groq/resources/audio/translations.py index b1529e2..c5226f0 100644 --- a/src/groq/resources/audio/translations.py +++ b/src/groq/resources/audio/translations.py @@ -46,7 +46,7 @@ def create( file: FileTypes, model: Union[str, Literal["whisper-large-v3"]], prompt: str | NotGiven = NOT_GIVEN, - response_format: str | NotGiven = NOT_GIVEN, + response_format: Literal["json", "text", "verbose_json"] | NotGiven = NOT_GIVEN, temperature: float | NotGiven = NOT_GIVEN, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. @@ -68,8 +68,8 @@ def create( segment. The [prompt](/docs/guides/speech-to-text/prompting) should be in English. - response_format: The format of the transcript output, in one of these options: `json`, `text`, - `srt`, `verbose_json`, or `vtt`. + response_format: The format of the transcript output, in one of these options: `json`, `text`, or + `verbose_json`. temperature: The sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and @@ -131,7 +131,7 @@ async def create( file: FileTypes, model: Union[str, Literal["whisper-large-v3"]], prompt: str | NotGiven = NOT_GIVEN, - response_format: str | NotGiven = NOT_GIVEN, + response_format: Literal["json", "text", "verbose_json"] | NotGiven = NOT_GIVEN, temperature: float | NotGiven = NOT_GIVEN, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. @@ -153,8 +153,8 @@ async def create( segment. The [prompt](/docs/guides/speech-to-text/prompting) should be in English. - response_format: The format of the transcript output, in one of these options: `json`, `text`, - `srt`, `verbose_json`, or `vtt`. + response_format: The format of the transcript output, in one of these options: `json`, `text`, or + `verbose_json`. temperature: The sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and diff --git a/src/groq/resources/chat/completions.py b/src/groq/resources/chat/completions.py index 28bba01..2e199f2 100644 --- a/src/groq/resources/chat/completions.py +++ b/src/groq/resources/chat/completions.py @@ -2,8 +2,7 @@ from __future__ import annotations -from typing import Dict, List, Union, Iterable, Optional, overload -from typing_extensions import Literal +from typing import Dict, List, Union, Iterable, Optional import httpx @@ -20,12 +19,10 @@ async_to_raw_response_wrapper, async_to_streamed_response_wrapper, ) -from ..._streaming import Stream, AsyncStream from ...types.chat import completion_create_params from ..._base_client import ( make_request_options, ) -from ...lib.chat_completion_chunk import ChatCompletionChunk from ...types.chat.chat_completion import ChatCompletion __all__ = ["Completions", "AsyncCompletions"] @@ -40,28 +37,29 @@ def with_raw_response(self) -> CompletionsWithRawResponse: def with_streaming_response(self) -> CompletionsWithStreamingResponse: return CompletionsWithStreamingResponse(self) - @overload 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, - n: int | NotGiven = NOT_GIVEN, - presence_penalty: float | NotGiven = NOT_GIVEN, - response_format: completion_create_params.ResponseFormat | NotGiven = NOT_GIVEN, - seed: int | NotGiven = NOT_GIVEN, + frequency_penalty: Optional[float] | NotGiven = NOT_GIVEN, + function_call: Optional[completion_create_params.FunctionCall] | NotGiven = NOT_GIVEN, + functions: Optional[Iterable[completion_create_params.Function]] | NotGiven = NOT_GIVEN, + logit_bias: Optional[Dict[str, int]] | NotGiven = NOT_GIVEN, + logprobs: Optional[bool] | NotGiven = NOT_GIVEN, + max_tokens: Optional[int] | NotGiven = NOT_GIVEN, + n: Optional[int] | NotGiven = NOT_GIVEN, + presence_penalty: Optional[float] | NotGiven = NOT_GIVEN, + response_format: Optional[completion_create_params.ResponseFormat] | NotGiven = NOT_GIVEN, + seed: Optional[int] | NotGiven = NOT_GIVEN, stop: Union[Optional[str], List[str], None] | NotGiven = NOT_GIVEN, - stream: Optional[Literal[False]] | NotGiven = NOT_GIVEN, - temperature: float | NotGiven = NOT_GIVEN, - tool_choice: completion_create_params.ToolChoice | NotGiven = NOT_GIVEN, - tools: Iterable[completion_create_params.Tool] | NotGiven = NOT_GIVEN, - top_logprobs: int | NotGiven = NOT_GIVEN, - top_p: float | NotGiven = NOT_GIVEN, - user: str | NotGiven = NOT_GIVEN, + stream: Optional[bool] | NotGiven = NOT_GIVEN, + temperature: Optional[float] | NotGiven = NOT_GIVEN, + tool_choice: Optional[completion_create_params.ToolChoice] | NotGiven = NOT_GIVEN, + tools: Optional[Iterable[completion_create_params.Tool]] | NotGiven = NOT_GIVEN, + top_logprobs: Optional[int] | NotGiven = NOT_GIVEN, + top_p: Optional[float] | NotGiven = NOT_GIVEN, + user: Optional[str] | NotGiven = NOT_GIVEN, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, @@ -69,105 +67,103 @@ def create( extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, ) -> ChatCompletion: - ... + """ + Creates a model response for the given chat conversation. - @overload - 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, - n: int | NotGiven = NOT_GIVEN, - presence_penalty: float | NotGiven = NOT_GIVEN, - response_format: completion_create_params.ResponseFormat | NotGiven = NOT_GIVEN, - seed: int | NotGiven = NOT_GIVEN, - stop: Union[Optional[str], List[str], None] | NotGiven = NOT_GIVEN, - stream: Literal[True], - temperature: float | NotGiven = NOT_GIVEN, - tool_choice: completion_create_params.ToolChoice | NotGiven = NOT_GIVEN, - tools: Iterable[completion_create_params.Tool] | NotGiven = NOT_GIVEN, - top_logprobs: int | NotGiven = NOT_GIVEN, - top_p: float | NotGiven = NOT_GIVEN, - user: str | NotGiven = NOT_GIVEN, - # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. - # The extra values given here take precedence over values defined on the client or passed to this method. - extra_headers: Headers | None = None, - extra_query: Query | None = None, - extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, - ) -> Stream[ChatCompletionChunk]: - ... + Args: + messages: A list of messages comprising the conversation so far. - @overload - 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, - n: int | NotGiven = NOT_GIVEN, - presence_penalty: float | NotGiven = NOT_GIVEN, - response_format: completion_create_params.ResponseFormat | NotGiven = NOT_GIVEN, - seed: int | NotGiven = NOT_GIVEN, - stop: Union[Optional[str], List[str], None] | NotGiven = NOT_GIVEN, - stream: bool, - temperature: float | NotGiven = NOT_GIVEN, - tool_choice: completion_create_params.ToolChoice | NotGiven = NOT_GIVEN, - tools: Iterable[completion_create_params.Tool] | NotGiven = NOT_GIVEN, - top_logprobs: int | NotGiven = NOT_GIVEN, - top_p: float | NotGiven = NOT_GIVEN, - user: str | NotGiven = NOT_GIVEN, - # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. - # The extra values given here take precedence over values defined on the client or passed to this method. - extra_headers: Headers | None = None, - extra_query: Query | None = None, - extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, - ) -> ChatCompletion | Stream[ChatCompletionChunk]: - ... + model: ID of the model to use. For details on which models are compatible with the Chat + API, see available [models](/docs/models) - 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, - n: int | NotGiven = NOT_GIVEN, - presence_penalty: float | NotGiven = NOT_GIVEN, - response_format: completion_create_params.ResponseFormat | NotGiven = NOT_GIVEN, - seed: int | NotGiven = NOT_GIVEN, - stop: Union[Optional[str], List[str], None] | NotGiven = NOT_GIVEN, - stream: Optional[Literal[False]] | Literal[True] | NotGiven = NOT_GIVEN, - temperature: float | NotGiven = NOT_GIVEN, - tool_choice: completion_create_params.ToolChoice | NotGiven = NOT_GIVEN, - tools: Iterable[completion_create_params.Tool] | NotGiven = NOT_GIVEN, - top_logprobs: int | NotGiven = NOT_GIVEN, - top_p: float | NotGiven = NOT_GIVEN, - user: str | NotGiven = NOT_GIVEN, - # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. - # The extra values given here take precedence over values defined on the client or passed to this method. - extra_headers: Headers | None = None, - extra_query: Query | None = None, - extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, - ) -> ChatCompletion | Stream[ChatCompletionChunk]: - """ - Creates a completion for a chat prompt + frequency_penalty: Number between -2.0 and 2.0. Positive values penalize new tokens based on their + existing frequency in the text so far, decreasing the model's likelihood to + repeat the same line verbatim. + + function_call: Deprecated in favor of `tool_choice`. + + Controls which (if any) function is called by the model. `none` means the model + will not call a function and instead generates a message. `auto` means the model + can pick between generating a message or calling a function. Specifying a + particular function via `{"name": "my_function"}` forces the model to call that + function. + + `none` is the default when no functions are present. `auto` is the default if + functions are present. + + functions: Deprecated in favor of `tools`. + + A list of functions the model may generate JSON inputs for. + + logit_bias: This is not yet supported by any of our models. Modify the likelihood of + specified tokens appearing in the completion. + + logprobs: This is not yet supported by any of our models. Whether to return log + probabilities of the output tokens or not. If true, returns the log + probabilities of each output token returned in the `content` of `message`. + + max_tokens: The maximum number of tokens that can be generated in the chat completion. The + total length of input tokens and generated tokens is limited by the model's + context length. + + n: How many chat completion choices to generate for each input message. Note that + you will be charged based on the number of generated tokens across all of the + choices. Keep `n` as `1` to minimize costs. + + presence_penalty: Number between -2.0 and 2.0. Positive values penalize new tokens based on + whether they appear in the text so far, increasing the model's likelihood to + talk about new topics. + + response_format: An object specifying the format that the model must output. + + Setting to `{ "type": "json" }` enables JSON mode, which guarantees the message + the model generates is valid JSON. + + Important: when using JSON mode, you must also instruct the model to produce + JSON yourself via a system or user message. Without this, the model may generate + an unending stream of whitespace until the generation reaches the token limit, + resulting in a long-running and seemingly "stuck" request. Also note that the + message content may be partially cut off if finish_reason="length", which + indicates the generation exceeded max_tokens or the conversation exceeded the + max context length. + + seed: If specified, our system will sample deterministically, such that repeated + requests with the same seed and parameters will return the same result. - Args: stop: Up to 4 sequences where the API will stop generating further tokens. The returned text will not contain the stop sequence. + stream: If set, partial message deltas will be sent. Tokens will be sent as data-only + server-sent events as they become available, with the stream terminated by a + data: [DONE]. [Example code](/docs/text-chat#streaming-a-chat-completion). + + temperature: What sampling temperature to use, between 0 and 2. Higher values like 0.8 will + make the output more random, while lower values like 0.2 will make it more + focused and deterministic. We generally recommend altering this or top_p but not + both + + tool_choice: Controls which (if any) function is called by the model. Specifying a particular + function via a structured object like + `{"type": "function", "function": {"name": "my_function"}}` forces the model to + call that function. + + tools: A list of tools the model may call. Currently, only functions are supported as a + tool. Use this to provide a list of functions the model may generate JSON inputs + for. A max of 128 functions are supported. + + top_logprobs: This is not yet supported by any of our models. An integer between 0 and 20 + specifying the number of most likely tokens to return at each token position, + each with an associated log probability. `logprobs` must be set to `true` if + this parameter is used. + + top_p: An alternative to sampling with temperature, called nucleus sampling, where the + model considers the results of the tokens with top_p probability mass. So 0.1 + means only the tokens comprising the top 10% probability mass are considered. We + generally recommend altering this or temperature but not both. + + user: A unique identifier representing your end-user, which can help us monitor and + detect abuse. + extra_headers: Send extra headers extra_query: Add additional query parameters to the request @@ -183,6 +179,8 @@ def create( "messages": messages, "model": model, "frequency_penalty": frequency_penalty, + "function_call": function_call, + "functions": functions, "logit_bias": logit_bias, "logprobs": logprobs, "max_tokens": max_tokens, @@ -205,8 +203,6 @@ def create( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ChatCompletion, - stream=stream or False, - stream_cls=Stream[ChatCompletionChunk], ) @@ -219,28 +215,29 @@ def with_raw_response(self) -> AsyncCompletionsWithRawResponse: def with_streaming_response(self) -> AsyncCompletionsWithStreamingResponse: return AsyncCompletionsWithStreamingResponse(self) - @overload 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, - n: int | NotGiven = NOT_GIVEN, - presence_penalty: float | NotGiven = NOT_GIVEN, - response_format: completion_create_params.ResponseFormat | NotGiven = NOT_GIVEN, - seed: int | NotGiven = NOT_GIVEN, + frequency_penalty: Optional[float] | NotGiven = NOT_GIVEN, + function_call: Optional[completion_create_params.FunctionCall] | NotGiven = NOT_GIVEN, + functions: Optional[Iterable[completion_create_params.Function]] | NotGiven = NOT_GIVEN, + logit_bias: Optional[Dict[str, int]] | NotGiven = NOT_GIVEN, + logprobs: Optional[bool] | NotGiven = NOT_GIVEN, + max_tokens: Optional[int] | NotGiven = NOT_GIVEN, + n: Optional[int] | NotGiven = NOT_GIVEN, + presence_penalty: Optional[float] | NotGiven = NOT_GIVEN, + response_format: Optional[completion_create_params.ResponseFormat] | NotGiven = NOT_GIVEN, + seed: Optional[int] | NotGiven = NOT_GIVEN, stop: Union[Optional[str], List[str], None] | NotGiven = NOT_GIVEN, - stream: Optional[Literal[False]] | NotGiven = NOT_GIVEN, - temperature: float | NotGiven = NOT_GIVEN, - tool_choice: completion_create_params.ToolChoice | NotGiven = NOT_GIVEN, - tools: Iterable[completion_create_params.Tool] | NotGiven = NOT_GIVEN, - top_logprobs: int | NotGiven = NOT_GIVEN, - top_p: float | NotGiven = NOT_GIVEN, - user: str | NotGiven = NOT_GIVEN, + stream: Optional[bool] | NotGiven = NOT_GIVEN, + temperature: Optional[float] | NotGiven = NOT_GIVEN, + tool_choice: Optional[completion_create_params.ToolChoice] | NotGiven = NOT_GIVEN, + tools: Optional[Iterable[completion_create_params.Tool]] | NotGiven = NOT_GIVEN, + top_logprobs: Optional[int] | NotGiven = NOT_GIVEN, + top_p: Optional[float] | NotGiven = NOT_GIVEN, + user: Optional[str] | NotGiven = NOT_GIVEN, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, @@ -248,105 +245,103 @@ async def create( extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, ) -> ChatCompletion: - ... + """ + Creates a model response for the given chat conversation. - @overload - 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, - n: int | NotGiven = NOT_GIVEN, - presence_penalty: float | NotGiven = NOT_GIVEN, - response_format: completion_create_params.ResponseFormat | NotGiven = NOT_GIVEN, - seed: int | NotGiven = NOT_GIVEN, - stop: Union[Optional[str], List[str], None] | NotGiven = NOT_GIVEN, - stream: Literal[True], - temperature: float | NotGiven = NOT_GIVEN, - tool_choice: completion_create_params.ToolChoice | NotGiven = NOT_GIVEN, - tools: Iterable[completion_create_params.Tool] | NotGiven = NOT_GIVEN, - top_logprobs: int | NotGiven = NOT_GIVEN, - top_p: float | NotGiven = NOT_GIVEN, - user: str | NotGiven = NOT_GIVEN, - # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. - # The extra values given here take precedence over values defined on the client or passed to this method. - extra_headers: Headers | None = None, - extra_query: Query | None = None, - extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, - ) -> AsyncStream[ChatCompletionChunk]: - ... + Args: + messages: A list of messages comprising the conversation so far. - @overload - 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, - n: int | NotGiven = NOT_GIVEN, - presence_penalty: float | NotGiven = NOT_GIVEN, - response_format: completion_create_params.ResponseFormat | NotGiven = NOT_GIVEN, - seed: int | NotGiven = NOT_GIVEN, - stop: Union[Optional[str], List[str], None] | NotGiven = NOT_GIVEN, - stream: bool, - temperature: float | NotGiven = NOT_GIVEN, - tool_choice: completion_create_params.ToolChoice | NotGiven = NOT_GIVEN, - tools: Iterable[completion_create_params.Tool] | NotGiven = NOT_GIVEN, - top_logprobs: int | NotGiven = NOT_GIVEN, - top_p: float | NotGiven = NOT_GIVEN, - user: str | NotGiven = NOT_GIVEN, - # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. - # The extra values given here take precedence over values defined on the client or passed to this method. - extra_headers: Headers | None = None, - extra_query: Query | None = None, - extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, - ) -> ChatCompletion | AsyncStream[ChatCompletionChunk]: - ... + model: ID of the model to use. For details on which models are compatible with the Chat + API, see available [models](/docs/models) - 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, - n: int | NotGiven = NOT_GIVEN, - presence_penalty: float | NotGiven = NOT_GIVEN, - response_format: completion_create_params.ResponseFormat | NotGiven = NOT_GIVEN, - seed: int | NotGiven = NOT_GIVEN, - stop: Union[Optional[str], List[str], None] | NotGiven = NOT_GIVEN, - stream: Optional[Literal[False]] | Literal[True] | NotGiven = NOT_GIVEN, - temperature: float | NotGiven = NOT_GIVEN, - tool_choice: completion_create_params.ToolChoice | NotGiven = NOT_GIVEN, - tools: Iterable[completion_create_params.Tool] | NotGiven = NOT_GIVEN, - top_logprobs: int | NotGiven = NOT_GIVEN, - top_p: float | NotGiven = NOT_GIVEN, - user: str | NotGiven = NOT_GIVEN, - # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. - # The extra values given here take precedence over values defined on the client or passed to this method. - extra_headers: Headers | None = None, - extra_query: Query | None = None, - extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, - ) -> ChatCompletion | AsyncStream[ChatCompletionChunk]: - """ - Creates a completion for a chat prompt + frequency_penalty: Number between -2.0 and 2.0. Positive values penalize new tokens based on their + existing frequency in the text so far, decreasing the model's likelihood to + repeat the same line verbatim. + + function_call: Deprecated in favor of `tool_choice`. + + Controls which (if any) function is called by the model. `none` means the model + will not call a function and instead generates a message. `auto` means the model + can pick between generating a message or calling a function. Specifying a + particular function via `{"name": "my_function"}` forces the model to call that + function. + + `none` is the default when no functions are present. `auto` is the default if + functions are present. + + functions: Deprecated in favor of `tools`. + + A list of functions the model may generate JSON inputs for. + + logit_bias: This is not yet supported by any of our models. Modify the likelihood of + specified tokens appearing in the completion. + + logprobs: This is not yet supported by any of our models. Whether to return log + probabilities of the output tokens or not. If true, returns the log + probabilities of each output token returned in the `content` of `message`. + + max_tokens: The maximum number of tokens that can be generated in the chat completion. The + total length of input tokens and generated tokens is limited by the model's + context length. + + n: How many chat completion choices to generate for each input message. Note that + you will be charged based on the number of generated tokens across all of the + choices. Keep `n` as `1` to minimize costs. + + presence_penalty: Number between -2.0 and 2.0. Positive values penalize new tokens based on + whether they appear in the text so far, increasing the model's likelihood to + talk about new topics. + + response_format: An object specifying the format that the model must output. + + Setting to `{ "type": "json" }` enables JSON mode, which guarantees the message + the model generates is valid JSON. + + Important: when using JSON mode, you must also instruct the model to produce + JSON yourself via a system or user message. Without this, the model may generate + an unending stream of whitespace until the generation reaches the token limit, + resulting in a long-running and seemingly "stuck" request. Also note that the + message content may be partially cut off if finish_reason="length", which + indicates the generation exceeded max_tokens or the conversation exceeded the + max context length. + + seed: If specified, our system will sample deterministically, such that repeated + requests with the same seed and parameters will return the same result. - Args: stop: Up to 4 sequences where the API will stop generating further tokens. The returned text will not contain the stop sequence. + stream: If set, partial message deltas will be sent. Tokens will be sent as data-only + server-sent events as they become available, with the stream terminated by a + data: [DONE]. [Example code](/docs/text-chat#streaming-a-chat-completion). + + temperature: What sampling temperature to use, between 0 and 2. Higher values like 0.8 will + make the output more random, while lower values like 0.2 will make it more + focused and deterministic. We generally recommend altering this or top_p but not + both + + tool_choice: Controls which (if any) function is called by the model. Specifying a particular + function via a structured object like + `{"type": "function", "function": {"name": "my_function"}}` forces the model to + call that function. + + tools: A list of tools the model may call. Currently, only functions are supported as a + tool. Use this to provide a list of functions the model may generate JSON inputs + for. A max of 128 functions are supported. + + top_logprobs: This is not yet supported by any of our models. An integer between 0 and 20 + specifying the number of most likely tokens to return at each token position, + each with an associated log probability. `logprobs` must be set to `true` if + this parameter is used. + + top_p: An alternative to sampling with temperature, called nucleus sampling, where the + model considers the results of the tokens with top_p probability mass. So 0.1 + means only the tokens comprising the top 10% probability mass are considered. We + generally recommend altering this or temperature but not both. + + user: A unique identifier representing your end-user, which can help us monitor and + detect abuse. + extra_headers: Send extra headers extra_query: Add additional query parameters to the request @@ -362,6 +357,8 @@ async def create( "messages": messages, "model": model, "frequency_penalty": frequency_penalty, + "function_call": function_call, + "functions": functions, "logit_bias": logit_bias, "logprobs": logprobs, "max_tokens": max_tokens, @@ -384,8 +381,6 @@ async def create( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ChatCompletion, - stream=stream or False, - stream_cls=AsyncStream[ChatCompletionChunk], ) diff --git a/src/groq/resources/embeddings.py b/src/groq/resources/embeddings.py index 157eddb..74f4604 100644 --- a/src/groq/resources/embeddings.py +++ b/src/groq/resources/embeddings.py @@ -43,7 +43,6 @@ def create( *, input: Union[str, List[str]], model: str, - dimensions: int | NotGiven = NOT_GIVEN, encoding_format: Literal["float", "base64"] | NotGiven = NOT_GIVEN, user: Optional[str] | NotGiven = NOT_GIVEN, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. @@ -64,9 +63,7 @@ def create( model: ID of the model to use. - dimensions: The number of dimensions to return the embeddings in. - - encoding_format: The format to return the embeddings in. + encoding_format: The format to return the embeddings in. Can only be `float` or `base64`. user: A unique identifier representing your end-user, which can help us monitor and detect abuse. @@ -85,7 +82,6 @@ def create( { "input": input, "model": model, - "dimensions": dimensions, "encoding_format": encoding_format, "user": user, }, @@ -112,7 +108,6 @@ async def create( *, input: Union[str, List[str]], model: str, - dimensions: int | NotGiven = NOT_GIVEN, encoding_format: Literal["float", "base64"] | NotGiven = NOT_GIVEN, user: Optional[str] | NotGiven = NOT_GIVEN, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. @@ -133,9 +128,7 @@ async def create( model: ID of the model to use. - dimensions: The number of dimensions to return the embeddings in. - - encoding_format: The format to return the embeddings in. + encoding_format: The format to return the embeddings in. Can only be `float` or `base64`. user: A unique identifier representing your end-user, which can help us monitor and detect abuse. @@ -154,7 +147,6 @@ async def create( { "input": input, "model": model, - "dimensions": dimensions, "encoding_format": encoding_format, "user": user, }, diff --git a/src/groq/types/audio/transcription_create_params.py b/src/groq/types/audio/transcription_create_params.py index 373793c..2f030e2 100644 --- a/src/groq/types/audio/transcription_create_params.py +++ b/src/groq/types/audio/transcription_create_params.py @@ -36,10 +36,10 @@ class TranscriptionCreateParams(TypedDict, total=False): language. """ - response_format: Literal["json", "text", "srt", "verbose_json", "vtt"] + response_format: Literal["json", "text", "verbose_json"] """ - The format of the transcript output, in one of these options: `json`, `text`, - `srt`, `verbose_json`, or `vtt`. + The format of the transcript output, in one of these options: `json`, `text`, or + `verbose_json`. """ temperature: float diff --git a/src/groq/types/audio/translation_create_params.py b/src/groq/types/audio/translation_create_params.py index c98b320..6e2d4b4 100644 --- a/src/groq/types/audio/translation_create_params.py +++ b/src/groq/types/audio/translation_create_params.py @@ -27,10 +27,10 @@ class TranslationCreateParams(TypedDict, total=False): The [prompt](/docs/guides/speech-to-text/prompting) should be in English. """ - response_format: str + response_format: Literal["json", "text", "verbose_json"] """ - The format of the transcript output, in one of these options: `json`, `text`, - `srt`, `verbose_json`, or `vtt`. + The format of the transcript output, in one of these options: `json`, `text`, or + `verbose_json`. """ temperature: float diff --git a/src/groq/types/chat/completion_create_params.py b/src/groq/types/chat/completion_create_params.py index 8214a44..f05c425 100644 --- a/src/groq/types/chat/completion_create_params.py +++ b/src/groq/types/chat/completion_create_params.py @@ -3,23 +3,30 @@ from __future__ import annotations from typing import Dict, List, Union, Iterable, Optional -from typing_extensions import Literal, Required, Annotated, TypedDict - -from ..._utils import PropertyInfo +from typing_extensions import Literal, Required, TypedDict __all__ = [ "CompletionCreateParams", "Message", - "MessageContentUnionMember1", - "MessageContentUnionMember1TypesChatCompletionRequestMessageContentPartText", - "MessageContentUnionMember1TypesChatCompletionRequestMessageContentPartImage", - "MessageContentUnionMember1TypesChatCompletionRequestMessageContentPartImageImageURL", - "MessageToolCall", - "MessageToolCallFunction", + "MessageChatCompletionRequestSystemMessage", + "MessageChatCompletionRequestUserMessage", + "MessageChatCompletionRequestUserMessageContentArrayOfContentPart", + "MessageChatCompletionRequestUserMessageContentArrayOfContentPartChatCompletionRequestMessageContentPartText", + "MessageChatCompletionRequestUserMessageContentArrayOfContentPartChatCompletionRequestMessageContentPartImage", + "MessageChatCompletionRequestUserMessageContentArrayOfContentPartChatCompletionRequestMessageContentPartImageImageURL", + "MessageChatCompletionRequestAssistantMessage", + "MessageChatCompletionRequestAssistantMessageFunctionCall", + "MessageChatCompletionRequestAssistantMessageToolCall", + "MessageChatCompletionRequestAssistantMessageToolCallFunction", + "MessageChatCompletionRequestToolMessage", + "MessageChatCompletionRequestFunctionMessage", + "FunctionCall", + "FunctionCallChatCompletionFunctionCallOption", + "Function", "ResponseFormat", "ToolChoice", - "ToolChoiceToolChoice", - "ToolChoiceToolChoiceFunction", + "ToolChoiceChatToolChoice", + "ToolChoiceChatToolChoiceFunction", "Tool", "ToolFunction", ] @@ -27,24 +34,95 @@ class CompletionCreateParams(TypedDict, total=False): messages: Required[Iterable[Message]] + """A list of messages comprising the conversation so far.""" model: Required[str] + """ID of the model to use. + + For details on which models are compatible with the Chat API, see available + [models](/docs/models) + """ + + frequency_penalty: Optional[float] + """Number between -2.0 and 2.0. + + Positive values penalize new tokens based on their existing frequency in the + text so far, decreasing the model's likelihood to repeat the same line verbatim. + """ + + function_call: Optional[FunctionCall] + """Deprecated in favor of `tool_choice`. + + Controls which (if any) function is called by the model. `none` means the model + will not call a function and instead generates a message. `auto` means the model + can pick between generating a message or calling a function. Specifying a + particular function via `{"name": "my_function"}` forces the model to call that + function. + + `none` is the default when no functions are present. `auto` is the default if + functions are present. + """ + + functions: Optional[Iterable[Function]] + """Deprecated in favor of `tools`. + + A list of functions the model may generate JSON inputs for. + """ + + logit_bias: Optional[Dict[str, int]] + """ + This is not yet supported by any of our models. Modify the likelihood of + specified tokens appearing in the completion. + """ + + logprobs: Optional[bool] + """ + This is not yet supported by any of our models. Whether to return log + probabilities of the output tokens or not. If true, returns the log + probabilities of each output token returned in the `content` of `message`. + """ + + max_tokens: Optional[int] + """The maximum number of tokens that can be generated in the chat completion. + + The total length of input tokens and generated tokens is limited by the model's + context length. + """ - frequency_penalty: float + n: Optional[int] + """How many chat completion choices to generate for each input message. - logit_bias: Dict[str, int] + Note that you will be charged based on the number of generated tokens across all + of the choices. Keep `n` as `1` to minimize costs. + """ - logprobs: bool + presence_penalty: Optional[float] + """Number between -2.0 and 2.0. - max_tokens: int + Positive values penalize new tokens based on whether they appear in the text so + far, increasing the model's likelihood to talk about new topics. + """ - n: int + response_format: Optional[ResponseFormat] + """An object specifying the format that the model must output. - presence_penalty: float + Setting to `{ "type": "json" }` enables JSON mode, which guarantees the message + the model generates is valid JSON. - response_format: ResponseFormat + Important: when using JSON mode, you must also instruct the model to produce + JSON yourself via a system or user message. Without this, the model may generate + an unending stream of whitespace until the generation reaches the token limit, + resulting in a long-running and seemingly "stuck" request. Also note that the + message content may be partially cut off if finish_reason="length", which + indicates the generation exceeded max_tokens or the conversation exceeded the + max context length. + """ - seed: int + seed: Optional[int] + """ + If specified, our system will sample deterministically, such that repeated + requests with the same seed and parameters will return the same result. + """ stop: Union[Optional[str], List[str], None] """Up to 4 sequences where the API will stop generating further tokens. @@ -52,22 +130,81 @@ class CompletionCreateParams(TypedDict, total=False): The returned text will not contain the stop sequence. """ - stream: bool + stream: Optional[bool] + """If set, partial message deltas will be sent. - temperature: float + Tokens will be sent as data-only server-sent events as they become available, + with the stream terminated by a data: [DONE]. + [Example code](/docs/text-chat#streaming-a-chat-completion). + """ - tool_choice: ToolChoice + temperature: Optional[float] + """What sampling temperature to use, between 0 and 2. - tools: Iterable[Tool] + Higher values like 0.8 will make the output more random, while lower values like + 0.2 will make it more focused and deterministic. We generally recommend altering + this or top_p but not both + """ + + tool_choice: Optional[ToolChoice] + """Controls which (if any) function is called by the model. + + Specifying a particular function via a structured object like + `{"type": "function", "function": {"name": "my_function"}}` forces the model to + call that function. + """ + + tools: Optional[Iterable[Tool]] + """A list of tools the model may call. + + Currently, only functions are supported as a tool. Use this to provide a list of + functions the model may generate JSON inputs for. A max of 128 functions are + supported. + """ - top_logprobs: int + top_logprobs: Optional[int] + """ + This is not yet supported by any of our models. An integer between 0 and 20 + specifying the number of most likely tokens to return at each token position, + each with an associated log probability. `logprobs` must be set to `true` if + this parameter is used. + """ - top_p: float + top_p: Optional[float] + """ + An alternative to sampling with temperature, called nucleus sampling, where the + model considers the results of the tokens with top_p probability mass. So 0.1 + means only the tokens comprising the top 10% probability mass are considered. We + generally recommend altering this or temperature but not both. + """ + + user: Optional[str] + """ + A unique identifier representing your end-user, which can help us monitor and + detect abuse. + """ - user: str +class MessageChatCompletionRequestSystemMessage(TypedDict, total=False): + content: Required[str] + """The contents of the system message.""" -class MessageContentUnionMember1TypesChatCompletionRequestMessageContentPartText(TypedDict, total=False): + role: Required[Literal["system"]] + """The role of the messages author, in this case `system`.""" + + name: str + """An optional name for the participant. + + Provides the model information to differentiate between participants of the same + role. + """ + + tool_call_id: Optional[str] + + +class MessageChatCompletionRequestUserMessageContentArrayOfContentPartChatCompletionRequestMessageContentPartText( + TypedDict, total=False +): text: Required[str] """The text content.""" @@ -75,7 +212,9 @@ class MessageContentUnionMember1TypesChatCompletionRequestMessageContentPartText """The type of the content part.""" -class MessageContentUnionMember1TypesChatCompletionRequestMessageContentPartImageImageURL(TypedDict, total=False): +class MessageChatCompletionRequestUserMessageContentArrayOfContentPartChatCompletionRequestMessageContentPartImageImageURL( + TypedDict, total=False +): url: Required[str] """Either a URL of the image or the base64 encoded image data.""" @@ -83,76 +222,202 @@ class MessageContentUnionMember1TypesChatCompletionRequestMessageContentPartImag """Specifies the detail level of the image.""" -class MessageContentUnionMember1TypesChatCompletionRequestMessageContentPartImage(TypedDict, total=False): - image_url: Required[MessageContentUnionMember1TypesChatCompletionRequestMessageContentPartImageImageURL] +class MessageChatCompletionRequestUserMessageContentArrayOfContentPartChatCompletionRequestMessageContentPartImage( + TypedDict, total=False +): + image_url: Required[ + MessageChatCompletionRequestUserMessageContentArrayOfContentPartChatCompletionRequestMessageContentPartImageImageURL + ] type: Required[Literal["image_url"]] """The type of the content part.""" -MessageContentUnionMember1 = Union[ - MessageContentUnionMember1TypesChatCompletionRequestMessageContentPartText, - MessageContentUnionMember1TypesChatCompletionRequestMessageContentPartImage, +MessageChatCompletionRequestUserMessageContentArrayOfContentPart = Union[ + MessageChatCompletionRequestUserMessageContentArrayOfContentPartChatCompletionRequestMessageContentPartText, + MessageChatCompletionRequestUserMessageContentArrayOfContentPartChatCompletionRequestMessageContentPartImage, ] -class MessageToolCallFunction(TypedDict, total=False): - arguments: str +class MessageChatCompletionRequestUserMessage(TypedDict, total=False): + content: Required[Union[str, Iterable[MessageChatCompletionRequestUserMessageContentArrayOfContentPart]]] + """The contents of the user message.""" - name: str + role: Required[Literal["user"]] + """The role of the messages author, in this case `user`.""" + name: Optional[str] + """An optional name for the participant. -class MessageToolCall(TypedDict, total=False): - id: str + Provides the model information to differentiate between participants of the same + role. + """ - function: MessageToolCallFunction + tool_call_id: Optional[str] - type: str +class MessageChatCompletionRequestAssistantMessageFunctionCall(TypedDict, total=False): + arguments: Required[str] + """ + The arguments to call the function with, as generated by the model in JSON + format. Note that the model does not always generate valid JSON, and may + hallucinate parameters not defined by your function schema. Validate the + arguments in your code before calling your function. + """ -class Message(TypedDict, total=False): - content: Required[Union[str, Iterable[MessageContentUnionMember1]]] + name: Required[str] + """The name of the function to call.""" - role: Required[str] - name: str +class MessageChatCompletionRequestAssistantMessageToolCallFunction(TypedDict, total=False): + arguments: Required[str] + """ + The arguments to call the function with, as generated by the model in JSON + format. Note that the model does not always generate valid JSON, and may + hallucinate parameters not defined by your function schema. Validate the + arguments in your code before calling your function. + """ - tool_call_id: str - """ToolMessage Fields""" + name: Required[str] + """The name of the function to call.""" - tool_calls: Iterable[MessageToolCall] - """AssistantMessage Fields""" +class MessageChatCompletionRequestAssistantMessageToolCall(TypedDict, total=False): + id: Required[str] + """The ID of the tool call.""" -class ResponseFormat(TypedDict, total=False): - type: str + function: Required[MessageChatCompletionRequestAssistantMessageToolCallFunction] + """The function that the model called.""" + + type: Required[Literal["function"]] + """The type of the tool. Currently, only `function` is supported.""" + + +class MessageChatCompletionRequestAssistantMessage(TypedDict, total=False): + role: Required[Literal["assistant"]] + """The role of the messages author, in this case `assistant`.""" + content: Optional[str] + """The contents of the assistant message. + + Required unless `tool_calls` or `function_call` is specified. + """ + + function_call: MessageChatCompletionRequestAssistantMessageFunctionCall + """Deprecated and replaced by `tool_calls`. + + The name and arguments of a function that should be called, as generated by the + model. + """ -class ToolChoiceToolChoiceFunction(TypedDict, total=False): name: str + """An optional name for the participant. + + Provides the model information to differentiate between participants of the same + role. + """ + + tool_call_id: Optional[str] + + tool_calls: Iterable[MessageChatCompletionRequestAssistantMessageToolCall] + """The tool calls generated by the model, such as function calls.""" + + +class MessageChatCompletionRequestToolMessage(TypedDict, total=False): + content: Required[str] + """The contents of the tool message.""" + + role: Required[Literal["tool"]] + """The role of the messages author, in this case `tool`.""" + + tool_call_id: Required[str] + """Tool call that this message is responding to.""" + + name: Optional[str] + + +class MessageChatCompletionRequestFunctionMessage(TypedDict, total=False): + content: Required[Optional[str]] + """The contents of the function message.""" + + name: Required[str] + """The name of the function to call.""" + + role: Required[Literal["function"]] + """The role of the messages author, in this case `function`.""" + + tool_call_id: Optional[str] + +Message = Union[ + MessageChatCompletionRequestSystemMessage, + MessageChatCompletionRequestUserMessage, + MessageChatCompletionRequestAssistantMessage, + MessageChatCompletionRequestToolMessage, + MessageChatCompletionRequestFunctionMessage, +] + + +class FunctionCallChatCompletionFunctionCallOption(TypedDict, total=False): + name: Required[str] + """The name of the function to call.""" + + +FunctionCall = Union[Literal["none", "auto"], FunctionCallChatCompletionFunctionCallOption] + + +class Function(TypedDict, total=False): + name: Required[str] + """The name of the function to be called. -class ToolChoiceToolChoice(TypedDict, total=False): - function: ToolChoiceToolChoiceFunction + Must be a-z, A-Z, 0-9, or contain underscores and dashes, with a maximum length + of 64. + """ + + description: str + """ + A description of what the function does, used by the model to choose when and + how to call the function. + """ + + parameters: Dict[str, object] + """The parameters the functions accepts, described as a JSON Schema object. + See the [guide](/docs/guides/text-generation/function-calling) for examples, and + the [JSON Schema reference](https://json-schema.org/understanding-json-schema/) + for documentation about the format. + + Omitting `parameters` defines a function with an empty parameter list. + """ + + +class ResponseFormat(TypedDict, total=False): type: str -class ToolChoice(TypedDict, total=False): - string: str +class ToolChoiceChatToolChoiceFunction(TypedDict, total=False): + name: Required[str] + """The name of the function to call.""" + + +class ToolChoiceChatToolChoice(TypedDict, total=False): + function: Required[ToolChoiceChatToolChoiceFunction] - tool_choice: Annotated[ToolChoiceToolChoice, PropertyInfo(alias="toolChoice")] + type: Required[Literal["function"]] + + +ToolChoice = Union[Literal["none", "auto"], ToolChoiceChatToolChoice] class ToolFunction(TypedDict, total=False): - description: str + name: Required[str] - name: str + description: str parameters: Dict[str, object] class Tool(TypedDict, total=False): - function: ToolFunction + function: Required[ToolFunction] - type: str + type: Required[Literal["function"]] diff --git a/src/groq/types/embedding_create_params.py b/src/groq/types/embedding_create_params.py index 42c2a4c..57f9371 100644 --- a/src/groq/types/embedding_create_params.py +++ b/src/groq/types/embedding_create_params.py @@ -20,11 +20,8 @@ class EmbeddingCreateParams(TypedDict, total=False): model: Required[str] """ID of the model to use.""" - dimensions: int - """The number of dimensions to return the embeddings in.""" - encoding_format: Literal["float", "base64"] - """The format to return the embeddings in.""" + """The format to return the embeddings in. Can only be `float` or `base64`.""" user: Optional[str] """ diff --git a/tests/api_resources/audio/test_translations.py b/tests/api_resources/audio/test_translations.py index b6c540b..06eafae 100644 --- a/tests/api_resources/audio/test_translations.py +++ b/tests/api_resources/audio/test_translations.py @@ -31,7 +31,7 @@ def test_method_create_with_all_params(self, client: Groq) -> None: file=b"raw file contents", model="whisper-1", prompt="string", - response_format="string", + response_format="json", temperature=0, ) assert_matches_type(TranslationCreateResponse, translation, path=["response"]) @@ -80,7 +80,7 @@ async def test_method_create_with_all_params(self, async_client: AsyncGroq) -> N file=b"raw file contents", model="whisper-1", prompt="string", - response_format="string", + response_format="json", temperature=0, ) assert_matches_type(TranslationCreateResponse, translation, path=["response"]) diff --git a/tests/api_resources/chat/test_completions.py b/tests/api_resources/chat/test_completions.py index 9a3c0d8..96e5cd9 100644 --- a/tests/api_resources/chat/test_completions.py +++ b/tests/api_resources/chat/test_completions.py @@ -23,15 +23,15 @@ def test_method_create(self, client: Groq) -> None: messages=[ { "content": "string", - "role": "string", + "role": "system", }, { "content": "string", - "role": "string", + "role": "system", }, { "content": "string", - "role": "string", + "role": "system", }, ], model="string", @@ -44,120 +44,54 @@ def test_method_create_with_all_params(self, client: Groq) -> None: messages=[ { "content": "string", + "role": "system", "name": "string", - "role": "string", "tool_call_id": "string", - "tool_calls": [ - { - "function": { - "arguments": "string", - "name": "string", - }, - "id": "string", - "type": "string", - }, - { - "function": { - "arguments": "string", - "name": "string", - }, - "id": "string", - "type": "string", - }, - { - "function": { - "arguments": "string", - "name": "string", - }, - "id": "string", - "type": "string", - }, - ], }, { "content": "string", + "role": "system", "name": "string", - "role": "string", "tool_call_id": "string", - "tool_calls": [ - { - "function": { - "arguments": "string", - "name": "string", - }, - "id": "string", - "type": "string", - }, - { - "function": { - "arguments": "string", - "name": "string", - }, - "id": "string", - "type": "string", - }, - { - "function": { - "arguments": "string", - "name": "string", - }, - "id": "string", - "type": "string", - }, - ], }, { "content": "string", + "role": "system", "name": "string", - "role": "string", "tool_call_id": "string", - "tool_calls": [ - { - "function": { - "arguments": "string", - "name": "string", - }, - "id": "string", - "type": "string", - }, - { - "function": { - "arguments": "string", - "name": "string", - }, - "id": "string", - "type": "string", - }, - { - "function": { - "arguments": "string", - "name": "string", - }, - "id": "string", - "type": "string", - }, - ], }, ], model="string", - frequency_penalty=0, + frequency_penalty=-2, + function_call="none", + functions=[ + { + "description": "string", + "name": "string", + "parameters": {"foo": "bar"}, + }, + { + "description": "string", + "name": "string", + "parameters": {"foo": "bar"}, + }, + { + "description": "string", + "name": "string", + "parameters": {"foo": "bar"}, + }, + ], logit_bias={"foo": 0}, logprobs=True, max_tokens=0, - n=0, - presence_penalty=0, + n=1, + presence_penalty=-2, response_format={"type": "string"}, seed=0, stop="\n", stream=True, temperature=0, - tool_choice={ - "string": "string", - "tool_choice": { - "function": {"name": "string"}, - "type": "string", - }, - }, + tool_choice="none", tools=[ { "function": { @@ -165,7 +99,7 @@ def test_method_create_with_all_params(self, client: Groq) -> None: "name": "string", "parameters": {"foo": "bar"}, }, - "type": "string", + "type": "function", }, { "function": { @@ -173,7 +107,7 @@ def test_method_create_with_all_params(self, client: Groq) -> None: "name": "string", "parameters": {"foo": "bar"}, }, - "type": "string", + "type": "function", }, { "function": { @@ -181,7 +115,7 @@ def test_method_create_with_all_params(self, client: Groq) -> None: "name": "string", "parameters": {"foo": "bar"}, }, - "type": "string", + "type": "function", }, ], top_logprobs=0, @@ -196,15 +130,15 @@ def test_raw_response_create(self, client: Groq) -> None: messages=[ { "content": "string", - "role": "string", + "role": "system", }, { "content": "string", - "role": "string", + "role": "system", }, { "content": "string", - "role": "string", + "role": "system", }, ], model="string", @@ -221,15 +155,15 @@ def test_streaming_response_create(self, client: Groq) -> None: messages=[ { "content": "string", - "role": "string", + "role": "system", }, { "content": "string", - "role": "string", + "role": "system", }, { "content": "string", - "role": "string", + "role": "system", }, ], model="string", @@ -252,15 +186,15 @@ async def test_method_create(self, async_client: AsyncGroq) -> None: messages=[ { "content": "string", - "role": "string", + "role": "system", }, { "content": "string", - "role": "string", + "role": "system", }, { "content": "string", - "role": "string", + "role": "system", }, ], model="string", @@ -273,120 +207,54 @@ async def test_method_create_with_all_params(self, async_client: AsyncGroq) -> N messages=[ { "content": "string", + "role": "system", "name": "string", - "role": "string", "tool_call_id": "string", - "tool_calls": [ - { - "function": { - "arguments": "string", - "name": "string", - }, - "id": "string", - "type": "string", - }, - { - "function": { - "arguments": "string", - "name": "string", - }, - "id": "string", - "type": "string", - }, - { - "function": { - "arguments": "string", - "name": "string", - }, - "id": "string", - "type": "string", - }, - ], }, { "content": "string", + "role": "system", "name": "string", - "role": "string", "tool_call_id": "string", - "tool_calls": [ - { - "function": { - "arguments": "string", - "name": "string", - }, - "id": "string", - "type": "string", - }, - { - "function": { - "arguments": "string", - "name": "string", - }, - "id": "string", - "type": "string", - }, - { - "function": { - "arguments": "string", - "name": "string", - }, - "id": "string", - "type": "string", - }, - ], }, { "content": "string", + "role": "system", "name": "string", - "role": "string", "tool_call_id": "string", - "tool_calls": [ - { - "function": { - "arguments": "string", - "name": "string", - }, - "id": "string", - "type": "string", - }, - { - "function": { - "arguments": "string", - "name": "string", - }, - "id": "string", - "type": "string", - }, - { - "function": { - "arguments": "string", - "name": "string", - }, - "id": "string", - "type": "string", - }, - ], }, ], model="string", - frequency_penalty=0, + frequency_penalty=-2, + function_call="none", + functions=[ + { + "description": "string", + "name": "string", + "parameters": {"foo": "bar"}, + }, + { + "description": "string", + "name": "string", + "parameters": {"foo": "bar"}, + }, + { + "description": "string", + "name": "string", + "parameters": {"foo": "bar"}, + }, + ], logit_bias={"foo": 0}, logprobs=True, max_tokens=0, - n=0, - presence_penalty=0, + n=1, + presence_penalty=-2, response_format={"type": "string"}, seed=0, stop="\n", stream=True, temperature=0, - tool_choice={ - "string": "string", - "tool_choice": { - "function": {"name": "string"}, - "type": "string", - }, - }, + tool_choice="none", tools=[ { "function": { @@ -394,7 +262,7 @@ async def test_method_create_with_all_params(self, async_client: AsyncGroq) -> N "name": "string", "parameters": {"foo": "bar"}, }, - "type": "string", + "type": "function", }, { "function": { @@ -402,7 +270,7 @@ async def test_method_create_with_all_params(self, async_client: AsyncGroq) -> N "name": "string", "parameters": {"foo": "bar"}, }, - "type": "string", + "type": "function", }, { "function": { @@ -410,7 +278,7 @@ async def test_method_create_with_all_params(self, async_client: AsyncGroq) -> N "name": "string", "parameters": {"foo": "bar"}, }, - "type": "string", + "type": "function", }, ], top_logprobs=0, @@ -425,15 +293,15 @@ async def test_raw_response_create(self, async_client: AsyncGroq) -> None: messages=[ { "content": "string", - "role": "string", + "role": "system", }, { "content": "string", - "role": "string", + "role": "system", }, { "content": "string", - "role": "string", + "role": "system", }, ], model="string", @@ -450,15 +318,15 @@ async def test_streaming_response_create(self, async_client: AsyncGroq) -> None: messages=[ { "content": "string", - "role": "string", + "role": "system", }, { "content": "string", - "role": "string", + "role": "system", }, { "content": "string", - "role": "string", + "role": "system", }, ], model="string", diff --git a/tests/api_resources/test_embeddings.py b/tests/api_resources/test_embeddings.py index bed1c18..9e663d1 100644 --- a/tests/api_resources/test_embeddings.py +++ b/tests/api_resources/test_embeddings.py @@ -21,7 +21,7 @@ class TestEmbeddings: def test_method_create(self, client: Groq) -> None: embedding = client.embeddings.create( input="The quick brown fox jumped over the lazy dog", - model="nomic-embed-text-v1.5", + model="nomic-embed-text-v1_5", ) assert_matches_type(CreateEmbeddingResponse, embedding, path=["response"]) @@ -29,8 +29,7 @@ def test_method_create(self, client: Groq) -> None: def test_method_create_with_all_params(self, client: Groq) -> None: embedding = client.embeddings.create( input="The quick brown fox jumped over the lazy dog", - model="nomic-embed-text-v1.5", - dimensions=1, + model="nomic-embed-text-v1_5", encoding_format="float", user="string", ) @@ -40,7 +39,7 @@ def test_method_create_with_all_params(self, client: Groq) -> None: def test_raw_response_create(self, client: Groq) -> None: response = client.embeddings.with_raw_response.create( input="The quick brown fox jumped over the lazy dog", - model="nomic-embed-text-v1.5", + model="nomic-embed-text-v1_5", ) assert response.is_closed is True @@ -52,7 +51,7 @@ def test_raw_response_create(self, client: Groq) -> None: def test_streaming_response_create(self, client: Groq) -> None: with client.embeddings.with_streaming_response.create( input="The quick brown fox jumped over the lazy dog", - model="nomic-embed-text-v1.5", + model="nomic-embed-text-v1_5", ) as response: assert not response.is_closed assert response.http_request.headers.get("X-Stainless-Lang") == "python" @@ -70,7 +69,7 @@ class TestAsyncEmbeddings: async def test_method_create(self, async_client: AsyncGroq) -> None: embedding = await async_client.embeddings.create( input="The quick brown fox jumped over the lazy dog", - model="nomic-embed-text-v1.5", + model="nomic-embed-text-v1_5", ) assert_matches_type(CreateEmbeddingResponse, embedding, path=["response"]) @@ -78,8 +77,7 @@ async def test_method_create(self, async_client: AsyncGroq) -> None: async def test_method_create_with_all_params(self, async_client: AsyncGroq) -> None: embedding = await async_client.embeddings.create( input="The quick brown fox jumped over the lazy dog", - model="nomic-embed-text-v1.5", - dimensions=1, + model="nomic-embed-text-v1_5", encoding_format="float", user="string", ) @@ -89,7 +87,7 @@ async def test_method_create_with_all_params(self, async_client: AsyncGroq) -> N async def test_raw_response_create(self, async_client: AsyncGroq) -> None: response = await async_client.embeddings.with_raw_response.create( input="The quick brown fox jumped over the lazy dog", - model="nomic-embed-text-v1.5", + model="nomic-embed-text-v1_5", ) assert response.is_closed is True @@ -101,7 +99,7 @@ async def test_raw_response_create(self, async_client: AsyncGroq) -> None: async def test_streaming_response_create(self, async_client: AsyncGroq) -> None: async with async_client.embeddings.with_streaming_response.create( input="The quick brown fox jumped over the lazy dog", - model="nomic-embed-text-v1.5", + model="nomic-embed-text-v1_5", ) as response: assert not response.is_closed assert response.http_request.headers.get("X-Stainless-Lang") == "python"