|
1 | 1 | from fastapi import APIRouter, UploadFile, File, HTTPException, Request |
2 | 2 | from fastapi.responses import JSONResponse |
3 | 3 | import os |
| 4 | + |
| 5 | +# from config import Config |
4 | 6 | from logger import logger |
5 | 7 | from time import perf_counter |
6 | 8 |
|
7 | 9 | from vector_database.qdrant_vdb import QdrantVDB |
8 | 10 | from rag.ingestion_pipeline import IngestionPipeline |
9 | 11 | from rag.llm.chat_model import ChatModel |
| 12 | +# from rag.llm.cloud_chat_model import CloudLLM |
10 | 13 | from service.rag_service import ( |
11 | 14 | retrieve_similar_docs, |
12 | 15 | prepare_prompt, |
|
26 | 29 |
|
27 | 30 | router = APIRouter() |
28 | 31 |
|
29 | | -llm = ChatModel(model_name="llama3.3:latest") |
| 32 | +# Set vector database |
30 | 33 | qdrant = QdrantVDB() |
31 | 34 |
|
| 35 | +# Set chat model for local llm models |
| 36 | +# Make calls to local models in openwebui hosted by the university |
| 37 | +llm = ChatModel(model_name="llama3.3:latest") |
| 38 | + |
| 39 | +# Alternatively, we can switch to a chat model based on cloud models as well |
| 40 | +# If you want to use other cloud models, please adjust model_name, |
| 41 | +# model_provider, and api key |
| 42 | +# accordingly |
| 43 | + |
| 44 | +# Examples: |
| 45 | +# llm_cloud_anthropic = CloudLLM( |
| 46 | +# model_name="claude-3-sonnet-20240229", |
| 47 | +# model_provider="anthropic", |
| 48 | +# api_key=Config.api_key_anthropic, |
| 49 | +# ) |
| 50 | +# llm_cloud_openai = CloudLLM( |
| 51 | +# model_name="gpt-4-1106-preview", |
| 52 | +# model_provider="openai", |
| 53 | +# api_key=Config.api_key_openai, |
| 54 | +# ) |
| 55 | +# |
| 56 | +# llm_cloud_mistral = CloudLLM( |
| 57 | +# model_name="mistral-medium", |
| 58 | +# model_provider="mistral", |
| 59 | +# api_key=Config.api_key_mistral, |
| 60 | +# ) |
| 61 | + |
| 62 | +# If no parameters are provided, the default cloud model will be openai. |
| 63 | +# If a cloud model is wanted, please remove the comment |
| 64 | +# for package import "CloudLLM" |
| 65 | + |
| 66 | +# Example: |
| 67 | +# llm = CloudLLM() # same as llm_cloud_openai |
| 68 | + |
32 | 69 |
|
33 | 70 | @router.post("/upload") |
34 | 71 | async def upload_file(file: UploadFile = File(...)): |
@@ -130,6 +167,7 @@ async def generate(request: Request): |
130 | 167 |
|
131 | 168 | response = llm.invoke(prompt) |
132 | 169 | logger.info("Response is generated") |
| 170 | + |
133 | 171 | generation_successfully_counter.inc() |
134 | 172 |
|
135 | 173 | return JSONResponse(content={"response": response.content}) |
|
0 commit comments