Skip to content

Commit 51f94a6

Browse files
author
noona
authored
rev-1: Added some fixes & improvements (#26)
* Added support for Moderations API * gofmt moderation.go * support for edits endpoint & other improvements * fix: Choice redeclared in this block * Added more parameters for the Search endpoint. (#3)
1 parent 1f71638 commit 51f94a6

File tree

3 files changed

+30
-17
lines changed

3 files changed

+30
-17
lines changed

completion.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ type CompletionRequest struct {
2727
User string `json:"user,omitempty"`
2828
}
2929

30-
// Choice represents one of possible completions
31-
type Choice struct {
30+
// CompletionChoice represents one of possible completions
31+
type CompletionChoice struct {
3232
Text string `json:"text"`
3333
Index int `json:"index"`
3434
FinishReason string `json:"finish_reason"`
@@ -52,12 +52,12 @@ type CompletionUsage struct {
5252

5353
// CompletionResponse represents a response structure for completion API
5454
type CompletionResponse struct {
55-
ID string `json:"id"`
56-
Object string `json:"object"`
57-
Created uint64 `json:"created"`
58-
Model string `json:"model"`
59-
Choices []Choice `json:"choices"`
60-
Usage CompletionUsage `json:"usage"`
55+
ID string `json:"id"`
56+
Object string `json:"object"`
57+
Created uint64 `json:"created"`
58+
Model string `json:"model"`
59+
Choices []CompletionChoice `json:"choices"`
60+
Usage CompletionUsage `json:"usage"`
6161
}
6262

6363
// CreateCompletion — API call to create a completion. This is the main endpoint of the API. Returns new text as well as, if requested, the probabilities over each alternative token at each position.

edits.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,18 @@ type EditsUsage struct {
2424
TotalTokens int `json:"total_tokens"`
2525
}
2626

27-
// Choice represents one of possible edits
28-
type Choice struct {
27+
// EditsChoice represents one of possible edits
28+
type EditsChoice struct {
2929
Text string `json:"text"`
3030
Index int `json:"index"`
3131
}
3232

3333
// EditsResponse represents a response structure for Edits API
3434
type EditsResponse struct {
35-
Object string `json:"object"`
36-
Created uint64 `json:"created"`
37-
Usage EditsUsage `json:"usage"`
38-
Choices []Choice `json:"choices"`
35+
Object string `json:"object"`
36+
Created uint64 `json:"created"`
37+
Usage EditsUsage `json:"usage"`
38+
Choices []EditsChoice `json:"choices"`
3939
}
4040

4141
// Perform an API call to the Edits endpoint.

search.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,34 @@ import (
88
"net/http"
99
)
1010

11-
// SearchRequest represents a request structure for search API
11+
/*
12+
- SearchRequest represents a request structure for search API.
13+
14+
- Info (*):
15+
- 1*) You should specify either 'documents' or a 'file', but not both.
16+
- 2*) This flag only takes effect when file is set.
17+
*/
1218
type SearchRequest struct {
13-
Documents []string `json:"documents"`
14-
Query string `json:"query"`
19+
Query string `json:"query"`
20+
Documents []string `json:"documents"` // 1*
21+
FileID string `json:"file"` // 1*
22+
MaxRerank int `json:"max_rerank"` // 2*
23+
ReturnMetadata bool `json:"return_metadata"`
24+
User string `json:"user"`
1525
}
1626

1727
// SearchResult represents single result from search API
1828
type SearchResult struct {
1929
Document int `json:"document"`
30+
Object string `json:"object"`
2031
Score float32 `json:"score"`
32+
Metadata string `json:"metadata"` // 2*
2133
}
2234

2335
// SearchResponse represents a response structure for search API
2436
type SearchResponse struct {
2537
SearchResults []SearchResult `json:"data"`
38+
Object string `json:"object"`
2639
}
2740

2841
// Search — perform a semantic search api call over a list of documents.

0 commit comments

Comments
 (0)