Update index.mdx

This commit is contained in:
Timothy Jaeryang Baek 2024-12-28 13:52:46 -08:00
parent 421e7b679d
commit e9d5e59e55

View File

@ -121,22 +121,38 @@ Lets rewrite a sample function to match the new structure:
#### Before (0.4): #### Before (0.4):
```python ```python
from pydantic import BaseModel
from open_webui.apps.openai import generate_chat_completion from open_webui.apps.openai import generate_chat_completion
class User(BaseModel):
id: str
email: str
name: str
role: str
class Pipe: class Pipe:
def __init__(self): def __init__(self):
pass pass
async def pipe(self, body: dict) -> str: async def pipe(self, body: dict, __user__: dict) -> str:
# Calls OpenAI endpoint # Calls OpenAI endpoint
return await openai.generate_chat_completion(body) user = User(**__user__)
return await openai.generate_chat_completion(body, user)
``` ```
#### After (0.5): #### After (0.5):
```python ```python
from open_webui.main import chat_completion from pydantic import BaseModel
from fastapi import Request from fastapi import Request
from open_webui.main import chat_completion
class User(BaseModel):
id: str
email: str
name: str
role: str
class Pipe: class Pipe:
def __init__(self): def __init__(self):
pass pass
@ -144,10 +160,12 @@ class Pipe:
async def pipe( async def pipe(
self, self,
body: dict, body: dict,
__user__: dict,
__request__: Request, __request__: Request,
) -> str: ) -> str:
# Uses the unified endpoint with updated signature # Uses the unified endpoint with updated signature
return await chat_completion(__request__, body) user = User(**__user__)
return await chat_completion(__request__, body, user)
``` ```
### Important Notes: ### Important Notes: