From c99373cdfd6b94a9d9346cf717a5354b378dc2f1 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 15 Feb 2024 19:08:36 +0000 Subject: [PATCH] feat: update via SDK Studio (#3) --- CONTRIBUTING.md | 4 +- README.md | 20 ++-- build | 6 +- examples/chat_completion.js | 102 ++++++++++--------- examples/chat_completion_stop.js | 14 +-- examples/chat_completion_streaming.js | 12 +-- jest.config.ts | 6 +- package.json | 6 +- scripts/postprocess-files.cjs | 4 +- src/_shims/README.md | 32 +++--- src/_shims/index.d.ts | 2 +- src/_shims/index.js | 2 +- src/_shims/index.mjs | 2 +- src/_shims/manual-types.d.ts | 4 +- src/_shims/registry.ts | 6 +- src/_shims/web-runtime.ts | 6 +- src/core.ts | 28 ++--- src/index.ts | 2 +- src/resources/chat/chat.ts | 4 +- src/resources/chat/completions.ts | 43 ++------ src/resources/models.ts | 6 +- tests/api-resources/chat/completions.test.ts | 2 +- tests/api-resources/models.test.ts | 2 +- tests/form.test.ts | 6 +- tests/index.test.ts | 6 +- tests/responses.test.ts | 4 +- tests/stringifyQuery.test.ts | 2 +- tests/uploads.test.ts | 4 +- tsconfig.build.json | 4 +- tsconfig.deno.json | 6 +- tsconfig.json | 6 +- 31 files changed, 155 insertions(+), 198 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 95bb5bc..c4f2d6f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -55,12 +55,12 @@ cd groq-node # With yarn yarn link cd ../my-package -yarn link groq +yarn link groq-sdk # With pnpm pnpm link --global cd ../my-package -pnpm link -—global groq +pnpm link -—global groq-sdk ``` ## Running tests diff --git a/README.md b/README.md index 250820e..b766786 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Groq Node API Library -[![NPM version](https://img.shields.io/npm/v/groq.svg)](https://npmjs.org/package/groq) +[![NPM version](https://img.shields.io/npm/v/groq-sdk.svg)](https://npmjs.org/package/groq-sdk) This library provides convenient access to the Groq REST API from server-side TypeScript or JavaScript. @@ -9,9 +9,9 @@ The REST API documentation can be found [on console.groq.com](https://console.gr ## Installation ```sh -npm install --save groq +npm install --save groq-sdk # or -yarn add groq +yarn add groq-sdk ``` ## Usage @@ -20,7 +20,7 @@ The full API of this library can be found in [api.md](api.md). ```js -import Groq from 'groq'; +import Groq from 'groq-sdk'; const groq = new Groq(); @@ -42,7 +42,7 @@ This library includes TypeScript definitions for all request params and response ```ts -import Groq from 'groq'; +import Groq from 'groq-sdk'; const groq = new Groq(); @@ -196,11 +196,11 @@ add the following import before your first import `from "Groq"`: ```ts // Tell TypeScript and the package to use the global web fetch instead of node-fetch. // Note, despite the name, this does not add any polyfills, but expects them to be provided if needed. -import 'groq/shims/web'; -import Groq from 'groq'; +import 'groq-sdk/shims/web'; +import Groq from 'groq-sdk'; ``` -To do the inverse, add `import "groq/shims/node"` (which does import polyfills). +To do the inverse, add `import "groq-sdk/shims/node"` (which does import polyfills). This can also be useful if you are getting the wrong TypeScript types for `Response` - more details [here](https://github.com/groq/groq-node/tree/main/src/_shims#readme). You may also provide a custom `fetch` function when instantiating the client, @@ -208,7 +208,7 @@ which can be used to inspect or alter the `Request` or `Response` before/after e ```ts import { fetch } from 'undici'; // as one example -import Groq from 'groq'; +import Groq from 'groq-sdk'; const client = new Groq({ fetch: async (url: RequestInfo, init?: RequestInfo): Promise => { @@ -265,7 +265,7 @@ TypeScript >= 4.5 is supported. The following runtimes are supported: - Node.js 18 LTS or later ([non-EOL](https://endoflife.date/nodejs)) versions. -- Deno v1.28.0 or higher, using `import Groq from "npm:groq"`. +- Deno v1.28.0 or higher, using `import Groq from "npm:groq-sdk"`. - Bun 1.0 or later. - Cloudflare Workers. - Vercel Edge Runtime. diff --git a/build b/build index 9bbdb4a..75f8cc4 100755 --- a/build +++ b/build @@ -5,7 +5,7 @@ node scripts/check-version.cjs # Build into dist and will publish the package from there, # so that src/resources/foo.ts becomes /resources/foo.js -# This way importing from `"groq/resources/foo"` works +# This way importing from `"groq-sdk/resources/foo"` works # even with `"moduleResolution": "node"` rm -rf dist; mkdir dist @@ -44,8 +44,8 @@ node scripts/postprocess-files.cjs # make sure that nothing crashes when we require the output CJS or # import the output ESM -(cd dist && node -e 'require("groq")') -(cd dist && node -e 'import("groq")' --input-type=module) +(cd dist && node -e 'require("groq-sdk")') +(cd dist && node -e 'import("groq-sdk")' --input-type=module) if command -v deno &> /dev/null && [ -e ./build-deno ] then diff --git a/examples/chat_completion.js b/examples/chat_completion.js index 426132d..28d0642 100644 --- a/examples/chat_completion.js +++ b/examples/chat_completion.js @@ -3,56 +3,58 @@ const Groq = require('groq'); const groq = new Groq(); async function main() { - groq.chat.completions.create({ - // - // Required parameters - // - messages: [ - // Set an optional system message. This sets the behavior of the - // assistant and can be used to provide specific instructions for - // how it should behave throughout the conversation. - { - "role": "system", - "content": "you are a helpful assistant." - }, - // Set a user message for the assistant to respond to. - { - "role": "user", - "content": "Explain the importance of low latency LLMs", - } - ], - - // The language model which will generate the completion. - model: "mixtral-8x7b-32768", - - // - // Optional parameters - // - - // Controls randomness: lowering results in less random completions. - // As the temperature approaches zero, the model will become deterministic - // and repetitive. - temperature: 0.5, - - // The maximum number of tokens to generate. Requests can use up to - // 2048 tokens shared between prompt and completion. - max_tokens: 1024, - - // Controls diversity via nucleus sampling: 0.5 means half of all - // likelihood-weighted options are considered. - top_p: 1, - - // A stop sequence is a predefined or user-specified text string that - // signals an AI to stop generating content, ensuring its responses - // remain focused and concise. Examples include punctuation marks and - // markers like "[end]". - stop: null, - - // If set, partial message deltas will be sent. - stream: false, - }).then((chatCompletion) => { - process.stdout.write(chatCompletion.choices[0]?.message?.content || ''); - }) + groq.chat.completions + .create({ + // + // Required parameters + // + messages: [ + // Set an optional system message. This sets the behavior of the + // assistant and can be used to provide specific instructions for + // how it should behave throughout the conversation. + { + role: 'system', + content: 'you are a helpful assistant.', + }, + // Set a user message for the assistant to respond to. + { + role: 'user', + content: 'Explain the importance of low latency LLMs', + }, + ], + + // The language model which will generate the completion. + model: 'mixtral-8x7b-32768', + + // + // Optional parameters + // + + // Controls randomness: lowering results in less random completions. + // As the temperature approaches zero, the model will become deterministic + // and repetitive. + temperature: 0.5, + + // The maximum number of tokens to generate. Requests can use up to + // 2048 tokens shared between prompt and completion. + max_tokens: 1024, + + // Controls diversity via nucleus sampling: 0.5 means half of all + // likelihood-weighted options are considered. + top_p: 1, + + // A stop sequence is a predefined or user-specified text string that + // signals an AI to stop generating content, ensuring its responses + // remain focused and concise. Examples include punctuation marks and + // markers like "[end]". + stop: null, + + // If set, partial message deltas will be sent. + stream: false, + }) + .then((chatCompletion) => { + process.stdout.write(chatCompletion.choices[0]?.message?.content || ''); + }); } main(); diff --git a/examples/chat_completion_stop.js b/examples/chat_completion_stop.js index d120530..22b91ac 100644 --- a/examples/chat_completion_stop.js +++ b/examples/chat_completion_stop.js @@ -12,18 +12,18 @@ async function main() { // assistant and can be used to provide specific instructions for // how it should behave throughout the conversation. { - "role": "system", - "content": "you are a helpful assistant." + role: 'system', + content: 'you are a helpful assistant.', }, // Set a user message for the assistant to respond to. { - "role": "user", - "content": "Start at 1 and count to 10. Separate each number with a comma and a space" - } + role: 'user', + content: 'Start at 1 and count to 10. Separate each number with a comma and a space', + }, ], // The language model which will generate the completion. - model: "mixtral-8x7b-32768", + model: 'mixtral-8x7b-32768', // // Optional parameters @@ -50,7 +50,7 @@ async function main() { // For this example, we will use ", 6" so that the llm stops counting at 5. // If multiple stop values are needed, an array of string may be passed, // stop: [", 6", ", six", ", Six"] - stop: ", 6", + stop: ', 6', // If set, partial message deltas will be sent. stream: true, diff --git a/examples/chat_completion_streaming.js b/examples/chat_completion_streaming.js index c3a2ab6..4549b83 100644 --- a/examples/chat_completion_streaming.js +++ b/examples/chat_completion_streaming.js @@ -12,18 +12,18 @@ async function main() { // assistant and can be used to provide specific instructions for // how it should behave throughout the conversation. { - "role": "system", - "content": "you are a helpful assistant." + role: 'system', + content: 'you are a helpful assistant.', }, // Set a user message for the assistant to respond to. { - "role": "user", - "content": "Explain the importance of low latency LLMs", - } + role: 'user', + content: 'Explain the importance of low latency LLMs', + }, ], // The language model which will generate the completion. - model: "mixtral-8x7b-32768", + model: 'mixtral-8x7b-32768', // // Optional parameters diff --git a/jest.config.ts b/jest.config.ts index 5436c4e..273b7a8 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -4,9 +4,9 @@ const config: JestConfigWithTsJest = { preset: 'ts-jest/presets/default-esm', testEnvironment: 'node', moduleNameMapper: { - '^groq$': '/src/index.ts', - '^groq/_shims/auto/(.*)$': '/src/_shims/auto/$1-node', - '^groq/(.*)$': '/src/$1', + '^groq-sdk$': '/src/index.ts', + '^groq-sdk/_shims/auto/(.*)$': '/src/_shims/auto/$1-node', + '^groq-sdk/(.*)$': '/src/$1', }, modulePathIgnorePatterns: [ '/ecosystem-tests/', diff --git a/package.json b/package.json index b94da78..3e4312a 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "groq", + "name": "groq-sdk", "version": "0.1.0", "description": "The official TypeScript library for the Groq API", "author": "Groq ", @@ -60,8 +60,8 @@ "./shims/web.mjs" ], "imports": { - "groq": ".", - "groq/*": "./src/*" + "groq-sdk": ".", + "groq-sdk/*": "./src/*" }, "exports": { "./_shims/auto/*": { diff --git a/scripts/postprocess-files.cjs b/scripts/postprocess-files.cjs index b69a27a..8be79a2 100644 --- a/scripts/postprocess-files.cjs +++ b/scripts/postprocess-files.cjs @@ -2,7 +2,7 @@ const fs = require('fs'); const path = require('path'); const { parse } = require('@typescript-eslint/parser'); -const pkgImportPath = process.env['PKG_IMPORT_PATH'] ?? 'groq/' +const pkgImportPath = process.env['PKG_IMPORT_PATH'] ?? 'groq-sdk/' const distDir = process.env['DIST_PATH'] ? @@ -142,7 +142,7 @@ async function postprocess() { if (file.endsWith('.d.ts')) { // work around bad tsc behavior - // if we have `import { type Readable } from 'groq/_shims/index'`, + // if we have `import { type Readable } from 'groq-sdk/_shims/index'`, // tsc sometimes replaces `Readable` with `import("stream").Readable` inline // in the output .d.ts transformed = transformed.replace(/import\("stream"\).Readable/g, 'Readable'); diff --git a/src/_shims/README.md b/src/_shims/README.md index a837e44..5583daf 100644 --- a/src/_shims/README.md +++ b/src/_shims/README.md @@ -1,9 +1,9 @@ # 👋 Wondering what everything in here does? -`groq` supports a wide variety of runtime environments like Node.js, Deno, Bun, browsers, and various +`groq-sdk` supports a wide variety of runtime environments like Node.js, Deno, Bun, browsers, and various edge runtimes, as well as both CommonJS (CJS) and EcmaScript Modules (ESM). -To do this, `groq` provides shims for either using `node-fetch` when in Node (because `fetch` is still experimental there) or the global `fetch` API built into the environment when not in Node. +To do this, `groq-sdk` provides shims for either using `node-fetch` when in Node (because `fetch` is still experimental there) or the global `fetch` API built into the environment when not in Node. It uses [conditional exports](https://nodejs.org/api/packages.html#conditional-exports) to automatically select the correct shims for each environment. However, conditional exports are a fairly new @@ -15,32 +15,32 @@ getting the wrong raw `Response` type from `.asResponse()`, for example. The user can work around these issues by manually importing one of: -- `import 'groq/shims/node'` -- `import 'groq/shims/web'` +- `import 'groq-sdk/shims/node'` +- `import 'groq-sdk/shims/web'` All of the code here in `_shims` handles selecting the automatic default shims or manual overrides. ### How it works - Runtime -Runtime shims get installed by calling `setShims` exported by `groq/_shims/registry`. +Runtime shims get installed by calling `setShims` exported by `groq-sdk/_shims/registry`. -Manually importing `groq/shims/node` or `groq/shims/web`, calls `setShims` with the respective runtime shims. +Manually importing `groq-sdk/shims/node` or `groq-sdk/shims/web`, calls `setShims` with the respective runtime shims. -All client code imports shims from `groq/_shims/index`, which: +All client code imports shims from `groq-sdk/_shims/index`, which: - checks if shims have been set manually -- if not, calls `setShims` with the shims from `groq/_shims/auto/runtime` -- re-exports the installed shims from `groq/_shims/registry`. +- if not, calls `setShims` with the shims from `groq-sdk/_shims/auto/runtime` +- re-exports the installed shims from `groq-sdk/_shims/registry`. -`groq/_shims/auto/runtime` exports web runtime shims. -If the `node` export condition is set, the export map replaces it with `groq/_shims/auto/runtime-node`. +`groq-sdk/_shims/auto/runtime` exports web runtime shims. +If the `node` export condition is set, the export map replaces it with `groq-sdk/_shims/auto/runtime-node`. ### How it works - Type time -All client code imports shim types from `groq/_shims/index`, which selects the manual types from `groq/_shims/manual-types` if they have been declared, otherwise it exports the auto types from `groq/_shims/auto/types`. +All client code imports shim types from `groq-sdk/_shims/index`, which selects the manual types from `groq-sdk/_shims/manual-types` if they have been declared, otherwise it exports the auto types from `groq-sdk/_shims/auto/types`. -`groq/_shims/manual-types` exports an empty namespace. -Manually importing `groq/shims/node` or `groq/shims/web` merges declarations into this empty namespace, so they get picked up by `groq/_shims/index`. +`groq-sdk/_shims/manual-types` exports an empty namespace. +Manually importing `groq-sdk/shims/node` or `groq-sdk/shims/web` merges declarations into this empty namespace, so they get picked up by `groq-sdk/_shims/index`. -`groq/_shims/auto/types` exports web type definitions. -If the `node` export condition is set, the export map replaces it with `groq/_shims/auto/types-node`, though TS only picks this up if `"moduleResolution": "nodenext"` or `"moduleResolution": "bundler"`. +`groq-sdk/_shims/auto/types` exports web type definitions. +If the `node` export condition is set, the export map replaces it with `groq-sdk/_shims/auto/types-node`, though TS only picks this up if `"moduleResolution": "nodenext"` or `"moduleResolution": "bundler"`. diff --git a/src/_shims/index.d.ts b/src/_shims/index.d.ts index 3f6f5af..0657d5f 100644 --- a/src/_shims/index.d.ts +++ b/src/_shims/index.d.ts @@ -2,7 +2,7 @@ * Disclaimer: modules in _shims aren't intended to be imported by SDK users. */ import { manual } from './manual-types'; -import * as auto from 'groq/_shims/auto/types'; +import * as auto from 'groq-sdk/_shims/auto/types'; import { type RequestOptions } from '../core'; type SelectType = unknown extends Manual ? Auto : Manual; diff --git a/src/_shims/index.js b/src/_shims/index.js index ecc328f..eb62c2d 100644 --- a/src/_shims/index.js +++ b/src/_shims/index.js @@ -2,7 +2,7 @@ * Disclaimer: modules in _shims aren't intended to be imported by SDK users. */ const shims = require('./registry'); -const auto = require('groq/_shims/auto/runtime'); +const auto = require('groq-sdk/_shims/auto/runtime'); if (!shims.kind) shims.setShims(auto.getRuntime(), { auto: true }); for (const property of Object.keys(shims)) { Object.defineProperty(exports, property, { diff --git a/src/_shims/index.mjs b/src/_shims/index.mjs index cc6acaa..9172531 100644 --- a/src/_shims/index.mjs +++ b/src/_shims/index.mjs @@ -2,6 +2,6 @@ * Disclaimer: modules in _shims aren't intended to be imported by SDK users. */ import * as shims from './registry.mjs'; -import * as auto from 'groq/_shims/auto/runtime'; +import * as auto from 'groq-sdk/_shims/auto/runtime'; if (!shims.kind) shims.setShims(auto.getRuntime(), { auto: true }); export * from './registry.mjs'; diff --git a/src/_shims/manual-types.d.ts b/src/_shims/manual-types.d.ts index 791aa95..58a7d2b 100644 --- a/src/_shims/manual-types.d.ts +++ b/src/_shims/manual-types.d.ts @@ -4,8 +4,8 @@ /** * Types will get added to this namespace when you import one of the following: * - * import 'groq/shims/node' - * import 'groq/shims/web' + * import 'groq-sdk/shims/node' + * import 'groq-sdk/shims/web' * * Importing more than one will cause type and runtime errors. */ diff --git a/src/_shims/registry.ts b/src/_shims/registry.ts index 27ea73a..95c7c44 100644 --- a/src/_shims/registry.ts +++ b/src/_shims/registry.ts @@ -42,11 +42,13 @@ export let isFsReadStream: Shims['isFsReadStream'] | undefined = undefined; export function setShims(shims: Shims, options: { auto: boolean } = { auto: false }) { if (auto) { throw new Error( - `you must \`import 'groq/shims/${shims.kind}'\` before importing anything else from groq`, + `you must \`import 'groq-sdk/shims/${shims.kind}'\` before importing anything else from groq-sdk`, ); } if (kind) { - throw new Error(`can't \`import 'groq/shims/${shims.kind}'\` after \`import 'groq/shims/${kind}'\``); + throw new Error( + `can't \`import 'groq-sdk/shims/${shims.kind}'\` after \`import 'groq-sdk/shims/${kind}'\``, + ); } auto = options.auto; kind = shims.kind; diff --git a/src/_shims/web-runtime.ts b/src/_shims/web-runtime.ts index c59dc88..8d17872 100644 --- a/src/_shims/web-runtime.ts +++ b/src/_shims/web-runtime.ts @@ -9,9 +9,9 @@ export function getRuntime({ manuallyImported }: { manuallyImported?: boolean } const recommendation = manuallyImported ? `You may need to use polyfills` - : `Add one of these imports before your first \`import … from 'groq'\`: -- \`import 'groq/shims/node'\` (if you're running on Node) -- \`import 'groq/shims/web'\` (otherwise) + : `Add one of these imports before your first \`import … from 'groq-sdk'\`: +- \`import 'groq-sdk/shims/node'\` (if you're running on Node) +- \`import 'groq-sdk/shims/web'\` (otherwise) `; let _fetch, _Request, _Response, _Headers; diff --git a/src/core.ts b/src/core.ts index 4520b4d..6875045 100644 --- a/src/core.ts +++ b/src/core.ts @@ -1,5 +1,4 @@ import { VERSION } from './version'; -import { Stream } from './lib/streaming'; import { GroqError, APIError, @@ -39,19 +38,6 @@ type APIResponseProps = { async function defaultParseResponse(props: APIResponseProps): Promise { const { response } = props; - if (props.options.stream) { - debug('response', response.status, response.url, response.headers, response.body); - - // Note: there is an invariant here that isn't represented in the type system - // that if you set `stream: true` the response type must also be `Stream` - - if (props.options.__streamClass) { - return props.options.__streamClass.fromSSEResponse(response, props.controller) as any; - } - - return Stream.fromSSEResponse(response, props.controller) as any; - } - // fetch refuses to read the body when the status code is 204. if (response.status === 204) { return null as T; @@ -111,9 +97,9 @@ export class APIPromise extends Promise { * * 👋 Getting the wrong TypeScript type for `Response`? * Try setting `"moduleResolution": "NodeNext"` if you can, - * or add one of these imports before your first `import … from 'groq'`: - * - `import 'groq/shims/node'` (if you're running on Node) - * - `import 'groq/shims/web'` (otherwise) + * or add one of these imports before your first `import … from 'groq-sdk'`: + * - `import 'groq-sdk/shims/node'` (if you're running on Node) + * - `import 'groq-sdk/shims/web'` (otherwise) */ asResponse(): Promise { return this.responsePromise.then((p) => p.response); @@ -127,9 +113,9 @@ export class APIPromise extends Promise { * * 👋 Getting the wrong TypeScript type for `Response`? * Try setting `"moduleResolution": "NodeNext"` if you can, - * or add one of these imports before your first `import … from 'groq'`: - * - `import 'groq/shims/node'` (if you're running on Node) - * - `import 'groq/shims/web'` (otherwise) + * or add one of these imports before your first `import … from 'groq-sdk'`: + * - `import 'groq-sdk/shims/node'` (if you're running on Node) + * - `import 'groq-sdk/shims/web'` (otherwise) */ async withResponse(): Promise<{ data: T; response: Response }> { const [data, response] = await Promise.all([this.parse(), this.asResponse()]); @@ -750,7 +736,6 @@ export type RequestOptions | Readable> = idempotencyKey?: string; __binaryResponse?: boolean | undefined; - __streamClass?: typeof Stream; }; // This is required so that we can determine if a given object matches the RequestOptions @@ -771,7 +756,6 @@ const requestOptionsKeys: KeysEnum = { idempotencyKey: true, __binaryResponse: true, - __streamClass: true, }; export const isRequestOptions = (obj: unknown): obj is RequestOptions => { diff --git a/src/index.ts b/src/index.ts index e079458..4def5b5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,7 +4,7 @@ import * as Core from './core'; import * as Errors from './error'; import { type Agent } from './_shims/index'; import * as Uploads from './uploads'; -import * as API from 'groq/resources/index'; +import * as API from 'groq-sdk/resources/index'; export interface ClientOptions { /** diff --git a/src/resources/chat/chat.ts b/src/resources/chat/chat.ts index ca6db46..00ff6f4 100644 --- a/src/resources/chat/chat.ts +++ b/src/resources/chat/chat.ts @@ -1,7 +1,7 @@ // File generated from our OpenAPI spec by Stainless. -import { APIResource } from 'groq/resource'; -import * as CompletionsAPI from 'groq/resources/chat/completions'; +import { APIResource } from 'groq-sdk/resource'; +import * as CompletionsAPI from 'groq-sdk/resources/chat/completions'; export class Chat extends APIResource { completions: CompletionsAPI.Completions = new CompletionsAPI.Completions(this._client); diff --git a/src/resources/chat/completions.ts b/src/resources/chat/completions.ts index 2c19dae..a4db5f6 100644 --- a/src/resources/chat/completions.ts +++ b/src/resources/chat/completions.ts @@ -1,34 +1,15 @@ // File generated from our OpenAPI spec by Stainless. -import * as Core from 'groq/core'; -import { APIResource } from 'groq/resource'; -import * as CompletionsAPI from 'groq/resources/chat/completions'; -import { Stream } from 'groq/lib/streaming'; -import { ChatCompletionChunk } from 'groq/lib/chat_completions_ext'; +import * as Core from 'groq-sdk/core'; +import { APIResource } from 'groq-sdk/resource'; +import * as CompletionsAPI from 'groq-sdk/resources/chat/completions'; export class Completions extends APIResource { /** * Creates a completion for a chat prompt */ - create( - body: ChatCompletionCreateParamsNonStreaming, - options?: Core.RequestOptions, - ): Core.APIPromise; - create( - body: ChatCompletionCreateParamsStreaming, - options?: Core.RequestOptions, - ): Core.APIPromise>; - create( - body: ChatCompletionCreateParamsBase, - options?: Core.RequestOptions, - ): Core.APIPromise | ChatCompletion>; - create( - body: ChatCompletionCreateParams, - options?: Core.RequestOptions, - ): Core.APIPromise | Core.APIPromise> { - return this._client.post('/openai/v1/chat/completions', { body, ...options, stream: body.stream ?? false }) as - | Core.APIPromise - | Core.APIPromise>; + create(body: CompletionCreateParams, options?: Core.RequestOptions): Core.APIPromise { + return this._client.post('/openai/v1/chat/completions', { body, ...options }); } } @@ -128,7 +109,7 @@ export namespace ChatCompletion { } } -export interface ChatCompletionCreateParamsBase { +export interface CompletionCreateParams { messages: Array; model: string; @@ -252,15 +233,3 @@ export namespace Completions { export import ChatCompletion = CompletionsAPI.ChatCompletion; export import CompletionCreateParams = CompletionsAPI.CompletionCreateParams; } - -export interface ChatCompletionCreateParamsNonStreaming extends ChatCompletionCreateParamsBase { - stream?: false; -} - -export interface ChatCompletionCreateParamsStreaming extends ChatCompletionCreateParamsBase { - stream: true; -} - -export type ChatCompletionCreateParams = - | ChatCompletionCreateParamsNonStreaming - | ChatCompletionCreateParamsStreaming; diff --git a/src/resources/models.ts b/src/resources/models.ts index 9aa4dcb..9fb6591 100644 --- a/src/resources/models.ts +++ b/src/resources/models.ts @@ -1,8 +1,8 @@ // File generated from our OpenAPI spec by Stainless. -import * as Core from 'groq/core'; -import { APIResource } from 'groq/resource'; -import * as ModelsAPI from 'groq/resources/models'; +import * as Core from 'groq-sdk/core'; +import { APIResource } from 'groq-sdk/resource'; +import * as ModelsAPI from 'groq-sdk/resources/models'; export class Models extends APIResource { /** diff --git a/tests/api-resources/chat/completions.test.ts b/tests/api-resources/chat/completions.test.ts index 1caf447..7d5dacf 100644 --- a/tests/api-resources/chat/completions.test.ts +++ b/tests/api-resources/chat/completions.test.ts @@ -1,6 +1,6 @@ // File generated from our OpenAPI spec by Stainless. -import Groq from 'groq'; +import Groq from 'groq-sdk'; import { Response } from 'node-fetch'; const groq = new Groq({ diff --git a/tests/api-resources/models.test.ts b/tests/api-resources/models.test.ts index 85755a3..867ffe2 100644 --- a/tests/api-resources/models.test.ts +++ b/tests/api-resources/models.test.ts @@ -1,6 +1,6 @@ // File generated from our OpenAPI spec by Stainless. -import Groq from 'groq'; +import Groq from 'groq-sdk'; import { Response } from 'node-fetch'; const groq = new Groq({ diff --git a/tests/form.test.ts b/tests/form.test.ts index 43c4aac..2f99b1d 100644 --- a/tests/form.test.ts +++ b/tests/form.test.ts @@ -1,6 +1,6 @@ -import { multipartFormRequestOptions, createForm } from 'groq/core'; -import { Blob } from 'groq/_shims/index'; -import { toFile } from 'groq'; +import { multipartFormRequestOptions, createForm } from 'groq-sdk/core'; +import { Blob } from 'groq-sdk/_shims/index'; +import { toFile } from 'groq-sdk'; describe('form data validation', () => { test('valid values do not error', async () => { diff --git a/tests/index.test.ts b/tests/index.test.ts index b55c679..b7b08a0 100644 --- a/tests/index.test.ts +++ b/tests/index.test.ts @@ -1,8 +1,8 @@ // File generated from our OpenAPI spec by Stainless. -import Groq from 'groq'; -import { APIUserAbortError } from 'groq'; -import { Headers } from 'groq/core'; +import Groq from 'groq-sdk'; +import { APIUserAbortError } from 'groq-sdk'; +import { Headers } from 'groq-sdk/core'; import defaultFetch, { Response, type RequestInit, type RequestInfo } from 'node-fetch'; describe('instantiate client', () => { diff --git a/tests/responses.test.ts b/tests/responses.test.ts index eccb0f2..524c12a 100644 --- a/tests/responses.test.ts +++ b/tests/responses.test.ts @@ -1,5 +1,5 @@ -import { createResponseHeaders } from 'groq/core'; -import { Headers } from 'groq/_shims/index'; +import { createResponseHeaders } from 'groq-sdk/core'; +import { Headers } from 'groq-sdk/_shims/index'; describe('response parsing', () => { // TODO: test unicode characters diff --git a/tests/stringifyQuery.test.ts b/tests/stringifyQuery.test.ts index c414569..7ad17bb 100644 --- a/tests/stringifyQuery.test.ts +++ b/tests/stringifyQuery.test.ts @@ -1,4 +1,4 @@ -import { APIClient } from 'groq/core'; +import { APIClient } from 'groq-sdk/core'; const { stringifyQuery } = APIClient.prototype as any; diff --git a/tests/uploads.test.ts b/tests/uploads.test.ts index 532bb1e..a6cbab1 100644 --- a/tests/uploads.test.ts +++ b/tests/uploads.test.ts @@ -1,6 +1,6 @@ import fs from 'fs'; -import { toFile, type ResponseLike } from 'groq/uploads'; -import { File } from 'groq/_shims/index'; +import { toFile, type ResponseLike } from 'groq-sdk/uploads'; +import { File } from 'groq-sdk/_shims/index'; class MyClass { name: string = 'foo'; diff --git a/tsconfig.build.json b/tsconfig.build.json index f2f31b7..4740de1 100644 --- a/tsconfig.build.json +++ b/tsconfig.build.json @@ -5,8 +5,8 @@ "compilerOptions": { "rootDir": "./dist/src", "paths": { - "groq/*": ["dist/src/*"], - "groq": ["dist/src/index.ts"], + "groq-sdk/*": ["dist/src/*"], + "groq-sdk": ["dist/src/index.ts"], "digest-fetch": ["./typings/digest-fetch"] }, "noEmit": false, diff --git a/tsconfig.deno.json b/tsconfig.deno.json index b7a976c..c972bda 100644 --- a/tsconfig.deno.json +++ b/tsconfig.deno.json @@ -6,9 +6,9 @@ "rootDir": "./deno", "lib": ["es2020", "DOM"], "paths": { - "groq/_shims/auto/*": ["deno/_shims/auto/*-deno"], - "groq/*": ["deno/*"], - "groq": ["deno/index.ts"], + "groq-sdk/_shims/auto/*": ["deno/_shims/auto/*-deno"], + "groq-sdk/*": ["deno/*"], + "groq-sdk": ["deno/index.ts"], "digest-fetch": ["./typings/digest-fetch"] }, "noEmit": true, diff --git a/tsconfig.json b/tsconfig.json index 7f1bead..73e2290 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -9,9 +9,9 @@ "esModuleInterop": true, "baseUrl": "./", "paths": { - "groq/_shims/auto/*": ["src/_shims/auto/*-node"], - "groq/*": ["src/*"], - "groq": ["src/index.ts"], + "groq-sdk/_shims/auto/*": ["src/_shims/auto/*-node"], + "groq-sdk/*": ["src/*"], + "groq-sdk": ["src/index.ts"], "digest-fetch": ["./typings/digest-fetch"] }, "noEmit": true,