Skip to content

Commit 518c4d8

Browse files
fix(demos): update client demo
1 parent 590b24b commit 518c4d8

1 file changed

Lines changed: 25 additions & 10 deletions

File tree

demos/use-client.js

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ const clientOptions = {
77
// reverseProxyUrl: 'https://chatgpt.hato.ai/completions',
88
// (Optional) Parameters as described in https://platform.openai.com/docs/api-reference/completions
99
modelOptions: {
10-
// You can override the model name and any other parameters here.
11-
// model: 'text-chat-davinci-002-20221122',
10+
// You can override the model name and any other parameters here, like so:
11+
model: 'gpt-3.5-turbo',
12+
// I'm overriding the temperature to 0 here for demonstration purposes, but you shouldn't need to override this
13+
// for normal usage.
14+
temperature: 0,
1215
// Set max_tokens here to override the default max_tokens of 1000 for the completion.
1316
// max_tokens: 1000,
1417
},
@@ -36,18 +39,30 @@ const cacheOptions = {
3639

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

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

42-
const response2 = await chatGptClient.sendMessage('Write a poem about cats.', { conversationId: response.conversationId, parentMessageId: response.messageId });
43-
console.log(response2.response); // Cats are the best pets in the world.
46+
response = await chatGptClient.sendMessage('Write a short poem about cats.', { conversationId: response.conversationId, parentMessageId: response.messageId });
47+
console.log(response.response); // Soft and sleek, with eyes that gleam,\nCats are creatures of grace supreme.\n...
48+
console.log();
49+
50+
response = await chatGptClient.sendMessage('Now write it in French.', {
51+
conversationId: response.conversationId,
52+
parentMessageId: response.messageId,
53+
// If you want streamed responses, you can set the `onProgress` callback to receive the response as it's generated.
54+
// You will receive one token at a time, so you will need to concatenate them yourself.
55+
onProgress: (token) => process.stdout.write(token),
56+
});
57+
console.log();
58+
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...
4459

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

0 commit comments

Comments
 (0)