diff --git a/.gitignore b/.gitignore index 3e57a39..ef79b3a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ test-results/ **.log -**/report.html \ No newline at end of file +**/report.html +docker-compose \ No newline at end of file diff --git a/app-backend/templates/tools/supervisor_agent_tools.yaml b/app-backend/templates/tools/supervisor_agent_tools.yaml deleted file mode 100644 index 30d76f0..0000000 --- a/app-backend/templates/tools/supervisor_agent_tools.yaml +++ /dev/null @@ -1,20 +0,0 @@ - # Copyright (C) 2024 Intel Corporation - # SPDX-License-Identifier: Apache-2.0 - - search_knowledge_base: - description: Search a knowledge base for a given query. Returns text related to the query. - callable_api: tools.py:search_knowledge_base - args_schema: - query: - type: str - description: query - return_output: retrieved_data - - search_sql_database: - description: Search a SQL database with a natural language query. Returns text related to the query. - callable_api: tools.py:search_sql_database - args_schema: - query: - type: str - description: natural language query - return_output: retrieved_data \ No newline at end of file diff --git a/app-backend/templates/tools/tools.py b/app-backend/templates/tools/tools.py deleted file mode 100644 index 6a0b643..0000000 --- a/app-backend/templates/tools/tools.py +++ /dev/null @@ -1,35 +0,0 @@ -# Copyright (C) 2024 Intel Corporation - # SPDX-License-Identifier: Apache-2.0 - -import os -import requests - - -def search_knowledge_base(query: str) -> str: - """Search a knowledge base about music and singers for a given query. - - Returns text related to the query. - """ - url = os.environ.get("WORKER_AGENT_URL") - print(url) - proxies = {"http": ""} - payload = { - "messages": query, - } - response = requests.post(url, json=payload, proxies=proxies) - return response.json()["text"] - - -def search_sql_database(query: str) -> str: - """Search a SQL database on artists and their music with a natural language query. - - Returns text related to the query. - """ - url = os.environ.get("SQL_AGENT_URL") - print(url) - proxies = {"http": ""} - payload = { - "messages": query, - } - response = requests.post(url, json=payload, proxies=proxies) - return response.json()["text"] \ No newline at end of file diff --git a/app-backend/templates/tools/worker_agent_tools.py b/app-backend/templates/tools/worker_agent_tools.py deleted file mode 100644 index 43c5647..0000000 --- a/app-backend/templates/tools/worker_agent_tools.py +++ /dev/null @@ -1,40 +0,0 @@ -# Copyright (C) 2024 Intel Corporation - # SPDX-License-Identifier: Apache-2.0 - -import os -import requests - -def search_knowledge_base(query: str) -> str: - """Search the knowledge base for a specific query.""" - url = os.environ.get("RETRIEVAL_TOOL_URL") - print(url) - proxies = {"http": ""} - payload = { - "text": query, - } - response = requests.post(url, json=payload, proxies=proxies) - print(response) - if "documents" in response.json(): - docs = response.json()["documents"] - context = "" - for i, doc in enumerate(docs): - if i == 0: - context = doc - else: - context += "\n" + doc - # print(context) - return context - elif "text" in response.json(): - return response.json()["text"] - elif "reranked_docs" in response.json(): - docs = response.json()["reranked_docs"] - context = "" - for i, doc in enumerate(docs): - if i == 0: - context = doc["text"] - else: - context += "\n" + doc["text"] - # print(context) - return context - else: - return "Error parsing response from the knowledge base." \ No newline at end of file diff --git a/app-backend/templates/tools/worker_agent_tools.yaml b/app-backend/templates/tools/worker_agent_tools.yaml deleted file mode 100644 index 1a0975e..0000000 --- a/app-backend/templates/tools/worker_agent_tools.yaml +++ /dev/null @@ -1,11 +0,0 @@ -# Copyright (C) 2024 Intel Corporation -# SPDX-License-Identifier: Apache-2.0 - -search_knowledge_base: - description: Search knowledge base for a given query. Returns text related to the query. - callable_api: worker_agent_tools.py:search_knowledge_base - args_schema: - query: - type: str - description: query - return_output: retrieved_data \ No newline at end of file diff --git a/app-frontend/react/src/components/Conversation/Conversation.tsx b/app-frontend/react/src/components/Conversation/Conversation.tsx index 6ee4499..716cb30 100644 --- a/app-frontend/react/src/components/Conversation/Conversation.tsx +++ b/app-frontend/react/src/components/Conversation/Conversation.tsx @@ -41,6 +41,7 @@ const Conversation = ({ title, enabledUiFeatures }: ConversationProps) => { const [startTime, setStartTime] = useState(null); const [isAssistantTyping, setIsAssistantTyping] = useState(false); const [showInferenceParams, setShowInferenceParams] = useState(true); + // const [isInThinkMode, setIsInThinkMode] = useState(false); const toSend = "Enter"; @@ -74,6 +75,7 @@ const Conversation = ({ title, enabledUiFeatures }: ConversationProps) => { maxTokens: tokenLimit, temperature: temperature, model: "Intel/neural-chat-7b-v3-3", + // setIsInThinkMode }); setPrompt(""); setStartTime(Date.now()); @@ -89,24 +91,38 @@ const Conversation = ({ title, enabledUiFeatures }: ConversationProps) => { let tokenLength: number; if (isAgent) { const currentSteps = getCurrentAgentSteps(); - const allContent = currentSteps.flatMap(step => step.content).join(" "); - tokenLength = allContent.split(" ").length; + const stepsContent = currentSteps.flatMap(step => step.content).join(" "); + const stepsSource = currentSteps.flatMap(step => step.source).join(" "); + const allContent = [stepsContent, stepsSource, onGoingResult].filter(str => str.trim()).join(" "); + let prevTokenLen = messageTokenData[`${selectedConversationId}-${currentMessageIndex}`]?.tokens || 0; + tokenLength = allContent.split(/\s+/).filter(token => token.length > 0).length + prevTokenLen; + + console.log("Agent Token Calc:", { + stepsContent, + stepsSource, + onGoingResult, + tokenLength + }); } else { - tokenLength = onGoingResult.split(" ").length; + tokenLength = onGoingResult.split(/\s+/).filter(token => token.length > 0).length; } - + const currentTimestamp = Date.now(); const elapsedTime = (currentTimestamp - startTime) / 1000; const tokenRate = elapsedTime > 0 ? tokenLength / elapsedTime : 0; - - setMessageTokenData((prev) => ({ - ...prev, - [`${selectedConversationId}-${currentMessageIndex}`]: { tokens: tokenLength, rate: tokenRate, time: elapsedTime }, - })); - + + setMessageTokenData((prev) => { + const updatedData = { + ...prev, + [`${selectedConversationId}-${currentMessageIndex}`]: { tokens: tokenLength, rate: tokenRate, time: elapsedTime }, + }; + console.log("Updated token data:", updatedData); + return updatedData; + }); + setIsAssistantTyping(false); } - + scrollToBottom(); }, [onGoingResult, startTime, selectedConversation?.Messages, currentMessageIndex, isAgent]); @@ -180,6 +196,7 @@ const Conversation = ({ title, enabledUiFeatures }: ConversationProps) => { tokenCount={message.role === MessageRole.Assistant ? tokens : undefined} tokenRate={message.role === MessageRole.Assistant ? rate : undefined} agentSteps={message.agentSteps || []} + // isInThink={isInThinkMode} /> ); })} @@ -194,6 +211,7 @@ const Conversation = ({ title, enabledUiFeatures }: ConversationProps) => { tokenCount={0} tokenRate={0} agentSteps={getCurrentAgentSteps()} + // isInThink={isInThinkMode} /> )} @@ -207,40 +225,40 @@ const Conversation = ({ title, enabledUiFeatures }: ConversationProps) => { tokenCount={messageTokenData[`${selectedConversationId}-${currentMessageIndex}`]?.tokens} tokenRate={messageTokenData[`${selectedConversationId}-${currentMessageIndex}`]?.rate} agentSteps={getCurrentAgentSteps()} + // isInThink={isInThinkMode} /> )}
- - - - Inference Settings - Token Limit: {tokenLimit} - - Temperature: {temperature.toFixed(2)} - -