-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: support image generation #19
Conversation
Seems you are using me but didn't get OPENAI_API_KEY seted in Variables/Secrets for this repo. you could follow readme for more information |
970d0b3
to
59603f4
Compare
@@ -48,6 +48,7 @@ make chatgpt-example | |||
- [x] Completion API (是主要的 gpt-3 API) | |||
- [x] 对 Completion API 的流式支持 | |||
- [x] 文档搜索 API | |||
- [x] 图片生成 API | |||
- [x] 替换默认 url、用户代理、超时和其他选项 | |||
|
|||
## 贡献者 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the code review:
- It seems that you have added a new feature to the code, which is a picture generating API. This should be tested to ensure it works as expected.
- The documentation should describe how to use the picture generating API, and provide examples to demonstrate its usage.
- You should also consider adding error handling code to catch any unexpected issues while using the API.
@@ -52,6 +52,7 @@ Check out the go docs for more detailed documentation on the types and methods p | |||
- [x] Completion API (this is the main gpt-3 API) | |||
- [x] Streaming support for the Completion API | |||
- [x] Document Search API | |||
- [x] Image generation API | |||
- [x] Overriding default url, user-agent, timeout, and other options | |||
|
|||
## Contributor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with code review:
-
Code format: The code is correctly indented, making it easier to read and understand.
-
Code consistency: All lines of code are consistent in terms of style and formatting.
-
Readability: The code is written in a way that makes it easy to read and understand.
-
Comments: The code is commented, making it easier to understand the purpose of each line.
-
Error handling: The code does not contain any error handling, which could lead to unexpected errors.
-
Security: The code does not contain any security measures, which could lead to vulnerabilities.
-
Performance: The code does not contain any performance optimization, which could lead to slow execution time.
-
Optimization: The code does not contain any optimization, which could lead to inefficient usage of resources.
@@ -48,6 +48,7 @@ make chatgpt-example | |||
- [x] Completion API (是主要的 gpt-3 API) | |||
- [x] 对 Completion API 的流式支持 | |||
- [x] 文档搜索 API | |||
- [x] 图片生成 API | |||
- [x] 替换默认 url、用户代理、超时和其他选项 | |||
|
|||
## 贡献者 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这段代码补丁增加了一个名为“图片生成 API”的功能。目前没有发现任何潜在风险或需要改进的地方。
该项目还实现了以下功能:
- 完成 API
- 对完成 API 的流式支持
- 文档搜索 API
- 替换默认 URL、用户代理、超时和其他选项
在贡献者方面,信息不足,无法评估贡献者对项目的影响。
} | ||
return &output, nil | ||
} | ||
|
||
func (c *client) performRequest(req *http.Request) (*http.Response, error) { | ||
rsp, err := c.httpClient.Do(req) | ||
if err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the Code Review:
It looks like this code implements a method that creates an image. The code appears to be syntactically correct, however, there are a few areas that could use improvement.
-
Firstly, it would be beneficial to add error handling throughout the code. This includes validating the inputs from the ImageRequest struct and handling any potential errors that occur during the request.
-
Secondly, it would be beneficial to add logging to the code in order to track any errors that do occur. This will help with debugging and troubleshooting any potential issues that arise.
-
Finally, it would be beneficial to add unit tests for this code. This will ensure that the code is functioning as expected and that any changes or updates do not cause unexpected behavior.
@@ -52,6 +52,7 @@ Check out the go docs for more detailed documentation on the types and methods p | |||
- [x] Completion API (this is the main gpt-3 API) | |||
- [x] Streaming support for the Completion API | |||
- [x] Document Search API | |||
- [x] Image generation API | |||
- [x] Overriding default url, user-agent, timeout, and other options | |||
|
|||
## Contributor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这段代码是一个列表,其中包括了API的完成度、主要使用的API以及一些选项。最近新增了 "Image generation API" 。从这里无法看出任何风险或错误,除非你提供更多的代码内容或上下文。如果你有更多的信息,可以为特定功能添加注释或修改代码以实现更好的性能,例如使用缓存来减少调用次数等。
type ImageResponseDataInner struct { | ||
URL string `json:"url,omitempty"` | ||
B64JSON string `json:"b64_json,omitempty"` | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review:
- The code appears to be valid, however, it is important to ensure that the ImageRequest and ImageResponse structs are properly defined with all necessary fields.
- It is also important to make sure that the response format specified in the ImageRequest struct is supported by the server.
- For security reasons, it might be a good idea to include a field indicating the type of image requested so that only valid image types can be requested.
- An additional validation should be done on the URL field of the ImageResponseDataInner struct to ensure that the requested image is in the correct format.
- Lastly, it would be a good idea to add logging to track any requests and responses for debugging purposes.
} | ||
return &output, nil | ||
} | ||
|
||
func (c *client) performRequest(req *http.Request) (*http.Response, error) { | ||
rsp, err := c.httpClient.Do(req) | ||
if err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这段代码是一个 Golang 代码片段,看起来它是使用 http.Client 发送请求来与某个 API 进行通信。这里的更改主要是添加了关于创建图像的新函数 Image,执行 新请求时会调用 newRequest,并在响应中返回 ImageResponse 对象。
从上面的更改来看,可能会有一些潜在问题或锅点:
- 调用
httpClient.Do(req)
参考文献不应该被单独转发,因为很容易在超时和连接错误方面出现问题。建议针对客户端调用设置时间限制并添加重试机制。 - 函数
getResponseObject()
必须验证是否正常解析数据;否则可能导致 JSON 注入问题。建议添加其他措施以确保解析的安全性。
同时,以下也是几点改进建议:
- 确保 client 的 HttpClient 字段仅在初始化时进行赋值操作,避免未期望的更改。
- 增加更多的注释,使得入口函数可以理解程序代码的工作方式、输入/输出类型以及其实际用途。
type ImageResponseDataInner struct { | ||
URL string `json:"url,omitempty"` | ||
B64JSON string `json:"b64_json,omitempty"` | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这是一个 Go 语言的代码补丁。根据补丁,增加了三个结构体类型:ImageRequest
、ImageResponse
和 ImageResponseDataInner
。
其中,ImageRequest
结构体用于表示针对图片 API 的请求,包括 Prompt
用于搜索关键字,N
用于限制返回结果数量,Size
用于控制图片大小,ResponseFormat
用于设置响应数据格式,User
则是用户信息。
ImageResponse
结构体对应的是针对图片 API 的响应,其中包括 Created
表示创建时间戳,以及由多个 ImageResponseDataInner
组成的 Data
字段。
最后,ImageResponseDataInner
结构体定义了每个图片 URL 及其 base64 格式的 JSON 数据。
这个代码块看起来没有技术上的 bug 风险,如果要改进的话,可以根据具体业务需求进行扩展和完善。
No description provided.