Skip to content

Chat API

The Chat API provides endpoints for managing chat sessions and messages. Below are the available endpoints along with examples of how to use them in various programming languages:

  • Create a New Chat Session
  • Continue a Chat Session
  • Delete a Chat Session
  • Get the Chat Session History
  • List all Chat Sessions for the User
  • Send feedback for the Chat Session
  • Regenerate the Last Response

Each section includes the endpoint details, request methods, descriptions, and example code snippets in Bash, Python, and JavaScript.

Create a New Chat Session

  • Endpoint: https://api.ia-2024b.algo-rythmn.ai/v1/chat/submit
  • Method: POST
  • Description: Create a new chat session and return a chat session ID.
  • Request Body:
  • model: The model to use for the chat session. Current models available are:
    • IA-1: The general chat model to retrieve the general information.
    • IA-2: The chat model provide the EDA and PSA information.
  • message: A ChatMessage object containing the message details.
  • additional_config: (Optional) Additional configuration for the chat session. This is optional and can include the following parameters:
    • companyIds: A company ID to filter the data.

Example

curl -X POST "https://api.ia-2024b.algo-rythmn.ai/v1/chat/submit" \
-H "agmri-access-token: $YOUR_AGMRI_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
    "model": "IA-1",
    "message": {
        "role": "user",
        "content": "Hello, how are you?"
    },
    "additional_config": {
        "companyIds": ["12345"]
    } // Optional
}'
import requests

response = requests.post(
    "https://api.ia-2024b.algo-rythmn.ai/v1/chat/submit",
    json={
        "model": "IA-1",
        "message": {
            "role": "user",
            "content": "Hello, how are you?"
        },
        "additional_config": {
            "companyIds": ["12345"]
        } # Optional
    },
    headers={"agmri-access-token": YOUR_AGMRI_ACCESS_TOKEN}
)
print(response.json())
fetch("https://api.ia-2024b.algo-rythmn.ai/v1/chat/submit", {
    method: "POST",
    body: JSON.stringify({
        model: "IA-1",
        message: {
            role: "user",
            content: "Hello, how are you?"
        },
        additional_config: {
            companyIds: ["12345"]
        } // Optional
    }),
    headers: {
        agmri-access-token: `${YOUR_AGMRI_ACCESS_TOKEN}`
    }
})
.then(response => response.json());

Response

{
    "id": "3b59b162-57be-4fc2-bf6e-1e33ad7a1bd0",
    "created": 1677652288,
    "model": "IA-1",
    "system_fingerprint": "fp_dfe0be2e",
    "messages": [
        {
            "index": 0,
            "messages": {
                "role": "user",
                "content": "Hello, how are you?",
            }
        },
        {
            "index": 1,
            "messages": {
                "role": "assistant",
                "content": "I am fine, thank you.",
            }
        }
    ],
    // The export HTML files will be available in the export_files list
    "export_files": [
        {
            "html_file_id": "a3d7c4eb-f0c9-45e3-a337-b69a98260345",
            "html_content": "<html>...</html>",
            "html_description": "This is a chart",
        },
        ...
    ]
}

Create a New Chat Session with Streaming

  • Endpoint: https://api.ia-2024b.algo-rythmn.ai/v1/chat/stream_submit
  • Method: POST
  • Description: Create a new chat session with streaming and return a chat session ID.
  • Request Body:
    • model: The model to use for the chat session.
    • message: A ChatMessage object containing the message details.

Example

curl -N POST "https://api.ia-2024b.algo-rythmn.ai/v1/chat/stream_submit" \
-H "agmri-access-token: $YOUR_AGMRI_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
    "model": "IA-1",
    "message": {
        "role": "user",
        "content": "Hello, how are you?"
    }
}'
import requests

response = requests.post(
    "https://api.ia-2024b.algo-rythmn.ai/v1/chat/stream_submit",
    json={
        "model": "IA-1",
        "message": {
            "role": "user",
            "content": "Hello, how are you?"
        }
    },
    headers={"agmri-access-token": YOUR_AGMRI_ACCESS_TOKEN},
    steam=True,
)
for chunk in response.iter_content(chunk_size=None):
    print(chunk)
fetch("https://api.ia-2024b.algo-rythmn.ai/v1/chat/stream_submit", {
    method: "POST",
    body: JSON.stringify({
        model: "IA-1",
        message: {
            role: "user",
            content: "Hello, how are you?"
        }
    }),
    headers: {
        agmri-access-token: `${YOUR_AGMRI_ACCESS_TOKEN}`
    }
})
.then(response => response.body.getReader().read())
.then(({ value, done }) => {
    if (!done) {
        console.log(value);
    }
});

Response

{"id": "...", "created": 1677652288, "model": "IA-1", "system_fingerprint": "9182736450", "message_chunks": [{"index": 0, "delta": {"content": "I"}, "finish_reason": null}]}

{"id": "...", "created": 1677652288, "model": "IA-1", "system_fingerprint": "9182736450", "message_chunks": [{"index": 0, "delta": {"content": " am"}, "finish_reason": null}]}

...

{"id": "...", "created": 1677652288, "model": "IA-1", "system_fingerprint": "9182736450", "message_chunks": [{"index": 0, "delta": {}, "finish_reason": "stop"}]}

// The last chunks will contain the complete final response, such as:
{
    "id": "...",
    "created": 1677652288,
    "model": "IA-1",
    "system_fingerprint": "9182736450",
    "messages": [
        {
            "index": 0,
            "messages": {
                "role": "user",
                "content": "Hello, how are you?",
            }
        },
        {
            "index": 1,
            "messages": {
                "role": "assistant",
                "content": "I am fine, thank you.",
            }
        }
    ]
}

// The export HTML files will be available in the export_files list
{
    "id": "...",
    "created": 1677652288,
    "model": "IA-1",
    "system_fingerprint": "9182736450",
    "export_files": [
        {
            "html_file_id": "a3d7c4eb-f0c9-45e3-a337-b69a98260345",
            "html_content": "<html>...</html>",
            "html_description": "This is a chart",
        },
        ...
    ]
}

Continue a Chat Session

  • Endpoint: https://api.ia-2024b.algo-rythmn.ai/v1/chat/submit
  • Method: POST
  • Description: Continue a chat session by providing the chat session id.
  • Request Body:
    • model: The model to use for the chat session.
    • chat_id: The ID of the chat session.
    • message: ChatMessage object containing the message details.

Example

curl -X POST "https://api.ia-2024b.algo-rythmn.ai/v1/chat/submit" \
-H "agmri-access-token: $YOUR_AGMRI_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
    "model": "IA-1",
    "chat_id": "3b59b162-57be-4fc2-bf6e-1e33ad7a1bd0",
    "message": {
        "role": "user",
        "content": "How can you help me?"
    }
}'
import requests

response = requests.post(
    "https://api.ia-2024b.algo-rythmn.ai/v1/chat/submit",
    json={
        "model": "IA-1",
        "chat_id": "3b59b162-57be-4fc2-bf6e-1e33ad7a1bd0",
        "message": {
            "role": "user",
            "content": "How can you help me?"
        }
    },
    headers={"agmri-access-token": YOUR_AGMRI_ACCESS_TOKEN}
)
print(response.json())
fetch("https://api.ia-2024b.algo-rythmn.ai/v1/chat/submit", {
    method: "POST",
    body: JSON.stringify({
        model: "IA-1",
        chat_id: "3b59b162-57be-4fc2-bf6e-1e33ad7a1bd0",
        message: {
            role: "user",
            content: "How can you help me?"
        }
    }),
    headers: {
        agmri-access-token: `${YOUR_AGMRI_ACCESS_TOKEN}`
    }
})
.then(response => response.json());

Response

{
    "id": "3b59b162-57be-4fc2-bf6e-1e33ad7a1bd0",
    "created": 1677652288,
    "model": "IA-1",
    "system_fingerprint": "fp_6f8ff704",
    "messages": [
        {
            "index": 0,
            "messages": {
                "role": "user",
                "content": "Hello, how are you?",
            }
        },
        {
            "index": 1,
            "messages": {
                "role": "assistant",
                "content": "I am fine, thank you.",
            }
        },
        {
            "index": 2,
            "messages": {
                "role": "user",
                "content": "How can you help me?",
            }
        },
        {
            "index": 3,
            "messages": {
                "role": "assistant",
                "content": "I'm professional AGMRI assistant. I can help you with any questions you have.",
            }
        }
    ]
}

Delete a Chat Session

  • Endpoint: https://api.ia-2024b.algo-rythmn.ai/v1/chat/delete
  • Method: DELETE
  • Description: Delete a chat session by providing the chat session ID.
  • Request Parameters:
    • chat_id: The ID of the chat session to delete.

Example

curl -X DELETE "https://api.ia-2024b.algo-rythmn.ai/v1/chat/delete?chat_id=3b59b162-57be-4fc2-bf6e-1e33ad7a1bd0" \
-H "agmri-access-token: $YOUR_AGMRI_ACCESS_TOKEN"
import requests

response = requests.delete(
    "https://api.ia-2024b.algo-rythmn.ai/v1/chat/delete",
    params={"chat_id": "3b59b162-57be-4fc2-bf6e-1e33ad7a1bd0"},
    headers={"agmri-access-token": YOUR_AGMRI_ACCESS_TOKEN}
)
print(response.status_code)
fetch("https://api.ia-2024b.algo-rythmn.ai/v1/chat/delete", {
    method: "DELETE",
    params: {
        chat_id: "3b59b162-57be-4fc2-bf6e-1e33ad7a1bd0"
    }
    headers: {
        agmri-access-token: `${YOUR_AGMRI_ACCESS_TOKEN}`
    }
})
.then(response => response.status);

Response

204

Get the Chat Session History

  • Endpoint: https://api.ia-2024b.algo-rythmn.ai/v1/chat/history
  • Method: GET
  • Description: Retrieve the history of a chat session by providing the chat session id.

Example

curl -X GET "https://api.ia-2024b.algo-rythmn.ai/v1/chat/history?chat_id=3b59b162-57be-4fc2-bf6e-1e33ad7" \
-H "agmri-access-token: $YOUR_AGMRI_ACCESS_TOKEN" \
import requests

response = requests.get(
    "https://api.ia-2024b.algo-rythmn.ai/v1/chat/history",
    params={"chat_id": "3b59b162-57be-4fc2-bf6e-1e33ad7"},
    headers={"agmri-access-token": YOUR_AGMRI_ACCESS_TOKEN}
)
print(response.json())
fetch("https://api.ia-2024b.algo-rythmn.ai/v1/chat/history?chat_id=3b59b162-57be-4fc2-bf6e-1e33ad7", {
    method: "GET",
    headers: {
        agmri-access-token: `${YOUR_AGMRI_ACCESS_TOKEN}`
    }
})
.then(response => response.json());

Response

{
    "id": "3b59b162-57be-4fc2-bf6e-1e33ad7a1bd0",
    "created": 1677652288,
    "model": "IA-1",
    "system_fingerprint": "fp_6f8ff704",
    "messages": [
        {
            "index": 0,
            "messages": {
                "role": "user",
                "content": "Hello, how are you?",
            }
        },
        {
            "index": 1,
            "messages": {
                "role": "assistant",
                "content": "I am fine, thank you.",
            }
        },
        {
            "index": 2,
            "messages": {
                "role": "user",
                "content": "How can you help me?",
            }
        },
        {
            "index": 3,
            "messages": {
                "role": "assistant",
                "content": "I'm professional AGMRI assistant. I can help you with any questions you have.",
            }
        }
    ]
}

List all chat sessions for the user

  • Endpoint: https://api.ia-2024b.algo-rythmn.ai/v1/chat/list
  • Method: GET
  • Description: List all chat sessions for the user.
  • Request Parameters:
    • companyIds: (Optional) A company IDs used to filter the data.

Example

curl -X GET "https://api.ia-2024b.algo-rythmn.ai/v1/chat/list \
-H "agmri-access-token: $YOUR_AGMRI_ACCESS_TOKEN" \
-d '{
    "companyIds": ["12345"]
}'
import requests

response = requests.get(
    "https://api.ia-2024b.algo-rythmn.ai/v1/chat/list",
    headers={"agmri-access-token": YOUR_AGMRI_ACCESS_TOKEN},
    params={"companyIds": ["12345"]}  # Optional
)
print(response.json())
fetch("https://api.ia-2024b.algo-rythmn.ai/v1/chat/list", {
    method: "GET",
    headers: {
        agmri-access-token: `${YOUR_AGMRI_ACCESS_TOKEN}`
    },
    params: {
        companyIds: ["12345"]  // Optional
    }
})
.then(response => response.json());

Response

[
    {
        "model": "IA-1",
        "user_id": "33c74fcc-46cc-4785-8245-83d33c04c8f9",
        "modified_time": "2024-12-01T07:06:30.946441",
        "chat_id": "3b59b162-57be-4fc2-bf6e-1e33ad7a1bd0",
        "remark": null,
        "additional_config": {"companyIds": ["12345"]},
        "created_time": "2024-12-01T07:01:12.944541",
    },
    {
        "model": "IA-1",
        ...
    },
    ...
]

Send feedback for the chat session

  • Endpoint: https://api.ia-2024b.algo-rythmn.ai/v1/chat/feedback
  • Method: POST
  • Description: Send feedback for the chat session.
  • Request Body:
    • chat_id: The ID of the chat session.
    • is_positive: A boolean value indicating whether the feedback is positive or negative.
    • comment: An optional comment for the feedback.

Example

curl -X POST "https://api.ia-2024b.algo-rythmn.ai/v1/chat/feedback" \
-H "Content-Type: application/json" \
-d '{
    "chat_id": "3b59b162-57be-4fc2-bf6e-1e33ad7a1bd0",
    "is_positive": true,
    "comment": "Great chat session!"
}'
import requests

response = requests.post(
    "https://api.ia-2024b.algo-rythmn.ai/v1/chat/feedback",
    json={
        "chat_id": "3b59b162-57be-4fc2-bf6e-1e33ad7a1bd0",
        "is_positive": True,
        "comment": "Great chat session!"    # Optional
    }
)
print(response.status_code)
fetch("https://api.ia-2024b.algo-rythmn.ai/v1/chat/feedback", {
    method: "POST",
    body: JSON.stringify({
        chat_id: "3b59b162-57be-4fc2-bf6e-1e33ad7a1bd0",
        is_positive: true,
        comment: "Great chat session!"    // Optional
    }),
    headers: {
        "Content-Type": "application/json"
    }
})
.then(response => response.status);

Response

{
    "message":"Feedback submitted successfully!",
    "feedback_id":"86dfe040-4e5e-4b3c-9907-d4f0ab116b0d"
}

Regenerate the last response

To regenerate the last response, you can use the following endpoint:

  • Endpoint: https://api.ia-2024b.algo-rythmn.ai/v1/chat/regenerate_message
  • Method: GET
  • Description: Regenerate the last response of a chat session by providing the chat session id.
  • Request Parameters:
    • chat_id: The ID of the chat session.

Example

curl -X GET "https://api.ia-2024b.algo-rythmn.ai/v1/chat/regenerate_message?chat_id=3b59b162-57be-4fc2-bf6e-1e33ad7a1bd0" \
-H "agmri-access-token: $YOUR_AGMRI_ACCESS_TOKEN"
import requests

response = requests.get(
    "https://api.ia-2024b.algo-rythmn.ai/v1/chat/regenerate_message",
    params={"chat_id": "3b59b162-57be-4fc2-bf6e-1e33ad7a1bd0"},
    headers={"agmri-access-token": YOUR_AGMRI_ACCESS_TOKEN}
)
print(response.json())
fetch("https://api.ia-2024b.algo-rythmn.ai/v1/chat/regenerate_message?chat_id=3b59b162-57be-4fc2-bf6e-1e33ad7a1bd0", {
    method: "GET",
    headers: {
        agmri-access-token: `${YOUR_AGMRI_ACCESS_TOKEN}`
    }
})
.then(response => response.json());

Response

{
    "id": "3b59b162-57be-4fc2-bf6e-1e33ad7a1bd0",
    "created": 1677652288,
    "model": "IA-1",
    "system_fingerprint": "fp_6f8ff704",
    "messages": [
        {
            "index": 0,
            "messages": {
                "role": "user",
                "content": "Hello, how are you?",
            }
        },
        {
            "index": 1,
            "messages": {
                "role": "assistant",
                "content": "I am fine, thank you.",
            }
        },
        {
            "index": 2,
            "messages": {
                "role": "user",
                "content": "How can you help me?",
            }
        },
        {
            "index": 3,         // The regenerated message
            "messages": {
                "role": "assistant",
                "content": "I am AGMRI assistant. I can help you with any questions you have.",
            }
        }
    ]
}