Skip to content

Commit d1c10af

Browse files
Merge pull request #6 from gleanwork/removeAskFromErrorHandlingExampleInREADME
fix: remove sdk.chat.ask() from Error Handling and examples
2 parents 78013ab + b547ad0 commit d1c10af

File tree

8 files changed

+60
-1342
lines changed

8 files changed

+60
-1342
lines changed

.speakeasy/workflow.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ speakeasyVersion: 1.540.1
22
sources:
33
Glean API:
44
sourceNamespace: glean-api-specs
5-
sourceRevisionDigest: sha256:33b8b6d8447549ad225d8eb93b6629385a696b9836c5c86f40e75f2dc9ae92e0
5+
sourceRevisionDigest: sha256:bb693058375d00f6308376d62438b7a64826195f9aa3d8063780acde0a58cbea
66
sourceBlobDigest: sha256:02dae61341a702b82c050ed3828f22d5a82de8e9f2fa6a99ddab6ad0dfe4a38a
77
tags:
88
- latest
@@ -17,7 +17,7 @@ targets:
1717
glean:
1818
source: Glean API
1919
sourceNamespace: glean-api-specs
20-
sourceRevisionDigest: sha256:33b8b6d8447549ad225d8eb93b6629385a696b9836c5c86f40e75f2dc9ae92e0
20+
sourceRevisionDigest: sha256:bb693058375d00f6308376d62438b7a64826195f9aa3d8063780acde0a58cbea
2121
sourceBlobDigest: sha256:02dae61341a702b82c050ed3828f22d5a82de8e9f2fa6a99ddab6ad0dfe4a38a
2222
workflow:
2323
workflowVersion: 1.0.0

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -732,15 +732,17 @@ The following errors may be thrown by the SDK:
732732
### Example
733733

734734
```typescript
735-
import { Glean } from "glean";
735+
import { Glean } from "@gleanwork/api-client";
736736
import { GleanDataError, GleanError } from "glean/models/errors";
737737

738738
const glean = new Glean({
739739
bearerAuth: process.env["GLEAN_BEARER_AUTH"] ?? "",
740740
});
741741

742742
try {
743-
const data = await glean.chat.ask({});
743+
const data = await glean.client.search.execute({
744+
query: "What are the company holidays this year?",
745+
});
744746
console.log(data);
745747
} catch (error) {
746748
if (error instanceof GleanError) {
@@ -755,8 +757,9 @@ try {
755757
console.error(error.errorMessages);
756758
console.error(error.invalidOperators);
757759
}
758-
}
759760

761+
throw error;
762+
}
760763
```
761764

762765
### Advanced Error Handling

examples/package-lock.json

Lines changed: 8 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"license": "ISC",
1414
"dependencies": {
1515
"dotenv": "^16.4.7",
16-
"glean": "file:../"
16+
"@gleanwork/api-client": "file:../"
1717
},
1818
"devDependencies": {
1919
"@types/node": "^20.11.4",

examples/src/delete_chats_example.js

Lines changed: 0 additions & 21 deletions
This file was deleted.
Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import { config } from "dotenv";
22
config();
3-
import { Glean } from "glean";
4-
import { GleanError, GleanDataError } from "glean/models/errors";
3+
import { Glean } from "@gleanwork/api-client";
4+
import {
5+
GleanDataError,
6+
GleanError,
7+
} from "@gleanwork/api-client/models/errors";
58

69
if (!process.env["SERVER_URL"]) {
710
throw new Error("SERVER_URL is not set");
@@ -15,12 +18,8 @@ const glean = new Glean({
1518
});
1619

1720
try {
18-
const data = await glean.chat.ask({
19-
askRequest: {
20-
searchRequest: {
21-
query: "What is the capital of France?",
22-
},
23-
},
21+
const data = await glean.client.search.execute({
22+
query: "What are the company holidays this year?",
2423
});
2524
console.log(data);
2625
} catch (error) {
@@ -31,10 +30,10 @@ try {
3130
console.error(error.body);
3231
}
3332

34-
// GleanDataError contains structured data
3533
if (error instanceof GleanDataError) {
3634
console.error(error.errorMessages);
3735
console.error(error.invalidOperators);
3836
}
37+
3938
throw error;
4039
}

examples/src/startChat.example.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { config } from "dotenv";
2+
config();
3+
import { Glean } from "@gleanwork/api-client";
4+
import { GleanError } from "@gleanwork/api-client/models/errors";
5+
6+
if (!process.env["SERVER_URL"]) {
7+
throw new Error("SERVER_URL is not set");
8+
}
9+
10+
console.log(process.env["SERVER_URL"]);
11+
12+
const glean = new Glean({
13+
domain: "customerName",
14+
bearerAuth: process.env["BEARER_AUTH"],
15+
});
16+
17+
try {
18+
const data = await glean.client.chat.start({
19+
messages: [
20+
{
21+
fragments: [{ text: "What are the company holidays this year?" }],
22+
},
23+
],
24+
});
25+
console.log(data);
26+
} catch (error) {
27+
if (error instanceof GleanError) {
28+
console.error(error.message);
29+
console.error(error.statusCode);
30+
console.error(error.rawResponse);
31+
console.error(error.body);
32+
}
33+
34+
throw error;
35+
}

0 commit comments

Comments
 (0)