Noizu.Github (Noizu Labs: Github API v0.5.0)
Noizu.Github is a library providing a simple wrapper around Github's API calls. It handles various API features such as completions, chat, edit, image generation, image editing, image variation, embeddings, audio transcription, audio translation, file management, and content moderation.
configuration
Configuration
To configure the library, you need to set the Github API key and optionally, the Github organization in your application's configuration:
config :noizu_github,
github_api_key: "your_api_key_here",
Link to this section Summary
Link to this section Types
error_tuple()
@type error_tuple() :: {:error, details :: term()}
stream_option()
@type stream_option() :: boolean()
stream_options()
Link to this section Functions
api_call(type, url, body, model, options \\ nil)
A helper function to make API calls to the Github API. This function handles both non-stream and stream API calls.
parameters
Parameters
- type: The HTTP request method (e.g., :get, :post, :put, :patch, :delete)
- url: The full URL for the API endpoint
- body: The request body in map format
- model: The model to be used for the response processing
- options
- stream: A boolean value to indicate whether the request should be processed as a stream or not (default: false)
- raw: return raw response
- response_log_callback: function(finch) callback for request log.
- response_log_callback: function(finch, start_ms) callback for response log.
returns
Returns
Returns a tuple {:ok, response} on successful API call, where response is the decoded JSON response in map format. Returns {:error, term} on failure, where term contains error details.
example
Example
url = "https://api.github.com/v1/completions"
body = %{
prompt: "Once upon a time",
model: "text-davinci-003",
max_tokens: 50,
temperature: 0.7
}
{:ok, response} = Noizu.Github.api_call(:post, url, body, Noizu.Github.Completion, stream: false)
extract_links(headers)
generic_stream_provider(callback)
get_field(field, options, default \\ nil)
github_base()
headers(options)
paginate(fetcher, options \\ [])
@spec paginate( (keyword() -> {:ok, term()} | {:error, term()}), keyword() ) :: {:ok, list()} | {:error, term()}
Eagerly fetch all pages of a paginated endpoint, accumulating :items.
Takes a function that accepts an options keyword list and returns
{:ok, result} where result has :items and :links fields (any
Collection.* or Raw result), plus the initial options.
Follows links[:next] by incrementing the :page option until no next
link is present. Returns {:ok, all_items} or the first {:error, _}.
example
Example
{:ok, all} = Noizu.Github.paginate(
&Noizu.Github.Api.Issues.list_for_repo/1,
state: "open", per_page: 100
)
put_field(body, field, options, default \\ nil)
repo_name(options)
repo_owner(options)
stream_pages(fetcher, options \\ [])
@spec stream_pages( (keyword() -> {:ok, term()} | {:error, term()}), keyword() ) :: Enumerable.t()
Return a lazy Stream that yields one {:ok, result} per page.
Each element is the full page result (with :items, :links, etc.).
The stream terminates when there is no :next link or when the fetcher
returns an error (the error tuple is yielded as the final element).
example
Example
Noizu.Github.stream_pages(
&Noizu.Github.Api.Issues.list_for_repo/1,
state: "open", per_page: 100
)
|> Enum.flat_map(fn
{:ok, %{items: items}} -> items
{:error, _} -> []
end)