-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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/messages api #546
Feat/messages api #546
Conversation
94c712d
to
6084633
Compare
Codecov Report
@@ Coverage Diff @@
## master #546 +/- ##
==========================================
+ Coverage 98.22% 98.31% +0.09%
==========================================
Files 22 23 +1
Lines 1181 1247 +66
==========================================
+ Hits 1160 1226 +66
Misses 15 15
Partials 6 6
|
6084633
to
290e8fd
Compare
- go map access is not deterministic - this can lead to a route: /foo/bar/1 matching /foo/bar before matching /foo/bar/1 if the map iteration go through /foo/bar first since the regex match wasn't bound to start and end anchors - registering handlers now converts * in routes to .* for proper regex matching - test server route handling now tries to fully match the handler route
290e8fd
to
46f7798
Compare
Hi, to cover your tests you need to add entries in |
messages.go
Outdated
|
||
type MessageContent struct { | ||
Type string `json:"type"` | ||
Text MessageText `json:"text"` |
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.
Text MessageText `json:"text"` | |
Text *MessageText `json:"text,omitempty"` | |
ImageFile *ImageFile `json:"image_file,omitempty"` // <- define this one |
May I ask when the message API would be ready? |
Thanks, I'll work on the fixes this weekend.
…On Fri, Nov 10, 2023, 9:40 AM Ti Wang ***@***.***> wrote:
May I ask when the message API would be ready?
—
Reply to this email directly, view it on GitHub
<#546 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAJLOR344QSLRTGXNR2EFS3YDZDHTAVCNFSM6AAAAAA7BZOV7OVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMBVHE3DANRUGQ>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Adding the test cases... However, when looking at these tests - It makes sense to push for a high coverage but some of the work done to keep it high seems forced. For example, covering the branch when the API returns an error. I'd suggest rethinking the requirement a little bit - it makes sense to cover the main logic but this test seem to add very little or no value - https://github.com/sashabaranov/go-openai/blob/master/client_test.go#L184 - am I missing something in the value of this test? It doesn't actually test that the request building failed due to bad/missing params, only that an |
Co-authored-by: Simone Vellei <[email protected]>
Co-authored-by: Simone Vellei <[email protected]>
messages.go
Outdated
} | ||
type MessageText struct { | ||
Value string `json:"value"` | ||
Annotations []interface{} `json:"annotations"` |
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.
let's use any
instead of interface{}
messages.go
Outdated
encodedValues = "?" + urlValues.Encode() | ||
} | ||
|
||
urlSuffix := fmt.Sprintf("/threads/%s%s%s", threadID, messagesSuffix, encodedValues) |
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.
Just a suggestion: changing messagesSuffix
from /messages
to messages
would make formatting more consistent without %s%s
mixed with %s/%s
@urjitbhatia thank you so much for the PR! A couple of minor additions and let's merge it 🙌🏻
You know, when I started working on this library a couple of years earlier, I would agree with you. I didn't see any point in extensive testing except for integration tests with the actual API to check that the client actually works. Now, I have come to realise a couple of things about testing:
I think the requirement of copy-pasting 3 lines of tests per client method is a reasonable requirement for all these benefits. So the way forward is to actually reach 100% coverage, add more randomisation(see #491), fuzzing, and integration tests in CI.
Currently, the validation happens on the OpenAI backend side. I'll be happy to accept any client validation, though 👍🏻 |
@sashabaranov added the style fixes from the last review :) |
HI @sashabaranov @urjitbhatia any updates by when this PR will be merged. |
// CreateMessage creates a new message. | ||
func (c *Client) CreateMessage(ctx context.Context, threadID string, request MessageRequest) (msg Message, err error) { | ||
urlSuffix := fmt.Sprintf("/threads/%s/%s", threadID, messagesSuffix) | ||
req, err := c.newRequest(ctx, http.MethodPost, c.fullURL(urlSuffix), withBody(request)) |
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.
Any reason for not adding withBetaAssistantV1()
here ? When using CreateMessage I still get the error You must provide the 'OpenAI-Beta' header to access the Assistants API. Please try again by setting the header 'OpenAI-Beta: assistants=v1'.
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.
* fix test server setup: - go map access is not deterministic - this can lead to a route: /foo/bar/1 matching /foo/bar before matching /foo/bar/1 if the map iteration go through /foo/bar first since the regex match wasn't bound to start and end anchors - registering handlers now converts * in routes to .* for proper regex matching - test server route handling now tries to fully match the handler route * add missing /v1 prefix to fine-tuning job cancel test server handler * add create message call * add messages list call * add get message call * add modify message call, fix return types for other message calls * add message file retrieve call * add list message files call * code style fixes * add test for list messages with pagination options * add beta header to msg calls now that sashabaranov#545 is merged * Update messages.go Co-authored-by: Simone Vellei <[email protected]> * Update messages.go Co-authored-by: Simone Vellei <[email protected]> * add missing object details for message, fix tests * fix merge formatting * minor style fixes --------- Co-authored-by: Simone Vellei <[email protected]>
This branch implements thread messages API
Sibling to the threads api implementation #536