基于源码分析,详细解读 Bifrost AI Gateway 的五大核心设计。所有行号引用基于当前 main 分支。
This file contains hidden or 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
| from gevent.wsgi import WSGIServer | |
| from prometheus_client import multiprocess | |
| from prometheus_client import generate_latest, CollectorRegistry, CONTENT_TYPE_LATEST | |
| # Expose metrics. | |
| def app(environ, start_response): | |
| registry = CollectorRegistry() | |
| multiprocess.MultiProcessCollector(registry) | |
| data = generate_latest(registry) | |
| status = '200 OK' |
This file contains hidden or 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
| func (s *server) respond(w http.ResponseWriter, r *http.Request, data interface{}, status int) { | |
| w.WriteHeader(status) | |
| if data != nil { | |
| err := json.NewEncoder(w).Encode(data) | |
| s.logf("json encode %s", err) | |
| } | |
| } | |
| func (s *server) decode(w http.ResponseWriter, r *http.Request, v interface{}) error { | |
| return json.NewDecoder(r.Body).Decode(v) |
This file contains hidden or 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
| package utils | |
| import ( | |
| "reflect" | |
| "unsafe" | |
| ) | |
| func BytesToString(b []byte) string { | |
| return *(*string)(unsafe.Pointer(&b)) | |
| } |
This file contains hidden or 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
| curl -w %{time_connect}:%{time_starttransfer}:%{time_total} -X POST 'http://service-uri' -H 'Content-Type: application/json' --data 'post-data' |
This file contains hidden or 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
| wrk.path = "/rest/ping" | |
| wrk.method = "POST" | |
| wrk.body = "id=7579764573763278289&platformid=ANDROID&version=1.0.0" | |
| wrk.headers["Content-Type"] = "application/x-www-form-urlencoded" | |
| wrk.headers["deviceid"] = "354435052821931" | |
| wrk.headers["Accept"] = "application/json" | |
| logfile = io.open("wrk.log", "w"); | |
| local cnt = 0; |
This file contains hidden or 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
| # coding: utf-8 | |
| from tornado import gen | |
| from tornado import httpclient | |
| from tornado import httputil | |
| from tornado import ioloop | |
| from tornado import websocket | |
| import json |
This file contains hidden or 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
| # coding: utf-8 | |
| from __future__ import print_function | |
| import re | |
| import sys | |
| filter = re.compile(r'site-packages/requests/.*') | |
| def tracer(frame, event, args): |
This file contains hidden or 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
| # coding: utf-8 | |
| import argparse | |
| from gevent import monkey | |
| monkey.patch_socket() | |
| import logging | |
| logging.basicConfig(level=logging.DEBUG) |
This file contains hidden or 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
| # coding:utf-8 | |
| class RC4: | |
| def __init__(self,public_key = None): | |
| if not public_key: | |
| public_key = 'none_public_key' | |
| self.public_key = public_key | |
| self.index_i = 0; | |
| self.index_j = 0; |
NewerOlder