Created
March 22, 2024 19:27
-
-
Save morganhein/0b487c330db3ecaca5abbd6d16899f07 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import gleam/io | |
pub type ClientResponse { | |
ClientResponse(data: String, error_code: Int) | |
} | |
pub type ClientError { | |
ClientError(error: String) | |
} | |
pub type Client { | |
Client( | |
chat: fn(String) -> Result(ClientResponse, ClientError), | |
transcribe: fn(String) -> Result(ClientResponse, ClientError), | |
) | |
} | |
// Create the open api specific client | |
pub fn create_openapi_client(_url: String, _auth_token: String) -> Client { | |
let chat = fn(_data: String) -> Result(ClientResponse, ClientError) { | |
// call the gleam_http library to call open api endpoint with auth token | |
Ok(ClientResponse("data", 200)) | |
} | |
let transcribe = fn(_data: String) -> Result(ClientResponse, ClientError) { | |
// call the gleam_http library to call open api endpoint with auth token | |
Ok(ClientResponse("data", 200)) | |
} | |
// implicit return | |
Client(chat, transcribe) | |
} | |
// Create the bard specific client | |
pub fn create_bard_client(_url: String, _auth_token: String) -> Client { | |
let chat = fn(_data: String) -> Result(ClientResponse, ClientError) { | |
// call the gleam_http library to call bard specific endpoint with auth token | |
Ok(ClientResponse("data", 200)) | |
} | |
let transcribe = fn(_data: String) -> Result(ClientResponse, ClientError) { | |
// call the gleam_http library to call bard specific endpoint with auth token | |
Ok(ClientResponse("data", 200)) | |
} | |
// implicit return | |
Client(chat, transcribe) | |
} | |
pub fn example_usage(client: Client) { | |
// do stuff | |
let result = client.chat("hello") | |
case result { | |
Ok(response) -> io.println("Got response: " <> response.data) | |
Error(error) -> io.println("Error: " <> error.error) | |
} | |
} | |
pub fn start() { | |
let openapi_client = create_openapi_client("https://openai.com", "auth_token") | |
example_usage(openapi_client) | |
let bard_client = create_bard_client("https://bard.com", "auth_token") | |
example_usage(bard_client) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment