Skip to content

Commit

Permalink
feat(api): OpenAPI spec update via Stainless API (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] authored and stainless-bot committed Aug 16, 2024
1 parent 90c2d43 commit c194ccd
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 28 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-5c5705160eccbf459f19906b209ddb30577ece64a2a39edfeab02a0f6f371534.yml
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/groqcloud%2Fgroqcloud-a10a2e26af1859694bf25612d54e7909296f7aaf82822c6a1681632bf28ec669.yml
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const client = new Groq({
});

async function main() {
const chatCompletion = await groq.chat.completions.create({
const chatCompletion = await client.chat.completions.create({
messages: [{ role: 'user', content: 'Explain the importance of low latency LLMs' }],
model: 'llama3-8b-8192',
});
Expand Down Expand Up @@ -58,7 +58,7 @@ async function main() {
],
model: 'llama3-8b-8192',
};
const chatCompletion: Groq.Chat.ChatCompletion = await groq.chat.completions.create(params);
const chatCompletion: Groq.Chat.ChatCompletion = await client.chat.completions.create(params);
}

main();
Expand All @@ -75,7 +75,7 @@ a subclass of `APIError` will be thrown:
<!-- prettier-ignore -->
```ts
async function main() {
const chatCompletion = await groq.chat.completions
const chatCompletion = await client.chat.completions
.create({
messages: [
{ role: 'system', content: 'You are a helpful assistant.' },
Expand Down Expand Up @@ -126,7 +126,7 @@ const client = new Groq({
});

// Or, configure per-request:
await groq.chat.completions.create({ messages: [{ role: 'system', content: 'You are a helpful assistant.' }, { role: 'user', content: 'Explain the importance of low latency LLMs' }], model: 'llama3-8b-8192' }, {
await client.chat.completions.create({ messages: [{ role: 'system', content: 'You are a helpful assistant.' }, { role: 'user', content: 'Explain the importance of low latency LLMs' }], model: 'llama3-8b-8192' }, {
maxRetries: 5,
});
```
Expand All @@ -143,7 +143,7 @@ const client = new Groq({
});

// Override per-request:
await groq.chat.completions.create({ messages: [{ role: 'system', content: 'You are a helpful assistant.' }, { role: 'user', content: 'Explain the importance of low latency LLMs' }], model: 'llama3-8b-8192' }, {
await client.chat.completions.create({ messages: [{ role: 'system', content: 'You are a helpful assistant.' }, { role: 'user', content: 'Explain the importance of low latency LLMs' }], model: 'llama3-8b-8192' }, {
timeout: 5 * 1000,
});
```
Expand All @@ -164,7 +164,7 @@ You can also use the `.withResponse()` method to get the raw `Response` along wi
```ts
const client = new Groq();

const response = await groq.chat.completions
const response = await client.chat.completions
.create({
messages: [
{ role: 'system', content: 'You are a helpful assistant.' },
Expand All @@ -176,7 +176,7 @@ const response = await groq.chat.completions
console.log(response.headers.get('X-My-Header'));
console.log(response.statusText); // access the underlying Response object

const { data: chatCompletion, response: raw } = await groq.chat.completions
const { data: chatCompletion, response: raw } = await client.chat.completions
.create({
messages: [
{ role: 'system', content: 'You are a helpful assistant.' },
Expand Down Expand Up @@ -290,7 +290,7 @@ const client = new Groq({
});

// Override per-request:
await groq.chat.completions.create(
await client.chat.completions.create(
{
messages: [
{ role: 'system', content: 'You are a helpful assistant.' },
Expand Down
6 changes: 3 additions & 3 deletions tests/api-resources/audio/transcriptions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
import Groq, { toFile } from 'groq-sdk';
import { Response } from 'node-fetch';

const groq = new Groq({
const client = new Groq({
apiKey: 'My API Key',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
});

describe('resource transcriptions', () => {
test('create: only required params', async () => {
const responsePromise = groq.audio.transcriptions.create({
const responsePromise = client.audio.transcriptions.create({
file: await toFile(Buffer.from('# my file contents'), 'README.md'),
model: 'whisper-large-v3',
});
Expand All @@ -24,7 +24,7 @@ describe('resource transcriptions', () => {
});

test('create: required and optional params', async () => {
const response = await groq.audio.transcriptions.create({
const response = await client.audio.transcriptions.create({
file: await toFile(Buffer.from('# my file contents'), 'README.md'),
model: 'whisper-large-v3',
language: 'string',
Expand Down
6 changes: 3 additions & 3 deletions tests/api-resources/audio/translations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
import Groq, { toFile } from 'groq-sdk';
import { Response } from 'node-fetch';

const groq = new Groq({
const client = new Groq({
apiKey: 'My API Key',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
});

describe('resource translations', () => {
test('create: only required params', async () => {
const responsePromise = groq.audio.translations.create({
const responsePromise = client.audio.translations.create({
file: await toFile(Buffer.from('# my file contents'), 'README.md'),
model: 'whisper-1',
});
Expand All @@ -24,7 +24,7 @@ describe('resource translations', () => {
});

test('create: required and optional params', async () => {
const response = await groq.audio.translations.create({
const response = await client.audio.translations.create({
file: await toFile(Buffer.from('# my file contents'), 'README.md'),
model: 'whisper-1',
prompt: 'prompt',
Expand Down
6 changes: 3 additions & 3 deletions tests/api-resources/chat/completions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
import Groq from 'groq-sdk';
import { Response } from 'node-fetch';

const groq = new Groq({
const client = new Groq({
apiKey: 'My API Key',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
});

describe('resource completions', () => {
test('create: only required params', async () => {
const responsePromise = groq.chat.completions.create({
const responsePromise = client.chat.completions.create({
messages: [{ content: 'content', role: 'system' }],
model: 'string',
});
Expand All @@ -24,7 +24,7 @@ describe('resource completions', () => {
});

test('create: required and optional params', async () => {
const response = await groq.chat.completions.create({
const response = await client.chat.completions.create({
messages: [{ content: 'content', role: 'system', name: 'name', tool_call_id: 'tool_call_id' }],
model: 'string',
frequency_penalty: -2,
Expand Down
6 changes: 3 additions & 3 deletions tests/api-resources/embeddings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
import Groq from 'groq-sdk';
import { Response } from 'node-fetch';

const groq = new Groq({
const client = new Groq({
apiKey: 'My API Key',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
});

describe('resource embeddings', () => {
test('create: only required params', async () => {
const responsePromise = groq.embeddings.create({
const responsePromise = client.embeddings.create({
input: 'The quick brown fox jumped over the lazy dog',
model: 'nomic-embed-text-v1_5',
});
Expand All @@ -24,7 +24,7 @@ describe('resource embeddings', () => {
});

test('create: required and optional params', async () => {
const response = await groq.embeddings.create({
const response = await client.embeddings.create({
input: 'The quick brown fox jumped over the lazy dog',
model: 'nomic-embed-text-v1_5',
encoding_format: 'float',
Expand Down
16 changes: 9 additions & 7 deletions tests/api-resources/models.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
import Groq from 'groq-sdk';
import { Response } from 'node-fetch';

const groq = new Groq({
const client = new Groq({
apiKey: 'My API Key',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
});

describe('resource models', () => {
test('retrieve', async () => {
const responsePromise = groq.models.retrieve('model');
const responsePromise = client.models.retrieve('model');
const rawResponse = await responsePromise.asResponse();
expect(rawResponse).toBeInstanceOf(Response);
const response = await responsePromise;
Expand All @@ -22,13 +22,13 @@ describe('resource models', () => {

test('retrieve: request options instead of params are passed correctly', async () => {
// ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
await expect(groq.models.retrieve('model', { path: '/_stainless_unknown_path' })).rejects.toThrow(
await expect(client.models.retrieve('model', { path: '/_stainless_unknown_path' })).rejects.toThrow(
Groq.NotFoundError,
);
});

test('list', async () => {
const responsePromise = groq.models.list();
const responsePromise = client.models.list();
const rawResponse = await responsePromise.asResponse();
expect(rawResponse).toBeInstanceOf(Response);
const response = await responsePromise;
Expand All @@ -40,11 +40,13 @@ describe('resource models', () => {

test('list: request options instead of params are passed correctly', async () => {
// ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
await expect(groq.models.list({ path: '/_stainless_unknown_path' })).rejects.toThrow(Groq.NotFoundError);
await expect(client.models.list({ path: '/_stainless_unknown_path' })).rejects.toThrow(
Groq.NotFoundError,
);
});

test('delete', async () => {
const responsePromise = groq.models.delete('model');
const responsePromise = client.models.delete('model');
const rawResponse = await responsePromise.asResponse();
expect(rawResponse).toBeInstanceOf(Response);
const response = await responsePromise;
Expand All @@ -56,7 +58,7 @@ describe('resource models', () => {

test('delete: request options instead of params are passed correctly', async () => {
// ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
await expect(groq.models.delete('model', { path: '/_stainless_unknown_path' })).rejects.toThrow(
await expect(client.models.delete('model', { path: '/_stainless_unknown_path' })).rejects.toThrow(
Groq.NotFoundError,
);
});
Expand Down

0 comments on commit c194ccd

Please sign in to comment.