@@ -7,7 +7,6 @@ The Glean Python SDK provides convenient access to the Glean REST API from any P
7
7
## Table of Contents
8
8
<!-- $toc-max-depth=2 -->
9
9
* [ Glean Python API Client] ( #glean-python-api-client )
10
- * [ Usage guidelines] ( #usage-guidelines )
11
10
* [ SDK Installation] ( #sdk-installation )
12
11
* [ IDE Support] ( #ide-support )
13
12
* [ SDK Example Usage] ( #sdk-example-usage )
@@ -100,40 +99,25 @@ Generally, the SDK will work well with most IDEs out of the box. However, when u
100
99
``` python
101
100
# Synchronous Example
102
101
from glean import Glean, models
103
- from glean.utils import parse_datetime
104
102
import os
105
103
106
104
107
105
with Glean(
108
106
bearer_auth = os.getenv(" GLEAN_BEARER_AUTH" , " " ),
109
107
) as g_client:
110
108
111
- g_client.client.activity.report( events = [
109
+ res = g_client.client.chat.start( messages = [
112
110
{
113
- " action" : models.ActivityEventAction.HISTORICAL_VIEW ,
114
- " timestamp" : parse_datetime(" 2000-01-23T04:56:07.000Z" ),
115
- " url" : " https://example.com/" ,
111
+ " fragments" : [
112
+ models.ChatMessageFragment(
113
+ text = " What are the company holidays this year?" ,
114
+ ),
115
+ ],
116
116
},
117
- {
118
- " action" : models.ActivityEventAction.SEARCH ,
119
- " params" : {
120
- " query" : " query" ,
121
- },
122
- " timestamp" : parse_datetime(" 2000-01-23T04:56:07.000Z" ),
123
- " url" : " https://example.com/search?q=query" ,
124
- },
125
- {
126
- " action" : models.ActivityEventAction.VIEW ,
127
- " params" : {
128
- " duration" : 20 ,
129
- " referrer" : " https://example.com/document" ,
130
- },
131
- " timestamp" : parse_datetime(" 2000-01-23T04:56:07.000Z" ),
132
- " url" : " https://example.com/" ,
133
- },
134
- ])
117
+ ], timeout_millis = 30000 )
135
118
136
- # Use the SDK ...
119
+ # Handle response
120
+ print (res)
137
121
```
138
122
139
123
</br >
@@ -143,7 +127,6 @@ The same SDK client can also be used to make asychronous requests by importing a
143
127
# Asynchronous Example
144
128
import asyncio
145
129
from glean import Glean, models
146
- from glean.utils import parse_datetime
147
130
import os
148
131
149
132
async def main ():
@@ -152,32 +135,18 @@ async def main():
152
135
bearer_auth = os.getenv(" GLEAN_BEARER_AUTH" , " " ),
153
136
) as g_client:
154
137
155
- await g_client.client.activity.report_async( events = [
138
+ res = await g_client.client.chat.start_async( messages = [
156
139
{
157
- " action" : models.ActivityEventAction.HISTORICAL_VIEW ,
158
- " timestamp" : parse_datetime(" 2000-01-23T04:56:07.000Z" ),
159
- " url" : " https://example.com/" ,
160
- },
161
- {
162
- " action" : models.ActivityEventAction.SEARCH ,
163
- " params" : {
164
- " query" : " query" ,
165
- },
166
- " timestamp" : parse_datetime(" 2000-01-23T04:56:07.000Z" ),
167
- " url" : " https://example.com/search?q=query" ,
168
- },
169
- {
170
- " action" : models.ActivityEventAction.VIEW ,
171
- " params" : {
172
- " duration" : 20 ,
173
- " referrer" : " https://example.com/document" ,
174
- },
175
- " timestamp" : parse_datetime(" 2000-01-23T04:56:07.000Z" ),
176
- " url" : " https://example.com/" ,
140
+ " fragments" : [
141
+ models.ChatMessageFragment(
142
+ text = " What are the company holidays this year?" ,
143
+ ),
144
+ ],
177
145
},
178
- ])
146
+ ], timeout_millis = 30000 )
179
147
180
- # Use the SDK ...
148
+ # Handle response
149
+ print (res)
181
150
182
151
asyncio.run(main())
183
152
```
0 commit comments