Azure OpenAI Swagger Validation Failure with APIM

news2025/1/10 13:22:46

题意:Azure OpenAI Swagger 验证失败与 APIM

问题背景:

I'm converting the Swagger for Azure OpenAI API Version 2023-07-01-preview from json to yaml

我正在将 Azure OpenAI API 版本 2023-07-01-preview 的 Swagger 从 JSON 转换为 YAML。

My Swagger looks like this        我的 Swagger 看起来是这样的

openapi: 3.0.1
info:
  title: OpenAI Models API
  description: ''
  version: '123'
servers:
  - url: https://def.com/openai
paths:
  /gpt-35-turbo/chat/completions:
    post:
      tags:
        - openai
      summary: Creates a completion for the chat message
      description: gpt-35-turbo-chat-completion
      operationId: GPT_35_Turbo_ChatCompletions_Create
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/createChatCompletionRequest'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/createChatCompletionResponse'
          headers:
            apim-request-id:
              description: Request ID for troubleshooting purposes
              schema:
                type: string
        default:
          description: Service unavailable
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/errorResponse'
          headers:
            apim-request-id:
              description: Request ID for troubleshooting purposes
              schema:
                type: string
components:
  schemas:
    errorResponse:
      type: object
      properties:
        error:
          $ref: '#/components/schemas/error'
    errorBase:
      type: object
      properties:
        code:
          type: string
        message:
          type: string
    error:
      type: object
      allOf:
        - $ref: '#/components/schemas/errorBase'
      properties:
        code:
          type: string
        message:
          type: string
        param:
          type: string
        type:
          type: string
        inner_error:
          $ref: '#/components/schemas/innerError'
    innerError:
      description: Inner error with additional details.
      type: object
      properties:
        code:
          $ref: '#/components/schemas/innerErrorCode'
        content_filter_results:
          $ref: '#/components/schemas/contentFilterResults'
    innerErrorCode:
      description: Error codes for the inner error object.
      enum:
        - ResponsibleAIPolicyViolation
      type: string
      x-ms-enum:
        name: InnerErrorCode
        modelAsString: true
        values:
          - value: ResponsibleAIPolicyViolation
            description: The prompt violated one of more content filter rules.  
    contentFilterResult:
      type: object
      properties:
        severity:
          type: string
          enum:
            - safe
            - low
            - medium
            - high
          x-ms-enum:
            name: ContentFilterSeverity
            modelAsString: true
            values:
              - value: safe
                description: >-
                  General content or related content in generic or non-harmful
                  contexts.
              - value: low
                description: Harmful content at a low intensity and risk level.
              - value: medium
                description: Harmful content at a medium intensity and risk level.
              - value: high
                description: Harmful content at a high intensity and risk level.
        filtered:
          type: boolean
      required:
        - severity
        - filtered
    contentFilterResults:
      type: object
      description: >-
        Information about the content filtering category (hate, sexual,
        violence, self_harm), if it has been detected, as well as the severity
        level (very_low, low, medium, high-scale that determines the intensity
        and risk level of harmful content) and if it has been filtered or not.
      properties:
        sexual:
          $ref: '#/components/schemas/contentFilterResult'
        violence:
          $ref: '#/components/schemas/contentFilterResult'
        hate:
          $ref: '#/components/schemas/contentFilterResult'
        self_harm:
          $ref: '#/components/schemas/contentFilterResult'
        error:
          $ref: '#/components/schemas/errorBase'
    promptFilterResult:
      type: object
      description: Content filtering results for a single prompt in the request.
      properties:
        prompt_index:
          type: integer
        content_filter_results:
          $ref: '#/components/schemas/contentFilterResults'
    promptFilterResults:
      type: array
      description: >-
        Content filtering results for zero or more prompts in the request. In a
        streaming request, results for different prompts may arrive at different
        times or in different orders.
      items:
        $ref: '#/components/schemas/promptFilterResult'  
    createChatCompletionRequest:
      type: object
      allOf:
        - $ref: '#/components/schemas/chatCompletionsRequestCommon'
        - properties:
            messages:
              description: >-
                A list of messages comprising the conversation so far. [Example
                Python
                code](https://github.com/openai/openai-cookbook/blob/main/examples/How_to_format_inputs_to_ChatGPT_models.ipynb).
              type: array
              minItems: 1
              items:
                $ref: '#/components/schemas/chatCompletionRequestMessage'
            functions:
              description: A list of functions the model may generate JSON inputs for.
              type: array
              minItems: 1
              items:
                $ref: '#/components/schemas/chatCompletionFunctions'
            function_call:
              description: >-
                Controls how the model responds to function calls. "none" means
                the model does not call a function, and responds to the
                end-user. "auto" means the model can pick between an end-user or
                calling a function.  Specifying a particular function via
                `{"name":\ "my_function"}` forces the model to call that
                function. "none" is the default when no functions are present.
                "auto" is the default if functions are present.
              oneOf:
                - type: string
                  enum:
                    - none
                    - auto
                - type: object
                  properties:
                    name:
                      type: string
                      description: The name of the function to call.
                  required:
                    - name
            'n':
              type: integer
              minimum: 1
              maximum: 128
              default: 1
              example: 1
              nullable: true
              description: >-
                How many chat completion choices to generate for each input
                message.
      required:
        - messages    
    chatCompletionsRequestCommon:
      type: object
      properties:
        temperature:
          description: >-
            What sampling temperature to use, between 0 and 2. Higher values
            like 0.8 will make the output more random, while lower values like
            0.2 will make it more focused and deterministic.

            We generally recommend altering this or `top_p` but not both.
          type: number
          minimum: 0
          maximum: 2
          default: 1
          example: 1
          nullable: true
        top_p:
          description: >-
            An alternative to sampling with temperature, called nucleus
            sampling, where the model considers the results of the tokens with
            top_p probability mass. So 0.1 means only the tokens comprising the
            top 10% probability mass are considered.

            We generally recommend altering this or `temperature` but not both.
          type: number
          minimum: 0
          maximum: 1
          default: 1
          example: 1
          nullable: true
        stop:
          description: Up to 4 sequences where the API will stop generating further tokens.
          oneOf:
            - type: string
              nullable: true
            - type: array
              items:
                type: string
                nullable: false
              minItems: 1
              maxItems: 4
              description: Array minimum size of 1 and maximum of 4
          default: null
        max_tokens:
          description: >-
            The maximum number of tokens allowed for the generated answer. By
            default, the number of tokens the model can return will be (4096 -
            prompt tokens).
          type: integer
          default: 4096
        presence_penalty:
          description: >-
            Number between -2.0 and 2.0. Positive values penalize new tokens
            based on whether they appear in the text so far, increasing the
            model's likelihood to talk about new topics.
          type: number
          default: 0
          minimum: -2
          maximum: 2
        frequency_penalty:
          description: >-
            Number between -2.0 and 2.0. Positive values penalize new tokens
            based on their existing frequency in the text so far, decreasing the
            model's likelihood to repeat the same line verbatim.
          type: number
          default: 0
          minimum: -2
          maximum: 2
        logit_bias:
          description: >-
            Modify the likelihood of specified tokens appearing in the
            completion. Accepts a json object that maps tokens (specified by
            their token ID in the tokenizer) to an associated bias value from
            -100 to 100. Mathematically, the bias is added to the logits
            generated by the model prior to sampling. The exact effect will vary
            per model, but values between -1 and 1 should decrease or increase
            likelihood of selection; values like -100 or 100 should result in a
            ban or exclusive selection of the relevant token.
          type: object
          nullable: true
        user:
          description: >-
            A unique identifier representing your end-user, which can help Azure
            OpenAI to monitor and detect abuse.
          type: string
          example: user-1234
          nullable: false
    chatCompletionRequestMessage:
      type: object
      properties:
        role:
          type: string
          enum:
            - system
            - user
            - assistant
            - function
          description: >-
            The role of the messages author. One of `system`, `user`,
            `assistant`, or `function`.
        content:
          type: string
          description: >-
            The contents of the message. `content` is required for all messages
            except assistant messages with function calls.
        name:
          type: string
          description: >-
            The name of the author of this message. `name` is required if role
            is `function`, and it should be the name of the function whose
            response is in the `content`. May contain a-z, A-Z, 0-9, and
            underscores, with a maximum length of 64 characters.
        function_call:
          type: object
          description: >-
            The name and arguments of a function that should be called, as
            generated by the model.
          properties:
            name:
              type: string
              description: The name of the function to call.
            arguments:
              type: string
              description: >-
                The arguments to call the function with, as generated by the
                model in JSON format. Note that the model does not always
                generate valid JSON, and may hallucinate parameters not defined
                by your function schema. Validate the arguments in your code
                before calling your function.
      required:
        - role
    createChatCompletionResponse:
      type: object
      allOf:
        - $ref: '#/components/schemas/chatCompletionsResponseCommon'
        - properties:
            prompt_filter_results:
              $ref: '#/components/schemas/promptFilterResults'
            choices:
              type: array
              items:
                type: object
                allOf:
                  - $ref: '#/components/schemas/chatCompletionChoiceCommon'
                  - properties:
                      message:
                        $ref: '#/components/schemas/chatCompletionResponseMessage'
                      content_filter_results:
                        $ref: '#/components/schemas/contentFilterResults'
      required:
        - id
        - object
        - created
        - model
        - choices                
    chatCompletionFunctions:
      type: object
      properties:
        name:
          type: string
          description: >-
            The name of the function to be called. Must be a-z, A-Z, 0-9, or
            contain underscores and dashes, with a maximum length of 64.
        description:
          type: string
          description: The description of what the function does.
        parameters:
          $ref: '#/components/schemas/chatCompletionFunctionParameters'
      required:
        - name
    chatCompletionFunctionParameters:
      type: object
      description: >-
        The parameters the functions accepts, described as a JSON Schema object.
        See the [guide](/docs/guides/gpt/function-calling) for examples, and the
        [JSON Schema
        reference](https://json-schema.org/understanding-json-schema/) for
        documentation about the format.
      additionalProperties: true
    chatCompletionsResponseCommon:
      type: object
      properties:
        id:
          type: string
        object:
          type: string
        created:
          type: integer
          format: unixtime
        model:
          type: string
        usage:
          type: object
          properties:
            prompt_tokens:
              type: integer
            completion_tokens:
              type: integer
            total_tokens:
              type: integer
          required:
            - prompt_tokens
            - completion_tokens
            - total_tokens
      required:
        - id
        - object
        - created
        - model
    chatCompletionChoiceCommon:
      type: object
      properties:
        index:
          type: integer
        finish_reason:
          type: string
    chatCompletionResponseMessage:
      type: object
      properties:
        role:
          type: string
          enum:
            - system
            - user
            - assistant
            - function
          description: The role of the author of this message.
        content:
          type: string
          description: The contents of the message.
        function_call:
          type: object
          description: >-
            The name and arguments of a function that should be called, as
            generated by the model.
          properties:
            name:
              type: string
              description: The name of the function to call.
            arguments:
              type: string
              description: >-
                The arguments to call the function with, as generated by the
                model in JSON format. Note that the model does not always
                generate valid JSON, and may hallucinate parameters not defined
                by your function schema. Validate the arguments in your code
                before calling your function.
      required:
        - role          
  securitySchemes:
    apiKeyHeader:
      type: apiKey
      name: Ocp-Apim-Subscription-Key
      in: header
    apiKeyQuery:
      type: apiKey
      name: subscription-key
      in: query
security:
  - apiKeyHeader: [ ]
  - apiKeyQuery: [ ]

I used this in azure apim and validating the content like this

我在 Azure APIM 中使用了这个,并像这样验证内容。

<validate-content unspecified-content-type-action="ignore" max-size="102400" size-exceeded-action="detect" errors-variable-name="requestBodyValidation">
            <content type="application/json" validate-as="json" action="prevent" allow-additional-properties="false" />
        </validate-content>

Now I tried to give the request like the actual property

现在我尝试像实际属性一样提供请求。

{
    "messages": [
        {
            "role": "user", 
            "content": "Find beachfront hotels in San Diego for less than $300 a month with free breakfast."
        }
    ],
    "temperature": 1,
    "top_p": 1,
    "stop": "",
    "max_tokens": 2000,
    "presence_penalty": 0,
    "frequency_penalty": 0,
    "logit_bias": {},
    "user": "user-1234",
    "n": 1,
    "function_call" : "auto",
    "functions" : [
            {
            "name": "search_hotels",
            "description": "Retrieves hotels from the search index based on the parameters provided",
            "parameters": {
                "type": "object",
                "properties": {
                    "location": {
                        "type": "string",
                        "description": "The location of the hotel (i.e. Seattle, WA)"
                    },
                    "max_price": {
                        "type": "number",
                        "description": "The maximum price for the hotel"
                    },
                    "features": {
                        "type": "string",
                        "description": "A comma separated list of features (i.e. beachfront, free wifi, etc.)"
                    }
                },
                "required": ["location"]
            }
        }
    ]
}

And the APIM is giving the error like

而 APIM 给出了如下错误:

{
  "statusCode": 400,
  "message": "Body of the request does not conform to the definition which is associated with the content type application/json. JSON does not match all schemas from 'allOf'. Invalid schema indexes: 0, 1. Line: 42, Position: 1"
}

But the same request is working when I directly hit the azure openai.

但当我直接请求 Azure OpenAI 时,同样的请求是有效的。

What could be the possible issue here ?

这里可能是什么问题?

问题解决:

I believe your problem is this line allow-additional-properties="false"

我认为你遇到的问题是这一行 allow-additional-properties="false"

allow-additional-properties Boolean. For a JSON schema, specifies whether to implement a runtime override of the additionalProperties value configured in the schema:

  • true: allow additional properties in the request or response body, even if the JSON schema's additionalProperties field is configured to not allow additional properties.

true:允许在请求或响应主体中添加额外的属性,即使 JSON 模式的 additionalProperties 字段配置为不允许额外属性。

  • false: do not allow additional properties in the request or response body, even if the JSON schema's additionalProperties field is configured to allow additional properties

false:不允许在请求或响应主体中添加额外的属性,即使 JSON 模式的 additionalProperties 字段配置为允许额外属性。

If the attribute isn't specified, the policy validates additional properties according to configuration of the additionalProperties field in the schema.

如果未指定该属性,则策略将根据模式中 additionalProperties 字段的配置来验证额外属性。

source:    来源        https://learn.microsoft.com/en-us/azure/api-management/validate-content-policy#content-attributes

This property overrides your JSON Schema. Even though your allOf definition does not use additionalProperties: false, apim will inject this constraint to the root schema, which translates to

此属性会覆盖你的 JSON Schema。即使你的 allOf 定义没有使用 additionalProperties: false,APIM 仍会将此约束注入到根模式中,这会转化为

{
  "type": "object",
  "additionalProperties": false,
  "allOf": [{...}, {...}]
}

This schema doesn't allow any properties to be validated because no properties are defined at the root.

该模式不允许验证任何属性,因为根本没有定义属性。

The only valid schemas in this situation would be

在这种情况下,唯一有效的模式是

{}

OR

true

There are a few ways to tackle this but IMHO, the best option is to use the schema definition, rather than the apim attribute because you're introducing constraints on the schema where they are not defined. If someone else were to review the schema, they would run into the same issue you are having.

解决这个问题有几种方法,但依我看来,最好的选择是使用模式定义,而不是使用 APIM 属性,因为你在模式中引入了未定义的约束。如果其他人来审查这个模式,他们也会遇到你现在面临的相同问题。

This is where it may get tricky for you depending on which version of JSON Schema is supported in APIM and which version you are using.

这可能会变得棘手,具体取决于 APIM 支持的 JSON Schema 版本以及你正在使用的版本。

Draft-04 - 07 requires some massaging to the schema, in most circumstances, to achieve the desired behavior of using allOf with additionalProperties": false

在大多数情况下,Draft-04 到 Draft-07 需要对模式进行一些调整,以实现使用 allOfadditionalProperties: false 的预期行为。

  • turn off the content attribute in your apim validation

在你的 APIM 验证中关闭 content 属性。

  • add all properties of the first depth of subschemas to the root with an empty schema. This will allow the validator to recognize those properties at the root level to satisfy additionalProperties

将所有子模式第一层的属性添加到根模式中,并使用一个空模式。这将允许验证器在根级别识别这些属性,以满足 additionalProperties 的要求。

{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "type": "object",
    "additionalProperties": false,
    "properties": {
        "messages": {},
        "temperature": {},
        "top_p": {},
        "stop": {},
        "max_tokens": {},
        "presence_penalty": {},
        "frequency_penalty": {},
        "logit_bias": {},
        "user": { },
        "n": { },
        "function_call": { },
        "functions": { }
    },
    "allOf": [
        {
            "type": "object",
            "properties": {
                "temperature": {},
                "top_p": {},
                "stop": {},
                "max_tokens": {},
                "presence_penalty": {},
                "frequency_penalty": {},
                "logit_bias": {},
                "user": {}
            }
        },
        {
            "type": "object",
            "properties": {
                "messages": {},
                "n": {},
                "function_call": {},
                "functions": {}
            }
        }
    ]
}

If you're using JSON Schema draft 2019-09 or later, you can use the newer keyword unevaluatedProperties which performs the behavior described above, automatically.

如果你使用的是 JSON Schema draft 2019-09 或更高版本,你可以使用较新的关键字 unevaluatedProperties,它会自动执行上述描述的行为。

{
    "$schema": "https://json-schema.org/draft/2019-09/schema",
    "type": "object",
    "unevaluatedProperties": false,
    "allOf": [
        {
            "type": "object",
            "properties": {
                "temperature": {},
                "top_p": {},
                "stop": {},
                "max_tokens": {},
                "presence_penalty": {},
                "frequency_penalty": {},
                "logit_bias": {},
                "user": {}
            }
        },
        {
            "type": "object",
            "properties": {
                "messages": {},
                "n": {},
                "function_call": {},
                "functions": {}
            }
        }
    ]
}

This example fails:        这个示例失败了

{
    "messages": [
        {
            "role": "user", 
            "content": "Find beachfront hotels in San Diego for less than $300 a month with free breakfast."
        }
    ],
    "stackOverflow": -1
}
Invalid

# fails schema constraint https://json-schema.hyperjump.io/schema#/unevaluatedProperties

#/stackOverflow fails schema constraint https://json-schema.hyperjump.io/schema#/unevaluatedProperties

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2040638.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

快速排序算法详解及Python实现

目录 引言 快速排序算法步骤 快速排序的Python实现 性能分析 注意事项 引言 快速排序&#xff08;Quick Sort&#xff09;是一种高效的排序算法&#xff0c;由C. A. R. Hoare在1960年提出。它的基本思想是&#xff1a;通过一趟排序将待排序的数据分割成独立的两部分&…

数维原动:如何应对亿级规模的数据分析挑战|OceanBase案例

本文作者&#xff1a;贾万利&#xff0c;北京数维原动教育科技 业务背景 作为国内专注于高端教育评估的机构&#xff0c;北京数维原动教育科技有限公司&#xff0c;其核心业务聚焦于中小学学校的诊断、评估与提升工作。自2009年起&#xff0c;公司便踏上了自主研发之路。经过十…

Visual Studio VS 插件之 ReSharper

集成在VS2022上的ReSharper暂无找到汉化方式&#xff0c;如果有大神可以汉化&#xff0c;请指导下。 首先ReSharper 是IDE 下的插件 主要是基于C# 语句优化的这么一个插件。 使用ReSharper可以使开发效率大大提高&#xff0c;但是也是比较吃电脑的配置。所以说如果配置低的小…

移动开发(一):使用.NET MAUI开发第一个安卓APP

目录 一、.NET MAUI官方介绍 二、开发工具安装 三、创建项目 四、Windows Machine模式运行 五、安卓虚拟机方式运行 六、总结 对于工作多年的C#程序员来说,近来想尝试开发一款安卓APP,考虑了很久最终选择使用.NET MAUI这个微软官方的框架来尝试体验开发安卓APP,毕竟是…

C/C++开发---全篇

1、统筹 学习目标&#xff1a; C/C、python精通。 就业匹配方向&#xff1a;专精一个领域&#xff0c;延长职业生涯。 &#xff08;1&#xff09;适配行业&#xff1b; &#xff08;2&#xff09;量化&#xff1b; &#xff08;3&#xff09;安全&#xff1b; &#xff08;4&…

嵌入式系统可靠性设计案例分析

目录 案例 【题目】 【问题 1】(共 9 分) 【问题 2】(共 8 分) 【问题 3】(共 8 分) 【问题 1】解析 【问题 2】解析 【问题 3】解析 相关知识 案例 阅读以下关于嵌入式系统可靠性设计方面的描述&#xff0c;回答问题 1 至问题 3。 【题目】 某宇航公司长期从事宇航装…

H7-TOOL混合脱机烧录以及1拖4不同的通道烧录不同的程序操作说明(2024-08-07)

【应用场景】 原本TOOL的1拖4是用于同时烧录相同程序给目标板&#xff0c;但有时候一个板子上有多个不同的MCU&#xff0c; 客户希望仅通过一个TOOL就可以完成对板子上多个MCU的烧录&#xff0c;也就是1拖4不同的通道烧录不同的程序&#xff0c;此贴为此制作。 【实验目标】…

Android+Jacoco+code-diff全量、增量覆盖率生成实战

背景 主要是记录下Android项目使用jacoco生成代码覆盖率的实战流程&#xff0c;目前已完成全量覆盖方案&#xff0c;仅使用jacoco就能实现&#xff1b; 由于我们的Android端是使用Java和kotlin语言,目前增量的方案code-diff仅针对Java代码&#xff0c;卡在kotlin文件的分析&am…

java 面试 PDF 资料整理

“尊贵的求知者&#xff0c;作者特此献上精心编纂的Java面试宝典PDF&#xff0c;这份资料凝聚了无数面试精华与实战经验&#xff0c;是通往Java技术殿堂的钥匙。若您渴望在Java编程的求职之路上稳健前行&#xff0c;只需轻轻一点&#xff0c;完成这象征支持与认可的一键三联&am…

Dubbo源码深度解析(五)

上一篇博客主要讲服务提供方服务的发布&#xff0c;以及Netty是如何启动的&#xff0c;客户端发过来的请求&#xff0c;会经过哪些处理器&#xff0c;以及补充之前没讲完的SPI机制等等。这篇博客将会接着继续讲&#xff0c;在看这篇博客之前&#xff0c;请先看上一篇博客&#…

VTK—vtkStructuredGrid提取维度面数据

1.在VTK自带的vtkStructuredGrid数据文件combq.bin和combxyz.bin 2.文件读取代码如下&#xff1a; //读取数据文件Create(vtkMultiBlockPLOT3DReader, reader);reader->SetXYZFileName("G:/Temp/vtkTest/combxyz.bin");reader->SetQFileName("G:/Temp/v…

Vitis AI 基本认知(训练过程)

目录 1. 目的 2. TensorBoard 2.1 In TensorFlow 2.2.1 安装 TensorBoard 2.2.2 导入必要的库 2.2.3 初始化 2.2.4 记录数据 2.2.5 启动 TensorBoard 2.2.6 刷新间隔 2.2 In PyTorch 3. 训练周期 Epoch 3.1 Epoch 3.2 Batch 3.3 Iteration 4. 总结 1. 目的 介绍…

传奇游戏发布渠道

传奇游戏发布渠道 回答&#xff1a;游戏发布平台|手机游戏发布平台 传奇游戏发布渠道作为游戏开发商直接控制的信息传播途径&#xff0c;其安全性自然有着较高的保障。首先&#xff0c;渠道通常会采用先进的加密技术和安全协议来保护数据传输过程中的安全&#xff0c;防止信息…

Centos 7 升级GCC时遇到 mirrorlist.centos.org; Unknown error“

问题描述 在执行如下操作的时候&#xff0c; yum install devtoolset-9-gcc devtoolset-9-gcc-c devtoolset-9-binutils 出现&#xff1a; 14: curl#6 - "Could not resolve host: mirrorlist.centos.org; Unknown error" 网上搜索了一下&#xff0c;原因是 mir…

redis集合若干记录

无序集合 redis通常使用字典结构保存集合数据&#xff0c;字典健存储集合元素&#xff0c;字典值为空。如果一个集合全为整数&#xff0c;使用字典就有点浪费了&#xff0c;redis使用intset保存。 插入元素到intset中 获取插入元素编码&#xff0c;如果插入元素编码级别高于int…

Chapter 36 PySpark数据计算

欢迎大家订阅【Python从入门到精通】专栏&#xff0c;一起探索Python的无限可能&#xff01; 文章目录 前言一、map算子二、flatMap算子三、reduceByKey算子四、filter算子五、distinct算子六、sortBy算子七、综合案例 前言 在大数据处理的时代&#xff0c;Apache Spark以其高…

猫头虎 分享:Python库 Pygame 的简介、安装、用法详解入门教程

猫头虎 分享&#xff1a;Python库 Pygame 的简介、安装、用法详解入门教程 &#x1f63a; 摘要&#xff1a;今天&#xff0c;猫头虎将带大家深入了解Python中常用的Pygame库。Pygame是开发2D游戏和多媒体应用的首选工具之一。在本文中&#xff0c;我们将从安装Pygame、了解Pyg…

深入学习零拷贝

在学习中遇到了一个问题就是什么是零拷贝&#xff0c;因此学习之后以此来记录一下。 零拷贝、直接I/O、异步I/O等&#xff0c;优化的目的就是为了提高系统的吞吐量&#xff0c;减少访问磁盘次数。访问磁盘的速度会比读写内存会慢十倍以上。因此就需要提高它的读写速度。 什么…

uniapp自定义请求头信息header

添加请求头&#xff1a;uniapp自定义请求头信息header 代码

Java性能优化之并发编程:深入解析与实战技巧

在Java应用程序的性能优化中&#xff0c;并发编程是一个关键领域。通过合理使用并发编程技术&#xff0c;可以充分利用多核CPU的计算能力&#xff0c;提高程序的执行效率。本文将深入探讨Java并发编程的优化策略&#xff0c;并提供一些实用的代码示例和实战技巧。 1. 线程与同…