Team Ai
Datasetpublic

Brunobkr/llama.cpp_AlgMor24_github

ΩFFFΣLLIa • llama.cpp • AlgMor24 ██████╗ ███████╗███████╗███████╗██╗ ██╗ ██╗ █████╗ ██╔═══██╗██╔════╝██╔════╝██╔════╝██║ ██║ ██║██╔══██╗ ██║ ██║█████╗ █████╗ █████╗ ██║ ██║ ██║███████║ ██║ ██║██╔══╝ ██╔══╝ ██╔══╝ ██║ ██║ ██║██╔══██║ ╚██████╔╝██║ ██║ ███████╗███████╗███████╗██║██║ ██║ ╚═════╝ ╚═╝ ╚═╝ ╚══════╝╚══════╝╚══════╝╚═╝╚═╝ ╚═╝ High-Performance LLM / VLM Inference & Autonomous Agentic Ecosystem… See the full description on the dataset page: https://huggingface.co/datasets/Brunobkr/llama.cpp_AlgMor24_github.

sourceHugging Faceupdated 2mo agoView on Hugging Face
0likes3.1kdownloads
README.md417 linesDownload Raw Back to router
1# router2 3[![NPM Version][npm-image]][npm-url]4[![NPM Downloads][downloads-image]][downloads-url]5[![Node.js Version][node-version-image]][node-version-url]6[![Build Status][ci-image]][ci-url]7[![Test Coverage][coveralls-image]][coveralls-url]8 9Simple middleware-style router10 11## Installation12 13This is a [Node.js](https://nodejs.org/en/) module available through the14[npm registry](https://www.npmjs.com/). Installation is done using the15[`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally):16 17```bash18$ npm install router19```20 21## API22 23```js24var finalhandler = require('finalhandler')25var http = require('http')26var Router = require('router')27 28var router = Router()29router.get('/', function (req, res) {30  res.setHeader('Content-Type', 'text/plain; charset=utf-8')31  res.end('Hello World!')32})33 34var server = http.createServer(function (req, res) {35  router(req, res, finalhandler(req, res))36})37 38server.listen(3000)39```40 41This module is currently an extracted version from the Express project,42but with the main change being it can be used with a plain `http.createServer`43object or other web frameworks by removing Express-specific API calls.44 45## Router(options)46 47Options48 49- `strict`        - When `false` trailing slashes are optional (default: `false`)50- `caseSensitive` - When `true` the routing will be case sensitive. (default: `false`)51- `mergeParams`   - When `true` any `req.params` passed to the router will be52  merged into the router's `req.params`. (default: `false`) ([example](#example-using-mergeparams))53 54Returns a function with the signature `router(req, res, callback)` where55`callback([err])` must be provided to handle errors and fall-through from56not handling requests.57 58### router.use([path], ...middleware)59 60Use the given [middleware function](#middleware) for all http methods on the61given `path`, defaulting to the root path.62 63`router` does not automatically see `use` as a handler. As such, it will not64consider it one for handling `OPTIONS` requests.65 66* Note: If a `path` is specified, that `path` is stripped from the start of67  `req.url`.68 69<!-- eslint-disable no-undef -->70 71```js72router.use(function (req, res, next) {73  // do your things74 75  // continue to the next middleware76  // the request will stall if this is not called77  next()78 79  // note: you should NOT call `next` if you have begun writing to the response80})81```82 83[Middleware](#middleware) can themselves use `next('router')` at any time to84exit the current router instance completely, invoking the top-level callback.85 86### router\[method](path, ...[middleware], handler)87 88The [http methods](https://github.com/jshttp/methods/blob/master/index.js) provide89the routing functionality in `router`.90 91Method middleware and handlers follow usual [middleware](#middleware) behavior,92except they will only be called when the method and path match the request.93 94<!-- eslint-disable no-undef -->95 96```js97// handle a `GET` request98router.get('/', function (req, res) {99  res.setHeader('Content-Type', 'text/plain; charset=utf-8')100  res.end('Hello World!')101})102```103 104[Middleware](#middleware) given before the handler have one additional trick,105they may invoke `next('route')`. Calling `next('route')` bypasses the remaining106middleware and the handler mounted for this route, passing the request to the107next route suitable for handling this request.108 109Route handlers and middleware can themselves use `next('router')` at any time110to exit the current router instance completely, invoking the top-level callback.111 112### router.param(name, param_middleware)113 114Maps the specified path parameter `name` to a specialized param-capturing middleware.115 116This function positions the middleware in the same stack as `.use`.117 118The function can optionally return a `Promise` object. If a `Promise` object119is returned from the function, the router will attach an `onRejected` callback120using `.then`. If the promise is rejected, `next` will be called with the121rejected value, or an error if the value is falsy.122 123Parameter mapping is used to provide pre-conditions to routes124which use normalized placeholders. For example a _:user_id_ parameter125could automatically load a user's information from the database without126any additional code:127 128<!-- eslint-disable no-undef -->129 130```js131router.param('user_id', function (req, res, next, id) {132  User.find(id, function (err, user) {133    if (err) {134      return next(err)135    } else if (!user) {136      return next(new Error('failed to load user'))137    }138    req.user = user139 140    // continue processing the request141    next()142  })143})144```145 146### router.route(path)147 148Creates an instance of a single `Route` for the given `path`.149(See `Router.Route` below)150 151Routes can be used to handle http `methods` with their own, optional middleware.152 153Using `router.route(path)` is a recommended approach to avoiding duplicate154route naming and thus typo errors.155 156<!-- eslint-disable no-undef, no-unused-vars -->157 158```js159var api = router.route('/api/')160```161 162## Router.Route(path)163 164Represents a single route as an instance that can be used to handle http165`methods` with it's own, optional middleware.166 167### route\[method](handler)168 169These are functions which you can directly call on a route to register a new170`handler` for the `method` on the route.171 172<!-- eslint-disable no-undef -->173 174```js175// handle a `GET` request176var status = router.route('/status')177 178status.get(function (req, res) {179  res.setHeader('Content-Type', 'text/plain; charset=utf-8')180  res.end('All Systems Green!')181})182```183 184### route.all(handler)185 186Adds a handler for all HTTP methods to this route.187 188The handler can behave like middleware and call `next` to continue processing189rather than responding.190 191<!-- eslint-disable no-undef -->192 193```js194router.route('/')195  .all(function (req, res, next) {196    next()197  })198  .all(checkSomething)199  .get(function (req, res) {200    res.setHeader('Content-Type', 'text/plain; charset=utf-8')201    res.end('Hello World!')202  })203```204 205## Middleware206 207Middleware (and method handlers) are functions that follow specific function208parameters and have defined behavior when used with `router`. The most common209format is with three parameters - "req", "res" and "next".210 211- `req`  - This is a [HTTP incoming message](https://nodejs.org/api/http.html#http_http_incomingmessage) instance.212- `res`  - This is a [HTTP server response](https://nodejs.org/api/http.html#http_class_http_serverresponse) instance.213- `next` - Calling this function that tells `router` to proceed to the next matching middleware or method handler. It accepts an error as the first argument.214 215The function can optionally return a `Promise` object. If a `Promise` object216is returned from the function, the router will attach an `onRejected` callback217using `.then`. If the promise is rejected, `next` will be called with the218rejected value, or an error if the value is falsy.219 220Middleware and method handlers can also be defined with four arguments. When221the function has four parameters defined, the first argument is an error and222subsequent arguments remain, becoming - "err", "req", "res", "next". These223functions are "error handling middleware", and can be used for handling224errors that occurred in previous handlers (E.g. from calling `next(err)`).225This is most used when you want to define arbitrary rendering of errors.226 227<!-- eslint-disable no-undef -->228 229```js230router.get('/error_route', function (req, res, next) {231  return next(new Error('Bad Request'))232})233 234router.use(function (err, req, res, next) {235  res.end(err.message) //= > "Bad Request"236})237```238 239Error handling middleware will **only** be invoked when an error was given. As240long as the error is in the pipeline, normal middleware and handlers will be241bypassed - only error handling middleware will be invoked with an error.242 243## Examples244 245```js246// import our modules247var http = require('http')248var Router = require('router')249var finalhandler = require('finalhandler')250var compression = require('compression')251var bodyParser = require('body-parser')252 253// store our message to display254var message = 'Hello World!'255 256// initialize the router & server and add a final callback.257var router = Router()258var server = http.createServer(function onRequest (req, res) {259  router(req, res, finalhandler(req, res))260})261 262// use some middleware and compress all outgoing responses263router.use(compression())264 265// handle `GET` requests to `/message`266router.get('/message', function (req, res) {267  res.statusCode = 200268  res.setHeader('Content-Type', 'text/plain; charset=utf-8')269  res.end(message + '\n')270})271 272// create and mount a new router for our API273var api = Router()274router.use('/api/', api)275 276// add a body parsing middleware to our API277api.use(bodyParser.json())278 279// handle `PATCH` requests to `/api/set-message`280api.patch('/set-message', function (req, res) {281  if (req.body.value) {282    message = req.body.value283 284    res.statusCode = 200285    res.setHeader('Content-Type', 'text/plain; charset=utf-8')286    res.end(message + '\n')287  } else {288    res.statusCode = 400289    res.setHeader('Content-Type', 'text/plain; charset=utf-8')290    res.end('Invalid API Syntax\n')291  }292})293 294// make our http server listen to connections295server.listen(8080)296```297 298You can get the message by running this command in your terminal,299 or navigating to `127.0.0.1:8080` in a web browser.300```bash301curl http://127.0.0.1:8080302```303 304You can set the message by sending it a `PATCH` request via this command:305```bash306curl http://127.0.0.1:8080/api/set-message -X PATCH -H "Content-Type: application/json" -d '{"value":"Cats!"}'307```308 309### Example using mergeParams310 311```js312var http = require('http')313var Router = require('router')314var finalhandler = require('finalhandler')315 316// this example is about the mergeParams option317var opts = { mergeParams: true }318 319// make a router with out special options320var router = Router(opts)321var server = http.createServer(function onRequest (req, res) {322  // set something to be passed into the router323  req.params = { type: 'kitten' }324 325  router(req, res, finalhandler(req, res))326})327 328router.get('/', function (req, res) {329  res.statusCode = 200330  res.setHeader('Content-Type', 'text/plain; charset=utf-8')331 332  // with respond with the the params that were passed in333  res.end(req.params.type + '\n')334})335 336// make another router with our options337var handler = Router(opts)338 339// mount our new router to a route that accepts a param340router.use('/:path', handler)341 342handler.get('/', function (req, res) {343  res.statusCode = 200344  res.setHeader('Content-Type', 'text/plain; charset=utf-8')345 346  // will respond with the param of the router's parent route347  res.end(req.params.path + '\n')348})349 350// make our http server listen to connections351server.listen(8080)352```353 354Now you can get the type, or what path you are requesting:355```bash356curl http://127.0.0.1:8080357> kitten358curl http://127.0.0.1:8080/such_path359> such_path360```361 362### Example of advanced `.route()` usage363 364This example shows how to implement routes where there is a custom365handler to execute when the path matched, but no methods matched.366Without any special handling, this would be treated as just a367generic non-match by `router` (which typically results in a 404),368but with a custom handler, a `405 Method Not Allowed` can be sent.369 370```js371var http = require('http')372var finalhandler = require('finalhandler')373var Router = require('router')374 375// create the router and server376var router = new Router()377var server = http.createServer(function onRequest (req, res) {378  router(req, res, finalhandler(req, res))379})380 381// register a route and add all methods382router.route('/pet/:id')383  .get(function (req, res) {384    // this is GET /pet/:id385    res.setHeader('Content-Type', 'application/json')386    res.end(JSON.stringify({ name: 'tobi' }))387  })388  .delete(function (req, res) {389    // this is DELETE /pet/:id390    res.end()391  })392  .all(function (req, res) {393    // this is called for all other methods not394    // defined above for /pet/:id395    res.statusCode = 405396    res.end()397  })398 399// make our http server listen to connections400server.listen(8080)401```402 403## License404 405[MIT](LICENSE)406 407[ci-image]: https://badgen.net/github/checks/pillarjs/router/master?label=ci408[ci-url]: https://github.com/pillarjs/router/actions/workflows/ci.yml409[npm-image]: https://img.shields.io/npm/v/router.svg410[npm-url]: https://npmjs.org/package/router411[node-version-image]: https://img.shields.io/node/v/router.svg412[node-version-url]: http://nodejs.org/download/413[coveralls-image]: https://img.shields.io/coveralls/pillarjs/router/master.svg414[coveralls-url]: https://coveralls.io/r/pillarjs/router?branch=master415[downloads-image]: https://img.shields.io/npm/dm/router.svg416[downloads-url]: https://npmjs.org/package/router417 
Brunobkr/llama.cpp_AlgMor24_github · Team Ai