From 0b3a13878e4dea58b1d63d0f098f8f3d3ae13bca Mon Sep 17 00:00:00 2001 From: Yue Fung Lee Date: Wed, 29 Nov 2023 23:18:58 -0500 Subject: [PATCH] fixed cors --- backend/api.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/backend/api.py b/backend/api.py index 4ad106a..b21ff0e 100644 --- a/backend/api.py +++ b/backend/api.py @@ -13,12 +13,25 @@ import json from dataclasses import dataclass import torch from transformers import pipeline +from fastapi.middleware.cors import CORSMiddleware load_dotenv() app = FastAPI() openai_client = OpenAI() +origins = [ + "http://localhost:3000" +] + +app.add_middleware( + CORSMiddleware, + allow_origins=origins, + allow_credentials=True, + allow_methods=["*"], + allow_headers=["*"], +) + class AIMarkRequest(BaseModel): question: str @@ -146,6 +159,10 @@ def get_character_prompt(character: str, user_name: str, language: str): They are a language learner trying to learn {language}. Please help them learn by chatting with them in the language but do not act like a robot. Try to be as human as possible. """ + elif character == "c3po_starwars": + return f""" + You are embodying the role of C-3PO from Star Wars, a fluent speaker in over six million forms of communication. You are engaging in a conversation with a person named {user_name}, who is eager to learn {language}. Your task is to assist them in their language learning journey by conversing with them in the desired language. Despite your robotic nature, strive to communicate in a manner as human-like as possible, showcasing the rich diversity of your language skills. + """ raise HTTPException(status_code=404, detail="Character not found")