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

Functions

A helper function to make API calls to the Github API. This function handles both non-stream and stream API calls.

Eagerly fetch all pages of a paginated endpoint, accumulating :items.

Return a lazy Stream that yields one {:ok, result} per page.

Link to this section Types

Link to this type

error_tuple()

@type error_tuple() :: {:error, details :: term()}
Link to this type

stream_option()

@type stream_option() :: boolean()
Link to this type

stream_options()

@type stream_options() :: %{optional(:stream) => boolean()} | Keyword.t() | nil

Link to this section Functions

Link to this function

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)
Link to this function

extract_links(headers)

Link to this function

generic_stream_provider(callback)

Link to this function

get_field(field, options, default \\ nil)

Link to this function

headers(options)

Link to this function

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
)
Link to this function

put_field(body, field, options, default \\ nil)

Link to this function

repo_name(options)

Link to this function

repo_owner(options)

Link to this function

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)