Supabase
提示
這是由社群維護的文件,如果您遇到 bug,請提出 issue https://github.com/BerriAI/litellm
Supabase 是開源的 Firebase 替代方案。 從 Postgres 資料庫、Authentication、即時 API、Edge Functions、Realtime subscriptions、Storage 和 Vector embeddings 開始您的專案。
使用 Supabase 記錄請求,並查看所有 LLM 提供者(OpenAI、Azure、Anthropic、Cohere、Replicate、PaLM)的總支出
liteLLM 提供 success_callbacks 和 failure_callbacks,讓您可以根據回應的狀態,輕鬆將資料傳送到特定提供者。
在這個情況下,我們希望在兩種情境下都將請求記錄到 Supabase——成功與失敗時。
建立 supabase 資料表
前往您的 Supabase 專案 > 前往 Supabase SQL Editor 並依照此設定建立新的資料表。
注意:您可以變更資料表名稱,但不要變更欄位名稱。
create table
public.request_logs (
id bigint generated by default as identity,
created_at timestamp with time zone null default now(),
model text null default ''::text,
messages json null default '{}'::json,
response json null default '{}'::json,
end_user text null default ''::text,
status text null default ''::text,
error json null default '{}'::json,
response_time real null default '0'::real,
total_cost real null,
additional_details json null default '{}'::json,
litellm_call_id text unique,
primary key (id)
) tablespace pg_default;
使用回呼
只要 2 行程式碼,就能立即透過 Supabase 查看成本並記錄您的回應,涵蓋所有提供者:
litellm.success_callback=["supabase"]
litellm.failure_callback=["supabase"]
完整程式碼
from litellm import completion
## set env variables
### SUPABASE
os.environ["SUPABASE_URL"] = "your-supabase-url"
os.environ["SUPABASE_KEY"] = "your-supabase-key"
## LLM API KEY
os.environ["OPENAI_API_KEY"] = ""
# set callbacks
litellm.success_callback=["supabase"]
litellm.failure_callback=["supabase"]
# openai call
response = completion(
model="gpt-3.5-turbo",
messages=[{"role": "user", "content": "Hi 👋 - i'm openai"}],
user="ishaan22" # identify users
)
# bad call, expect this call to fail and get logged
response = completion(
model="chatgpt-test",
messages=[{"role": "user", "content": "Hi 👋 - i'm a bad call to test error logging"}]
)
其他控制項
識別終端使用者
傳入 user 至 litellm.completion,即可將您的 llm 呼叫對應到終端使用者。
response = completion(
model="gpt-3.5-turbo",
messages=[{"role": "user", "content": "Hi 👋 - i'm openai"}],
user="ishaan22" # identify users
)
不同的資料表名稱
如果您修改了資料表名稱,以下是傳入新名稱的方式。
litellm.modify_integration("supabase",{"table_name": "litellm_logs"})
支援與創辦人交流
- 預約示範 👋
- 社群 Discord 💭
- 我們的電子郵件 ✉️ ishaan@berri.ai / krrish@berri.ai