Skip to content

Commit

Permalink
feat(api): Add support for image_url in chat user messages
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] authored and gradenr committed May 22, 2024
1 parent cf59ec3 commit a8f7743
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configured_endpoints: 7
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/groqcloud%2Fgroqcloud-a3e82ffbc462174007a5f736784cde91069ac2fd1468c89b0b9faea2fa82580a.yml
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/groqcloud%2Fgroqcloud-4643bbeed7059f8301560a9fa93e4196393cf65a0ce9b243f5bc071efadd2748.yml
5 changes: 1 addition & 4 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ Methods:

# Audio

Types:

- <code><a href="./src/resources/audio/audio.ts">Translation</a></code>

## Transcriptions

Types:
Expand All @@ -42,6 +38,7 @@ Methods:

Types:

- <code><a href="./src/resources/audio/translations.ts">Translation</a></code>
- <code><a href="./src/resources/audio/translations.ts">TranslationCreateResponse</a></code>

Methods:
Expand Down
14 changes: 13 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ export interface ClientOptions {
* param to `undefined` in request options.
*/
defaultQuery?: Core.DefaultQuery;

/**
* By default, client-side use of this library is not allowed, as it risks exposing your secret API credentials to attackers.
* Only set this option to `true` if you understand the risks and have appropriate mitigations in place.
*/
dangerouslyAllowBrowser?: boolean;
}

/** API Client for interfacing with the Groq API. */
Expand All @@ -86,6 +92,7 @@ export class Groq extends Core.APIClient {
* @param {number} [opts.maxRetries=2] - The maximum number of times the client will retry a request.
* @param {Core.Headers} opts.defaultHeaders - Default headers to include with every request to the API.
* @param {Core.DefaultQuery} opts.defaultQuery - Default query parameters to include with every request to the API.
* @param {boolean} [opts.dangerouslyAllowBrowser=false] - By default, client-side use of this library is not allowed, as it risks exposing your secret API credentials to attackers.
*/
constructor({
baseURL = Core.readEnv('GROQ_BASE_URL'),
Expand All @@ -104,6 +111,12 @@ export class Groq extends Core.APIClient {
baseURL: baseURL || `https://api.groq.com`,
};

if (!options.dangerouslyAllowBrowser && Core.isRunningInBrowser()) {
throw new Errors.GroqError(
"It looks like you're running in a browser-like environment.\n\nThis is disabled by default, as it risks exposing your secret API credentials to attackers.\nIf you understand the risks and have appropriate mitigations in place,\nyou can set the `dangerouslyAllowBrowser` option to `true`, e.g.,\n\nnew Groq({ apiKey, dangerouslyAllowBrowser: true })",
);
}

super({
baseURL: options.baseURL!,
timeout: options.timeout ?? 60000 /* 1 minute */,
Expand Down Expand Up @@ -186,7 +199,6 @@ export namespace Groq {
export import Chat = API.Chat;

export import Audio = API.Audio;
export import Translation = API.Translation;

export import Models = API.Models;
export import Model = API.Model;
Expand Down
7 changes: 1 addition & 6 deletions src/resources/audio/audio.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

import { APIResource } from '../../resource';
import * as AudioAPI from './audio';
import * as TranscriptionsAPI from './transcriptions';
import * as TranslationsAPI from './translations';

Expand All @@ -10,17 +9,13 @@ export class Audio extends APIResource {
translations: TranslationsAPI.Translations = new TranslationsAPI.Translations(this._client);
}

export interface Translation {
text: string;
}

export namespace Audio {
export import Translation = AudioAPI.Translation;
export import Transcriptions = TranscriptionsAPI.Transcriptions;
export import Transcription = TranscriptionsAPI.Transcription;
export import TranscriptionCreateResponse = TranscriptionsAPI.TranscriptionCreateResponse;
export import TranscriptionCreateParams = TranscriptionsAPI.TranscriptionCreateParams;
export import Translations = TranslationsAPI.Translations;
export import Translation = TranslationsAPI.Translation;
export import TranslationCreateResponse = TranslationsAPI.TranslationCreateResponse;
export import TranslationCreateParams = TranslationsAPI.TranslationCreateParams;
}
9 changes: 7 additions & 2 deletions src/resources/audio/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

export { Audio } from './audio';
export {
Transcription,
TranscriptionCreateResponse,
TranscriptionCreateParams,
Transcriptions,
} from './transcriptions';
export { Translation, Audio } from './audio';
export { TranslationCreateResponse, TranslationCreateParams, Translations } from './translations';
export {
Translation,
TranslationCreateResponse,
TranslationCreateParams,
Translations,
} from './translations';
8 changes: 6 additions & 2 deletions src/resources/audio/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import * as Core from '../../core';
import { APIResource } from '../../resource';
import * as TranslationsAPI from './translations';
import * as AudioAPI from './audio';
import { type Uploadable, multipartFormRequestOptions } from '../../core';

export class Translations extends APIResource {
Expand All @@ -21,8 +20,12 @@ export class Translations extends APIResource {
}
}

export interface Translation {
text: string;
}

export type TranslationCreateResponse =
| AudioAPI.Translation
| Translation
| TranslationCreateResponse.CreateTranslationResponseVerboseJson;

export namespace TranslationCreateResponse {
Expand Down Expand Up @@ -142,6 +145,7 @@ export interface TranslationCreateParams {
}

export namespace Translations {
export import Translation = TranslationsAPI.Translation;
export import TranslationCreateResponse = TranslationsAPI.TranslationCreateResponse;
export import TranslationCreateParams = TranslationsAPI.TranslationCreateParams;
}
42 changes: 41 additions & 1 deletion src/resources/chat/completions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,12 @@ export interface CompletionCreateParams {

export namespace CompletionCreateParams {
export interface Message {
content: string;
content:
| string
| Array<
| Message.TypesChatCompletionRequestMessageContentPartText
| Message.TypesChatCompletionRequestMessageContentPartImage
>;

role: string;

Expand All @@ -173,6 +178,41 @@ export namespace CompletionCreateParams {
}

export namespace Message {
export interface TypesChatCompletionRequestMessageContentPartText {
/**
* The text content.
*/
text: string;

/**
* The type of the content part.
*/
type: 'text';
}

export interface TypesChatCompletionRequestMessageContentPartImage {
image_url: TypesChatCompletionRequestMessageContentPartImage.ImageURL;

/**
* The type of the content part.
*/
type: 'image_url';
}

export namespace TypesChatCompletionRequestMessageContentPartImage {
export interface ImageURL {
/**
* Either a URL of the image or the base64 encoded image data.
*/
url: string;

/**
* Specifies the detail level of the image.
*/
detail?: 'auto' | 'low' | 'high';
}
}

export interface ToolCall {
id?: string;

Expand Down
2 changes: 1 addition & 1 deletion src/resources/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

export { Audio } from './audio/audio';
export { Chat } from './chat/chat';
export { CreateEmbeddingResponse, Embedding, EmbeddingCreateParams, Embeddings } from './embeddings';
export { Model, ModelList, Models } from './models';
export { Translation, Audio } from './audio/audio';

0 comments on commit a8f7743

Please sign in to comment.