Skip to content

Commit 56f07b5

Browse files
Merge pull request #3 from gleanwork/removeAskFromExampleAndErrorHandling
Remove .ask() examples
2 parents 6da3d7c + 27c24c3 commit 56f07b5

File tree

3 files changed

+70
-31
lines changed

3 files changed

+70
-31
lines changed

README.md

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -529,26 +529,58 @@ All operations return a response object or raise an exception:
529529
### Example
530530

531531
```python
532-
from glean import Glean, errors
532+
from glean import Glean, errors, models
533533
import os
534534

535535

536536
with Glean(
537537
bearer_auth=os.getenv("GLEAN_BEARER_AUTH", ""),
538-
server_url=os.getenv("GLEAN_SERVER_URL", "https://customer-be.glean.com")
539-
) as glean:
538+
) as g_client:
540539
try:
541-
res = glean.chat.ask()
540+
res = g_client.client.search.execute(search_request=models.SearchRequest(
541+
tracking_token="trackingToken",
542+
page_size=10,
543+
query="vacation policy",
544+
request_options=models.SearchRequestOptions(
545+
facet_filters=[
546+
models.FacetFilter(
547+
field_name="type",
548+
values=[
549+
models.FacetFilterValue(
550+
value="article",
551+
relation_type=models.RelationType.EQUALS,
552+
),
553+
models.FacetFilterValue(
554+
value="document",
555+
relation_type=models.RelationType.EQUALS,
556+
),
557+
],
558+
),
559+
models.FacetFilter(
560+
field_name="department",
561+
values=[
562+
models.FacetFilterValue(
563+
value="engineering",
564+
relation_type=models.RelationType.EQUALS,
565+
),
566+
],
567+
),
568+
],
569+
facet_bucket_size=246815,
570+
),
571+
))
572+
573+
# Handle response
542574
print(res)
543-
# If the server returned structured data
544-
except errors.GleanDataError as e:
545-
print(e.data)
546-
print(e.data.errorMessage)
547575
except errors.GleanError as e:
548576
print(e.message)
549577
print(e.status_code)
550578
print(e.raw_response)
551579
print(e.body)
580+
# If the server returned structured data
581+
except errors.GleanDataError as e:
582+
print(e.data)
583+
print(e.data.errorMessage)
552584
```
553585

554586
By default, an API error will raise a errors.GleanError exception, which has the following properties:

examples/ask_example.py

Lines changed: 0 additions & 23 deletions
This file was deleted.

examples/chat_example.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# To run the example:
2+
# poetry install
3+
# poetry run python examples/ask_example.py
4+
5+
from glean import Glean, errors, models
6+
import os
7+
8+
9+
with Glean(
10+
bearer_auth=os.getenv("GLEAN_BEARER_AUTH", ""),
11+
domain="customerName"
12+
) as glean:
13+
try:
14+
res = glean.client.chat.start(messages=[
15+
{
16+
"fragments": [
17+
models.ChatMessageFragment(
18+
text="What are the company holidays this year?",
19+
),
20+
],
21+
},
22+
], timeout_millis=30000)
23+
24+
# Handle response
25+
print(res)
26+
except errors.GleanError as e:
27+
print(e.message)
28+
print(e.status_code)
29+
print(e.raw_response)
30+
print(e.body)

0 commit comments

Comments
 (0)