Update README to add how to use the server.
This commit is contained in:
+209
@@ -3,6 +3,215 @@ GLiNER_Inference_Server
|
||||
|
||||
GLiNER_Inference_Server - an inference server using FastAPI.
|
||||
|
||||
Quick start
|
||||
-----------
|
||||
|
||||
1. Build the Docker image
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
.. code:: bash
|
||||
|
||||
docker build -t gliner-server .
|
||||
|
||||
2. Run the container
|
||||
~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
.. code:: bash
|
||||
|
||||
docker run -p 8000:8000 gliner-server
|
||||
|
||||
Use PORT enviroment variable to override port:
|
||||
|
||||
.. code:: bash
|
||||
|
||||
docker run -p 9000:9000 -e PORT=9000 gliner-server
|
||||
|
||||
3. Health check
|
||||
~~~~~~~~~~~~~~~
|
||||
|
||||
.. code:: bash
|
||||
|
||||
curl http://localhost:8000/health
|
||||
|
||||
enviroment variables
|
||||
--------------------
|
||||
|
||||
- ``PORT`` - server's port (default: 8000)
|
||||
- ``MODEL_NAME`` - model name HuggingFace (default: knowledgator/gliner-multitask-large-v0.5)
|
||||
- ``MAX_TEXT_LENGTH`` - maximum text length (default: 10000)
|
||||
|
||||
API Endpoints
|
||||
-------------
|
||||
|
||||
1. ``/general`` - Named Entity Recognition
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
**Single request:**
|
||||
|
||||
.. code:: bash
|
||||
|
||||
curl -X POST http://localhost:8000/general \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"text": "Apple Inc. was founded by Steve Jobs in California.",
|
||||
"entities": ["organization", "person", "location"],
|
||||
"threshold": 0.5
|
||||
}'
|
||||
|
||||
**Batch request:**
|
||||
|
||||
.. code:: bash
|
||||
|
||||
curl -X POST http://localhost:8000/general \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"texts": [
|
||||
"Apple Inc. was founded by Steve Jobs in California.",
|
||||
"Microsoft is located in Redmond, Washington."
|
||||
],
|
||||
"entities": ["organization", "person", "location"],
|
||||
"threshold": 0.5
|
||||
}'
|
||||
|
||||
**Response:**
|
||||
|
||||
.. code:: json
|
||||
|
||||
{
|
||||
"outputs": [
|
||||
{
|
||||
"entity": "organization",
|
||||
"span": "Apple Inc.",
|
||||
"start": 0,
|
||||
"end": 10,
|
||||
"score": 0.95
|
||||
},
|
||||
{
|
||||
"entity": "person",
|
||||
"span": "Steve Jobs",
|
||||
"start": 27,
|
||||
"end": 37,
|
||||
"score": 0.92
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
2. ``/relation-extraction`` - Extraction відносин
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
**Single request:**
|
||||
|
||||
.. code:: bash
|
||||
|
||||
curl -X POST http://localhost:8000/relation-extraction \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"text": "Steve Jobs founded Apple Inc. in California.",
|
||||
"relations": ["founded_by", "located_in"],
|
||||
"entities": ["person", "organization", "location"],
|
||||
"threshold": 0.5
|
||||
}'
|
||||
|
||||
**Batch request:**
|
||||
|
||||
.. code:: bash
|
||||
|
||||
curl -X POST http://localhost:8000/relation-extraction \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"texts": [
|
||||
"Steve Jobs founded Apple Inc. in California.",
|
||||
"Bill Gates leads Microsoft."
|
||||
],
|
||||
"relations": ["founded_by", "leads"],
|
||||
"threshold": 0.5
|
||||
}'
|
||||
|
||||
**Response:**
|
||||
|
||||
.. code:: json
|
||||
|
||||
{
|
||||
"outputs": [
|
||||
{
|
||||
"source": {
|
||||
"entity": "organization",
|
||||
"span": "Apple Inc.",
|
||||
"start": 20,
|
||||
"end": 30,
|
||||
"score": 0.95
|
||||
},
|
||||
"relation": "founded_by",
|
||||
"target": {
|
||||
"entity": "person",
|
||||
"span": "Steve Jobs",
|
||||
"start": 0,
|
||||
"end": 10,
|
||||
"score": 0.92
|
||||
},
|
||||
"score": 0.88
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
3. ``/summarization`` - Summarization
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
**Single request:**
|
||||
|
||||
.. code:: bash
|
||||
|
||||
curl -X POST http://localhost:8000/summarization \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"text": "Artificial intelligence is transforming industries worldwide. Machine learning enables computers to learn from data. Deep learning uses neural networks for complex tasks.",
|
||||
"threshold": 0.5
|
||||
}'
|
||||
|
||||
**Batch request:**
|
||||
|
||||
.. code:: bash
|
||||
|
||||
curl -X POST http://localhost:8000/summarization \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"texts": [
|
||||
"First document about AI and ML...",
|
||||
"Second document about data science..."
|
||||
],
|
||||
"threshold": 0.5
|
||||
}'
|
||||
|
||||
Error handling
|
||||
--------------
|
||||
|
||||
All errors are returned in the standard format:
|
||||
|
||||
.. code:: json
|
||||
|
||||
{
|
||||
"error": {
|
||||
"code": "INVALID_INPUT",
|
||||
"message": "Provide either 'text' or 'texts', not both",
|
||||
"details": {}
|
||||
}
|
||||
}
|
||||
|
||||
Error codes
|
||||
~~~~~~~~~~~
|
||||
|
||||
- ``INVALID_INPUT`` (400) - invalid input data
|
||||
- ``INTERNAL_ERROR`` (500) - internal server error
|
||||
|
||||
Validation
|
||||
----------
|
||||
|
||||
- **text** or **texts** - one of them is mandatory (but not both)
|
||||
- **entities/relations** - cannot be empty lists
|
||||
- **threshold** - value from 0.0 to 1.0
|
||||
- **texts** - cannot be an empty list
|
||||
- The maximum length of the text is controlled through ``MAX_TEXT_LENGTH``
|
||||
|
||||
Author
|
||||
======
|
||||
|
||||
|
||||
Reference in New Issue
Block a user