|
4 | 4 |
|
5 | 5 | from datetime import datetime |
6 | 6 | from typing import TYPE_CHECKING as _TYPE_CHECKING |
7 | | -from typing import Optional |
| 7 | +from typing import Any, Optional |
8 | 8 |
|
9 | 9 | from codex import AuthenticationError |
10 | 10 |
|
@@ -178,37 +178,43 @@ def query( |
178 | 178 | question: str, |
179 | 179 | *, |
180 | 180 | fallback_answer: Optional[str] = None, |
181 | | - analytics_metadata: Optional[_AnalyticsMetadata] = None, |
| 181 | + metadata: Optional[dict[str, Any]] = None, |
| 182 | + _analytics_metadata: Optional[_AnalyticsMetadata] = None, |
182 | 183 | ) -> tuple[Optional[str], Entry]: |
183 | 184 | """Query Codex to check if this project contains an answer to the question. If the question is not yet in the project, it will be added for SME review. |
184 | 185 |
|
185 | 186 | Args: |
186 | 187 | question (str): The question to ask the Codex API. |
187 | 188 | fallback_answer (str, optional): Optional fallback answer to return if Codex is unable to answer the question. |
| 189 | + metadata (dict, optional): Additional custom metadata to associate with the query. |
188 | 190 |
|
189 | 191 | Returns: |
190 | 192 | tuple[Optional[str], Entry]: A tuple representing the answer for the query and the existing or new entry in the Codex project. |
191 | 193 | If Codex is able to answer the question, the first element will be the answer returned by Codex and the second element will be the existing [`Entry`](/codex/api/python/types.entry#class-entry) in the Codex project. |
192 | 194 | If Codex is unable to answer the question, the first element will be `fallback_answer` if provided, otherwise None. The second element will be a new [`Entry`](/codex/api/python/types.entry#class-entry) in the Codex project. |
193 | 195 | """ |
194 | | - if not analytics_metadata: |
195 | | - analytics_metadata = _AnalyticsMetadata(integration_type=IntegrationType.BACKUP) |
| 196 | + if not _analytics_metadata: |
| 197 | + _analytics_metadata = _AnalyticsMetadata(integration_type=IntegrationType.BACKUP) |
196 | 198 |
|
197 | 199 | return self._query_project( |
198 | 200 | question=question, |
199 | 201 | fallback_answer=fallback_answer, |
200 | | - analytics_metadata=analytics_metadata, |
| 202 | + client_metadata=metadata, |
| 203 | + analytics_metadata=_analytics_metadata, |
201 | 204 | ) |
202 | 205 |
|
203 | 206 | def _query_project( |
204 | 207 | self, |
205 | 208 | question: str, |
206 | 209 | *, |
207 | 210 | fallback_answer: Optional[str] = None, |
| 211 | + client_metadata: Optional[dict[str, Any]] = None, |
208 | 212 | analytics_metadata: Optional[_AnalyticsMetadata] = None, |
209 | 213 | ) -> tuple[Optional[str], Entry]: |
210 | 214 | extra_headers = analytics_metadata.to_headers() if analytics_metadata else None |
211 | | - query_res = self._sdk_client.projects.entries.query(self._id, question=question, extra_headers=extra_headers) |
| 215 | + query_res = self._sdk_client.projects.entries.query( |
| 216 | + self._id, question=question, client_metadata=client_metadata, extra_headers=extra_headers |
| 217 | + ) |
212 | 218 |
|
213 | 219 | entry = Entry.model_validate(query_res.entry.model_dump()) |
214 | 220 | if query_res.answer is not None: |
|
0 commit comments