# Copyright 2026 zhaoxi826 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from fastapi import APIRouter, Request, Depends from pydantic import BaseModel from typing import Literal from pretor.utils.access import TokenData, Accessor from typing import Dict from pretor.core.global_state_machine.model_provider.base_provider import Provider from pretor.utils.ray_hook import ray_actor_hook provider_router = APIRouter(prefix="/api/v1/provider", tags=["provider"]) class ProviderRegister(BaseModel): provider_type: Literal["openai", "gemini", "claude"] provider_title: str provider_url: str provider_apikey: str @provider_router.post("") async def create_provider(provider_register: ProviderRegister, token_data: TokenData = Depends(Accessor.get_current_user)) -> None: global_state_machine = ray_actor_hook("global_state_machine") await global_state_machine.add_provider.remote(provider_type=provider_register.provider_type, provider_title=provider_register.provider_title, provider_url=provider_register.provider_url, provider_apikey=provider_register.provider_apikey, provider_owner=token_data.user_id) @provider_router.get("/list") async def get_provider_list(_: TokenData = Depends(Accessor.get_current_user)) -> Dict[str, Provider]: global_state_machine = ray_actor_hook("global_state_machine") provider_list: Dict[str, Provider] = await global_state_machine.get_provider_list.remote() return {"provider_list": provider_list}