Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix REST API documentation #591

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

devin-ai-integration[bot]
Copy link
Contributor

@devin-ai-integration devin-ai-integration bot commented Dec 18, 2024

🔍 Review Summary

Purpose

To enhance testing reliability and documentation clarity in the REST API integration for developers. This update includes a comprehensive REST API test script, revised API documentation, and fixes critical database constraint requirements.

Changes

Critical Fixes

  • Added required 'id' field to event payloads to resolve database constraint error
  • Added required 'session_id' field to event payloads to resolve agents table constraint error
  • Updated all event examples to include UUID-formatted 'id' field and proper session_id
  • Fixed potential null value constraint violations in both actions and agents tables

New Feature

  • Introduced a comprehensive REST API test script under tests/test_rest_api.py

Test Enhancements

  • Utilized requests_mock to simulate API responses
  • Added comprehensive test cases for LLM and tool events with proper 'id' and 'session_id' fields
  • Improved test coverage for event creation endpoint

Documentation Updates

  • Updated REST API documentation with required 'id' and 'session_id' fields in all event payloads
  • Added examples showing proper UUID generation for event IDs
  • Provided clear guidance on event payload structure
  • Included detailed Python examples with error handling

Impact

  • Fixes critical database constraint errors for event and agent creation
  • Enhances testing reliability
  • Provides clearer REST API documentation for developers
  • Facilitates smoother API integration experience

Link to Devin run: https://app.devin.ai/sessions/cd9b1ff1a5ad4a8da4519e32039d768c

devin-ai-integration bot and others added 4 commits December 18, 2024 02:04
Co-Authored-By: Alex Reibman <[email protected]>
- Add consistent /v2/ prefix to all endpoints
- Fix payload structures (session_id instead of id)
- Add proper headers (Content-Type with charset, Accept)
- Add comprehensive error handling documentation
- Update Python example with error handling

Co-Authored-By: Alex Reibman <[email protected]>
Copy link
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR
  • Look at CI failures and help fix them

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

Add "(aside)" to your comment to have me ignore it.

@devin-ai-integration devin-ai-integration bot changed the title docs: update REST API documentation to match SDK implementation Fix REST API documentation Dec 18, 2024
Copy link

Walkthrough

This update introduces a comprehensive REST API test script designed to validate various endpoints, such as session creation, event creation, and session updates. The script employs requests_mock to simulate API responses, allowing tests to run without actual server interaction. Additionally, the REST API documentation has been revised to align with the SDK implementation, ensuring consistent endpoint prefixes, payload structure adjustments, and enhanced error handling guidelines. These changes aim to improve testing reliability and documentation clarity for developers integrating with the API.

Changes

File(s) Summary
tests/test_rest_api.py Introduced a comprehensive REST API test script with methods for session creation, event creation, and session updates. Integrated requests_mock for simulating API responses, ensuring tests run independently of the server. Adjusted header configurations and encoded payloads as bytes to align with SDK implementation.
docs/v1/integrations/rest.mdx Updated REST API documentation to align with SDK implementation, ensuring consistent endpoint prefixes, corrected payload structures, and comprehensive error handling guidelines. Added detailed Python examples with error handling.

🔗 Related PRs

Instructions

Emoji Descriptions:

  • ⚠️ Potential Issue - May require further investigation.
  • 🔒 Security Vulnerability - Fix to ensure system safety.
  • 💻 Code Improvement - Suggestions to enhance code quality.
  • 🔨 Refactor Suggestion - Recommendations for restructuring code.
  • ℹ️ Others - General comments and information.

Interact with the Bot:

  • Send a message or request using the format:
    @bot + *your message*
Example: @bot Can you suggest improvements for this code?
  • Help the Bot learn by providing feedback on its responses.
    @bot + *feedback*
Example: @bot Do not comment on `save_auth` function !

Execute a command using the format:

@bot + */command*

Example: @bot /updateCommit

Available Commands:

  • /updateCommit ✨: Apply the suggested changes and commit them (or Click on the Github Action button to apply the changes !)
  • /updateGuideline 🛠️: Modify an existing guideline.
  • /addGuideline ➕: Introduce a new guideline.

Tips for Using @bot Effectively:

  • Specific Queries: For the best results, be specific with your requests.
    🔍 Example: @bot summarize the changes in this PR.
  • Focused Discussions: Tag @bot directly on specific code lines or files for detailed feedback.
    📑 Example: @bot review this line of code.
  • Managing Reviews: Use review comments for targeted discussions on code snippets, and PR comments for broader queries about the entire PR.
    💬 Example: @bot comment on the entire PR.

Need More Help?

📚 Visit our documentation for detailed guides on using Entelligence.AI.
🌐 Join our community to connect with others, request features, and share feedback.
🔔 Follow us for updates on new features and improvements.

Comment on lines 251 to 262
<CodeGroup>
```bash curl
curl -X POST https://api.agentops.ai/v2/update_session \
-H "Content-Type: application/json" \
-H "Content-Type: application/json; charset=UTF-8" \
-H "Accept: */*" \
-H "Authorization: Bearer your_jwt_token" \
-d '{
"session": {
"id": "550e8400-e29b-41d4-a716-446655440000",
"session_id": "550e8400-e29b-41d4-a716-446655440000",
"end_timestamp": "2024-03-14T12:05:00Z",
"end_state": "Success",
"end_state_reason": "Task successfully completed",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential Issue:

Ensure Backward Compatibility for API Payload Change
The change from 'id' to 'session_id' in the API payload is a significant modification that can disrupt existing integrations. This change should be clearly documented and communicated to all API users to prevent unexpected failures.

Actionable Steps:

  • Documentation: Update the API documentation to reflect this change and highlight it as a breaking change.
  • Communication: Notify all users through appropriate channels (e.g., email, developer portal) about the change and its implications.
  • Backward Compatibility: Consider implementing a temporary backward compatibility layer that accepts both 'id' and 'session_id' to give users time to transition.
  • Migration Guide: Provide a detailed migration guide to assist users in updating their integrations.

These steps will help mitigate the impact of this change and ensure a smoother transition for users. 📢


Comment on lines 291 to 306
<CodeGroup>
```bash curl
curl -X POST https://api.agentops.ai/v2/create_events \
-H "Content-Type: application/json" \
-H "Content-Type: application/json; charset=UTF-8" \
-H "Accept: */*" \
-H "Authorization: Bearer your_jwt_token" \
-d '{
"events": [
{
"type": "llm",
"event_type": "llm",
"init_timestamp": "2024-03-14T12:01:00Z",
"end_timestamp": "2024-03-14T12:01:02Z",
"session_id": "550e8400-e29b-41d4-a716-446655440000",
"model": "gpt-4",
"prompt": [
{"role": "system", "content": "You are a helpful assistant"},

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential Issue:

Potential Breaking Change in JSON Payload Key
The change from 'type' to 'event_type' in the JSON payload is a significant modification that could lead to breaking changes if the receiving API is not updated to handle the new key. This could result in failures in data processing or rejection of requests.

Actionable Steps:

  • Verify API Compatibility: Confirm with the API documentation or the API development team that the change from 'type' to 'event_type' is intentional and supported.
  • System Update: Ensure that all parts of the system interacting with this API are updated to use 'event_type' instead of 'type'.
  • Testing: Conduct thorough testing to ensure that the change does not introduce any regressions or failures in the system.

This change is critical and should be handled with caution to avoid disruptions in service.


Comment on lines 251 to 262
<CodeGroup>
```bash curl
curl -X POST https://api.agentops.ai/v2/update_session \
-H "Content-Type: application/json" \
-H "Content-Type: application/json; charset=UTF-8" \
-H "Accept: */*" \
-H "Authorization: Bearer your_jwt_token" \
-d '{
"session": {
"id": "550e8400-e29b-41d4-a716-446655440000",
"session_id": "550e8400-e29b-41d4-a716-446655440000",
"end_timestamp": "2024-03-14T12:05:00Z",
"end_state": "Success",
"end_state_reason": "Task successfully completed",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential Issue:

Potential Breaking Change in JSON Structure
The change from 'id' to 'session_id' in the JSON structure is a significant modification that could lead to compatibility issues. This change might break existing functionality if other parts of the codebase or external systems rely on the original 'id' field.

Actionable Steps:

  • Review Dependencies: Thoroughly review all parts of the codebase and any external systems that interact with this JSON structure to ensure they are updated to use 'session_id' instead of 'id'.
  • Backward Compatibility: Consider implementing a backward compatibility layer or a migration path to handle systems that still expect the 'id' field.
  • Testing: Conduct comprehensive testing to ensure that the change does not introduce any regressions or unexpected behavior.
  • Documentation: Update any relevant documentation to reflect this change, ensuring that all stakeholders are aware of the new structure.

By following these steps, you can mitigate the risk of breaking existing functionality and ensure a smooth transition to the new JSON structure. 🚀


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

0 participants