Documentation IndexFetch the complete documentation index at: /llms.txtUse this file to discover all available pages before exploring further.
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
5 分钟内从零到一个可运行的 LLM 函数调用
pip install SimpleLLMFunc
poetry add SimpleLLMFunc
provider.json
{ "openrouter": [ { "model_name": "openai/gpt-4o", "api_keys": ["sk-your-key"], "base_url": "https://openrouter.ai/api/v1", "max_retries": 3, "retry_delay": 1.0, "rate_limit_capacity": 20, "rate_limit_refill_rate": 3.0 } ] }
import asyncio from pydantic import BaseModel, Field from SimpleLLMFunc import OpenAICompatible, llm_function class Summary(BaseModel): headline: str = Field(description="一句话摘要") key_points: list[str] = Field(description="3-5 个要点") tone: str = Field(description="formal、casual 或 technical") models = OpenAICompatible.load_from_json_file("provider.json") llm = models["openrouter"]["openai/gpt-4o"] @llm_function(llm_interface=llm) async def summarize(text: str) -> Summary: """ 简洁地总结输入文本。 重点关注最有价值的信息。 """ pass async def main(): result = await summarize("SimpleLLMFunc 将每次 LLM 调用视为类型化的 Python 函数...") print(result.headline) print(result.key_points) asyncio.run(main())
from SimpleLLMFunc import APIKeyPool, OpenAICompatible llm = OpenAICompatible( api_key_pool=APIKeyPool( api_keys=["sk-your-key"], provider_id="openai", ), model_name="gpt-4o", base_url="https://api.openai.com/v1", )
此页面对您有帮助吗?