Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .speakeasy/workflow.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ speakeasyVersion: 1.540.1
sources:
Glean API:
sourceNamespace: glean-api-specs
sourceRevisionDigest: sha256:33b8b6d8447549ad225d8eb93b6629385a696b9836c5c86f40e75f2dc9ae92e0
sourceRevisionDigest: sha256:bb693058375d00f6308376d62438b7a64826195f9aa3d8063780acde0a58cbea
sourceBlobDigest: sha256:02dae61341a702b82c050ed3828f22d5a82de8e9f2fa6a99ddab6ad0dfe4a38a
tags:
- latest
Expand All @@ -17,7 +17,7 @@ targets:
glean:
source: Glean API
sourceNamespace: glean-api-specs
sourceRevisionDigest: sha256:33b8b6d8447549ad225d8eb93b6629385a696b9836c5c86f40e75f2dc9ae92e0
sourceRevisionDigest: sha256:bb693058375d00f6308376d62438b7a64826195f9aa3d8063780acde0a58cbea
sourceBlobDigest: sha256:02dae61341a702b82c050ed3828f22d5a82de8e9f2fa6a99ddab6ad0dfe4a38a
workflow:
workflowVersion: 1.0.0
Expand Down
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -732,15 +732,17 @@ The following errors may be thrown by the SDK:
### Example

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

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

try {
const data = await glean.chat.ask({});
const data = await glean.client.search.execute({
query: "What are the company holidays this year?",
});
console.log(data);
} catch (error) {
if (error instanceof GleanError) {
Expand All @@ -755,8 +757,9 @@ try {
console.error(error.errorMessages);
console.error(error.invalidOperators);
}
}

throw error;
}
```

### Advanced Error Handling
Expand Down
29 changes: 8 additions & 21 deletions examples/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"license": "ISC",
"dependencies": {
"dotenv": "^16.4.7",
"glean": "file:../"
"@gleanwork/api-client": "file:../"
},
"devDependencies": {
"@types/node": "^20.11.4",
Expand Down
21 changes: 0 additions & 21 deletions examples/src/delete_chats_example.js

This file was deleted.

17 changes: 8 additions & 9 deletions examples/src/example.ts → examples/src/search.example.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { config } from "dotenv";
config();
import { Glean } from "glean";
import { GleanError, GleanDataError } from "glean/models/errors";
import { Glean } from "@gleanwork/api-client";
import {
GleanDataError,
GleanError,
} from "@gleanwork/api-client/models/errors";

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

try {
const data = await glean.chat.ask({
askRequest: {
searchRequest: {
query: "What is the capital of France?",
},
},
const data = await glean.client.search.execute({
query: "What are the company holidays this year?",
});
console.log(data);
} catch (error) {
Expand All @@ -31,10 +30,10 @@ try {
console.error(error.body);
}

// GleanDataError contains structured data
if (error instanceof GleanDataError) {
console.error(error.errorMessages);
console.error(error.invalidOperators);
}

throw error;
}
35 changes: 35 additions & 0 deletions examples/src/startChat.example.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { config } from "dotenv";
config();
import { Glean } from "@gleanwork/api-client";
import { GleanError } from "@gleanwork/api-client/models/errors";

if (!process.env["SERVER_URL"]) {
throw new Error("SERVER_URL is not set");
}

console.log(process.env["SERVER_URL"]);

const glean = new Glean({
domain: "customerName",
bearerAuth: process.env["BEARER_AUTH"],
});

try {
const data = await glean.client.chat.start({
messages: [
{
fragments: [{ text: "What are the company holidays this year?" }],
},
],
});
console.log(data);
} catch (error) {
if (error instanceof GleanError) {
console.error(error.message);
console.error(error.statusCode);
console.error(error.rawResponse);
console.error(error.body);
}

throw error;
}
Loading