File tree Expand file tree Collapse file tree 8 files changed +60
-1342
lines changed Expand file tree Collapse file tree 8 files changed +60
-1342
lines changed Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ speakeasyVersion: 1.540.1
22sources:
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
2222workflow:
2323 workflowVersion: 1.0.0
Original file line number Diff line number Diff 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 " ;
736736import { GleanDataError , GleanError } from " glean/models/errors" ;
737737
738738const glean = new Glean ({
739739 bearerAuth: process .env [" GLEAN_BEARER_AUTH" ] ?? " " ,
740740});
741741
742742try {
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
Original file line number Diff line number Diff line change 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" ,
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 11import { config } from "dotenv" ;
22config ( ) ;
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
69if ( ! process . env [ "SERVER_URL" ] ) {
710 throw new Error ( "SERVER_URL is not set" ) ;
@@ -15,12 +18,8 @@ const glean = new Glean({
1518} ) ;
1619
1720try {
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}
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments