vector-bridge 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (26) hide show
  1. vector_bridge-1.0.0/PKG-INFO +902 -0
  2. vector_bridge-1.0.0/README.md +888 -0
  3. vector_bridge-1.0.0/pyproject.toml +26 -0
  4. vector_bridge-1.0.0/vector_bridge/__init__.py +2763 -0
  5. vector_bridge-1.0.0/vector_bridge/schema/__init__.py +0 -0
  6. vector_bridge-1.0.0/vector_bridge/schema/ai_knowledge/__init__.py +34 -0
  7. vector_bridge-1.0.0/vector_bridge/schema/ai_knowledge/filesystem.py +140 -0
  8. vector_bridge-1.0.0/vector_bridge/schema/ai_knowledge/schemaless.py +45 -0
  9. vector_bridge-1.0.0/vector_bridge/schema/api_keys.py +32 -0
  10. vector_bridge-1.0.0/vector_bridge/schema/chat.py +74 -0
  11. vector_bridge-1.0.0/vector_bridge/schema/error.py +13 -0
  12. vector_bridge-1.0.0/vector_bridge/schema/functions.py +87 -0
  13. vector_bridge-1.0.0/vector_bridge/schema/helpers/__init__.py +0 -0
  14. vector_bridge-1.0.0/vector_bridge/schema/helpers/enums.py +326 -0
  15. vector_bridge-1.0.0/vector_bridge/schema/helpers/weaviate_schema.py +159 -0
  16. vector_bridge-1.0.0/vector_bridge/schema/instruction.py +182 -0
  17. vector_bridge-1.0.0/vector_bridge/schema/integrations.py +76 -0
  18. vector_bridge-1.0.0/vector_bridge/schema/logs.py +28 -0
  19. vector_bridge-1.0.0/vector_bridge/schema/messages.py +210 -0
  20. vector_bridge-1.0.0/vector_bridge/schema/notifications.py +51 -0
  21. vector_bridge-1.0.0/vector_bridge/schema/organization.py +13 -0
  22. vector_bridge-1.0.0/vector_bridge/schema/security_group.py +153 -0
  23. vector_bridge-1.0.0/vector_bridge/schema/settings.py +140 -0
  24. vector_bridge-1.0.0/vector_bridge/schema/usage.py +31 -0
  25. vector_bridge-1.0.0/vector_bridge/schema/user.py +166 -0
  26. vector_bridge-1.0.0/vector_bridge/schema/user_integrations.py +32 -0
@@ -0,0 +1,902 @@
1
+ Metadata-Version: 2.1
2
+ Name: vector-bridge
3
+ Version: 1.0.0
4
+ Summary: A client library for accessing VectorBridge.ai: API
5
+ Requires-Python: >=3.10,<4.0
6
+ Classifier: Programming Language :: Python :: 3
7
+ Classifier: Programming Language :: Python :: 3.10
8
+ Classifier: Programming Language :: Python :: 3.11
9
+ Classifier: Programming Language :: Python :: 3.12
10
+ Requires-Dist: pydantic (>=2.10.6,<3.0.0)
11
+ Requires-Dist: requests (>=2.32.3,<3.0.0)
12
+ Requires-Dist: weaviate (>=4.10.4,<5.0.0)
13
+ Description-Content-Type: text/markdown
14
+
15
+ # VectorBridge Python Client
16
+
17
+ [![Python Version](https://img.shields.io/badge/python-3.10%2B-blue.svg)](https://www.python.org/downloads/)
18
+ [![License](https://img.shields.io/badge/license-MIT-green.svg)](https://opensource.org/licenses/MIT)
19
+
20
+ A comprehensive Python client for interacting with the [VectorBridge.ai](https://vectorbridge.ai) API. This client provides complete access to all aspects of the VectorBridge platform including authentication, user management, AI processing, vector operations, and more.
21
+
22
+ ## Installation
23
+
24
+ ```bash
25
+ pip install vector-bridge
26
+ ```
27
+
28
+ ## Quick Start
29
+
30
+ ### Initialize the Client
31
+
32
+ For user authentication (admin access):
33
+
34
+ ```python
35
+ from vector_bridge import VectorBridgeClient
36
+
37
+ # Initialize the client
38
+ client = VectorBridgeClient(integration_name="default")
39
+
40
+ # Login with credentials
41
+ client.login(username="your_email@example.com", password="your_password")
42
+
43
+ # Check if API is accessible
44
+ status = client.ping() # Should return "OK"
45
+ ```
46
+
47
+ For API key authentication (application access):
48
+
49
+ ```python
50
+ from vector_bridge import VectorBridgeClient
51
+
52
+ # Initialize with API key
53
+ client = VectorBridgeClient(
54
+ integration_name="default",
55
+ api_key="your_api_key"
56
+ )
57
+ ```
58
+
59
+ ## Authentication Methods
60
+
61
+ ### Username/Password Authentication (Admin Access)
62
+
63
+ ```python
64
+ from vector_bridge import VectorBridgeClient
65
+
66
+ client = VectorBridgeClient(integration_name="default")
67
+ token = client.login(username="your_email@example.com", password="your_password")
68
+
69
+ # Now you can access admin functionality
70
+ me = client.admin.user.get_me()
71
+ print(f"Logged in as: {me.email}")
72
+ ```
73
+
74
+ ### API Key Authentication (Application Access)
75
+
76
+ ```python
77
+ from vector_bridge import VectorBridgeClient, SortOrder
78
+
79
+ client = VectorBridgeClient(
80
+ integration_name="default",
81
+ api_key="your_api_key"
82
+ )
83
+
84
+ # Process a message with AI
85
+ response = client.ai_message.process_message_stream(
86
+ content="What can you tell me about vector databases?",
87
+ user_id="user123"
88
+ )
89
+
90
+ # Print the streaming response
91
+ for chunk in response.chunks:
92
+ print(chunk, end="")
93
+
94
+ # Get the complete message after streaming
95
+ complete_message = response.message
96
+ ```
97
+
98
+ ## Core Features
99
+
100
+ ### AI Message Processing
101
+
102
+ Process messages and get AI responses with streaming support:
103
+
104
+ ```python
105
+ # Process a message and get streaming AI response
106
+ message_stream = client.ai_message.process_message_stream(
107
+ content="Tell me about artificial intelligence",
108
+ user_id="user123"
109
+ )
110
+
111
+ # Print the streaming response chunks
112
+ for chunk in message_stream.chunks:
113
+ print(chunk, end="")
114
+
115
+ # Access the complete message
116
+ whole_message = message_stream.message
117
+ ```
118
+
119
+ Retrieve conversation history:
120
+
121
+ ```python
122
+ # From DynamoDB
123
+ messages = client.ai_message.fetch_messages_from_dynamo_db(
124
+ user_id="user123",
125
+ sort_order=SortOrder.DESCENDING,
126
+ limit=50
127
+ )
128
+
129
+ # From Vector Database with semantic search capability
130
+ messages = client.ai_message.fetch_messages_from_vector_db(
131
+ user_id="user123",
132
+ near_text="machine learning"
133
+ )
134
+ ```
135
+
136
+ ### AI Agents
137
+
138
+ ```python
139
+ # Set a specific agent for a user conversation
140
+ chat = client.ai.set_current_agent(
141
+ user_id="user123",
142
+ agent_name="sales_manager"
143
+ )
144
+
145
+ # Provide core knowledge for an agent
146
+ chat = client.ai.set_core_knowledge(
147
+ user_id="user123",
148
+ core_knowledge={
149
+ "product_line": ["widgets", "gadgets"],
150
+ "company_info": "Founded in 2020"
151
+ }
152
+ )
153
+ ```
154
+
155
+ ### Function Execution
156
+
157
+ ```python
158
+ # Execute a previously defined function
159
+ result = client.functions.run_function(
160
+ function_name="calculator",
161
+ function_args={
162
+ "a": 10,
163
+ "b": 5,
164
+ "operation": "multiply"
165
+ }
166
+ )
167
+
168
+ print(f"Result: {result}")
169
+ ```
170
+
171
+ ### Vector Database Queries
172
+
173
+ ```python
174
+ # Run a semantic search query
175
+ results = client.queries.run_search_query(
176
+ vector_schema="Documents",
177
+ query_kwargs={
178
+ "content": "artificial intelligence applications",
179
+ "full_document": False
180
+ }
181
+ )
182
+
183
+ # Find similar documents based on a reference document
184
+ similar_docs = client.queries.run_find_similar_query(
185
+ vector_schema="Documents",
186
+ query_kwargs={
187
+ "uuid": "8c03ff2f-36f9-45f7-9918-48766c968f45"
188
+ }
189
+ )
190
+ ```
191
+
192
+ ## Admin Functionality
193
+
194
+ ### User Management
195
+
196
+ ```python
197
+ # Get current user info
198
+ me = client.admin.user.get_me()
199
+
200
+ # Update user details
201
+ updated_me = client.admin.user.update_me(
202
+ user_data=UserUpdate(
203
+ full_name="John Doe",
204
+ phone_number="+1234567890",
205
+ country="US",
206
+ city="New York"
207
+ )
208
+ )
209
+
210
+ # Change password
211
+ client.admin.user.change_password(
212
+ old_password="current_password",
213
+ new_password="new_secure_password"
214
+ )
215
+
216
+ # Add an agent user
217
+ new_agent = client.admin.user.add_agent(
218
+ email="agent@example.com",
219
+ first_name="Agent",
220
+ last_name="User",
221
+ password="secure_password"
222
+ )
223
+
224
+ # List users in your organization
225
+ users = client.admin.user.get_users_in_my_organization()
226
+
227
+ # Get user by ID or email
228
+ user = client.admin.user.get_user_by_id("user_id")
229
+ user = client.admin.user.get_user_by_email("user@example.com")
230
+ ```
231
+
232
+ ### Security Groups
233
+
234
+ ```python
235
+ # Create a security group
236
+ sg = client.admin.security_groups.create_security_group(
237
+ security_group_data=SecurityGroupCreate(
238
+ group_name="Content Creators",
239
+ description="Users who can create and edit content"
240
+ )
241
+ )
242
+
243
+ # List security groups
244
+ security_groups = client.admin.security_groups.list_security_groups()
245
+
246
+ # Update security group permissions
247
+ permissions = security_groups.security_groups[0].group_permissions
248
+ permissions.logs.read = True
249
+ updated_sg = client.admin.security_groups.update_security_group(
250
+ group_id=security_groups.security_groups[0].group_id,
251
+ security_group_data=SecurityGroupUpdate(permissions=permissions)
252
+ )
253
+
254
+ # Get security group details
255
+ sg = client.admin.security_groups.get_security_group(group_id="group_id")
256
+
257
+ # Delete security group
258
+ client.admin.security_groups.delete_security_group(group_id="group_id")
259
+ ```
260
+
261
+ ### Integration Management
262
+
263
+ ```python
264
+ # List all integrations
265
+ integrations = client.admin.integrations.get_integrations_list()
266
+
267
+ # Get integration by name
268
+ integration = client.admin.integrations.get_integration_by_name("default")
269
+
270
+ # Get integration by ID
271
+ integration = client.admin.integrations.get_integration_by_id("integration_id")
272
+
273
+ # Create a new integration
274
+ new_integration = client.admin.integrations.add_integration(
275
+ integration_data=IntegrationCreate(
276
+ integration_name="API Integration",
277
+ integration_description="Integration for API access",
278
+ openai_api_key="sk-your-openai-key",
279
+ weaviate_url="https://your-weaviate-instance.cloud",
280
+ weaviate_api_key="your-weaviate-key"
281
+ )
282
+ )
283
+
284
+ # Update integration settings
285
+ updated = client.admin.integrations.update_integration_weaviate(
286
+ weaviate_key=WeaviateKey.MAX_SIMILARITY_DISTANCE,
287
+ weaviate_value=0.7
288
+ )
289
+
290
+ # Update AI provider API key
291
+ updated = client.admin.integrations.update_integration_ai_api_key(
292
+ api_key="your-api-key",
293
+ ai_provider=AIProviders.DEEP_SEEK
294
+ )
295
+
296
+ # Update message storage mode
297
+ updated = client.admin.integrations.update_message_storage_mode(
298
+ message_storage_mode=MessageStorageMode.DYNAMO_DB
299
+ )
300
+
301
+ # Update environment variables
302
+ updated = client.admin.integrations.update_environment_variables(
303
+ env_variables={
304
+ "API_KEY": "value1",
305
+ "SECRET": "value2"
306
+ }
307
+ )
308
+
309
+ # Delete an integration
310
+ client.admin.integrations.delete_integration("integration_name")
311
+ ```
312
+
313
+ ### User Access Management
314
+
315
+ ```python
316
+ # Add user to integration
317
+ users_in_integration = client.admin.integrations.add_user_to_integration(
318
+ user_id="user_id",
319
+ security_group_id="security_group_id"
320
+ )
321
+
322
+ # Remove user from integration
323
+ users_in_integration = client.admin.integrations.remove_user_from_integration(
324
+ user_id="user_id"
325
+ )
326
+
327
+ # Update user's security group
328
+ users = client.admin.integrations.update_users_security_group(
329
+ security_group_id="new_group_id",
330
+ user_id="user_id"
331
+ )
332
+
333
+ # Get users in an integration
334
+ users = client.admin.integrations.get_users_from_integration()
335
+ ```
336
+
337
+ ### Instructions Management
338
+
339
+ ```python
340
+ # Create an instruction
341
+ instruction = client.admin.instructions.add_instruction(
342
+ instruction_data=InstructionCreate(
343
+ instruction_name="Sales Assistant",
344
+ description="Instruction for sales assistance",
345
+ open_ai_api_key="sk-your-openai-key"
346
+ )
347
+ )
348
+
349
+ # Get instruction by name
350
+ instruction = client.admin.instructions.get_instruction_by_name("Sales Assistant")
351
+
352
+ # Get instruction by ID
353
+ instruction = client.admin.instructions.get_instruction_by_id("instruction_id")
354
+
355
+ # List instructions
356
+ instructions = client.admin.instructions.list_instructions()
357
+
358
+ # Delete instruction
359
+ client.admin.instructions.delete_instruction("instruction_id")
360
+ ```
361
+
362
+ ### Function Management
363
+
364
+ ```python
365
+ # Create a function
366
+ function = client.admin.functions.add_function(
367
+ function_data=FunctionCreate(
368
+ function_name="calculator",
369
+ description="Perform math operations",
370
+ function_action=GPTActions.CODE_EXEC,
371
+ code="import math\nresult = math.pow(float(base), float(exponent))\nprint(f'Result: {result}')",
372
+ function_parameters=FunctionParametersStorageStructure(
373
+ properties=[
374
+ FunctionPropertyStorageStructure(
375
+ name="base",
376
+ description="Base number"
377
+ ),
378
+ FunctionPropertyStorageStructure(
379
+ name="exponent",
380
+ description="Exponent"
381
+ )
382
+ ]
383
+ )
384
+ )
385
+ )
386
+
387
+ # Get function by name
388
+ function = client.admin.functions.get_function_by_name("calculator")
389
+
390
+ # Get function by ID
391
+ function = client.admin.functions.get_function_by_id("function_id")
392
+
393
+ # Update a function
394
+ updated_function = client.admin.functions.update_function(
395
+ function_id="function_id",
396
+ function_data=FunctionUpdate(
397
+ description="Updated function description",
398
+ code="print('Updated function code')"
399
+ )
400
+ )
401
+
402
+ # List functions
403
+ functions = client.admin.functions.list_functions()
404
+
405
+ # List default functions
406
+ default_functions = client.admin.functions.list_default_functions()
407
+
408
+ # Execute a function
409
+ result = client.admin.functions.run_function(
410
+ function_name="calculator",
411
+ function_args={
412
+ "base": 2,
413
+ "exponent": 8
414
+ }
415
+ )
416
+
417
+ # Delete a function
418
+ client.admin.functions.delete_function("function_id")
419
+ ```
420
+
421
+ ### API Key Management
422
+
423
+ ```python
424
+ # Create an API key
425
+ api_key = client.admin.api_keys.create_api_key(
426
+ api_key_data=APIKeyCreate(
427
+ key_name="Client API Key",
428
+ user_id="user_id",
429
+ expire_days=30,
430
+ monthly_request_limit=10000
431
+ )
432
+ )
433
+
434
+ # Get API key details
435
+ api_key = client.admin.api_keys.get_api_key("api_key")
436
+
437
+ # List all API keys
438
+ api_keys = client.admin.api_keys.list_api_keys()
439
+
440
+ # Delete an API key
441
+ client.admin.api_keys.delete_api_key("api_key")
442
+ ```
443
+
444
+ ### Chat Management
445
+
446
+ ```python
447
+ # Get all chats in my organization
448
+ chats = client.admin.chat.fetch_chats_for_my_organization(
449
+ integration_name="default"
450
+ )
451
+
452
+ # Get my chats
453
+ my_chats = client.admin.chat.fetch_my_chats(
454
+ integration_name="default"
455
+ )
456
+
457
+ # Delete a chat
458
+ client.admin.chat.delete_chat(
459
+ user_id="user_id"
460
+ )
461
+ ```
462
+
463
+ ### Internal Message Processing
464
+
465
+ ```python
466
+ # Process an internal message with AI
467
+ message_stream = client.admin.message.process_internal_message(
468
+ content="Write a product description for our new AI-powered toaster",
469
+ suffix="marketing_team",
470
+ integration_name="default"
471
+ )
472
+
473
+ for chunk in message_stream.chunks:
474
+ print(chunk)
475
+
476
+ full_message = message_stream.message
477
+ ```
478
+
479
+ ### AI Knowledge Management
480
+
481
+ #### File Storage
482
+
483
+ ```python
484
+ # Create a folder
485
+ folder = client.admin.ai_knowledge.file_storage.create_folder(
486
+ folder_name="Project Documents",
487
+ folder_description="Documentation for our project",
488
+ private=True
489
+ )
490
+
491
+ # Upload a file
492
+ file = client.admin.ai_knowledge.file_storage.upload_file(
493
+ file_path="document.pdf",
494
+ file_name="project-specs.pdf",
495
+ parent_id=folder.id,
496
+ private=True,
497
+ tags=["project", "documentation"]
498
+ )
499
+
500
+ # Rename a file
501
+ renamed_file = client.admin.ai_knowledge.file_storage.rename_file_or_folder(
502
+ item_id=file.id,
503
+ new_name="updated-specs.pdf"
504
+ )
505
+
506
+ # Update file properties
507
+ updated_file = client.admin.ai_knowledge.file_storage.update_file_or_folder(
508
+ item_id=file.id,
509
+ is_starred=True,
510
+ tags=["important", "reference"]
511
+ )
512
+
513
+ # Get file details
514
+ file = client.admin.ai_knowledge.file_storage.get_file_or_folder(
515
+ item_id="file_id"
516
+ )
517
+
518
+ # Get file path
519
+ path = client.admin.ai_knowledge.file_storage.get_file_or_folder_path(
520
+ item_id="file_id"
521
+ )
522
+
523
+ # List files and folders
524
+ items = client.admin.ai_knowledge.file_storage.list_files_and_folders(
525
+ filters=AIKnowledgeFileSystemFilters(
526
+ parent_id=folder.id
527
+ )
528
+ )
529
+
530
+ # Count files and folders
531
+ count = client.admin.ai_knowledge.file_storage.count_files_and_folders(
532
+ parents=[folder.id]
533
+ )
534
+
535
+ # Get download link
536
+ download_link = client.admin.ai_knowledge.file_storage.get_download_link_for_document(
537
+ item_id="file_id"
538
+ )
539
+
540
+ # Grant user access to a file
541
+ client.admin.ai_knowledge.file_storage.grant_or_revoke_user_access(
542
+ item_id="file_id",
543
+ user_id="user_id",
544
+ has_access=True,
545
+ access_type=FileAccessType.READ
546
+ )
547
+
548
+ # Grant security group access
549
+ client.admin.ai_knowledge.file_storage.grant_or_revoke_security_group_access(
550
+ item_id="file_id",
551
+ group_id="group_id",
552
+ has_access=True,
553
+ access_type=FileAccessType.READ
554
+ )
555
+
556
+ # Delete a file or folder
557
+ client.admin.ai_knowledge.file_storage.delete_file_or_folder(
558
+ item_id="item_id"
559
+ )
560
+ ```
561
+
562
+ #### Database Operations
563
+
564
+ ```python
565
+ # Process content for database
566
+ content = client.admin.ai_knowledge.database.process_content(
567
+ content_data=AIKnowledgeCreate(
568
+ content="Sample content for vectorization",
569
+ other={
570
+ "price": 123,
571
+ "category": "electronics"
572
+ }
573
+ ),
574
+ schema_name="Products",
575
+ unique_identifier="prod123"
576
+ )
577
+
578
+ # Update an item
579
+ updated_item = client.admin.ai_knowledge.database.update_item(
580
+ item_data={"price": 149.99},
581
+ schema_name="Products",
582
+ item_id="item_id"
583
+ )
584
+
585
+ # Get content by identifier
586
+ item = client.admin.ai_knowledge.database.get_content(
587
+ schema_name="Products",
588
+ unique_identifier="prod123"
589
+ )
590
+
591
+ # List content with filters
592
+ items = client.admin.ai_knowledge.database.get_content_list(
593
+ filters={"category": "electronics"},
594
+ schema_name="Products"
595
+ )
596
+
597
+ # Delete content
598
+ client.admin.ai_knowledge.database.delete_content(
599
+ schema_name="Products",
600
+ unique_identifier="prod123"
601
+ )
602
+ ```
603
+
604
+ ### Vector Queries
605
+
606
+ ```python
607
+ # Run a search query
608
+ results = client.admin.queries.run_search_query(
609
+ vector_schema="Documents",
610
+ query_kwargs={
611
+ "content": "machine learning algorithms",
612
+ "full_document": False
613
+ }
614
+ )
615
+
616
+ # Find similar items
617
+ similar = client.admin.queries.run_find_similar_query(
618
+ vector_schema="Documents",
619
+ query_kwargs={
620
+ "uuid": "document_uuid"
621
+ }
622
+ )
623
+ ```
624
+
625
+ ### System Information
626
+
627
+ ```python
628
+ # Get settings
629
+ settings = client.admin.settings.get_settings()
630
+
631
+ # Get logs
632
+ logs = client.admin.logs.list_logs(
633
+ integration_name="default",
634
+ limit=25
635
+ )
636
+
637
+ # Get notifications
638
+ notifications = client.admin.notifications.list_notifications(
639
+ integration_name="default"
640
+ )
641
+
642
+ # Get usage statistics
643
+ usage = client.admin.usage.list_usage(
644
+ primary_key="integration_id"
645
+ )
646
+
647
+ # Get organization info
648
+ org = client.admin.organization.get_my_organization()
649
+ ```
650
+
651
+ ## Complete Workflow Examples
652
+
653
+ ### Document Processing and Query Workflow
654
+
655
+ ```python
656
+ from vector_bridge import VectorBridgeClient, FileAccessType, AIKnowledgeFileSystemFilters
657
+
658
+ # Initialize client and authenticate
659
+ client = VectorBridgeClient(integration_name="Knowledge Base")
660
+ client.login(username="admin@example.com", password="secure_password")
661
+
662
+ # 1. Create a folder structure
663
+ main_folder = client.admin.ai_knowledge.file_storage.create_folder(
664
+ folder_name="Research Papers",
665
+ folder_description="Academic papers on machine learning",
666
+ private=False
667
+ )
668
+
669
+ # 2. Upload documents
670
+ paper = client.admin.ai_knowledge.file_storage.upload_file(
671
+ file_path="papers/transformer_models.pdf",
672
+ parent_id=main_folder.id,
673
+ tags=["nlp", "transformers", "research"],
674
+ vectorized=True # Ensure the document is vectorized for search
675
+ )
676
+
677
+ print(f"Uploaded paper with ID: {paper.id}")
678
+
679
+ # 3. Make the document accessible to a specific user
680
+ user = client.admin.user.get_user_by_email("researcher@example.com")
681
+ client.admin.ai_knowledge.file_storage.grant_or_revoke_user_access(
682
+ item_id=paper.id,
683
+ user_id=user.id,
684
+ has_access=True,
685
+ access_type=FileAccessType.READ
686
+ )
687
+
688
+ # 4. Query the document
689
+ results = client.admin.queries.run_search_query(
690
+ vector_schema="Documents",
691
+ query_kwargs={
692
+ "content": "attention mechanism in transformer models",
693
+ "limit": 5,
694
+ "full_document": False
695
+ }
696
+ )
697
+
698
+ # 5. Process the results
699
+ for i, result in enumerate(results):
700
+ print(f"Result {i+1}:")
701
+ print(f"Document: {result.get('document_name')}")
702
+ print(f"Content: {result.get('content')[:200]}...")
703
+ print(f"Similarity score: {result.get('_additional', {}).get('score')}")
704
+ print("---")
705
+ ```
706
+
707
+ ### AI Assistant with Function Calls
708
+
709
+ ```python
710
+ from vector_bridge import VectorBridgeClient, FunctionCreate, GPTActions, FunctionParametersStorageStructure, FunctionPropertyStorageStructure
711
+
712
+ # Initialize client with API key
713
+ client = VectorBridgeClient(
714
+ integration_name="Virtual Assistant",
715
+ api_key="your_api_key"
716
+ )
717
+
718
+ # 1. Create a currency conversion function
719
+ currency_function = client.admin.functions.add_function(
720
+ function_data=FunctionCreate(
721
+ function_name="currency_converter",
722
+ description="Convert an amount from one currency to another",
723
+ function_action=GPTActions.CODE_EXEC,
724
+ code="""
725
+ import requests
726
+
727
+ def convert_currency(amount, from_currency, to_currency):
728
+ url = f"https://api.exchangerate-api.com/v4/latest/{from_currency}"
729
+ response = requests.get(url)
730
+ data = response.json()
731
+
732
+ if to_currency not in data['rates']:
733
+ return {"error": f"Currency {to_currency} not found"}
734
+
735
+ conversion_rate = data['rates'][to_currency]
736
+ converted_amount = amount * conversion_rate
737
+
738
+ return {
739
+ "from": from_currency,
740
+ "to": to_currency,
741
+ "amount": amount,
742
+ "converted_amount": converted_amount,
743
+ "rate": conversion_rate
744
+ }
745
+
746
+ result = convert_currency(float(amount), from_currency, to_currency)
747
+ print(result)
748
+ """,
749
+ function_parameters=FunctionParametersStorageStructure(
750
+ properties=[
751
+ FunctionPropertyStorageStructure(
752
+ name="amount",
753
+ description="Amount to convert"
754
+ ),
755
+ FunctionPropertyStorageStructure(
756
+ name="from_currency",
757
+ description="Source currency code (e.g., USD)"
758
+ ),
759
+ FunctionPropertyStorageStructure(
760
+ name="to_currency",
761
+ description="Target currency code (e.g., EUR)"
762
+ )
763
+ ]
764
+ )
765
+ )
766
+ )
767
+
768
+ # 2. Use the AI to interact with a user and call the function when needed
769
+ conversation_id = "user_1234"
770
+
771
+ # User asks about currency conversion
772
+ message_stream = client.ai_message.process_message_stream(
773
+ content="How much is 100 US dollars in euros today?",
774
+ user_id=conversation_id
775
+ )
776
+
777
+ # Print the AI's response
778
+ print("AI Response:")
779
+ for chunk in message_stream.chunks:
780
+ print(chunk, end="")
781
+
782
+ # The AI will automatically call the currency_converter function when needed
783
+
784
+ # User can then continue the conversation
785
+ follow_up_stream = client.ai_message.process_message_stream(
786
+ content="And how much would that be in Japanese yen?",
787
+ user_id=conversation_id
788
+ )
789
+
790
+ print("\n\nFollow-up response:")
791
+ for chunk in follow_up_stream.chunks:
792
+ print(chunk, end="")
793
+ ```
794
+
795
+ ### User Management and Permissions
796
+
797
+ ```python
798
+ from vector_bridge import VectorBridgeClient, SecurityGroupCreate, SecurityGroupUpdate, APIKeyCreate, UserUpdate
799
+
800
+ # Initialize client and authenticate
801
+ client = VectorBridgeClient(integration_name="Admin Portal")
802
+ client.login(username="admin@example.com", password="secure_password")
803
+
804
+ # 1. Create security groups with different permission levels
805
+ editors_group = client.admin.security_groups.create_security_group(
806
+ security_group_data=SecurityGroupCreate(
807
+ group_name="Content Editors",
808
+ description="Can edit and upload content"
809
+ )
810
+ )
811
+
812
+ viewers_group = client.admin.security_groups.create_security_group(
813
+ security_group_data=SecurityGroupCreate(
814
+ group_name="Content Viewers",
815
+ description="Can only view content"
816
+ )
817
+ )
818
+
819
+ # 2. Update permissions for viewers group
820
+ permissions = viewers_group.group_permissions
821
+ permissions.ai_knowledge.read = True
822
+ permissions.ai_knowledge.write = False
823
+ client.admin.security_groups.update_security_group(
824
+ group_id=viewers_group.group_id,
825
+ security_group_data=SecurityGroupUpdate(permissions=permissions)
826
+ )
827
+
828
+ # 3. Add new users
829
+ editor = client.admin.user.add_agent(
830
+ email="editor@example.com",
831
+ first_name="Editor",
832
+ last_name="User",
833
+ password="editor_password"
834
+ )
835
+
836
+ viewer = client.admin.user.add_agent(
837
+ email="viewer@example.com",
838
+ first_name="Viewer",
839
+ last_name="User",
840
+ password="viewer_password"
841
+ )
842
+
843
+ # 4. Assign users to security groups
844
+ client.admin.integrations.add_user_to_integration(
845
+ user_id=editor.id,
846
+ security_group_id=editors_group.group_id
847
+ )
848
+
849
+ client.admin.integrations.add_user_to_integration(
850
+ user_id=viewer.id,
851
+ security_group_id=viewers_group.group_id
852
+ )
853
+
854
+ # 5. Create API keys for users
855
+ editor_key = client.admin.api_keys.create_api_key(
856
+ api_key_data=APIKeyCreate(
857
+ key_name="Editor API Key",
858
+ user_id=editor.id,
859
+ expire_days=90,
860
+ monthly_request_limit=5000
861
+ )
862
+ )
863
+
864
+ viewer_key = client.admin.api_keys.create_api_key(
865
+ api_key_data=APIKeyCreate(
866
+ key_name="Viewer API Key",
867
+ user_id=viewer.id,
868
+ expire_days=90,
869
+ monthly_request_limit=3000
870
+ )
871
+ )
872
+
873
+ print(f"Editor API Key: {editor_key.key}")
874
+ print(f"Viewer API Key: {viewer_key.key}")
875
+ ```
876
+
877
+ ## Error Handling
878
+
879
+ The client raises `HTTPException` when API requests fail:
880
+
881
+ ```python
882
+ from vector_bridge import VectorBridgeClient, HTTPException
883
+
884
+ client = VectorBridgeClient(integration_name="default")
885
+
886
+ try:
887
+ client.login(username="user@example.com", password="wrong_password")
888
+ except HTTPException as e:
889
+ print(f"Authentication failed: {e.status_code} - {e.detail}")
890
+
891
+ try:
892
+ client.admin.functions.get_function_by_name("non_existent_function")
893
+ except HTTPException as e:
894
+ if e.status_code == 404:
895
+ print("Function not found")
896
+ else:
897
+ print(f"Error: {e.detail}")
898
+ ```
899
+
900
+ ## License
901
+
902
+ This project is licensed under the MIT License - see the LICENSE file for details.