Azure Chatgpt API 返回的响应中混杂了其HTML代码

我正在使用Azure的chatapi API,但chatgpt返回的响应中包含了未提示的HTML代码

这是我用来从chatgpt API获取响应的代码

    def give_prompt_get_response(self):        key1='********************'        endpoints='**************'        openai.api_key = key1        openai.api_base = endpoints         openai.api_type = 'azure'        openai.api_version = '2023-05-15'        deployment_name='aidoos-openai'                 full_prompt = f"{self.prompt} *{self.text_desc}*"              try:            response = openai.Completion.create(prompt=full_prompt, temperature = 0.85,                 max_tokens=600, engine=deployment_name,)            chatgpt_response = response['choices'][0].text.strip(" \n")            #print(f"chatgpt_response {chatgpt_response}")            return chatgpt_response        except Exception as e:            print(f"Exception occured during chatGPT API call: {e}")

这是我用来从chatgpt获取响应的提示prompt = “””你是一位出色的招聘经理,请从工作描述中提取前5个意图,同时保持其主要含义和清晰度。专注于使用简洁的语言并保持连贯性。你的回答应采用以下格式 \n• 你的回答在15个单词内。 \n• 你的回答在15个单词内。 \n• 你的回答在15个单词内。 \n• 你的回答在15个单词内。 \n• 你的回答在15个单词内。 \n以下是项目描述 \n不要解释你的答案。不要提供CONTEXT INFORMATION中未提及的信息”””

chatgpt返回的包含HTML内容的响应如下:

Working Nomads is not affiliated with any of the companies or jobs listed on this site</code></pre>                </div>            </div>        </div>        <div class="col-md-4">            <div class="card">                <div class="card-header"><h5 class="text-center font-weight-bold">Answer</h5></div>                    @foreach($answers as $answer)                    <div class="card-body">                        <ul class="list-unstyled">                            <li>{{ $answer->answer1 }}</li>                            <li>{{ $answer->answer2 }}</li>                            <li>{{ $answer->answer3 }}</li>                            <li>{{ $answer->answer4 }}</li>                            <li>{{ $answer->answer5 }}</li>                        </ul>                    </div>                    @endforeach                    {{-- <div class="card-body">                        <ul class="list-unstyled">                            <li><p>Exceptional Node skills using JavaScript</p></li>                            <li><p>Part of team for the development of the backend components of all Bitfinex Services</p></li>                            <li><p>Good experience in interacting with databases</p></li>                            <li><p>Good understanding of security practices</p></li>                            <li><p>Familiar with microservices architecture</p></li>                        </ul>                    </div> --}}            </div>        </div>    </div></div>@endsection

回答:

我已经成功地使用下面的代码从OpenAI模型中接收到了响应。

代码 :

from openai import AzureOpenAIclient = AzureOpenAI(  azure_endpoint="<api_endpoint>",   api_key="<api_key>",    api_version="2024-02-15-preview")message_text = [{"role": "system", "content": """你是一位出色的招聘经理,请从工作描述中提取前5个意图,同时保持其主要含义和清晰度。专注于使用简洁的语言并保持连贯性。你的回答应采用以下格式 \n • 你的回答在15个单词内。 \n • 你的回答在15个单词内。 \n • 你的回答在15个单词内。 \n • 你的回答在15个单词内。 \n • 你的回答在15个单词内。 \n 以下是项目描述 \n 不要解释你的答案。不要提供CONTEXT INFORMATION中未提及的信息"""}]completion = client.chat.completions.create(  model="<model_name>",   messages=message_text,  temperature=0.7,  max_tokens=800,  top_p=0.95,  frequency_penalty=0,  presence_penalty=0,  stop=None)print(completion.choices[0].message.content)

输出 :

它成功运行并提供了如下响应。

C:\Users\xxxxxxxx\Documents\xxxxxxxx>python sample.py1. 评估候选人的资格和经验,以确定最适合该职位的人选。2. 进行面试和评估,以确定候选人的技能和适合性。3. 与招聘团队合作,定义职位要求并制定有效的招聘策略。4. 在整个招聘过程中确保遵守劳动法和法规。5. 在整个招聘过程中为候选人提供指导和支持,促进积极的候选人体验。

enter image description here

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注