标签: azure-openai

为什么我的新 Azure OpenAI 部署收到 404 未找到资源?

我已完成此快速入门,并创建了 Azure OpenAI 资源 + 创建了状态成功的模型部署。我还在https://oai.azure.com/中尝试过它并且它在那里工作。

但是,如果我尝试从 REST API 访问它,则会返回 404 Resource Not Found。我定义了header,并从 Playground 内部的->api-key获取了 url 和 json 。Code Viewjson

我正在执行

发布 https://raz-openai.openai.azure.com/openai/deployments/raz-model-2/completions?api-version=2022-12-01 {“提示”:“”,“max_tokens”:100 }带有 api-key 标头

我还错过了另一个步骤吗?

azure azure-cognitive-services azure-openai

10
推荐指数
2
解决办法
1万
查看次数

如何使用 Azure OpenAI 进行函数调用

这是我的代码


response = openai.ChatCompletion.create(
    engine="XXX", # The deployment name you chose when you deployed the ChatGPT or GPT-4 model.
    messages=[
        {"role": "system", "content": "Assistant is a large language model trained by OpenAI."},
        {"role": "user", "content": "Calculate the circumference of circle with radius 5?"}
    ],
    functions=[{'name': 'circumference_calc', 'description': 'Calculate the circumference of circle given the radius', 'parameters': {'type': 'object', 'properties': {'radius': {'description': 'The radius of the circle', 'type': 'number'}}}, 'required': ['radius']}]
)
Run Code Online (Sandbox Code Playgroud)

结果是 :

InvalidRequestError:提供了无法识别的请求参数:函数

写了上面的代码

azure-openai

10
推荐指数
1
解决办法
8055
查看次数

为什么在调用 Azure OpenAI GPT 时使用“函数”时会收到错误“无法识别的请求参数提供:函数”?

我尝试functions在调用 Azure OpenAI GPT 时使用,如https://platform.openai.com/docs/api-reference/chat/create#chat/create-functions中所述

我用:

import openai
openai.api_type = "azure"
openai.api_base = "https://XXXXXXXX.openai.azure.com/"
openai.api_version = "2023-06-01-preview"
openai.api_key = os.getenv("OPENAI_API_KEY")
response = openai.ChatCompletion.create(
            engine="gpt-35-turbo-XXX",
            model="gpt-35-turbo-0613-XXXX"
            messages=messages,
            functions=functions,
            function_call="auto",
        )
Run Code Online (Sandbox Code Playgroud)

但我收到错误:

openai.error.InvalidRequestError:
Unrecognized request argument supplied: functions
Run Code Online (Sandbox Code Playgroud)

为什么?


运行上面示例代码的数据(messages并且functions需要定义):

messages = [{"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "Hello!"}]
functions = [
    {
        "name": "fetch_pages",
        "description": "Fetch the content of specified pages from the document.",
        "parameters": {
            "type": "object",
            "properties": …
Run Code Online (Sandbox Code Playgroud)

python azure gpt-3 azure-openai large-language-model

9
推荐指数
1
解决办法
7757
查看次数

不清楚 Azure OpenAI 端点 /extensions/chat/completions 如何在幕后进行检索

我正在尝试这个示例聊天应用程序,它从认知搜索中检索最相关的文档,以帮助聊天机器人回答用户的问题。文档检索本身不是应用程序代码的一部分,而是在应用程序调用“/deployments/{deployment-id}/extensions/chat/completions”端点时被抽象出来。

我无法从文档中理解/deployments/{deployment-id}/extensions/chat/completions端点如何在幕后与认知搜索交互。背景是我试图了解它提供的灵活性以及如果我们想要更改某些内容,需要如何手动实现文档检索和集成到法学硕士的提示中。

扩展程序调用什么认知搜索端点以及使用哪些参数?以下是我自己发送的 API 请求示例,用于尝试重现工具引用中的前 5 个结果

curl --location 'https://[deployment].search.windows.net/indexes/[index]/docs/search?api-version=2023-07-01-Preview' \
--header 'Content-Type: application/json' \
--header 'api-key: [key]' \
--data '{  
     "queryType": [I tried full, simple and semantic here, semantic with different settings for other required parameters]
     "search": "[question text]",  
     "top": 5
   }  '
Run Code Online (Sandbox Code Playgroud)

我得到的文档与 Azure 门户中认知搜索的搜索资源管理器中返回的文档相同,但它们与请求返回的文档不同extensions/chat/completions。对于相同的块,相关性分数有时相同,但有时也不同。您能透露一下为什么会发生这种情况吗?

在 Azure OpenAI 游乐场和此示例应用程序中实现的文档检索中未使用嵌入,这是否正确?

是否有更多的系统文本隐藏在某个地方,指示模型查看源代码并以这种 [doc1] 格式提供参考?如果我们对引用准确性不满意,我们将如何修改?

azure azure-cognitive-search openai-api azure-openai

7
推荐指数
1
解决办法
2166
查看次数

OpenAI API 错误:“没有名为‘openai.embeddings_utils’的模块;‘openai’不是一个包”

我想使用openai.embeddings_utils import get_embeddings 所以已经安装openai

Name: openai
Version: 0.26.5
Summary: Python client library for the OpenAI API
Home-page: https://github.com/openai/openai-python
Author: OpenAI
Author-email: support@openai.com
License: 
Location: /Users/lima/Desktop/Paprika/Openai/.venv/lib/python3.9/site-packages
Requires: aiohttp, requests, tqdm
Required-by: 
Run Code Online (Sandbox Code Playgroud)

这是我的 openai 但为什么不使用 openai.embeddings_utils 呢?

python pip python-3.x openai-api azure-openai

6
推荐指数
2
解决办法
2万
查看次数

使用 Azure OpenAI GPT4 进行图像到文本转换

我部署了 Azure 开放 AI 帐户和 GPT4 模型。我可以使用它的API进行图像到文本的描述吗?如果是,我将如何给它图像?我正在使用这段代码。但它给我一个错误。

import openai
# open ai key
openai.api_type = "azure"
openai.api_version = "2023-03-15-preview"
openai.api_base = 'https://xxxxxx.openai.azure.com/'
openai.api_key = "xxxxxxxxxxxxx"

image_url="https://cdn.repliers.io/IMG-X5925532_9.jpg"

def generate_image_description(image_url):
    prompt = f"What is in this image? {image_url}"
    print(prompt)
    response = openai.ChatCompletion.create(
        engine="GPT4v0314",
        prompt=prompt,
        max_tokens=1024,
        n=1,
        stop=None,
        temperature=0.0,
    )
    description = response.choices[0].text.strip()
    return description
Run Code Online (Sandbox Code Playgroud)

错误就像;APIError:来自 API 的无效响应对象:“不支持的数据类型\n”(HTTP 响应代码为 400)

我在解释里面提到过。

python openai-api azure-openai gpt-4

5
推荐指数
1
解决办法
2592
查看次数

AzureOpenAI 和 LangChain 奇怪,多个答案

我正在使用AzureOpenAI来测试LangChain使用宪法的自我批评。

\n

这一切都有效,除了我得到了多个答案,最奇怪的部分是,它生成随机的、不需要的问题,并回答它们。

\n

这是我的 Python 代码(我用 替换了敏感信息[XXX-XXX]):

\n
import os\nfrom langchain.llms import AzureOpenAI\nfrom langchain.prompts import PromptTemplate\nfrom langchain.chains.llm import LLMChain\n\nfrom langchain.chains.constitutional_ai.base import ConstitutionalChain\nfrom langchain.chains.constitutional_ai.models import ConstitutionalPrinciple\n\nos.environ["OPENAI_API_TYPE"] = "azure"\nos.environ["OPENAI_API_VERSION"] = "2023-03-15-preview"\nos.environ["OPENAI_API_BASE"] = "https://[XXX-XXX].openai.azure.com/"\nos.environ["OPENAI_API_KEY"] = "[XXX-XXX]"\n\nqa_prompt = PromptTemplate(\n    template="""You are a Microsoft specialist and know everything about the software it sells.  Your aim is to help operators and employees when using the software.\n\nQuestion: {question}\n\nAnswer:""",\n    input_variables=["question"],\n)\n\nllm = AzureOpenAI(\n    deployment_name="[XXX-XXX]",\n    model_name="[XXX-XXX]"\n)\n\n\nqa_chain = LLMChain(llm=llm, prompt=qa_prompt)\n\nethical_principle = ConstitutionalPrinciple(\n    name="Ethical Principle",\n    critique_request="The model should only …
Run Code Online (Sandbox Code Playgroud)

python azure openai-api azure-openai langchain

5
推荐指数
1
解决办法
2640
查看次数

如何选择合适的 openai.api_version?

我在https://learn.microsoft.com/en-us/azure/cognitive-services/openai/how-to/chatgpt?pivots=programming-language-chat-c ​​ompletions 上读到:

openai.api_version = "2023-05-15" 
Run Code Online (Sandbox Code Playgroud)

并在https://learn.microsoft.com/en-us/answers/questions/1193969/how-to-integrate-tiktoken-library-with-azure-opena上:

openai.api_version = "2023-03-15-preview" 
Run Code Online (Sandbox Code Playgroud)

这让我想知道:我怎样才能选择合适的openai.api_version?这是否取决于我的 Azure OpenAI 实例或部署的模型或我在 Python 代码中使用的功能?或者是其他东西?

我在部署的模型中找不到信息:

在此输入图像描述

python azure python-3.x azure-openai

5
推荐指数
1
解决办法
1万
查看次数

向 Azure Open AI 发出 API 请求时不支持的数据类型

尝试向 Azure OpenAI 发送发布请求时收到“数据不受支持”错误。我应该怎么做才能修复该错误?

https://myopenai.openai.azure.com/openai/deployments/code-davinci-002/completions?api-version=2023-03-15-preview&API-KEY=xxxxxxxxxxxx&content-type=application/json

api-version = 2023-03-15-preview
API-KEY = xxxxx
content-type = application/json


{
     "model": "gpt-3.5-turbo",
     "messages": [{"role": "user", "content": "Say this is a test!"}],
     "temperature": 0.7
}
Run Code Online (Sandbox Code Playgroud)

azure azure-openai

4
推荐指数
1
解决办法
5391
查看次数

OpenAI Embeddings API:嵌入如何工作?

embeddingsOpenAI有相当多的教程。我无法理解它们是如何工作的。

参考https://platform.openai.com/docs/guides/embeddings/what-are-embeddings, anembedding是 avectorlist。将字符串传递给embedding模型,模型返回一个数字(用最简单的术语来说)。我可以使用这个号码。

如果我使用一个简单的字符串来获取它embeddings,我会得到一个巨大的列表

result = get_embedding("I live in space", engine = "textsearchcuriedoc001mc")
Run Code Online (Sandbox Code Playgroud)

result打印时

[5.4967957112239674e-05,
 -0.01301578339189291,
 -0.002223075833171606,
 0.013594076968729496,
 -0.027540158480405807,
 0.008867159485816956,
 0.009403547272086143,
 -0.010987567715346813,
 0.01919262297451496,
 0.022209804505109787,
 -0.01397960539907217,
 -0.012806257233023643,
 -0.027908924967050552,
 0.013074451126158237,
 0.024942029267549515,
 0.0200139675289392 , ..... -> truncated this much, much, much longer list 
Run Code Online (Sandbox Code Playgroud)

问题 1 - 这个庞大的列表与我的 4 字文本有何关联?

问题2 -

我创建embeddings了要在查询中使用的文本。注意,与原文内容的文字完全一致I live in space

queryembedding = get_embedding(
        'I live in space',
        engine="textsearchcuriequery001mc"
    )
queryembedding …
Run Code Online (Sandbox Code Playgroud)

azure openai-api azure-openai

4
推荐指数
1
解决办法
4803
查看次数

OpenAI API、ChatCompletion 和 Completion 使用相同的参数给出完全不同的答案。为什么?

我正在探索 gpt3.5-turbo 上不同提示的用法。

调查“ChatCompletion”和“Completion”之间的差异,一些参考文献说它们应该或多或少相同,例如:https ://platform.openai.com/docs/guides/gpt/chat-c​​ompletions-vs - 完工量

其他消息来源称,正如预期的那样,ChatCompletion 对于聊天机器人来说更有用,因为你有“角色”(系统、用户和助理),这样你就可以编排一些事情,比如一些例子和/或之前聊天消息的记忆。而完成对于摘要或文本生成更有用。

但差别似乎要大得多。我找不到解释幕后发生的事情的参考资料。

即使使用具有相同参数的相同模型,以下实验也给出了完全不同的结果。

通过聊天完成

import os
import openai
openai.api_type = "azure"
openai.api_version = "2023-03-15-preview"
openai.api_base = ...
openai.api_key = ...

chat_response = openai.ChatCompletion.create(
  engine="my_model", # gpt-35-turbo
  messages = [{"role":"user","content":"Give me something intresting:\n"}],
  temperature=0,
  max_tokens=800,
  top_p=0.95,
  frequency_penalty=0,
  presence_penalty=0,
  stop=None)

print(chat_response.choices[0]['message']['content'])
Run Code Online (Sandbox Code Playgroud)

结果是关于战争的事实:

Did you know that the shortest war in history was between Britain and Zanzibar in 1896? It lasted only 38 minutes!
Run Code Online (Sandbox Code Playgroud)

完成后

Did you know that the shortest war in history …
Run Code Online (Sandbox Code Playgroud)

python openai-api azure-openai chatgpt-api

2
推荐指数
1
解决办法
4330
查看次数

如何通过 Postman 将 ChatGPT 请求发送到 Azure OpenAI?

我想向 Azure OpenAI 的 ChatGPT 提问

我已经添加了帖子网址。我添加了参数“API_KEY”(从 Azure 门户复制的密钥),我添加了 json 正文。

我的访问被拒绝。我想密钥一定是正确的。有人可以发送示例工作 API 网址吗?

    "error": {
        "code": "401",
        "message": "Access denied due to invalid subscription key       or wrong API endpoint. Make sure to provide a valid key for an active       subscription and use a correct regional API endpoint for your   resource."
    } 
}. 
Run Code Online (Sandbox Code Playgroud)

azure azure-openai

1
推荐指数
1
解决办法
3666
查看次数