Thanks to visit codestin.com
Credit goes to github.com

Skip to content

chhabi-gurzu/test-cerebras-gcloud

Repository files navigation

Cerebras LLM API

A simple FastAPI application that provides a REST API for interacting with Cerebras LLM using LangChain.

Features

  • Single /chat endpoint for sending messages to Cerebras LLM
  • Support for custom models and API keys
  • Health check endpoints
  • Async support for better performance

Installation

  1. Install dependencies:
pip install -r requirements.txt
  1. Set your Cerebras API key (optional if provided in requests):
export CEREBRAS_API_KEY="your-api-key-here"

Usage

Running the Server

python main.py

The server will start on http://localhost:8000

API Endpoints

POST /chat

Send a message to the Cerebras LLM.

Request Body:

{
  "message": "Hello, how are you?",
  "model": "llama-3.1-8b-instruct",
  "api_key": "your-api-key" // optional if set as environment variable
}

Response:

{
  "response": "I'm doing well, thank you for asking!",
  "provider_info": {
    "provider": "cerebras",
    "model": "llama-3.1-8b-instruct",
    "api_key_available": true
  }
}

GET /

Health check endpoint.

GET /health

Detailed health check endpoint.

Interactive API Documentation

Once the server is running, visit:

  • Swagger UI: http://localhost:8000/docs
  • ReDoc: http://localhost:8000/redoc

Example Usage with curl

curl -X POST "http://localhost:8000/chat" \
     -H "Content-Type: application/json" \
     -d '{
       "message": "What is the capital of France?",
       "model": "llama-3.1-8b-instruct"
     }'

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published