SvelteKit

Using the API & Integration

1. REST API - GET

import requests

url = "http://127.0.0.1:8000/predict"
params = {"data": "Hello AlphaLLM"}
headers = {"Authorization": "Bearer mytoken"}  # optional

response = requests.get(url, params=params, headers=headers)
print(response.json())

2. REST API - POST

import requests

url = "http://127.0.0.1:8000/predict"
payload = {"data": "Hello AlphaLLM"}
headers = {"Authorization": "Bearer mytoken"}  # optional

response = requests.post(url, json=payload, headers=headers)
print(response.json())

3. WebSocket API

import asyncio
import websockets

async def send_data():
    url = "ws://127.0.0.1:8000/ws_predict"
    async with websockets.connect(url) as ws:
        await ws.send("Hello AlphaLLM")
        response = await ws.recv()
        print(response)

asyncio.run(send_data())

4. Integrating into Your Python App

def query_alpha_llm(data: str):
    import requests
    url = "http://127.0.0.1:8000/predict"
    payload = {"data": data}
    response = requests.post(url, json=payload)
    return response.json()["response"]

result = query_alpha_llm("How are you?")
print(result)