JSON Mode
1. Use Cases
Currently, the SiliconFlow large model API platform, SiliconCloud, by default generates unstructured text. However, in certain application scenarios, you may want the model to output content in a structured format, but simply instructing the model via prompts might not yield the desired structured output.
As a standardized and lightweight data exchange format, JSON mode is an important feature for enabling structured outputs from large model APIs. When you make a request to the large model API, the results returned by the model are presented in JSON format, which is easy for humans to read and write, and also easy for machines to parse and generate.
Now, on the SiliconCloud platform, apart from the DeepSeek R1 series and V3 models, most other major language models support JSON mode. This allows the model to output strings in JSON format, ensuring that the model produces outputs in the expected structure, facilitating subsequent logical parsing of the output content.
For example, you can now use the SiliconCloud API to attempt structured outputs for the following cases:
- Build a news database from company-related reports, including news titles, links, etc.
- Extract sentiment analysis structures from product purchase reviews, including sentiment polarity (positive, negative, neutral), sentiment intensity, sentiment keywords, etc.
- Extract product lists from purchase histories, including product information, reasons for recommendation, prices, promotional details, etc.
2. How to Use
Add the following to your request:
3. Supported Models
Currently, online models, except for the DeepSeek R1 series and V3 models, support the above parameter.
max_tokens
appropriately to prevent JSON strings from being truncated.4. Example Usage
Below is an example using OpenAI:
The model will output: