mirror of
http://88.130.71.182:3000/BlitTech/contexta_be.git
synced 2026-06-12 23:23:21 +00:00
fixed bugs
This commit is contained in:
25
app/database.py
Normal file
25
app/database.py
Normal file
@@ -0,0 +1,25 @@
|
||||
from supabase import create_client, Client
|
||||
from app.config import settings
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
_supabase_client: Client = None
|
||||
|
||||
|
||||
def get_supabase() -> Client:
|
||||
global _supabase_client
|
||||
if _supabase_client is None:
|
||||
_supabase_client = create_client(
|
||||
settings.supabase_url,
|
||||
settings.supabase_service_role_key,
|
||||
)
|
||||
return _supabase_client
|
||||
|
||||
|
||||
def get_supabase_anon() -> Client:
|
||||
"""For user-scoped operations (respects RLS)"""
|
||||
return create_client(
|
||||
settings.supabase_url,
|
||||
settings.supabase_anon_key,
|
||||
)
|
||||
@@ -98,7 +98,7 @@ class ChatbotCreate(BaseModel):
|
||||
name: str = Field(min_length=2, max_length=100)
|
||||
description: Optional[str] = None
|
||||
system_prompt: Optional[str] = None
|
||||
model: str = "accounts/fireworks/models/llama-v3p1-70b-instruct"
|
||||
model: str = "accounts/fireworks/models/kimi-k2-instruct-0905"
|
||||
temperature: float = Field(default=0.7, ge=0.0, le=2.0)
|
||||
max_tokens: int = Field(default=1000, ge=100, le=8000)
|
||||
primary_color: str = "#6366f1"
|
||||
|
||||
@@ -32,11 +32,10 @@ class LLMService:
|
||||
except Exception as e:
|
||||
logger.error(f"LLM error ({provider}/{model}): {e}")
|
||||
# Fallback to a basic model if available
|
||||
if model != "accounts/fireworks/models/llama-v3p1-70b-instruct" and settings.fireworks_api_key:
|
||||
logger.info("Falling back to Fireworks AI")
|
||||
if model != "accounts/fireworks/models/kimi-k2-instruct-0905" and settings.fireworks_api_key:
|
||||
return await self._call_fireworks(
|
||||
messages,
|
||||
"accounts/fireworks/models/llama-v3p1-70b-instruct",
|
||||
"accounts/fireworks/models/kimi-k2-instruct-0905",
|
||||
max_tokens,
|
||||
temperature,
|
||||
)
|
||||
@@ -137,7 +136,7 @@ class LLMService:
|
||||
max_tokens: int,
|
||||
temperature: float,
|
||||
) -> Dict[str, Any]:
|
||||
import google.generativeai as genai
|
||||
import google.genai as genai
|
||||
|
||||
genai.configure(api_key=settings.google_api_key)
|
||||
gemini_model = genai.GenerativeModel(model)
|
||||
|
||||
@@ -103,7 +103,7 @@ class RAGEngine:
|
||||
messages.append({"role": "user", "content": query})
|
||||
|
||||
# Step 5: Generate response
|
||||
model = chatbot_config.get("model", "accounts/fireworks/models/llama-v3p1-70b-instruct")
|
||||
model = chatbot_config.get("model", "accounts/fireworks/models/kimi-k2-instruct-0905")
|
||||
try:
|
||||
result = await self.llm_svc.generate(
|
||||
messages=messages,
|
||||
|
||||
@@ -29,7 +29,6 @@ class VectorStoreService:
|
||||
self.client = get_qdrant_client()
|
||||
|
||||
def create_collection(self, collection_name: str) -> bool:
|
||||
"""Create a new collection for a chatbot"""
|
||||
try:
|
||||
self.client.create_collection(
|
||||
collection_name=collection_name,
|
||||
@@ -38,6 +37,12 @@ class VectorStoreService:
|
||||
distance=Distance.COSINE,
|
||||
),
|
||||
)
|
||||
# Create payload index for filtering/deleting by document_id
|
||||
self.client.create_payload_index(
|
||||
collection_name=collection_name,
|
||||
field_name="document_id",
|
||||
field_schema="keyword",
|
||||
)
|
||||
logger.info(f"Created collection: {collection_name}")
|
||||
return True
|
||||
except Exception as e:
|
||||
@@ -102,12 +107,12 @@ class VectorStoreService:
|
||||
) -> List[Dict[str, Any]]:
|
||||
"""Search for similar vectors"""
|
||||
try:
|
||||
results = self.client.search(
|
||||
results = self.client.query_points(
|
||||
collection_name=collection_name,
|
||||
query_vector=query_vector,
|
||||
query=query_vector,
|
||||
limit=limit,
|
||||
score_threshold=score_threshold,
|
||||
)
|
||||
).points
|
||||
return [
|
||||
{
|
||||
"id": str(r.id),
|
||||
|
||||
Reference in New Issue
Block a user