diff --git a/README.md b/README.md index 1b8fb75..a7fad9c 100644 --- a/README.md +++ b/README.md @@ -95,6 +95,7 @@ pip install -r requirements.txt To run the plugin, enter the following command: ```bash +uvicorn main:app --reload python main.py ``` diff --git a/backend/Dockerfile.backend b/backend/Dockerfile.backend index 8af52ab..b1a4486 100644 --- a/backend/Dockerfile.backend +++ b/backend/Dockerfile.backend @@ -2,6 +2,6 @@ FROM python:3.8-slim-buster WORKDIR /app ADD . /app -RUN pip install --no-cache-dir fastapi uvicorn +RUN pip install -r requirements.txt --no-cache-dir EXPOSE 5003 CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "5003"] diff --git a/backend/logo.png b/backend/logo.png old mode 100755 new mode 100644 index 114f752..b20769b Binary files a/backend/logo.png and b/backend/logo.png differ diff --git a/backend/main.py b/backend/main.py index 307d99e..6dfa822 100644 --- a/backend/main.py +++ b/backend/main.py @@ -1,44 +1,56 @@ +import os + +# Importing fastAPI from fastapi import FastAPI, HTTPException from fastapi.responses import FileResponse, JSONResponse from fastapi.middleware.cors import CORSMiddleware -from pydantic import BaseModel -from typing import List import uvicorn -class Todo(BaseModel): - todo: str +# Importing langchain +from langchain import LLMChain +from langchain.chat_models import ChatOpenAI +from langchain.prompts import PromptTemplate, ChatPromptTemplate + +from dotenv import load_dotenv + +load_dotenv() + +apikey = os.getenv("OPENAI_API_KEY") +# use the gpt-3.5-turbo LLM +openai_model = ChatOpenAI(openai_api_key=apikey, model_name = 'gpt-3.5-turbo') + +chat_prompt = ChatPromptTemplate.from_template("tell me a joke about {subject}") +chat_prompt_value = chat_prompt.format_prompt(subject="soccer") + +llm_chain = LLMChain( + prompt = chat_prompt, + llm = openai_model +) app = FastAPI() app.add_middleware( CORSMiddleware, - allow_origins=["https://chat.openai.com"], + allow_origins=["https://chat.openai.com", "http://localhost:8080", "http://localhost:5173"], allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) -_TODOS = {} - @app.get("/") async def read_root(): - return {"message": "Hello!"} - -@app.post("/todos/{username}", response_model=Todo) -async def add_todo(username: str, todo: Todo): - _TODOS.setdefault(username, []).append(todo.todo) - return todo - -@app.get("/todos/{username}", response_model=List[str]) -async def get_todos(username: str): - return _TODOS.get(username, []) - -@app.delete("/todos/{username}") -async def delete_todo(username: str, todo: Todo): - if username in _TODOS and todo.todo in _TODOS[username]: - _TODOS[username].remove(todo.todo) - return JSONResponse(content='OK', status_code=200) - raise HTTPException(status_code=404, detail="Todo not found") + return {"message": "This is the backend for ADM Project!"} + +@app.get("/api") +async def read_api_root(): + return {"message": "Welcome to the ADM Backend!"} + +@app.get("/api/joke") +async def read_(): + # joke question + question = "Tell me a joke" + response = llm_chain.run(question) + return {"message": response} @app.get("/logo.png") async def logo(): diff --git a/backend/requirements.txt b/backend/requirements.txt index c68a0b6..859978b 100644 --- a/backend/requirements.txt +++ b/backend/requirements.txt @@ -1,2 +1,7 @@ quart -quart-cors \ No newline at end of file +quart-cors +langchain +fastapi +uvicorn +openai +python-dotenv \ No newline at end of file diff --git a/frontend/package-lock.json b/frontend/package-lock.json index f75b2d9..8fe3a3d 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -9,7 +9,8 @@ "version": "0.0.1", "dependencies": { "daisyui": "^2.51.6", - "pocketbase": "^0.15.0" + "pocketbase": "^0.15.0", + "zod": "^3.21.4" }, "devDependencies": { "@iconify/json": "^2.2.67", @@ -4697,6 +4698,14 @@ "funding": { "url": "https://github.com/sponsors/sindresorhus" } + }, + "node_modules/zod": { + "version": "3.21.4", + "resolved": "https://registry.npmjs.org/zod/-/zod-3.21.4.tgz", + "integrity": "sha512-m46AKbrzKVzOzs/DZgVnG5H55N1sv1M8qZU3A8RIKbs3mrACDNeIOeilDymVb2HdmP8uwshOCF4uJ8uM9rCqJw==", + "funding": { + "url": "https://github.com/sponsors/colinhacks" + } } } } diff --git a/frontend/package.json b/frontend/package.json index 1e0d6d8..c637e3a 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -39,6 +39,7 @@ "type": "module", "dependencies": { "daisyui": "^2.51.6", - "pocketbase": "^0.15.0" + "pocketbase": "^0.15.0", + "zod": "^3.21.4" } } diff --git a/frontend/src/lib/components/footer.svelte b/frontend/src/lib/components/footer.svelte index 839f06c..dca3119 100644 --- a/frontend/src/lib/components/footer.svelte +++ b/frontend/src/lib/components/footer.svelte @@ -1,8 +1,8 @@ -