Skip to main content

Autonomous integration

Basic AI functions include: worksheet field suggestions, worksheet custom fields, automatic generation of workflow code blocks, and application of multilingual intelligent translation

The basic AI functions in HAP are based on OpenAI by default https://api.openai.com/v1/chat/completions implementation, complete interface definition reference: https://platform.openai.com/docs/api-reference/chat/create

HAP sends request header parameters to OpenAI:

Authorization: Bearer $API_KEY

The request body sent by HAP to OpenAI only contains the following parameters:

{
"model": "gpt-4o-mini", // model
"messages": [
{
"role": "developer", // role
"content": "You are a helpful assistant." // content
}
],
"temperature": 1, // control the randomness of generated text. The higher the value, the more random the generated text will be
"top_p": 1, // core probability threshold. control the diversity of generated text
"frequency_penalty": 0, // punish repeated words and reduce repetition
"presence_penalty": 0, // punish words that have not appeared before and increase the probability of new words appearing
"stream": false // whether to enable streaming transmission
}

HAP only uses the following parameters to receive OpenAI return values:

When the stream is false

{
"choices": [
{
"message": {
"content": "Full content"
}
}
]
}

When the stream is true

{
"choices": [
{
"delta": {
"content": "Chunk content"
}
}
]
}

So in the autonomous integration mode, developers need to encapsulate interfaces and meet the above input and output formats. It can be understood that in HAP products, the original call to OpenAI interface is now changed to call an independently implemented interface, and the input and output of the interface are completely consistent with OpenAI.For example:Example code based on Baidu AI autonomous integration

After the interface development is completed and deployed, go to HAP System Configuration>Integration>AI services>Basic AI Functions, select the type of autonomous integration, configure the service address (baseURL), model name, and key, as shown in the following figure: