-
Notifications
You must be signed in to change notification settings - Fork 283
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore:update configuration files && readme
- Loading branch information
Showing
16 changed files
with
206 additions
and
66 deletions.
There are no files selected for viewing
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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
name: Close inactive issues | ||
on: | ||
schedule: | ||
- cron: '0 9 * * *' | ||
|
||
jobs: | ||
close-issues: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
issues: write | ||
pull-requests: write | ||
steps: | ||
- uses: actions/stale@v5 | ||
with: | ||
days-before-issue-stale: 30 | ||
days-before-issue-close: 7 | ||
stale-issue-label: stale | ||
stale-issue-message: This issue is stale because it has been open for 30 days with no activity. | ||
close-issue-message: This issue was closed because it has been inactive for 7 days since being marked as stale. | ||
days-before-pr-stale: -1 | ||
days-before-pr-close: -1 | ||
repo-token: ${{ secrets.GITHUB_TOKEN }} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
|
||
[log] | ||
chat = true | ||
|
||
|
||
[openai] | ||
# 指定具有openai接口风格的服务的转发 | ||
base_url = ["https://api.openai.com", "http://localhost:8080"] | ||
route_prefix = ["/openai", "/localai"] | ||
api_key = ["sk-xxx1", "sk-xxx2", "sk-xxx3"] | ||
forward_key = ["fk-xxx1"] | ||
|
||
|
||
[extra] | ||
# 可指定任意接口服务的转发 | ||
base_url = ["http://localhost:8882", "http://localhost:8881"] | ||
route_prefix = ["/tts", "/translate"] | ||
|
||
|
||
[rate_limit] | ||
# format: route = limit value | ||
'openai/v1/chat/completions' = '100/minute' # nums/second, nums/minute, nums/hour | ||
'localai/v1/chat/completions' = '200/minute' | ||
|
||
|
||
[proxy] | ||
global = "http://localhost:7890" | ||
|
||
|
||
[timezone] | ||
tz = "Asia/Shanghai" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import aiohttp | ||
|
||
timeout = aiohttp.ClientTimeout(total=self.timeout) | ||
session = aiohttp.ClientSession(base_url=self.BASE_URL, timeout=timeout) | ||
url_path = '/v1/chat/completions' | ||
request_url_query = "name=kunyuan" | ||
aio_url = aiohttp.client.URL(f"{url_path}?{request_url_query}") | ||
print(f"{aio_url=}") |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
import time | ||
|
||
import openai | ||
from rich import print | ||
from sparrow import yaml_load | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from openai_forward.helper import retry, toml_load | ||
|
||
|
||
# config = toml_load('aifd.toml') | ||
# print(config) | ||
class TestClass: | ||
def __init__(self): | ||
self.counter = 0 | ||
|
||
@retry(max_retries=5, delay=1, exceptions=(ValueError,)) | ||
def test_method(self): | ||
self.counter += 1 | ||
print(f"Attempt {self.counter}") | ||
|
||
# 为了演示,这里抛出一个ValueError异常 | ||
if self.counter < 4: | ||
raise ValueError("This is a test error") | ||
else: | ||
print("Success on the 4th try!") | ||
|
||
|
||
# 使用示例 | ||
obj = TestClass() | ||
obj.test_method() |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from contextvars import ContextVar | ||
|
||
from fastapi import FastAPI, Request, status | ||
|
||
app = FastAPI() | ||
_request_ctx_var: ContextVar[str] = ContextVar("request_context", default=None) | ||
|
||
|
||
@app.middleware("http") | ||
async def request_context_middleware(request: Request, call_next): | ||
try: | ||
request_ctx = _request_ctx_var.set(request) | ||
response = await call_next(request) | ||
_request_ctx_var.reset(request_ctx) | ||
return response | ||
except Exception as e: | ||
raise e | ||
|
||
|
||
def dynamic_rate_limit(key: str): | ||
request: Request = _request_ctx_var.get() | ||
print(request.headers) | ||
return None |
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
Oops, something went wrong.