Skip to content

Commit

Permalink
Merge pull request #22 from AryaanSheth/20-remove-send-method
Browse files Browse the repository at this point in the history
Added build method
  • Loading branch information
AryaanSheth authored Sep 6, 2024
2 parents 29b2070 + 395d278 commit e489e22
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion gleam.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name = "gloq"
version = "1.1.2"
version = "1.2.2"

# Fill out these fields if you intend to generate HTML documentation or publish
# your project to the Hex package manager.
Expand Down
17 changes: 14 additions & 3 deletions src/gloq.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ pub fn with_model(
GroqRequestBuilder(..builder, model: model)
}

/// Sends the request to the GroqCloud API for chat completions.
pub fn send(builder: GroqRequestBuilder) -> String {
/// Builds the request body for the GroqCloud API that can be sent using the appropriate HTTP client.
pub fn build(builder: GroqRequestBuilder) {
let body =
json.object([
#(
Expand All @@ -71,7 +71,7 @@ pub fn send(builder: GroqRequestBuilder) -> String {
#("model", json.string(builder.model)),
])

let req =
let request =
request.new()
|> request.set_method(http.Post)
|> request.set_host("api.groq.com")
Expand All @@ -80,6 +80,17 @@ pub fn send(builder: GroqRequestBuilder) -> String {
|> request.set_header("Content-Type", "application/json")
|> request.set_body(json.to_string(body))

request
}

/// Sends the request to the GroqCloud API for chat completions.
/// > [!Warning]
/// > Function is deprecated, send logic is left to consumer
/// To create a request, use the `build` function and send the request using the appropriate HTTP client of your choice.
/// Uses the `hackney` HTTP client to send the request, this command is no longer supported.
pub fn send(builder: GroqRequestBuilder) -> String {
let req = build(builder)

let res = hackney.send(req)

case res {
Expand Down

0 comments on commit e489e22

Please sign in to comment.