@@ -7,7 +7,6 @@ The Glean Python SDK provides convenient access to the Glean REST API from any P
77## Table of Contents
88<!-- $toc-max-depth=2 -->
99* [ Glean Python API Client] ( #glean-python-api-client )
10- * [ Usage guidelines] ( #usage-guidelines )
1110 * [ SDK Installation] ( #sdk-installation )
1211 * [ IDE Support] ( #ide-support )
1312 * [ 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
10099``` python
101100# Synchronous Example
102101from glean import Glean, models
103- from glean.utils import parse_datetime
104102import os
105103
106104
107105with Glean(
108106 bearer_auth = os.getenv(" GLEAN_BEARER_AUTH" , " " ),
109107) as g_client:
110108
111- g_client.client.activity.report( events = [
109+ res = g_client.client.chat.start( messages = [
112110 {
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+ ],
116116 },
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 )
135118
136- # Use the SDK ...
119+ # Handle response
120+ print (res)
137121```
138122
139123</br >
@@ -143,7 +127,6 @@ The same SDK client can also be used to make asychronous requests by importing a
143127# Asynchronous Example
144128import asyncio
145129from glean import Glean, models
146- from glean.utils import parse_datetime
147130import os
148131
149132async def main ():
@@ -152,32 +135,18 @@ async def main():
152135 bearer_auth = os.getenv(" GLEAN_BEARER_AUTH" , " " ),
153136 ) as g_client:
154137
155- await g_client.client.activity.report_async( events = [
138+ res = await g_client.client.chat.start_async( messages = [
156139 {
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+ ],
177145 },
178- ])
146+ ], timeout_millis = 30000 )
179147
180- # Use the SDK ...
148+ # Handle response
149+ print (res)
181150
182151asyncio.run(main())
183152```
0 commit comments