Skip to content

Commit 183d25c

Browse files
committed
fix: Lint and Formatting
1 parent 42d3f8b commit 183d25c

File tree

4 files changed

+62
-60
lines changed

4 files changed

+62
-60
lines changed

examples/studio/chat/chat-documents.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,21 @@ const document0: DocumentSchema = {
88
making up 35% of total sales. We've expanded into the Asian market, notably Japan, and increased our global presence.
99
Committed to sustainability, we reduced our carbon footprint by 20%. Looking ahead, we plan to integrate more advanced
1010
machine learning features and expand into South America.`,
11-
metadata: { topic: "revenue" },
12-
}
11+
metadata: { topic: 'revenue' },
12+
};
1313

1414
const document1: DocumentSchema = {
15-
id: uuidv4(),
16-
content: `Shnokel Corp. Annual Report - 2024. Shnokel Corp., a pioneer in renewable energy solutions, "
15+
id: uuidv4(),
16+
content: `Shnokel Corp. Annual Report - 2024. Shnokel Corp., a pioneer in renewable energy solutions, "
1717
"reported a 20% increase in revenue this year, reaching $200 million. The successful deployment of "
1818
"our advanced solar panels, SolarFlex, accounted for 40% of our sales. We entered new markets in Europe "
1919
"and have plans to develop wind energy projects next year. Our commitment to reducing environmental "
2020
"impact saw a 25% decrease in operational emissions. Upcoming initiatives include a significant "
2121
"investment in R&D for sustainable technologies.`,
22-
metadata: { topic: "revenue" },
23-
}
24-
25-
const documents = [document0, document1]
22+
metadata: { topic: 'revenue' },
23+
};
2624

25+
const documents = [document0, document1];
2726

2827
async function main() {
2928
const client = new AI21({ apiKey: process.env.AI21_API_KEY });
@@ -32,10 +31,12 @@ async function main() {
3231
const response = await client.chat.completions.create({
3332
model: 'jamba-1.5-mini',
3433
messages: [
35-
{ role: 'system',
36-
content: "You are a helpful assistant that receives revenue documents and answers related questions"
34+
{
35+
role: 'system',
36+
content:
37+
'You are a helpful assistant that receives revenue documents and answers related questions',
3738
},
38-
{ role: 'user', content: '"Hi, which company earned more during 2024 - Schnoodel or Shnokel?"' }
39+
{ role: 'user', content: '"Hi, which company earned more during 2024 - Schnoodel or Shnokel?"' },
3940
],
4041
documents: documents,
4142
});
Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,36 @@
11
import { AI21, ResponseFormat } from 'ai21';
22

33
async function main() {
4-
const client = new AI21({ apiKey: process.env.AI21_API_KEY });
5-
const responseFormat: ResponseFormat = { type: 'json_object' };
6-
const messages = [
7-
{
8-
role: 'user' as const,
9-
content: `Please create a JSON object for ordering zoo tickets for September 22, 2024,
4+
const client = new AI21({ apiKey: process.env.AI21_API_KEY });
5+
const responseFormat: ResponseFormat = { type: 'json_object' };
6+
const messages = [
7+
{
8+
role: 'user' as const,
9+
content: `Please create a JSON object for ordering zoo tickets for September 22, 2024,
1010
for myself and two kids, based on the following JSON schema: ${JSON.stringify({
11-
date: "string",
12-
tickets: [{
13-
ticket_type: ["adult", "child"],
14-
quantity: "number"
15-
}]
11+
date: 'string',
12+
tickets: [
13+
{
14+
ticket_type: ['adult', 'child'],
15+
quantity: 'number',
16+
},
17+
],
1618
})}`,
17-
},
18-
];
19+
},
20+
];
1921

20-
try {
21-
const response = await client.chat.completions.create({
22-
messages,
23-
model: 'jamba-1.5-large',
24-
responseFormat,
25-
});
22+
try {
23+
const response = await client.chat.completions.create({
24+
messages,
25+
model: 'jamba-1.5-large',
26+
responseFormat,
27+
});
2628

27-
const content = response.choices[0].message.content;
28-
console.log('Response:', content);
29-
} catch (error) {
30-
console.error('Error:', error);
31-
}
29+
const content = response.choices[0].message.content;
30+
console.log('Response:', content);
31+
} catch (error) {
32+
console.error('Error:', error);
33+
}
3234
}
3335

34-
main().catch(console.error);
36+
main().catch(console.error);

examples/studio/chat/tools-chat-completions.ts

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { AI21, ChatMessage, ToolDefinition } from 'ai21';
33
// Mock database function
44
const getOrderDeliveryDate = (orderId: string): string => {
55
console.log(`Retrieving the delivery date for order ID: ${orderId} from the database...`);
6-
return "2025-05-04";
6+
return '2025-05-04';
77
};
88

99
async function main() {
@@ -19,23 +19,25 @@ async function main() {
1919
{ role: 'user', content: 'i think it is order_12345' },
2020
];
2121

22-
const tools: ToolDefinition[] = [{
23-
type: 'function',
24-
function: {
25-
name: 'get_order_delivery_date',
26-
description: 'Retrieve the delivery date associated with the specified order ID',
27-
parameters: {
28-
type: 'object',
29-
properties: {
30-
order_id: {
31-
type: 'string',
32-
description: 'The customer\'s order ID.',
22+
const tools: ToolDefinition[] = [
23+
{
24+
type: 'function',
25+
function: {
26+
name: 'get_order_delivery_date',
27+
description: 'Retrieve the delivery date associated with the specified order ID',
28+
parameters: {
29+
type: 'object',
30+
properties: {
31+
order_id: {
32+
type: 'string',
33+
description: "The customer's order ID.",
34+
},
3335
},
36+
required: ['order_id'],
3437
},
35-
required: ['order_id'],
3638
},
3739
},
38-
}];
40+
];
3941

4042
try {
4143
// First response with streaming
@@ -45,10 +47,10 @@ async function main() {
4547
tools,
4648
});
4749

48-
const assistantMessage = response.choices[0].message
49-
console.log(assistantMessage)
50+
const assistantMessage = response.choices[0].message;
51+
console.log(assistantMessage);
5052

51-
messages.push(assistantMessage)
53+
messages.push(assistantMessage);
5254

5355
// Handle tool calls
5456
if (assistantMessage.tool_calls?.length) {
@@ -57,7 +59,7 @@ async function main() {
5759
const args = JSON.parse(toolCall.function.arguments);
5860
if (args.order_id) {
5961
const deliveryDate = getOrderDeliveryDate(args.order_id);
60-
62+
6163
// Add tool response to messages
6264
messages.push({
6365
role: 'tool',
@@ -76,10 +78,9 @@ async function main() {
7678
}
7779
}
7880
}
79-
8081
} catch (error) {
8182
console.error('Error:', error);
8283
}
8384
}
8485

85-
main().catch(console.error);
86+
main().catch(console.error);

package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,9 @@
1717
"test": "jest --coverage --no-cache --runInBand --config jest.config.ts",
1818
"unused-deps": "npx depcheck --json | jq '.dependencies == []'",
1919
"clean-build": "rm -rf ./dist",
20-
"lint": "npx eslint 'src/**/*.{ts,tsx}' --no-ignore",
21-
"format": "prettier --write \"(src|test)/**\" --no-error-on-unmatched-pattern",
20+
"lint": "npx eslint '{src,examples}/**/*.{ts,tsx}' --no-ignore",
21+
"format": "prettier --write \"(src|test|examples)/**\" --no-error-on-unmatched-pattern",
2222
"prepare": "npm run build",
23-
"chatExample": "npx tsx src/examples/chatExample.ts",
24-
"convRagExample": "npx tsx src/examples/convRagExample.ts",
2523
"circular": "madge --circular --extensions ts src",
2624
"quality": "npm run circular && npm run lint && tsc --noEmit && npm run format && npm run unused-deps",
2725
"quality:fix": "npm run circular && npm run lint -- --fix && tsc --noEmit && npm run format",

0 commit comments

Comments
 (0)