Skip to content

Commit

Permalink
feat(api): OpenAPI spec update via Stainless API (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] authored and stainless-bot committed Sep 23, 2024
1 parent f908edb commit cd15af0
Show file tree
Hide file tree
Showing 13 changed files with 262 additions and 139 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: 50
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/julep-ai-inc-dash%2Fjulep-6a1e46c04a25dba0557ccbab92a9b9ccfbdb804849b91a8a780949c771321b12.yml
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/julep-ai-inc-dash%2Fjulep-f81af3213db01ef83d8f104374a7f47b8d46c3817e26d587a555ae05f2cae02c.yml
2 changes: 1 addition & 1 deletion api.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Methods:
- <code title="get /sessions">client.sessions.<a href="./src/resources/sessions.ts">list</a>({ ...params }) -> SessionsOffsetPagination</code>
- <code title="delete /sessions/{session_id}">client.sessions.<a href="./src/resources/sessions.ts">delete</a>(sessionId) -> ResourceDeleted</code>
- <code title="post /sessions/{session_id}/chat">client.sessions.<a href="./src/resources/sessions.ts">chat</a>(sessionId, { ...params }) -> SessionChatResponse</code>
- <code title="post /sessions/{session_id}">client.sessions.<a href="./src/resources/sessions.ts">createOrUpdate</a>(sessionId, { ...params }) -> ResourceCreated</code>
- <code title="post /sessions/{session_id}">client.sessions.<a href="./src/resources/sessions.ts">createOrUpdate</a>(sessionId, { ...params }) -> ResourceUpdated</code>
- <code title="get /sessions/{session_id}">client.sessions.<a href="./src/resources/sessions.ts">get</a>(sessionId) -> Session</code>
- <code title="get /sessions/{session_id}/history">client.sessions.<a href="./src/resources/sessions.ts">history</a>(sessionId) -> History</code>
- <code title="patch /sessions/{session_id}">client.sessions.<a href="./src/resources/sessions.ts">patch</a>(sessionId, { ...params }) -> ResourceUpdated</code>
Expand Down
79 changes: 76 additions & 3 deletions src/resources/sessions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,18 @@ export class Sessions extends APIResource {
*/
chat(
sessionId: string,
body: SessionChatParams,
params: SessionChatParams,
options?: Core.RequestOptions,
): Core.APIPromise<SessionChatResponse> {
return this._client.post(`/sessions/${sessionId}/chat`, { body, ...options });
const { 'X-Custom-Api-Key': xCustomAPIKey, ...body } = params;
return this._client.post(`/sessions/${sessionId}/chat`, {
body,
...options,
headers: {
...(xCustomAPIKey != null ? { 'X-Custom-Api-Key': xCustomAPIKey } : undefined),
...options?.headers,
},
});
}

/**
Expand All @@ -70,7 +78,7 @@ export class Sessions extends APIResource {
sessionId: string,
body: SessionCreateOrUpdateParams,
options?: Core.RequestOptions,
): Core.APIPromise<Shared.ResourceCreated> {
): Core.APIPromise<Shared.ResourceUpdated> {
return this._client.post(`/sessions/${sessionId}`, { body, ...options });
}

Expand Down Expand Up @@ -1005,48 +1013,113 @@ export interface SessionListParams extends OffsetPaginationParams {
}

export interface SessionChatParams {
/**
* Body param:
*/
messages: Array<Message>;

/**
* Body param:
*/
agent?: string | null;

/**
* Body param:
*/
frequency_penalty?: number | null;

/**
* Body param:
*/
length_penalty?: number | null;

/**
* Body param:
*/
logit_bias?: Record<string, number> | null;

/**
* Body param:
*/
max_tokens?: number | null;

/**
* Body param:
*/
min_p?: number | null;

/**
* Body param:
*/
model?: string | null;

/**
* Body param:
*/
presence_penalty?: number | null;

/**
* Body param:
*/
recall?: boolean;

/**
* Body param:
*/
repetition_penalty?: number | null;

/**
* Body param:
*/
response_format?:
| SessionChatParams.SimpleCompletionResponseFormat
| SessionChatParams.SchemaCompletionResponseFormat
| null;

/**
* Body param:
*/
save?: boolean;

/**
* Body param:
*/
seed?: number | null;

/**
* Body param:
*/
stop?: Array<string>;

/**
* Body param:
*/
stream?: boolean;

/**
* Body param:
*/
temperature?: number | null;

/**
* Body param:
*/
tool_choice?: 'auto' | 'none' | SessionChatParams.NamedToolChoice | null;

/**
* Body param:
*/
tools?: Array<SessionChatParams.Tool>;

/**
* Body param:
*/
top_p?: number | null;

/**
* Header param:
*/
'X-Custom-Api-Key'?: string;
}

export namespace SessionChatParams {
Expand Down
20 changes: 10 additions & 10 deletions tests/api-resources/agents/agents.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('resource agents', () => {
});

test('update', async () => {
const responsePromise = client.agents.update('agent_id', {});
const responsePromise = client.agents.update('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', {});
const rawResponse = await responsePromise.asResponse();
expect(rawResponse).toBeInstanceOf(Response);
const response = await responsePromise;
Expand Down Expand Up @@ -60,7 +60,7 @@ describe('resource agents', () => {
});

test('delete', async () => {
const responsePromise = client.agents.delete('agent_id');
const responsePromise = client.agents.delete('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e');
const rawResponse = await responsePromise.asResponse();
expect(rawResponse).toBeInstanceOf(Response);
const response = await responsePromise;
Expand All @@ -72,9 +72,9 @@ describe('resource agents', () => {

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(client.agents.delete('agent_id', { path: '/_stainless_unknown_path' })).rejects.toThrow(
Julep.NotFoundError,
);
await expect(
client.agents.delete('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', { path: '/_stainless_unknown_path' }),
).rejects.toThrow(Julep.NotFoundError);
});

test('createOrUpdate', async () => {
Expand All @@ -89,7 +89,7 @@ describe('resource agents', () => {
});

test('get', async () => {
const responsePromise = client.agents.get('agent_id');
const responsePromise = client.agents.get('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e');
const rawResponse = await responsePromise.asResponse();
expect(rawResponse).toBeInstanceOf(Response);
const response = await responsePromise;
Expand All @@ -101,13 +101,13 @@ describe('resource agents', () => {

test('get: 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(client.agents.get('agent_id', { path: '/_stainless_unknown_path' })).rejects.toThrow(
Julep.NotFoundError,
);
await expect(
client.agents.get('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', { path: '/_stainless_unknown_path' }),
).rejects.toThrow(Julep.NotFoundError);
});

test('patch', async () => {
const responsePromise = client.agents.patch('agent_id', {});
const responsePromise = client.agents.patch('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', {});
const rawResponse = await responsePromise.asResponse();
expect(rawResponse).toBeInstanceOf(Response);
const response = await responsePromise;
Expand Down
38 changes: 27 additions & 11 deletions tests/api-resources/agents/docs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ const client = new Julep({

describe('resource docs', () => {
test('create: only required params', async () => {
const responsePromise = client.agents.docs.create('agent_id', { content: 'string', title: 'title' });
const responsePromise = client.agents.docs.create('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', {
content: 'string',
title: 'title',
});
const rawResponse = await responsePromise.asResponse();
expect(rawResponse).toBeInstanceOf(Response);
const response = await responsePromise;
Expand All @@ -21,15 +24,15 @@ describe('resource docs', () => {
});

test('create: required and optional params', async () => {
const response = await client.agents.docs.create('agent_id', {
const response = await client.agents.docs.create('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', {
content: 'string',
title: 'title',
metadata: {},
});
});

test('list', async () => {
const responsePromise = client.agents.docs.list('agent_id');
const responsePromise = client.agents.docs.list('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e');
const rawResponse = await responsePromise.asResponse();
expect(rawResponse).toBeInstanceOf(Response);
const response = await responsePromise;
Expand All @@ -41,24 +44,27 @@ describe('resource docs', () => {

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(client.agents.docs.list('agent_id', { path: '/_stainless_unknown_path' })).rejects.toThrow(
Julep.NotFoundError,
);
await expect(
client.agents.docs.list('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', { path: '/_stainless_unknown_path' }),
).rejects.toThrow(Julep.NotFoundError);
});

test('list: request options and 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(
client.agents.docs.list(
'agent_id',
'182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',
{ direction: 'asc', limit: 0, metadata_filter: 'metadata_filter', offset: 0, sort_by: 'created_at' },
{ path: '/_stainless_unknown_path' },
),
).rejects.toThrow(Julep.NotFoundError);
});

test('delete', async () => {
const responsePromise = client.agents.docs.delete('agent_id', 'doc_id');
const responsePromise = client.agents.docs.delete(
'182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',
'182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',
);
const rawResponse = await responsePromise.asResponse();
expect(rawResponse).toBeInstanceOf(Response);
const response = await responsePromise;
Expand All @@ -71,12 +77,18 @@ describe('resource docs', () => {
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(
client.agents.docs.delete('agent_id', 'doc_id', { path: '/_stainless_unknown_path' }),
client.agents.docs.delete(
'182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',
'182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',
{ path: '/_stainless_unknown_path' },
),
).rejects.toThrow(Julep.NotFoundError);
});

test('search: only required params', async () => {
const responsePromise = client.agents.docs.search('agent_id', { text: 'text' });
const responsePromise = client.agents.docs.search('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', {
text: 'text',
});
const rawResponse = await responsePromise.asResponse();
expect(rawResponse).toBeInstanceOf(Response);
const response = await responsePromise;
Expand All @@ -87,6 +99,10 @@ describe('resource docs', () => {
});

test('search: required and optional params', async () => {
const response = await client.agents.docs.search('agent_id', { text: 'text', lang: 'en-US', limit: 1 });
const response = await client.agents.docs.search('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', {
text: 'text',
lang: 'en-US',
limit: 1,
});
});
});
8 changes: 4 additions & 4 deletions tests/api-resources/docs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('resource docs', () => {
});

test('get', async () => {
const responsePromise = client.docs.get('doc_id');
const responsePromise = client.docs.get('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e');
const rawResponse = await responsePromise.asResponse();
expect(rawResponse).toBeInstanceOf(Response);
const response = await responsePromise;
Expand All @@ -37,8 +37,8 @@ describe('resource docs', () => {

test('get: 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(client.docs.get('doc_id', { path: '/_stainless_unknown_path' })).rejects.toThrow(
Julep.NotFoundError,
);
await expect(
client.docs.get('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', { path: '/_stainless_unknown_path' }),
).rejects.toThrow(Julep.NotFoundError);
});
});
Loading

0 comments on commit cd15af0

Please sign in to comment.