token_classification
Identify and extract named entities from text using named entity recognition (NER) to categorize entities like people, organizations, and locations.
Instructions
Perform named entity recognition (NER) on text using DeepInfra OpenAI-compatible API.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| model | No | ||
| text | Yes |
Implementation Reference
- src/mcp_deepinfra/server.py:241-262 (handler)The core handler function for the 'token_classification' tool, decorated with @app.tool() for MCP registration. It performs named entity recognition (NER) on input text using a prompted completions call to the configured DeepInfra model.@app.tool() async def token_classification(text: str) -> str: """Perform token classification (NER) using DeepInfra OpenAI-compatible API.""" model = DEFAULT_MODELS["token_classification"] prompt = f"""Perform named entity recognition on the following text. Identify all named entities (persons, organizations, locations, dates, etc.) and classify them. Provide your analysis in JSON format with an array of entities, each having 'entity', 'type', and 'position' fields. Text: {text} Response format: {{"entities": [{{"entity": "entity_name", "type": "PERSON/ORG/LOC/DATE/etc", "position": [start, end]}}]}}""" try: response = await client.completions.create( model=model, prompt=prompt, max_tokens=500, temperature=0.1, ) if response.choices: return response.choices[0].text else: return "Unable to perform token classification" except Exception as e: return f"Error performing token classification: {type(e).__name__}: {str(e)}"
- src/mcp_deepinfra/server.py:40-40 (helper)Configuration for the default model used by the token_classification tool in the DEFAULT_MODELS dictionary."token_classification": os.getenv("MODEL_TOKEN_CLASSIFICATION", "microsoft/DialoGPT-medium"),
- src/mcp_deepinfra/server.py:241-241 (registration)The @app.tool() decorator registers the token_classification function as an MCP tool.@app.tool()