fix get_chat_records usage

This commit is contained in:
Xin Wang
2026-01-08 11:27:21 +08:00
parent 53874935d6
commit 6a6d736991

View File

@@ -189,54 +189,67 @@ async def get_chat_records():
print(f"Chat records:")
for record in data['data']['list']:
print(f" - [{record['dataId']}] {record.get('content', {}).get('text', 'N/A')[:50]}...")
# Extract text from the value array structure
text = 'N/A'
value_array = record.get('value', [])
if value_array and len(value_array) > 0:
# Get the first item in the value array
first_item = value_array[0]
if first_item.get('type') == 'text' and 'text' in first_item:
text = first_item['text'].get('content', 'N/A')
# Get role (obj field: "Human" or "AI")
role = record.get('obj', 'Unknown')
print(f" - [{role}] [{record.get('dataId', 'N/A')}] {text[:50] if text != 'N/A' else 'N/A'}...")
except Exception as e:
print(f"Error: {e}")
async def main():
"""Run all examples."""
print("=== Simple Chat ===")
try:
await simple_chat()
except Exception as e:
print(f"Error: {e}")
# print("=== Simple Chat ===")
# try:
# await simple_chat()
# except Exception as e:
# print(f"Error: {e}")
print("\n=== Streaming Chat ===")
try:
await streaming_chat()
except Exception as e:
print(f"Error: {e}")
# print("\n=== Streaming Chat ===")
# try:
# await streaming_chat()
# except Exception as e:
# print(f"Error: {e}")
print("\n=== Chat with Context ===")
try:
await chat_with_context()
except Exception as e:
print(f"Error: {e}")
# print("\n=== Chat with Context ===")
# try:
# await chat_with_context()
# except Exception as e:
# print(f"Error: {e}")
print("\n=== Get Histories ===")
try:
await get_histories()
except Exception as e:
print(f"Error: {e}")
# print("\n=== Get Histories ===")
# try:
# await get_histories()
# except Exception as e:
# print(f"Error: {e}")
print("\n=== Get App Analytics ===")
try:
await get_app_analytics()
except Exception as e:
print(f"Error: {e}")
# print("\n=== Get App Analytics ===")
# try:
# await get_app_analytics()
# except Exception as e:
# print(f"Error: {e}")
print("\n=== Multiple Requests (Concurrent) ===")
try:
await multiple_requests()
except Exception as e:
print(f"Error: {e}")
# print("\n=== Multiple Requests (Concurrent) ===")
# try:
# await multiple_requests()
# except Exception as e:
# print(f"Error: {e}")
print("\n=== Chat with Variables ===")
try:
await chat_with_variables()
except Exception as e:
print(f"Error: {e}")
# print("\n=== Chat with Variables ===")
# try:
# await chat_with_variables()
# except Exception as e:
# print(f"Error: {e}")
print("\n=== Get Chat Records ===")
try: