标签: gpt-3

如何使用 Langchain 获得更详细的结果来源

我正在尝试使用 Langchain 和特定 URL 作为源数据来整理一个简单的“来源问答”。URL 由一个页面组成,其中包含大量信息。

问题是RetrievalQAWithSourcesChain只给我返回整个 URL 作为结果的来源,这在这种情况下不是很有用。

有没有办法获得更详细的源信息?也许页面上特定部分的标题?指向页面正确部分的可点击 URL 会更有帮助!

我有点不确定 的生成是result source语言模型、URL 加载器的函数还是仅仅是RetrievalQAWithSourcesChain单独的。

我尝试过使用UnstructuredURLLoader和 ,SeleniumURLLoader希望更详细的数据读取和输入会有所帮助 - 遗憾的是没有。

相关代码摘录:

llm = ChatOpenAI(temperature=0, model_name='gpt-3.5-turbo')
chain = RetrievalQAWithSourcesChain.from_llm(llm=llm, retriever=VectorStore.as_retriever())

result = chain({"question": question})

print(result['answer'])
print("\n Sources : ",result['sources'] )
Run Code Online (Sandbox Code Playgroud)

python openai-api gpt-3 chatgpt-api langchain

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

如何在 GPT-3 上保存预训练的 API?

我有一个关于 GPT-3 的问题。正如我们所知,我们可以给网络提供一些例子并“调整”模型。

  1. 向模型展示示例。
  2. 保存这些示例。
  3. 重用 API。

import openai

class Example():
    """Stores an input, output pair and formats it to prime the model."""
def __init__(self, inp, out):
    self.input = inp
    self.output = out

def get_input(self):
    """Returns the input of the example."""
    return self.input

def get_output(self):
    """Returns the intended output of the example."""
    return self.output

def format(self):
    """Formats the input, output pair."""
    return f"input: {self.input}\noutput: {self.output}\n"


class GPT:
    """The main class for a user to interface with the OpenAI API.
    A …
Run Code Online (Sandbox Code Playgroud)

python gpt-3

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

如何将 OpenAI stream=true 属性与 Django Rest Framework 响应结合使用,并仍然保存返回的内容?

我尝试按如下方式使用stream=true 属性。

completion = openai.Completion.create(
            model="text-davinci-003",
            prompt="Write me a story about dogs.",
            temperature=0.7,
            max_tokens=MAX_TOKENS,
            frequency_penalty=1.0,
            presence_penalty=1.0,
            stream=True,
        )
Run Code Online (Sandbox Code Playgroud)

不幸的是,我不知道如何从这里将其返回到我的 React 前端。通常,我使用标准响应对象,设置状态和 serializer.data 作为数据。从我的在线阅读来看,似乎我必须使用StreamingHttpResponse,但我不确定如何将其与 的迭代器对象集成completion,并在完成流式传输后实际保存输出的数据,因为视图将在返回迭代器后结束到终点。有什么帮助吗?

django reactjs gpt-3

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

OpenAI GPT-3 API:如何让模型记住过去的对话?

有没有办法训练大型语言模型(LLM)来存储特定的上下文?例如,我有一个很长的故事,我想提出问题,但我不想把整个故事放在每个提示中。如何才能让LLM“记住这个故事”?

openai-api gpt-3

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

OpenAI GPT-3 API 错误:“无效 URL (POST /v1/chat/completions)”

这是我的代码片段:

const { Configuration, OpenAI, OpenAIApi } = require ("openai");
const configuration = new Configuration({
    apiKey: 'MY KEY'
})

const openai = new OpenAIApi(configuration)

async function start() {
    const response = await openai.createChatCompletion({
        model:"text-davinci-003",
        prompt: "Write a 90 word essay about Family Guy",
        temperature: 0,
        max_tokens: 1000
    })

    console.log(response.data.choices[0].text)
}

start()
Run Code Online (Sandbox Code Playgroud)

当我跑步时:node index

我遇到这个问题:

data: {
      error: {
        message: 'Invalid URL (POST /v1/chat/completions)',
        type: 'invalid_request_error',
        param: null,
        code: null
      }
    }
  },
  isAxiosError: true,
  toJSON: [Function: toJSON]
}
Run Code Online (Sandbox Code Playgroud)

Node.js …

node.js openai-api gpt-3

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

使用GPT-4 API时,我需要每次都发回整个对话吗?

我是 OpenAI API 的新手。我使用 GPT-3.5-Turbo,使用以下代码:

\n
messages = [\n        {"role": "system", "content": "You\xe2\x80\x99re a helpful assistant"}\n    ]\n\n    while True:\n        content = input("User: ")\n        if content == 'end':\n            save_log(messages)\n            break\n        messages.append({"role": "user", "content": content})\n\n        completion = openai.ChatCompletion.create(\n            model="gpt-3.5-turbo-16k",\n            messages=messages\n        )\n\n        chat_response = completion.choices[0].message.content\n        print(f'ChatGPT: {chat_response}')\n        messages.append({"role": "assistant", "content": chat_response})\n
Run Code Online (Sandbox Code Playgroud)\n

结果:\n用户:谁是第一个登上月球的人?\nGPT:第一个踏上月球的人是美国宇航员尼尔·阿姆斯特朗,于 1969 年 7 月 20 日执行 NASA 阿波罗 11 号任务。\ n用户:他有多高?\nGPT:尼尔阿姆斯特朗身高约为 5 英尺 11 英寸(180 厘米)。

\n

但它需要大量的代币。我听说 GPT-4 与 GPT-3 的不同之处在于它能够(自行)记住之前的消息。那是对的吗?

\n

但是,如果我删除在“消息”列表中附加最新消息的行并仅发送一条消息:\n completion = openai.ChatCompletion.create( model="gpt-4", messages=[{"role": …

openai-api gpt-3 chatgpt-api gpt-4

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

OpenAI API 错误:“您尝试访问 openai.Completion,但 openai>=1.0.0 不再支持此操作”

我想使用 GPT 4 模型将 csv 文件中的文本翻译成英语,但我不断收到以下错误。即使我更新了版本,我仍然收到相同的错误。

\n
import openai\nimport pandas as pd\nimport os\nfrom tqdm import tqdm\n\n\nopenai.api_key = os.getenv("API")\n\ndef translate_text(text):\n    response = openai.Completion.create(\n        model="text-davinci-003",  # GPT-4 modeli\n        prompt=f"Translate the following Turkish text to English: '{text}'",\n        max_tokens=60\n    )\n    # Yeni API yap\xc4\xb1s\xc4\xb1na g\xc3\xb6re yan\xc4\xb1t\xc4\xb1n al\xc4\xb1nmas\xc4\xb1\n    return response.choices[0].text.strip()\n\ndf = pd.read_excel('/content/3500-turkish-dataset-column-name.xlsx')\n\ncolumn_to_translate = 'review'\n\ndf[column_to_translate + '_en'] = ''\n\nfor index, row in tqdm(df.iterrows(), total=df.shape[0]):\n    translated_text = translate_text(row[column_to_translate])\n    df.at[index, column_to_translate + '_en'] = translated_text\n\ndf.to_csv('path/to/your/translated_csvfile.csv', index=False)\n\n
Run Code Online (Sandbox Code Playgroud)\n
 0%|          | 0/3500 [00:00<?, ?it/s]\n---------------------------------------------------------------------------\nAPIRemovedInV1                            Traceback (most recent call last)\n<ipython-input-27-337b5b6f4d32> in …
Run Code Online (Sandbox Code Playgroud)

python openai-api gpt-3

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

如何修复 Python pip install openai 错误:subprocess-exited-with-error

我正在尝试使用 Python 3.11、Windows 操作系统、pip 完全升级来安装 OpenAI,但出现此错误。

\n

这是完整的错误消息:

\n
Collecting openai\n  Using cached openai-0.26.0.tar.gz (54 kB)\n  Installing build dependencies ... done\n  Getting requirements to build wheel ... error\n  error: subprocess-exited-with-error\n\n  \xc3\x97 Getting requirements to build wheel did not run successfully.\n  \xe2\x94\x82 exit code: 1\n  \xe2\x95\xb0\xe2\x94\x80> [21 lines of output]\n      Traceback (most recent call last):\n        File "C:\\Users\\vocal\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages\\pip\\_vendor\\pep517\\in_process\\_in_process.py", line 351, in <module>\n          main()\n        File "C:\\Users\\vocal\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages\\pip\\_vendor\\pep517\\in_process\\_in_process.py", line 333, in main\n          json_out[\'return_val\'] = hook(**hook_input[\'kwargs\'])\n                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n        File "C:\\Users\\vocal\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages\\pip\\_vendor\\pep517\\in_process\\_in_process.py", line 118, in get_requires_for_build_wheel\n          return hook(config_settings)\n                 ^^^^^^^^^^^^^^^^^^^^^\n …
Run Code Online (Sandbox Code Playgroud)

python windows python-3.x openai-api gpt-3

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

如何在离线模式电脑上使用tiktoken

import tiktoken

tokenizer = tiktoken.get_encoding("cl100k_base") tokenizer = tiktoken.encoding_for_model("gpt-3.5-turbo")

text = "Hello, nice to meet you"

tokenizer.encode(text)

Run Code Online (Sandbox Code Playgroud)

这一直显示名为 requests.exceptions.SSLError 的错误。由 SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] 证书验证失败:证书链中的自签名证书 (_ssl.c:1002)')) ... 引起。

我想运行这段代码来查看令牌的数量。但正如我之前提到的,它一直显示错误。我缺少什么代码?

python tokenize gpt-3

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

OpenAI GPT-3 API:davinci 和 text-davinci-003 之间有什么区别?

我正在测试 OpenAI 的不同模型,我注意到并非所有模型都经过足够的开发或训练以给出可靠的响应。

我测试的型号如下:

model_engine = "text-davinci-003"
model_engine = "davinci" 
model_engine = "curie" 
model_engine = "babbage" 
model_engine = "ada" 
Run Code Online (Sandbox Code Playgroud)

davinci我需要了解和之间的区别text-davinci-003,以及如何改进响应以匹配使用 ChatGPT 时的响应。

openai-api gpt-3

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