Skip to content

Commit

Permalink
feat(api): api update (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
Stainless Bot committed Nov 1, 2024
1 parent 5d82d2d commit ae555c1
Show file tree
Hide file tree
Showing 18 changed files with 190 additions and 134 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ yarn-error.log
codegen.log
Brewfile.lock.json
dist
/deno
dist-deno
/*.tgz
.idea/

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-e832198c20514199804ae71f3213d3747cfea8dbae37304e852fd58912abb2c1.yml
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/groqcloud%2Fgroqcloud-2e2427d7a1c97af4cb989c736fabccf1531532dd3487d330c851db96d6c5da1c.yml
10 changes: 5 additions & 5 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ export abstract class APIClient {
error: Object | undefined,
message: string | undefined,
headers: Headers | undefined,
) {
): APIError {
return APIError.generate(status, error, message, headers);
}

Expand Down Expand Up @@ -682,17 +682,17 @@ export abstract class AbstractPage<Item> implements AsyncIterable<Item> {
return await this.#client.requestAPIList(this.constructor as any, nextOptions);
}

async *iterPages() {
async *iterPages(): AsyncGenerator<this> {
// eslint-disable-next-line @typescript-eslint/no-this-alias
let page: AbstractPage<Item> = this;
let page: this = this;
yield page;
while (page.hasNextPage()) {
page = await page.getNextPage();
yield page;
}
}

async *[Symbol.asyncIterator]() {
async *[Symbol.asyncIterator](): AsyncGenerator<Item> {
for await (const page of this.iterPages()) {
for (const item of page.getPaginatedItems()) {
yield item;
Expand Down Expand Up @@ -735,7 +735,7 @@ export class PagePromise<
* console.log(item)
* }
*/
async *[Symbol.asyncIterator]() {
async *[Symbol.asyncIterator](): AsyncGenerator<Item> {
const page = await this;
for await (const item of page) {
yield item;
Expand Down
2 changes: 1 addition & 1 deletion src/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class APIError extends GroqError {
errorResponse: Object | undefined,
message: string | undefined,
headers: Headers | undefined,
) {
): APIError {
if (!status) {
return new APIConnectionError({ message, cause: castToError(errorResponse) });
}
Expand Down
61 changes: 40 additions & 21 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

import * as Errors from './error';
import * as Uploads from './uploads';
import { type Agent } from './_shims/index';
import * as Core from './core';
import * as Errors from './error';
import * as Uploads from './uploads';
import * as API from './resources/index';
import { CompletionUsage, Completions } from './resources/completions';
import {
CreateEmbeddingResponse,
Embedding,
EmbeddingCreateParams,
Embeddings,
} from './resources/embeddings';
import { Model, ModelDeleted, ModelListResponse, Models } from './resources/models';
import { Audio } from './resources/audio/audio';
import { Chat } from './resources/chat/chat';

export interface ClientOptions {
/**
Expand Down Expand Up @@ -174,7 +184,7 @@ export class Groq extends Core.APIClient {
static fileFromPath = Uploads.fileFromPath;
}

export const {
export {
GroqError,
APIError,
APIConnectionError,
Expand All @@ -188,34 +198,43 @@ export const {
InternalServerError,
PermissionDeniedError,
UnprocessableEntityError,
} = Errors;
} from './error';

export import toFile = Uploads.toFile;
export import fileFromPath = Uploads.fileFromPath;

export namespace Groq {
export import RequestOptions = Core.RequestOptions;
Groq.Completions = Completions;
Groq.Chat = Chat;
Groq.Embeddings = Embeddings;
Groq.Audio = Audio;
Groq.Models = Models;

export declare namespace Groq {
export type RequestOptions = Core.RequestOptions;

export import Completions = API.Completions;
export import CompletionUsage = API.CompletionUsage;
export { Completions as Completions, type CompletionUsage as CompletionUsage };

export import Chat = API.Chat;
export { Chat as Chat };

export import Embeddings = API.Embeddings;
export import CreateEmbeddingResponse = API.CreateEmbeddingResponse;
export import Embedding = API.Embedding;
export import EmbeddingCreateParams = API.EmbeddingCreateParams;
export {
Embeddings as Embeddings,
type CreateEmbeddingResponse as CreateEmbeddingResponse,
type Embedding as Embedding,
type EmbeddingCreateParams as EmbeddingCreateParams,
};

export import Audio = API.Audio;
export { Audio as Audio };

export import Models = API.Models;
export import Model = API.Model;
export import ModelDeleted = API.ModelDeleted;
export import ModelListResponse = API.ModelListResponse;
export {
Models as Models,
type Model as Model,
type ModelDeleted as ModelDeleted,
type ModelListResponse as ModelListResponse,
};

export import ErrorObject = API.ErrorObject;
export import FunctionDefinition = API.FunctionDefinition;
export import FunctionParameters = API.FunctionParameters;
export type ErrorObject = API.ErrorObject;
export type FunctionDefinition = API.FunctionDefinition;
export type FunctionParameters = API.FunctionParameters;
}

export default Groq;
24 changes: 17 additions & 7 deletions src/resources/audio/audio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,28 @@

import { APIResource } from '../../resource';
import * as TranscriptionsAPI from './transcriptions';
import { Transcription, TranscriptionCreateParams, Transcriptions } from './transcriptions';
import * as TranslationsAPI from './translations';
import { Translation, TranslationCreateParams, Translations } from './translations';

export class Audio extends APIResource {
transcriptions: TranscriptionsAPI.Transcriptions = new TranscriptionsAPI.Transcriptions(this._client);
translations: TranslationsAPI.Translations = new TranslationsAPI.Translations(this._client);
}

export namespace Audio {
export import Transcriptions = TranscriptionsAPI.Transcriptions;
export import Transcription = TranscriptionsAPI.Transcription;
export import TranscriptionCreateParams = TranscriptionsAPI.TranscriptionCreateParams;
export import Translations = TranslationsAPI.Translations;
export import Translation = TranslationsAPI.Translation;
export import TranslationCreateParams = TranslationsAPI.TranslationCreateParams;
Audio.Transcriptions = Transcriptions;
Audio.Translations = Translations;

export declare namespace Audio {
export {
Transcriptions as Transcriptions,
type Transcription as Transcription,
type TranscriptionCreateParams as TranscriptionCreateParams,
};

export {
Translations as Translations,
type Translation as Translation,
type TranslationCreateParams as TranslationCreateParams,
};
}
4 changes: 2 additions & 2 deletions src/resources/audio/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

export { Audio } from './audio';
export { Transcription, TranscriptionCreateParams, Transcriptions } from './transcriptions';
export { Translation, TranslationCreateParams, Translations } from './translations';
export { Transcriptions, type Transcription, type TranscriptionCreateParams } from './transcriptions';
export { Translations, type Translation, type TranslationCreateParams } from './translations';
6 changes: 2 additions & 4 deletions src/resources/audio/transcriptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import { APIResource } from '../../resource';
import * as Core from '../../core';
import * as TranscriptionsAPI from './transcriptions';

export class Transcriptions extends APIResource {
/**
Expand Down Expand Up @@ -178,7 +177,6 @@ export interface TranscriptionCreateParams {
timestamp_granularities?: Array<'word' | 'segment'>;
}

export namespace Transcriptions {
export import Transcription = TranscriptionsAPI.Transcription;
export import TranscriptionCreateParams = TranscriptionsAPI.TranscriptionCreateParams;
export declare namespace Transcriptions {
export { type Transcription as Transcription, type TranscriptionCreateParams as TranscriptionCreateParams };
}
6 changes: 2 additions & 4 deletions src/resources/audio/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import { APIResource } from '../../resource';
import * as Core from '../../core';
import * as TranslationsAPI from './translations';

export class Translations extends APIResource {
/**
Expand Down Expand Up @@ -55,7 +54,6 @@ export interface TranslationCreateParams {
temperature?: number;
}

export namespace Translations {
export import Translation = TranslationsAPI.Translation;
export import TranslationCreateParams = TranslationsAPI.TranslationCreateParams;
export declare namespace Translations {
export { type Translation as Translation, type TranslationCreateParams as TranslationCreateParams };
}
71 changes: 49 additions & 22 deletions src/resources/chat/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,58 @@

import { APIResource } from '../../resource';
import * as CompletionsAPI from './completions';
import {
ChatCompletion,
ChatCompletionAssistantMessageParam,
ChatCompletionChunk,
ChatCompletionContentPart,
ChatCompletionContentPartImage,
ChatCompletionContentPartText,
ChatCompletionFunctionCallOption,
ChatCompletionFunctionMessageParam,
ChatCompletionMessage,
ChatCompletionMessageParam,
ChatCompletionMessageToolCall,
ChatCompletionNamedToolChoice,
ChatCompletionRole,
ChatCompletionSystemMessageParam,
ChatCompletionTokenLogprob,
ChatCompletionTool,
ChatCompletionToolChoiceOption,
ChatCompletionToolMessageParam,
ChatCompletionUserMessageParam,
CompletionCreateParams,
Completions,
} from './completions';

export class Chat extends APIResource {
completions: CompletionsAPI.Completions = new CompletionsAPI.Completions(this._client);
}

export namespace Chat {
export import Completions = CompletionsAPI.Completions;
export import ChatCompletion = CompletionsAPI.ChatCompletion;
export import ChatCompletionAssistantMessageParam = CompletionsAPI.ChatCompletionAssistantMessageParam;
export import ChatCompletionChunk = CompletionsAPI.ChatCompletionChunk;
export import ChatCompletionContentPart = CompletionsAPI.ChatCompletionContentPart;
export import ChatCompletionContentPartImage = CompletionsAPI.ChatCompletionContentPartImage;
export import ChatCompletionContentPartText = CompletionsAPI.ChatCompletionContentPartText;
export import ChatCompletionFunctionCallOption = CompletionsAPI.ChatCompletionFunctionCallOption;
export import ChatCompletionFunctionMessageParam = CompletionsAPI.ChatCompletionFunctionMessageParam;
export import ChatCompletionMessage = CompletionsAPI.ChatCompletionMessage;
export import ChatCompletionMessageParam = CompletionsAPI.ChatCompletionMessageParam;
export import ChatCompletionMessageToolCall = CompletionsAPI.ChatCompletionMessageToolCall;
export import ChatCompletionNamedToolChoice = CompletionsAPI.ChatCompletionNamedToolChoice;
export import ChatCompletionRole = CompletionsAPI.ChatCompletionRole;
export import ChatCompletionSystemMessageParam = CompletionsAPI.ChatCompletionSystemMessageParam;
export import ChatCompletionTokenLogprob = CompletionsAPI.ChatCompletionTokenLogprob;
export import ChatCompletionTool = CompletionsAPI.ChatCompletionTool;
export import ChatCompletionToolChoiceOption = CompletionsAPI.ChatCompletionToolChoiceOption;
export import ChatCompletionToolMessageParam = CompletionsAPI.ChatCompletionToolMessageParam;
export import ChatCompletionUserMessageParam = CompletionsAPI.ChatCompletionUserMessageParam;
export import CompletionCreateParams = CompletionsAPI.CompletionCreateParams;
Chat.Completions = Completions;

export declare namespace Chat {
export {
Completions as Completions,
type ChatCompletion as ChatCompletion,
type ChatCompletionAssistantMessageParam as ChatCompletionAssistantMessageParam,
type ChatCompletionChunk as ChatCompletionChunk,
type ChatCompletionContentPart as ChatCompletionContentPart,
type ChatCompletionContentPartImage as ChatCompletionContentPartImage,
type ChatCompletionContentPartText as ChatCompletionContentPartText,
type ChatCompletionFunctionCallOption as ChatCompletionFunctionCallOption,
type ChatCompletionFunctionMessageParam as ChatCompletionFunctionMessageParam,
type ChatCompletionMessage as ChatCompletionMessage,
type ChatCompletionMessageParam as ChatCompletionMessageParam,
type ChatCompletionMessageToolCall as ChatCompletionMessageToolCall,
type ChatCompletionNamedToolChoice as ChatCompletionNamedToolChoice,
type ChatCompletionRole as ChatCompletionRole,
type ChatCompletionSystemMessageParam as ChatCompletionSystemMessageParam,
type ChatCompletionTokenLogprob as ChatCompletionTokenLogprob,
type ChatCompletionTool as ChatCompletionTool,
type ChatCompletionToolChoiceOption as ChatCompletionToolChoiceOption,
type ChatCompletionToolMessageParam as ChatCompletionToolMessageParam,
type ChatCompletionUserMessageParam as ChatCompletionUserMessageParam,
type CompletionCreateParams as CompletionCreateParams,
};
}
44 changes: 23 additions & 21 deletions src/resources/chat/completions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -892,25 +892,27 @@ export interface ChatCompletionCreateParamsStreaming extends ChatCompletionCreat
stream: true;
}

export namespace Completions {
export import ChatCompletion = ChatCompletionsAPI.ChatCompletion;
export import ChatCompletionAssistantMessageParam = ChatCompletionsAPI.ChatCompletionAssistantMessageParam;
export import ChatCompletionChunk = ChatCompletionsAPI.ChatCompletionChunk;
export import ChatCompletionContentPart = ChatCompletionsAPI.ChatCompletionContentPart;
export import ChatCompletionContentPartImage = ChatCompletionsAPI.ChatCompletionContentPartImage;
export import ChatCompletionContentPartText = ChatCompletionsAPI.ChatCompletionContentPartText;
export import ChatCompletionFunctionCallOption = ChatCompletionsAPI.ChatCompletionFunctionCallOption;
export import ChatCompletionFunctionMessageParam = ChatCompletionsAPI.ChatCompletionFunctionMessageParam;
export import ChatCompletionMessage = ChatCompletionsAPI.ChatCompletionMessage;
export import ChatCompletionMessageParam = ChatCompletionsAPI.ChatCompletionMessageParam;
export import ChatCompletionMessageToolCall = ChatCompletionsAPI.ChatCompletionMessageToolCall;
export import ChatCompletionNamedToolChoice = ChatCompletionsAPI.ChatCompletionNamedToolChoice;
export import ChatCompletionRole = ChatCompletionsAPI.ChatCompletionRole;
export import ChatCompletionSystemMessageParam = ChatCompletionsAPI.ChatCompletionSystemMessageParam;
export import ChatCompletionTokenLogprob = ChatCompletionsAPI.ChatCompletionTokenLogprob;
export import ChatCompletionTool = ChatCompletionsAPI.ChatCompletionTool;
export import ChatCompletionToolChoiceOption = ChatCompletionsAPI.ChatCompletionToolChoiceOption;
export import ChatCompletionToolMessageParam = ChatCompletionsAPI.ChatCompletionToolMessageParam;
export import ChatCompletionUserMessageParam = ChatCompletionsAPI.ChatCompletionUserMessageParam;
export import CompletionCreateParams = ChatCompletionsAPI.CompletionCreateParams;
export declare namespace Completions {
export {
type ChatCompletion as ChatCompletion,
type ChatCompletionAssistantMessageParam as ChatCompletionAssistantMessageParam,
type ChatCompletionChunk as ChatCompletionChunk,
type ChatCompletionContentPart as ChatCompletionContentPart,
type ChatCompletionContentPartImage as ChatCompletionContentPartImage,
type ChatCompletionContentPartText as ChatCompletionContentPartText,
type ChatCompletionFunctionCallOption as ChatCompletionFunctionCallOption,
type ChatCompletionFunctionMessageParam as ChatCompletionFunctionMessageParam,
type ChatCompletionMessage as ChatCompletionMessage,
type ChatCompletionMessageParam as ChatCompletionMessageParam,
type ChatCompletionMessageToolCall as ChatCompletionMessageToolCall,
type ChatCompletionNamedToolChoice as ChatCompletionNamedToolChoice,
type ChatCompletionRole as ChatCompletionRole,
type ChatCompletionSystemMessageParam as ChatCompletionSystemMessageParam,
type ChatCompletionTokenLogprob as ChatCompletionTokenLogprob,
type ChatCompletionTool as ChatCompletionTool,
type ChatCompletionToolChoiceOption as ChatCompletionToolChoiceOption,
type ChatCompletionToolMessageParam as ChatCompletionToolMessageParam,
type ChatCompletionUserMessageParam as ChatCompletionUserMessageParam,
type CompletionCreateParams as CompletionCreateParams,
};
}
Loading

0 comments on commit ae555c1

Please sign in to comment.