Skip to content
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

Added build method #22

Merged
merged 1 commit into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading