Update index.mdx

This commit is contained in:
Timothy Jaeryang Baek 2024-12-28 13:56:27 -08:00
parent e9d5e59e55
commit 385d38b6ce

View File

@ -122,7 +122,7 @@ Lets rewrite a sample function to match the new structure:
#### Before (0.4): #### Before (0.4):
```python ```python
from pydantic import BaseModel from pydantic import BaseModel
from open_webui.apps.openai import generate_chat_completion from open_webui.apps.ollama import generate_chat_completion
class User(BaseModel): class User(BaseModel):
id: str id: str
@ -137,7 +137,8 @@ class Pipe:
async def pipe(self, body: dict, __user__: dict) -> str: async def pipe(self, body: dict, __user__: dict) -> str:
# Calls OpenAI endpoint # Calls OpenAI endpoint
user = User(**__user__) user = User(**__user__)
return await openai.generate_chat_completion(body, user) body["model"] = "llama3.2:latest"
return await ollama.generate_chat_completion(body, user)
``` ```
#### After (0.5): #### After (0.5):
@ -147,12 +148,14 @@ from fastapi import Request
from open_webui.main import chat_completion from open_webui.main import chat_completion
class User(BaseModel): class User(BaseModel):
id: str id: str
email: str email: str
name: str name: str
role: str role: str
class Pipe: class Pipe:
def __init__(self): def __init__(self):
pass pass
@ -160,11 +163,12 @@ class Pipe:
async def pipe( async def pipe(
self, self,
body: dict, body: dict,
__user__: dict, __user__: dict,
__request__: Request, __request__: Request,
) -> str: ) -> str:
# Uses the unified endpoint with updated signature # Uses the unified endpoint with updated signature
user = User(**__user__) user = User(**__user__)
body["model"] = "llama3.2:latest"
return await chat_completion(__request__, body, user) return await chat_completion(__request__, body, user)
``` ```