You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure OpenAI Completion API返回非预期HTML代码问题求助

解决Azure OpenAI Completion API返回无关HTML的问题

问题说明

调用Azure OpenAI Completion API提取职位描述核心意图时,返回了Laravel模板HTML代码,而非预期的纯文本列表。

具体解决步骤

1. 重构提示词,强化约束

修正原提示词拼写错误,明确禁止返回HTML、模板代码等非目标内容,强化格式要求:

You are a professional Hiring Manager. Extract the top 5 core intents from the following job description.
- Keep each intent concise (around 15 words), preserve original meaning, and ensure clarity.
- Format your response as 5 bullet points starting with "•", no other formatting allowed.
- **DO NOT return HTML, code templates, or any content not directly related to the intents.**
- Do not justify your answers, only include information from the provided job description.

Below is the job description:
{text_desc}

2. 调整API调用参数

  • 降低temperature值至0.3-0.5,减少输出随机性,让模型更严格遵循指令
  • 添加stop参数,截断无关内容的输出:
    response = openai.Completion.create(
        prompt=full_prompt,
        temperature=0.4,
        max_tokens=600,
        engine=deployment_name,
        stop=["</div>", "@endforeach", "@endsection"]
    )
    

3. 响应后处理过滤

在获取响应后,添加代码过滤HTML标签和无关内容,提取有效条目:

import re

# 获取原始响应
chatgpt_response = response['choices'][0].text.strip(" \n")

# 移除所有HTML标签
cleaned_response = re.sub(r'<.*?>', '', chatgpt_response)
# 提取以•开头的条目
valid_items = [item.strip() for item in cleaned_response.split('•') if item.strip()]
# 取前5条(如果有多余)
final_response = '\n• '.join(valid_items[:5])

4. 检查部署模型

确认Azure上部署的aidoos-openai模型版本是否适配,建议使用gpt-3.5-turbo-instruct(Completion API对应模型),避免使用训练数据包含大量模板代码的旧模型。

内容的提问来源于stack exchange,提问作者REHAMAN SHAIK

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.29 07:08:17