⚡ Live Interactive Code Sandbox: AI Dev Tool: No Mans Sky Cosmos
▶️ Run Code
💳 Unlock Source Code ($5)
📝 Editable Code Sandbox
```python # AI Dev Tool: Cosmos LLM Edge Function # ====================================== # Import required libraries import json from typing import Dict, List import numpy as np from fastapi import FastAPI, HTTPException from fastapi.responses import JSONResponse from pydantic import BaseModel import torch from transformers import AutoModelForCausalLM, AutoTokenizer # Define the application app = FastAPI() # Define the request model class LLMRequest(BaseModel): """Request model for the LLM edge function""" prompt: str max_length: int = 128 temperature: float = 0.7 # Define the response model class LLMResponse(BaseModel): """Response model for the LLM edge function""" response: str # Load the LLM model and tokenizer model_name = "hugo-v/huggingface-3.8B-llm" model = AutoModelForCausalLM.from_pretrained(model_name) tokenizer = AutoTokenizer.from_pretrained(model_name) # Define the edge function @app.post("/cosmos_llm", response_model=LLMResponse) async def cosmos_llm(request: LLMRequest): """ Cosmos LLM
🖥️ Interactive Execution Terminal Console
⚡ Ready! Click ▶️ Run Code to execute code in browser terminal...