dirk1983 / chatgpt

演示站现在可以免费使用ChatGPT对话和画图了。全网最易部署,响应速度最快的ChatGPT环境。PHP版调用OpenAI接口进行问答和画图,采用Stream流模式通信,一边生成一边输出。前端采用EventSource,支持Markdown格式解析,支持公式显示,代码有着色处理,支持画图。页面UI简洁,支持上下文连续会话。源码只有几个文件,没用任何框架,支持所有PHP版本,全部开源,极易二开。保姆级教程,账号等周边资源,欢迎进群交流,一切全免费。

Home Page:https://mm1.ltd

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Stop output key

oleteacher opened this issue · comments

commented

More of a question but maybe feature request...

Student was using and asked me: how do you stop the output after pressing send?

Sometime the answer is not correct or student wish to stop the output and ask new question.

Good example shown in video below. Sometimes requesting to write PHP is destroyed and not shown correctly. Being able to stop output with key press would be wonderful.

Asking in prompt: "write php code example for text based flat file cms"

Screen.recording.webm

Other times request is perfect:

image

Input for this question greatly appreciated.

commented

Just tried the latest release and still issues with output and need to stop output:
image

In the lasted release just submitted, I have fixed the bug of code display problem. Due to the markdown tags sometimes present and sometimes absent in the data returned by the OpenAI interface, as well as issues with the markdown parsing logic of the showdown component, some code was displayed abnormally. I have handled the known special cases, and if there are still abnormal situations, please provide example questions. Thank you!

commented

@dirk1983 Thank you my friend for your hard work!

Will give the very latest code another run and let you know if I catch any issues.

commented

Seem to have another similar error.

Prompt: error Warning: Invalid argument supplied for foreach() in previous code

Answer:
I apologize for the error in the previous code. The issue is that the data array returned by the Dall-E2 API may contain multiple images, so we need to use a foreach loop to iterate over each image and display it on the page. Here's the corrected code for generate_image.php:\n\n\n<?php\n\n// Set API endpoint and parameters\n$url = 'https://api.openai.com/v1/images/generations';\n$data = array(\n 'model' => 'image-alpha-001',\n 'prompt' => $_POST['prompt'],\n 'num_images' => $_POST['num_images'],\n 'size' => $_POST['size'],\n 'response_format' => 'url'\n);\n\n// Set API key and headers\n$api_key = 'YOUR_API_KEY_HERE';\n$headers = array(\n 'Content-Type: application/json',\n 'Authorization: Bearer ' . $api_key\n);\n\n// Initialize curl session\n$ch = curl_init();\n\n// Set curl options\ncurl_setopt($ch, CURLOPT_URL, $url);\ncurl_setopt($ch, CURLOPT_POST, true);\ncurl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));\ncurl_setopt($ch, CURLOPT_HTTPHEADER, $headers);\ncurl_setopt($ch, CURLOPT_RETURNTRANSFER, true);\n\n// Execute curl session and get response\n$response = curl_exec($ch);\n\n// Handle response data\nif ($response === false) {\n echo 'Curl error: ' . curl_error($ch);\n} else {\n $response_data = json_decode($response, true);\n foreach ($response_data['data'] as $image_data) {\n $image_url = $image_data['url'];\n echo '<img src="' . $image_url . '"><br><br>';\n }\n}\n\n// Close curl session\ncurl_close($ch);\n\n?>\n\n\nThis code should now work correctly and display all the generated images on the page. Again, please make sure to replace YOUR_API_KEY_HERE with your actual API key obtained from the OpenAI website.

commented

Yes, it is worse than before and outputting jumbled code often now.

Please provide a sample question for me, thanks.

commented

@dirk1983 Very sorry, I meant to do that:

replace <input type="text" name="url" id="url" required> with prompt to create image.

image
I do not see anything wrong with this prompt.

commented

It is the prompt that cause me issue, sorry it did not for you.

Is thare anyway to stop the output? Sometimes very long output and you must wait until finished.

Is thare anyway to stop the output? Sometimes very long output and you must wait until finished.

This feature has been implemented in the latest version.

commented

Thank you thank you @dirk1983

We have younger people (kids) using and this feature will be very welcomed:)

I will close this issue for now. If I find more issues will let you know.

commented

I forgot to ask: what key or action stops the output?

Click send button while outputing.

commented

Thank you for the stop method!

Another formatting issue. When the tokens run out and using the continue command resulted in this:

image