Initial commit of Marketing Assistant AI project, including backend setup with FastAPI, brand style management, and marketing copy generation features. Added .gitignore, README, and various data files for brand voice, past campaigns, and book excerpts. Implemented vector store for content retrieval and embeddings using Cohere API. Included HTML template for user interface.

This commit is contained in:
boladeE
2025-04-17 22:24:53 +01:00
commit e80ba5c0d7
18 changed files with 840 additions and 0 deletions
+37
View File
@@ -0,0 +1,37 @@
import cohere
from typing import List
import numpy as np
from config import settings
class CohereEmbeddings:
def __init__(self):
self.settings = settings
self.client = cohere.Client(self.settings.COHERE_API_KEY)
def generate_embedding(self, text: str) -> np.ndarray:
"""Generate embeddings for a single text using Cohere."""
response = self.client.embed(
texts=[text],
model="embed-english-v3.0",
input_type="search_document"
)
return np.array(response.embeddings[0])
def rerank_results(self, query: str, documents: List[str], top_n: int = 5) -> List[str]:
"""Rerank documents based on relevance to the query."""
results = self.client.rerank(
query=query,
documents=documents,
top_n=top_n,
model="rerank-english-v2.0"
)
# Extract the reranked documents in order
reranked_docs = []
for result in results.results:
# Get the document at the index returned by the rerank API
doc_index = result.index
if 0 <= doc_index < len(documents):
reranked_docs.append(documents[doc_index])
return reranked_docs