gpt4 book ai didi

python - 从 Cosmos DB 查询时出现连续 token 问题

转载 作者:行者123 更新时间:2023-12-01 00:59:48 26 4
gpt4 key购买 nike

从 CosmosDB 查询项目时,我遇到了连续性问题。

我已经尝试过the following solution但没有成功。即使我得到的 token 不是 NULL,我也只能查询页面的前 10 个结果。

token 的大小为 10733 字节,如下所示。

{"token":"+RID:gtQwAJ9KbavOAAAAAAAAAA==#RT:1#TRC:10#FPP:AggAAAAAAAAAAGoAAAAAKAAAAAAAAAAAAADCBc6AEoAGgAqADoASgAaACoAOgBKABoAKgA6AE4AHgAuAD4ASgAeACoAPgBOAB4ALgA+AE4AHgAqAD4ASgAeAC4APgBOAB4ALgA+AE4AIgA2AEYAFgAmADYARgAaACYAPgBKABYAKgA6AE4AHgAuAD4ATgAeAC4APgBOAB4ALgA+AE4AIgAuAD4ATgAeAC4APgBOACIAMgA+AFIAIgAyAD4AUgAmADIAQgAWACIALgBCABIAIgAyAEIAEgAiADIAQgAOACYANgBKAB4AJgA6AEYAGgAqADoATgAeAC4APgB....etc...etc","range":{"min":"","max":"05C1BF3FB3CFC0"}}

代码如下所示。函数QueryDocuments 不起作用。相反,我必须使用QueryItems

options = {} 
options['enableCrossPartitionQuery'] = True
options['maxItemCount'] = 10

q = client.QueryItems(collection_link, query, options)
results_1 = q._fetch_function(options)
#this is a string representing a JSON object
token = results_1[1]['x-ms-continuation']

data = list(q._fetch_function({'maxItemCount':10,'enableCrossPartitionQuery':True, 'continuation':token}))

这个问题有解决办法吗?感谢您的帮助。

最佳答案

请使用pydocumentdb打包并引用下面的示例代码。

from pydocumentdb import document_client

endpoint = "https://***.documents.azure.com:443/";
primaryKey = "***";

client = document_client.DocumentClient(endpoint, {'masterKey': primaryKey})

collection_link = "dbs/db/colls/coll"

query = "select c.id from c"

query_with_optional_parameters = [];

q = client.QueryDocuments(collection_link, query, {'maxItemCount': 2})
results_1 = q._fetch_function({'maxItemCount': 2})

print(results_1)
token = results_1[1]['x-ms-continuation']
results_2 = q._fetch_function({'maxItemCount': 2, 'continuation': token})

print(results_2)

输出:

enter image description here

关于python - 从 Cosmos DB 查询时出现连续 token 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55898282/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com