Skip to content

Commit

Permalink
fix(demos): update client demo
Browse files Browse the repository at this point in the history
  • Loading branch information
waylaidwanderer committed Mar 5, 2023
1 parent 590b24b commit 518c4d8
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions demos/use-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ const clientOptions = {
// reverseProxyUrl: 'https://chatgpt.hato.ai/completions',
// (Optional) Parameters as described in https://platform.openai.com/docs/api-reference/completions
modelOptions: {
// You can override the model name and any other parameters here.
// model: 'text-chat-davinci-002-20221122',
// You can override the model name and any other parameters here, like so:
model: 'gpt-3.5-turbo',
// I'm overriding the temperature to 0 here for demonstration purposes, but you shouldn't need to override this
// for normal usage.
temperature: 0,
// Set max_tokens here to override the default max_tokens of 1000 for the completion.
// max_tokens: 1000,
},
Expand Down Expand Up @@ -36,18 +39,30 @@ const cacheOptions = {

const chatGptClient = new ChatGPTClient('OPENAI_API_KEY', clientOptions, cacheOptions);

const response = await chatGptClient.sendMessage('Hello!');
console.log(response); // { response: 'Hi! How can I help you today?', conversationId: '...', messageId: '...' }
let response;
response = await chatGptClient.sendMessage('Hello!');
console.log(response); // { response: 'Hello! How can I assist you today?', conversationId: '...', messageId: '...' }

const response2 = await chatGptClient.sendMessage('Write a poem about cats.', { conversationId: response.conversationId, parentMessageId: response.messageId });
console.log(response2.response); // Cats are the best pets in the world.
response = await chatGptClient.sendMessage('Write a short poem about cats.', { conversationId: response.conversationId, parentMessageId: response.messageId });
console.log(response.response); // Soft and sleek, with eyes that gleam,\nCats are creatures of grace supreme.\n...
console.log();

response = await chatGptClient.sendMessage('Now write it in French.', {
conversationId: response.conversationId,
parentMessageId: response.messageId,
// If you want streamed responses, you can set the `onProgress` callback to receive the response as it's generated.
// You will receive one token at a time, so you will need to concatenate them yourself.
onProgress: (token) => process.stdout.write(token),
});
console.log();
console.log(response.response); // Doux et élégant, avec des yeux qui brillent,\nLes chats sont des créatures de grâce suprême.\n...

const response3 = await chatGptClient.sendMessage('Now write it in French.', {
conversationId: response2.conversationId,
parentMessageId: response2.messageId,
response = await chatGptClient.sendMessage('Repeat my 2nd message verbatim.', {
conversationId: response.conversationId,
parentMessageId: response.messageId,
// If you want streamed responses, you can set the `onProgress` callback to receive the response as it's generated.
// You will receive one token at a time, so you will need to concatenate them yourself.
onProgress: (token) => process.stdout.write(token),
});
console.log();
console.log(response3.response); // Les chats sont les meilleurs animaux de compagnie du monde.
console.log(response.response); // "Write a short poem about cats."

0 comments on commit 518c4d8

Please sign in to comment.