我正在使用 Langchain 与一长段文本进行交互。文本被分成块,这些块作为下面的变量传入docs。
我已经建立了一个链来传输我的响应,但是我发现handleLLMNewToken在 OpenAI 返回所有代的令牌(其中包括每个文档的映射步骤)时调用该链。
这会导致混乱的响应,这是所有一代的组合,而不仅仅是输出一代。我找不到一种方法可以让我仅在生成最终结果时对其进行流式传输。
如果我使用该变量,我可以访问已完成的提示chainResult- 但与回调不同,它不可流式传输。
const SUMMARISE_MODEL = {
temperature: 0.5,
modelName: "gpt-3.5-turbo-16k",
maxTokens: 5000,
verbose: false,
maxConcurrency: 2,
streaming: true,
}
//...OTHER CODE
const chain = loadQAMapReduceChain(model, {returnIntermediateSteps: true});
const chainResult = await chain.call({
input_documents: docs,
question: templateString,
}, [
{
handleLLMNewToken(token: string) {
updateResponse(token);
},
}
],);
Run Code Online (Sandbox Code Playgroud) 尝试访问 OpenAPI 示例 -解释代码 但它显示错误为 -
InvalidRequestError:找不到引擎
enter code response = openai.Completion.create(
engine="code-davinci-002",
prompt="class Log:\n def __init__(self, path):\n dirname = os.path.dirname(path)\n os.makedirs(dirname, exist_ok=True)\n f = open(path, \"a+\")\n\n # Check that the file is newline-terminated\n size = os.path.getsize(path)\n if size > 0:\n f.seek(size - 1)\n end = f.read(1)\n if end != \"\\n\":\n f.write(\"\\n\")\n self.f = f\n self.path = path\n\n def log(self, event):\n event[\"_event_id\"] = str(uuid.uuid4())\n json.dump(event, self.f)\n self.f.write(\"\\n\")\n\n def state(self):\n state = {\"complete\": set(), \"last\": None}\n for line in open(self.path):\n …Run Code Online (Sandbox Code Playgroud) 我需要帮助理解https://packagist.org/packages/orhanerday/open-ai上的模糊说明
我从https://github.com/orhanerday/open-ai下载了软件包
我通过在命令提示符中运行“composer require orhanerday/open-ai”来安装该软件包
指示从那里开始就没有意义了......
“use Orhanerday\OpenAi\OpenAi;” 是什么意思?代码的含义及其应用在哪里?我是否要创建一个 php 文件,例如 index.php,其内容为:
<?php
use Orhanerday\OpenAi\OpenAi;
$complete = $open_ai->complete([
'engine' => 'davinci',
'prompt' => 'Hello',
'temperature' => 0.9,
'max_tokens' => 150,
'frequency_penalty' => 0,
'presence_penalty' => 0.6,
]
?>
Run Code Online (Sandbox Code Playgroud)
如何以及在哪里添加我的 api 密钥?我是否要创建一个文件 Orhanerday\OpenAi\OpenAi.php 并在其中输入我的 api 密钥?IEOPENAI_API_KEY=sk-**********************************************
我使用 OpenAI 的Whisper python 库进行语音识别。我如何给出一些提示短语,就像使用其他 ASR(例如Google)可以完成的那样?
使用 OpenAI 的Whisper进行转录(在 Ubuntu 20.04 x64 LTS 上使用 Nvidia GeForce RTX 3090 进行测试):
conda create -y --name whisperpy39 python==3.9
conda activate whisperpy39
pip install git+https://github.com/openai/whisper.git
sudo apt update && sudo apt install ffmpeg
whisper recording.wav
whisper recording.wav --model large
Run Code Online (Sandbox Code Playgroud)
如果使用 Nvidia GeForce RTX 3090,请在后面添加以下内容conda activate whisperpy39:
pip install -f https://download.pytorch.org/whl/torch_stable.html
conda install pytorch==1.10.1 torchvision torchaudio cudatoolkit=11.0 -c pytorch
Run Code Online (Sandbox Code Playgroud) python speech-recognition openai-api openai-whisper hint-phrases
这是我的功能
async function generateImage() {
try {
const response = await openai.createImage({
prompt: 'a white siamese cat',
n: 1,
size: '1024x1024',
});
console.log(response);
} catch (error) {
console.error(error);
}
}
Run Code Online (Sandbox Code Playgroud)
我在移动设备上使用时收到此错误:错误:URL.search 未实现
我真的陷入了困境,所以非常感谢任何帮助
我正在构建一个使用OpenAI API的应用程序
他们为我提供了一个 API 令牌,我用它来从我的 Android 移动应用程序(反应本机)进行 API 调用
我知道在移动客户端上存储此 API 令牌是一种不好的做法,因为攻击者可能会保留它并使用我的配额和资金。
我有什么选择?简单的解决方案是构建一个后端,但我不想开始实现所有原始 API 方法,我只是更喜欢直接从客户端使用它。
我尝试以无法找到的方式存储令牌,但找不到方法。
有没有办法训练大型语言模型(LLM)来存储特定的上下文?例如,我有一个很长的故事,我想提出问题,但我不想把整个故事放在每个提示中。如何才能让LLM“记住这个故事”?
我的 MERN 堆栈代码文件中有这个,并且运行良好。
exports.chatbot = async (req, res) => {
console.log("OpenAI Chatbot Post");
const { textInput } = req.body;
try {
const response = await openai.createCompletion({
model: "text-davinci-003",
prompt: `
What is your name?
My name is Chatbot.
How old are you?
I am 900 years old.
${textInput}`,
max_tokens: 100,
temperature: 0,
});
if (response.data) {
if (response.data.choices[0].text) {
return res.status(200).json(response.data.choices[0].text);
}
}
} catch (err) {
return res.status(404).json({ message: err.message });
}
};
Run Code Online (Sandbox Code Playgroud)
当我更改API请求时,使用新的API来完成聊天,这个不起作用(API代码来自openAI网站,并且适用于postman)
exports.chatbot = async (req, res) …Run Code Online (Sandbox Code Playgroud) 尝试调用刚刚为 ChatGPT 发布的 got-3.5-turbo API,但我收到了错误的请求错误?
var body = new
{
model = "gpt-3.5-turbo",
messages = data
};
string jsonMessage = JsonConvert.SerializeObject(body);
using (HttpClient client = new HttpClient())
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
HttpRequestMessage requestMessage = new
HttpRequestMessage(HttpMethod.Post, "https://api.openai.com/v1/completions")
{
Content = new StringContent(jsonMessage, Encoding.UTF8, "application/json")
};
string api_key = PageExtension_CurrentUser.Community.CAIChatGPTAPIKey.Length > 30 ? PageExtension_CurrentUser.Community.CAIChatGPTAPIKey : Genesis.Generic.ReadAppSettingsValue("chatGPTAPIKey");
requestMessage.Headers.Add("Authorization", $"Bearer {api_key}");
HttpResponseMessage response = client.SendAsync(requestMessage).Result;
if (response.StatusCode == HttpStatusCode.OK)
{
string responseData = response.Content.ReadAsStringAsync().Result;
dynamic responseObj = JsonConvert.DeserializeObject(responseData);
string choices = responseObj.choices[0].text;
} …Run Code Online (Sandbox Code Playgroud) openai-api ×10
python ×3
chatgpt-api ×2
react-native ×2
android ×1
api ×1
axios ×1
gpt-2 ×1
gpt-3 ×1
hint-phrases ×1
langchain ×1
nlp ×1
php ×1
post ×1
security ×1
typescript ×1