Skip to content

Commit

Permalink
feat(api): OpenAPI spec update via Stainless API (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] authored and stainless-bot committed Apr 8, 2024
1 parent 50dff67 commit 4148b6e
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 79 deletions.
69 changes: 13 additions & 56 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,39 +20,15 @@ The full API of this library can be found in [api.md](api.md).
```js
import Retell from 'retell-sdk';

const retell = new Retell({
apiKey: 'RETELL_API_KEY',
});
const retell = new Retell();

async function main() {
const llmResponse = await retell.llm.create({
begin_message: "Hi, I'm your virtual weather assistant, how can I help you?",
general_prompt: 'You are a friendly agent that helps people retrieves weather information.',
general_tools: [
{
type: 'end_call',
name: 'end_call',
description: 'End the call with user only when user explicitly requests it.',
},
{
type: 'custom',
name: 'get_weather',
description: 'Get the current weather, called when user is asking whether of a specific city.',
parameters: {
type: 'object',
properties: {
city: { type: 'string', description: 'The city for which the weather is to be fetched.' },
},
required: ['city'],
},
speak_during_execution: true,
speak_after_execution: true,
url: 'http://your-server-url-here/get_weawther',
},
],
const agentResponse = await retell.agent.create({
llm_websocket_url: 'wss://your-websocket-endpoint',
voice_id: '11labs-Adrian',
});

console.log(llmResponse.llm_websocket_url);
console.log(agentResponse.agent_id);
}

main();
Expand All @@ -66,15 +42,12 @@ This library includes TypeScript definitions for all request params and response
```ts
import Retell from 'retell-sdk';

const retell = new Retell({
apiKey: 'RETELL_API_KEY',
});
const retell = new Retell();

async function main() {
const params: Retell.AgentCreateParams = {
llm_websocket_url: 'llm-websocket-url from retell.llm.create()',
llm_websocket_url: 'wss://your-websocket-endpoint',
voice_id: '11labs-Adrian',
agent_name: 'Ryan',
};
const agentResponse: Retell.AgentResponse = await retell.agent.create(params);
}
Expand All @@ -94,11 +67,7 @@ a subclass of `APIError` will be thrown:
```ts
async function main() {
const agentResponse = await retell.agent
.create({
llm_websocket_url: 'llm-websocket-url from retell.llm.create()',
voice_id: '11labs-Adrian',
agent_name: 'Ryan',
})
.create({ llm_websocket_url: 'wss://your-websocket-endpoint', voice_id: '11labs-Adrian' })
.catch(async (err) => {
if (err instanceof Retell.APIError) {
console.log(err.status); // 400
Expand Down Expand Up @@ -142,7 +111,7 @@ const retell = new Retell({
});

// Or, configure per-request:
await retell.agent.create({ llm_websocket_url: 'llm-websocket-url from retell.llm.create()', voice_id: '11labs-Adrian', agent_name: 'Ryan' }, {
await retell.agent.create({ llm_websocket_url: 'wss://your-websocket-endpoint', voice_id: '11labs-Adrian' }, {
maxRetries: 5,
});
```
Expand All @@ -159,7 +128,7 @@ const retell = new Retell({
});

// Override per-request:
await retell.agent.create({ llm_websocket_url: 'llm-websocket-url from retell.llm.create()', voice_id: '11labs-Adrian', agent_name: 'Ryan' }, {
await retell.agent.create({ llm_websocket_url: 'wss://your-websocket-endpoint', voice_id: '11labs-Adrian' }, {
timeout: 5 * 1000,
});
```
Expand All @@ -181,21 +150,13 @@ You can also use the `.withResponse()` method to get the raw `Response` along wi
const retell = new Retell();

const response = await retell.agent
.create({
llm_websocket_url: 'llm-websocket-url from retell.llm.create()',
voice_id: '11labs-Adrian',
agent_name: 'Ryan',
})
.create({ llm_websocket_url: 'wss://your-websocket-endpoint', voice_id: '11labs-Adrian' })
.asResponse();
console.log(response.headers.get('X-My-Header'));
console.log(response.statusText); // access the underlying Response object

const { data: agentResponse, response: raw } = await retell.agent
.create({
llm_websocket_url: 'llm-websocket-url from retell.llm.create()',
voice_id: '11labs-Adrian',
agent_name: 'Ryan',
})
.create({ llm_websocket_url: 'wss://your-websocket-endpoint', voice_id: '11labs-Adrian' })
.withResponse();
console.log(raw.headers.get('X-My-Header'));
console.log(agentResponse.agent_id);
Expand Down Expand Up @@ -303,11 +264,7 @@ const retell = new Retell({

// Override per-request:
await retell.agent.create(
{
llm_websocket_url: 'llm-websocket-url from retell.llm.create()',
voice_id: '11labs-Adrian',
agent_name: 'Ryan',
},
{ llm_websocket_url: 'wss://your-websocket-endpoint', voice_id: '11labs-Adrian' },
{
httpAgent: new http.Agent({ keepAlive: false }),
},
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export class Retell extends Core.APIClient {
constructor({ baseURL = Core.readEnv('RETELL_BASE_URL'), apiKey, ...opts }: ClientOptions) {
if (apiKey === undefined) {
throw new Errors.RetellError(
"Missing required client option apiKey; you need to instantiate the Retell client with an apiKey option, like new Retell({ apiKey: 'RETELL_API_KEY' }).",
"Missing required client option apiKey; you need to instantiate the Retell client with an apiKey option, like new Retell({ apiKey: 'YOUR_RETELL_API_KEY' }).",
);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/api-resources/agent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Retell from 'retell-sdk';
import { Response } from 'node-fetch';

const retell = new Retell({
apiKey: 'RETELL_API_KEY',
apiKey: 'YOUR_RETELL_API_KEY',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
});

Expand Down
2 changes: 1 addition & 1 deletion tests/api-resources/call.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Retell from 'retell-sdk';
import { Response } from 'node-fetch';

const retell = new Retell({
apiKey: 'RETELL_API_KEY',
apiKey: 'YOUR_RETELL_API_KEY',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
});

Expand Down
2 changes: 1 addition & 1 deletion tests/api-resources/llm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Retell from 'retell-sdk';
import { Response } from 'node-fetch';

const retell = new Retell({
apiKey: 'RETELL_API_KEY',
apiKey: 'YOUR_RETELL_API_KEY',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
});

Expand Down
2 changes: 1 addition & 1 deletion tests/api-resources/phone-number.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Retell from 'retell-sdk';
import { Response } from 'node-fetch';

const retell = new Retell({
apiKey: 'RETELL_API_KEY',
apiKey: 'YOUR_RETELL_API_KEY',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
});

Expand Down
42 changes: 24 additions & 18 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('instantiate client', () => {
const client = new Retell({
baseURL: 'http://localhost:5000/',
defaultHeaders: { 'X-My-Default-Header': '2' },
apiKey: 'RETELL_API_KEY',
apiKey: 'YOUR_RETELL_API_KEY',
});

test('they are used in the request', () => {
Expand Down Expand Up @@ -55,7 +55,7 @@ describe('instantiate client', () => {
const client = new Retell({
baseURL: 'http://localhost:5000/',
defaultQuery: { apiVersion: 'foo' },
apiKey: 'RETELL_API_KEY',
apiKey: 'YOUR_RETELL_API_KEY',
});
expect(client.buildURL('/foo', null)).toEqual('http://localhost:5000/foo?apiVersion=foo');
});
Expand All @@ -64,7 +64,7 @@ describe('instantiate client', () => {
const client = new Retell({
baseURL: 'http://localhost:5000/',
defaultQuery: { apiVersion: 'foo', hello: 'world' },
apiKey: 'RETELL_API_KEY',
apiKey: 'YOUR_RETELL_API_KEY',
});
expect(client.buildURL('/foo', null)).toEqual('http://localhost:5000/foo?apiVersion=foo&hello=world');
});
Expand All @@ -73,7 +73,7 @@ describe('instantiate client', () => {
const client = new Retell({
baseURL: 'http://localhost:5000/',
defaultQuery: { hello: 'world' },
apiKey: 'RETELL_API_KEY',
apiKey: 'YOUR_RETELL_API_KEY',
});
expect(client.buildURL('/foo', { hello: undefined })).toEqual('http://localhost:5000/foo');
});
Expand All @@ -82,7 +82,7 @@ describe('instantiate client', () => {
test('custom fetch', async () => {
const client = new Retell({
baseURL: 'http://localhost:5000/',
apiKey: 'RETELL_API_KEY',
apiKey: 'YOUR_RETELL_API_KEY',
fetch: (url) => {
return Promise.resolve(
new Response(JSON.stringify({ url, custom: true }), {
Expand All @@ -99,7 +99,7 @@ describe('instantiate client', () => {
test('custom signal', async () => {
const client = new Retell({
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
apiKey: 'RETELL_API_KEY',
apiKey: 'YOUR_RETELL_API_KEY',
fetch: (...args) => {
return new Promise((resolve, reject) =>
setTimeout(
Expand All @@ -124,12 +124,18 @@ describe('instantiate client', () => {

describe('baseUrl', () => {
test('trailing slash', () => {
const client = new Retell({ baseURL: 'http://localhost:5000/custom/path/', apiKey: 'RETELL_API_KEY' });
const client = new Retell({
baseURL: 'http://localhost:5000/custom/path/',
apiKey: 'YOUR_RETELL_API_KEY',
});
expect(client.buildURL('/foo', null)).toEqual('http://localhost:5000/custom/path/foo');
});

test('no trailing slash', () => {
const client = new Retell({ baseURL: 'http://localhost:5000/custom/path', apiKey: 'RETELL_API_KEY' });
const client = new Retell({
baseURL: 'http://localhost:5000/custom/path',
apiKey: 'YOUR_RETELL_API_KEY',
});
expect(client.buildURL('/foo', null)).toEqual('http://localhost:5000/custom/path/foo');
});

Expand All @@ -138,41 +144,41 @@ describe('instantiate client', () => {
});

test('explicit option', () => {
const client = new Retell({ baseURL: 'https://example.com', apiKey: 'RETELL_API_KEY' });
const client = new Retell({ baseURL: 'https://example.com', apiKey: 'YOUR_RETELL_API_KEY' });
expect(client.baseURL).toEqual('https://example.com');
});

test('env variable', () => {
process.env['RETELL_BASE_URL'] = 'https://example.com/from_env';
const client = new Retell({ apiKey: 'RETELL_API_KEY' });
const client = new Retell({ apiKey: 'YOUR_RETELL_API_KEY' });
expect(client.baseURL).toEqual('https://example.com/from_env');
});

test('empty env variable', () => {
process.env['RETELL_BASE_URL'] = ''; // empty
const client = new Retell({ apiKey: 'RETELL_API_KEY' });
const client = new Retell({ apiKey: 'YOUR_RETELL_API_KEY' });
expect(client.baseURL).toEqual('https://api.retellai.com');
});

test('blank env variable', () => {
process.env['RETELL_BASE_URL'] = ' '; // blank
const client = new Retell({ apiKey: 'RETELL_API_KEY' });
const client = new Retell({ apiKey: 'YOUR_RETELL_API_KEY' });
expect(client.baseURL).toEqual('https://api.retellai.com');
});
});

test('maxRetries option is correctly set', () => {
const client = new Retell({ maxRetries: 4, apiKey: 'RETELL_API_KEY' });
const client = new Retell({ maxRetries: 4, apiKey: 'YOUR_RETELL_API_KEY' });
expect(client.maxRetries).toEqual(4);

// default
const client2 = new Retell({ apiKey: 'RETELL_API_KEY' });
const client2 = new Retell({ apiKey: 'YOUR_RETELL_API_KEY' });
expect(client2.maxRetries).toEqual(2);
});
});

describe('request building', () => {
const client = new Retell({ apiKey: 'RETELL_API_KEY' });
const client = new Retell({ apiKey: 'YOUR_RETELL_API_KEY' });

describe('Content-Length', () => {
test('handles multi-byte characters', () => {
Expand Down Expand Up @@ -214,7 +220,7 @@ describe('retries', () => {
return new Response(JSON.stringify({ a: 1 }), { headers: { 'Content-Type': 'application/json' } });
};

const client = new Retell({ apiKey: 'RETELL_API_KEY', timeout: 10, fetch: testFetch });
const client = new Retell({ apiKey: 'YOUR_RETELL_API_KEY', timeout: 10, fetch: testFetch });

expect(await client.request({ path: '/foo', method: 'get' })).toEqual({ a: 1 });
expect(count).toEqual(2);
Expand All @@ -241,7 +247,7 @@ describe('retries', () => {
return new Response(JSON.stringify({ a: 1 }), { headers: { 'Content-Type': 'application/json' } });
};

const client = new Retell({ apiKey: 'RETELL_API_KEY', fetch: testFetch });
const client = new Retell({ apiKey: 'YOUR_RETELL_API_KEY', fetch: testFetch });

expect(await client.request({ path: '/foo', method: 'get' })).toEqual({ a: 1 });
expect(count).toEqual(2);
Expand All @@ -268,7 +274,7 @@ describe('retries', () => {
return new Response(JSON.stringify({ a: 1 }), { headers: { 'Content-Type': 'application/json' } });
};

const client = new Retell({ apiKey: 'RETELL_API_KEY', fetch: testFetch });
const client = new Retell({ apiKey: 'YOUR_RETELL_API_KEY', fetch: testFetch });

expect(await client.request({ path: '/foo', method: 'get' })).toEqual({ a: 1 });
expect(count).toEqual(2);
Expand Down

0 comments on commit 4148b6e

Please sign in to comment.