Spaces:
Sleeping
Sleeping
import os | |
from fastapi import FastAPI | |
from fastapi.staticfiles import StaticFiles | |
from fastapi.responses import FileResponse | |
from pydantic import BaseModel | |
import openai | |
#openai.api_key = "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" | |
api_key = os.environ.getattribute("apikey") | |
app = FastAPI() | |
class ChatInput(BaseModel): | |
input: str | |
def chatgpt(input: ChatInput): | |
try: | |
prompt = {"role": "user", "content": input.input} | |
result = openai.ChatCompletion.create(model="gpt-3.5-turbo", messages=[prompt]) | |
output = result.get('choices')[0].get('message').get('content') | |
except Exception as e: | |
output = {"output": str(e)} | |
return {"output": output} | |
app.mount("/", StaticFiles(directory="static", html=True), name="static") | |
def index() -> FileResponse: | |
return FileResponse(path="/app/static/index.html", media_type="text/html") | |