Skip to content

Commit

Permalink
Added forced preamble, minimap is active by default, and search now u…
Browse files Browse the repository at this point in the history
…ses v1 endpoints
  • Loading branch information
ClaytonSmith committed Aug 9, 2024
1 parent f0914ed commit a34c024
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 51 deletions.
28 changes: 0 additions & 28 deletions .github/workflows/docker_push_frontend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,6 @@ jobs:
contents: read

steps:
# - name: Checkout repository
# uses: actions/checkout@v4

# - id: 'auth'
# uses: 'google-github-actions/auth@v1'
# with:
# credentials_json: '${{ secrets.GCP_SA_KEY }}'

# - name: Set up Cloud SDK
# uses: google-github-actions/setup-gcloud@v1
# with:
# project_id: ${{ env.GCP_PROJECT_ID }}

# - name: Authenticate Docker to Artifact Registry
# run: gcloud auth configure-docker ${{ vars.REGISTRY }}

# - name: Extract metadata (tags, labels) for Docker
# id: meta
# uses: docker/metadata-action@v3
# with:
# images: ${{ vars.REGISTRY }}/${{ env.IMAGE_NAME }}

# - name: Build and push Docker image
# uses: docker/build-push-action@v2
# with:
# context: ./src/interfaces/coral_web
# tags: ${{ env.IMAGE_NAME }}
# push: true
- name: Login
uses: google-github-actions/setup-gcloud@v0
with:
Expand Down
1 change: 1 addition & 0 deletions src/backend/model_deployments/cohere_platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
Today's date is {time.strftime("%Y-%m-%d")}.
"""


class CohereDeployment(BaseDeployment):
"""Cohere Platform Deployment."""

Expand Down
50 changes: 40 additions & 10 deletions src/backend/tools/minimap.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import datetime
import os
import pandas as pd
from typing import Any, Dict, List
Expand Down Expand Up @@ -70,12 +71,13 @@ class MinimapAPIWrapper(BaseModel):
parse: Any #: :meta private:

base_url: str = os.environ.get("MINIMAP_API_URL", "http://host.docker.internal:8081")
search_endpoint: str = urljoin(base_url, "/api/v0/platform/elastic_search")
search_endpoint: str = urljoin(base_url, "/api/v1/platform/search")
search_content_endpoint: str = urljoin(base_url, "/api/v1/platform/search/results/content")

max_retry: int = 5

# Default values for the parameters
top_k_results: int = 50
top_k_results: int = 15
MAX_QUERY_LENGTH: int = 300
doc_content_chars_max: int = 2000

Expand All @@ -85,35 +87,63 @@ def run(self, query: str) -> str:
Run search queries against the Minimap search PI
Returns a list of documents, each with a title, summary, and id.
"""

try:
# Create teh url params
query_params = {
'query': query,
'map_id': 5541696631538816
}

response = requests.get(self.search_endpoint, params=query_params)


if response.status_code != 200:
return f"Minimap API returned status code {response.status_code}"

response_json = response.json()
search_status = response.json()
search_key = search_status['key']

# Wait 0.25 seconds before checking the status
time.sleep(0.25)
tries = self.max_retry
search_results = None
while True:
response = requests.get(self.search_content_endpoint, params={'search_key': search_key})
if response.status_code == 404:
if tries > 0:
time.sleep(0.5)
continue
else:
raise Exception(f"Error fetching results. The API returned status code {response.status_code}")

if response.status_code != 200:
raise Exception(f"Error fetching results. The API returned status code {response.status_code}")

results = response_json.get("results", [])

search_results = response.json()
break

df = pd.DataFrame(results)
df = pd.DataFrame(search_results['results'])

df['title_hash'] = df['title'].apply(hash_string)

# Rename description to text
df.rename(columns={
'description': 'text',
'id': 'document_id'
}, inplace=True)

# drop duplicates
df = df.drop_duplicates(subset=['title_hash'])
df['search_key'] = search_key

results = df.to_dict(orient='records')

# limit the number of results to top_k_results
results = results[:self.top_k_results]

logging.info(results)

return results

except Exception as ex:
Expand Down Expand Up @@ -158,8 +188,8 @@ def call(self, parameters: dict, **kwargs: Any) -> List[Dict[str, Any]]:
query = parameters.get("query", "")
results = self.client.run(query)

# remap `id` to `document_id`
for result in results:
result["document_id"] = result.pop("id")
logging.info(results)
logging.info(f"Minimap results")


return [dict(result) for result in results]
return results # [dict(result) for result in results]
2 changes: 1 addition & 1 deletion src/interfaces/coral_web/src/cohere-client/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const COHERE_PLATFORM_DEPLOYMENT_DEFAULT_CHAT_MODEL = 'command';
export const SAGEMAKER_DEPLOYMENT_DEFAULT_CHAT_MODEL = 'command-r';

export const DEFAULT_CHAT_TEMPERATURE = 0.3;
export const DEFAULT_CHAT_TOOL = 'Wikipedia';
export const DEFAULT_CHAT_TOOL = 'Minimap';
export const FILE_TOOL_CATEGORY = 'File loader';

export const ERROR_FINISH_REASON_TO_MESSAGE = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,6 @@ const ToolSection = () => {
updateEnabledTools(updatedTools);
};

// // useEffect to enable all tools by default
// React.useEffect(() => {
// if (tools.length > 0 && enabledTools.length === 0) {
// updateEnabledTools(tools);
// }
// }, []);

return (
<section className="relative flex flex-col gap-y-5 px-5">
<ToolsInfoBox />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,17 +104,20 @@ const Content: React.FC<Props> = (props) => {
.flat()
.filter((citation: any) => citation.tool_name === 'Minimap')

console.log('minimapCitations', minimapCitations)

// Extract and deduplicate doc_ids
let minimapCitationsUnique = new Set(minimapCitations.map((c: any) => parseInt(c.fields.document_id, 10)));

const payload = {
ids: Array.from(minimapCitationsUnique),
citationId: generationId,
search_key: parseInt((minimapCitations[0] as { fields: { search_key: string } }).fields.search_key),
}

// Send to parent window
window.top && window.top.postMessage({ type: 'newCitations', payload }, '*')
console.log('newCitations', minimapCitationsUnique, window.top)
console.log('newCitations', payload, window.top)
}
}
}, [streamingMessage])
Expand Down Expand Up @@ -188,11 +191,11 @@ const Messages = forwardRef<HTMLDivElement, MessagesProps>(function MessagesInte
const isConversationEmpty = messages.length === 0;
return (
<div className="flex h-full flex-col gap-y-4 px-4 py-6 md:gap-y-6" ref={ref}>
{/* {startOptionsEnabled && (
{startOptionsEnabled && (
<div className="flex h-full w-full flex-col justify-center p-4">
<StartModes show={isConversationEmpty} onPromptSelected={onPromptSelected} />
</div>
)} */}
)}

<div className="mt-auto flex flex-col gap-y-4 md:gap-y-6">
{messages.map((m, i) => {
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/coral_web/src/components/StartModes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const StartModes: React.FC<Props> = ({ show, className = '', onPromptSele
className={cn('flex flex-col items-center gap-y-6', className)}
>
<Text styleAs="h5" className="text-center">
Ask about news
Ask about anything in the news
</Text>
</Transition>
);
Expand Down
3 changes: 2 additions & 1 deletion src/interfaces/coral_web/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { DehydratedState, QueryClient, dehydrate } from '@tanstack/react-query';
import { GetServerSideProps, NextPage } from 'next';
import { useContext, useEffect } from 'react';

import { CohereClient } from '@/cohere-client';
import { CohereClient, DEFAULT_CHAT_TOOL } from '@/cohere-client';
import Conversation from '@/components/Conversation';
import ConversationListPanel from '@/components/ConversationList/ConversationListPanel';
import { Layout, LayoutSection } from '@/components/Layout';
Expand Down Expand Up @@ -40,6 +40,7 @@ const ChatPage: NextPage<Props> = () => {
if (!deployment && allDeployments) {
const firstAvailableDeployment = allDeployments.find((d) => d.is_available);
if (firstAvailableDeployment) {
setParams({ tools: [{name: DEFAULT_CHAT_TOOL}] });
setParams({ deployment: firstAvailableDeployment.name });
}
}
Expand Down

0 comments on commit a34c024

Please sign in to comment.